Skip to content

Commit b6c12e3

Browse files
author
Patrick Ingraham
committed
Monochromator grating enums are known to be incorrect, so modify to use integers for the time being. Also modify config to support custom sequences.
1 parent a80ab83 commit b6c12e3

File tree

3 files changed

+124
-15
lines changed

3 files changed

+124
-15
lines changed

python/lsst/ts/externalscripts/auxtel/latiss_take_flats.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ def get_schema(cls):
102102
latiss_grating:
103103
type: string
104104
default: 'empty_1'
105-
sequences:
106-
type: string
105+
sequence:
106+
description: Yaml string with all required data.
107+
anyOf:
108+
- type: string
109+
- type: "null"
110+
default: null
111+
107112
s3instance:
108113
type: string
109114
default: 'cp'
@@ -131,7 +136,12 @@ async def configure(self, config):
131136

132137
self.config = config
133138
self.s3instance = config.s3instance
134-
self.sequence = config.sequences
139+
140+
self.log.debug(f"in config, {self.sequence=}")
141+
142+
if config.sequence is not None:
143+
self.log.debug("Loading custom configuration")
144+
self.sequence = yaml.safe_load(config.sequence)
135145

136146
async def handle_checkpoint(self, checkpoint_active, checkpoint_message):
137147

@@ -162,15 +172,16 @@ def get_flat_sequence(self, latiss_filter: str, latiss_grating: str):
162172
163173
"""
164174
self.log.debug(
165-
f"Running get_flat_sequence with {latiss_filter=} and {latiss_grating=}"
175+
f"Running get_flat_sequence with the default for {latiss_filter=} and {latiss_grating=}"
166176
)
167177

168178
# Check that the LATISS filter/grating combination is valid
169179
if latiss_filter == "SDSSr_65mm" and latiss_grating == "empty_1":
170180
# Returns a dictionary of sequences
171181
step1 = {
172-
"wavelength": 580,
173-
"grating": 1, # enums.ATMonochromator.Grating.RED, --> Enums are wrong!
182+
"wavelength": 580.0,
183+
# enums.ATMonochromator.Grating.RED, --> Enums are wrong!
184+
"grating": 1,
174185
"spec_res": 7,
175186
"exit_slit_width": 4.5,
176187
"entrance_slit_width": 4.5,
@@ -182,7 +193,7 @@ def get_flat_sequence(self, latiss_filter: str, latiss_grating: str):
182193
"em_n_exp": 1,
183194
}
184195
step2 = {
185-
"wavelength": 620,
196+
"wavelength": 620.0,
186197
"grating": 1, # enums.ATMonochromator.Grating.RED,
187198
"spec_res": 8,
188199
"exit_slit_width": 4.5,
@@ -202,6 +213,7 @@ def get_flat_sequence(self, latiss_filter: str, latiss_grating: str):
202213
"do not have an established flat sequence. Exiting."
203214
)
204215

216+
self.log.debug(f"returning sequence of: {sequence}")
205217
return sequence
206218

207219
def get_atmonochromator_setup(self, wavelength: float, spec_res: float):
@@ -234,7 +246,7 @@ def get_atmonochromator_setup(self, wavelength: float, spec_res: float):
234246
async def setup_atmonochromator_axes(
235247
self,
236248
wavelength: float,
237-
grating: str,
249+
grating: int,
238250
entrance_slit_width: float,
239251
exit_slit_width: float,
240252
):
@@ -398,7 +410,9 @@ async def arun(self, checkpoint_active=False, simulation_mode: bool = 0):
398410
await self.setup_electrometer()
399411

400412
# Get sequences for the given setup if not defined explicitly
413+
self.log.debug(f"In arun, and {self.sequence=}")
401414
if self.sequence is None:
415+
self.log.debug("No sequence defined, grabbing default")
402416
self.sequence = self.get_flat_sequence(
403417
self.config.latiss_filter, self.config.latiss_grating
404418
)
@@ -414,8 +428,11 @@ async def arun(self, checkpoint_active=False, simulation_mode: bool = 0):
414428
)
415429

416430
# will be replaced by setup_atmonochromator in the future?
431+
self.log.debug(f"{self.step=}")
417432
self.log.debug(
418-
f'Inputs to monochromator setup are: {self.step["wavelength"]=}, {self.step["grating"]=}, {self.step["exit_slit_width"]=}, {self.step["entrance_slit_width"]}'
433+
f'Inputs to monochromator setup are: {self.step["wavelength"]=},'
434+
f'{self.step["grating"]=}, {self.step["exit_slit_width"]=},'
435+
f'{self.step["entrance_slit_width"]=}'
419436
)
420437
await self.setup_atmonochromator_axes(
421438
self.step["wavelength"],
@@ -433,11 +450,13 @@ async def arun(self, checkpoint_active=False, simulation_mode: bool = 0):
433450
task1 = asyncio.create_task(
434451
self.latiss.take_flats(
435452
self.step["exp_time"],
436-
nflats=1,
453+
n_flats=1,
437454
group_id=self.group_id,
438455
program="AT_flats",
439-
# reason=f"flats_{self.config.latiss_filter}_{self.config.latiss_grating}",
440-
# note=f"sequence_lfa_key={self.s3_key_name}",
456+
reason=(
457+
f"flats_{self.config.latiss_filter}_{self.config.latiss_grating}"
458+
),
459+
note=("atmono charact."),
441460
)
442461
)
443462

tests/auxtel/test_latiss_take_flats.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import random
2727
import unittest
2828
import shutil
29+
import yaml
2930

3031
import pytest
3132
from lsst.ts import externalscripts, standardscripts
3233
from lsst.ts.externalscripts.auxtel import LatissTakeFlats
34+
from lsst.utils import getPackageDir
3335

3436
random.seed(47) # for set_random_lsst_dds_partition_prefix
3537

@@ -61,7 +63,9 @@ async def basic_make_script(self, index):
6163
self.script.setup_electrometer = unittest.mock.AsyncMock()
6264

6365
# Mock setup of atmonochromator
64-
self.script.setup_atmonochromator_axes = unittest.mock.AsyncMock()
66+
self.script.setup_atmonochromator_axes = unittest.mock.AsyncMock(
67+
side_effect=self.setup_atmonochromator_axes_callback
68+
)
6569

6670
# mock fiber spectrograph exposures
6771
self.script.take_fs_exposures = unittest.mock.AsyncMock(
@@ -90,6 +94,26 @@ async def basic_make_script(self, index):
9094
# Return a single element tuple
9195
return (self.script,)
9296

97+
async def setup_atmonochromator_axes_callback(
98+
self,
99+
wavelength: float,
100+
grating: str,
101+
entrance_slit_width: float,
102+
exit_slit_width: float,
103+
):
104+
"""
105+
Mocks the monochromator setup.
106+
"""
107+
108+
# Check that all inputs are the correct type.
109+
110+
assert type(wavelength) == float
111+
assert type(grating) == int
112+
assert type(entrance_slit_width) == float
113+
assert type(exit_slit_width) == float
114+
115+
return
116+
93117
async def take_fs_exposures_callback(self, expTime, n):
94118
"""
95119
Mocks the taking of fiber spectrograph images
@@ -147,6 +171,27 @@ async def test_configure(self):
147171
latiss_grating=latiss_grating,
148172
)
149173

174+
async with self.make_script():
175+
# Try more complex parameters
176+
latiss_filter = "SDSSr_65mm"
177+
latiss_grating = "empty_1"
178+
# load a complex sequence defined as yaml
179+
test_sequence_path = os.path.join(
180+
getPackageDir("ts_externalscripts"),
181+
"tests",
182+
"data",
183+
"auxtel",
184+
"test_sequence1.yaml",
185+
)
186+
with open(test_sequence_path, "r") as file:
187+
sequence = yaml.safe_load(file)
188+
189+
await self.configure_script(
190+
latiss_filter=latiss_filter,
191+
latiss_grating=latiss_grating,
192+
sequence=sequence,
193+
)
194+
150195
async def test_invalid_sequence(self):
151196
# invalid filters, script should configure and hardware will get
152197
# setup but fail.
@@ -167,10 +212,10 @@ async def test_invalid_sequence(self):
167212
await self.script.arun()
168213

169214
async def test_sequence(self):
170-
# valid sequence
215+
# valid sequence, using the default
171216

172217
async with self.make_script():
173-
# Try configure with invalid sequence data. This should fail
218+
# Try configure with invalid sequence data.
174219
latiss_filter = "SDSSr_65mm"
175220
latiss_grating = "empty_1"
176221

@@ -181,6 +226,34 @@ async def test_sequence(self):
181226
# indication simulation for s3 bucket.
182227
await self.script.arun(simulation_mode=1)
183228

229+
async def test_sequence_custom(self):
230+
# valid sequence, using a custom input
231+
232+
async with self.make_script():
233+
# Try configure with complex sequence data.
234+
latiss_filter = "SDSSr_65mm"
235+
latiss_grating = "empty_1"
236+
# load a complex sequence defined as yaml
237+
test_sequence_path = os.path.join(
238+
getPackageDir("ts_externalscripts"),
239+
"tests",
240+
"data",
241+
"auxtel",
242+
"test_sequence1.yaml",
243+
)
244+
245+
with open(test_sequence_path, "r") as file:
246+
sequence = yaml.safe_load(file)
247+
248+
await self.configure_script(
249+
latiss_filter=latiss_filter,
250+
latiss_grating=latiss_grating,
251+
sequence=sequence,
252+
)
253+
254+
# indication of simulation for s3 bucket.
255+
await self.script.arun(simulation_mode=1)
256+
184257
async def test_executable(self):
185258
scripts_dir = externalscripts.get_scripts_dir()
186259
script_path = scripts_dir / "auxtel" / "latiss_take_flats.py"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"- em_exp_time: 5\n em_n_exp: 1\n entrance_slit_width: 4.5\n exit_slit_width: 4.5\n\
2+
\ exp_time: 3\n fs_exp_time: 5\n fs_n_exp: 1\n grating: 1\n n_exp: 5\n spec_res:\
3+
\ -1\n wavelength: 550.0\n- em_exp_time: 5\n em_n_exp: 1\n entrance_slit_width:\
4+
\ 4.5\n exit_slit_width: 4.5\n exp_time: 3\n fs_exp_time: 5\n fs_n_exp: 1\n\
5+
\ grating: 1\n n_exp: 5\n spec_res: -1\n wavelength: 570.0\n- em_exp_time: 5\n\
6+
\ em_n_exp: 1\n entrance_slit_width: 4.5\n exit_slit_width: 4.5\n exp_time:\
7+
\ 3\n fs_exp_time: 5\n fs_n_exp: 1\n grating: 1\n n_exp: 5\n spec_res: -1\n\
8+
\ wavelength: 590.0\n- em_exp_time: 5\n em_n_exp: 1\n entrance_slit_width: 4.5\n\
9+
\ exit_slit_width: 4.5\n exp_time: 3\n fs_exp_time: 5\n fs_n_exp: 1\n grating:\
10+
\ 1\n n_exp: 5\n spec_res: -1\n wavelength: 610.0\n- em_exp_time: 5\n em_n_exp:\
11+
\ 1\n entrance_slit_width: 4.5\n exit_slit_width: 4.5\n exp_time: 3\n fs_exp_time:\
12+
\ 5\n fs_n_exp: 1\n grating: 1\n n_exp: 5\n spec_res: -1\n wavelength: 630.0\n\
13+
- em_exp_time: 5\n em_n_exp: 1\n entrance_slit_width: 4.5\n exit_slit_width:\
14+
\ 4.5\n exp_time: 3\n fs_exp_time: 5\n fs_n_exp: 1\n grating: 1\n n_exp: 5\n\
15+
\ spec_res: -1\n wavelength: 650.0\n- em_exp_time: 5\n em_n_exp: 1\n entrance_slit_width:\
16+
\ 4.5\n exit_slit_width: 4.5\n exp_time: 3\n fs_exp_time: 5\n fs_n_exp: 1\n\
17+
\ grating: 1\n n_exp: 5\n spec_res: -1\n wavelength: 670.0\n"

0 commit comments

Comments
 (0)