Skip to content

Commit

Permalink
One unit test still failling. Add messages, fix configs, fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanmartim committed Jul 26, 2024
1 parent 0794d17 commit 39436e2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 243 deletions.
273 changes: 48 additions & 225 deletions python/lsst/ts/externalscripts/base_take_ptc_flats.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,209 +33,6 @@
class BaseTakePTCFlats(BaseBlockScript, metaclass=abc.ABCMeta):
"""Base class for taking PTC flats interleaved with darks."""

DEFAULT_PTC_EXP_TIMES = [
7.25,
7.25,
9.13,
9.13,
0.48,
0.48,
0.42,
0.42,
8.62,
8.62,
41.16,
41.16,
2.15,
2.15,
0.28,
0.28,
2.71,
2.71,
24.44,
24.44,
3.22,
3.22,
15.38,
15.38,
1.7,
1.7,
0.95,
0.95,
1.35,
1.35,
0.6,
0.6,
18.3,
18.3,
32.65,
32.65,
1.43,
1.43,
0.22,
0.22,
2.56,
2.56,
19.39,
19.39,
13.7,
13.7,
2.41,
2.41,
0.64,
0.64,
12.2,
12.2,
0.27,
0.27,
0.32,
0.32,
0.57,
0.57,
6.45,
6.45,
2.87,
2.87,
0.85,
0.85,
16.3,
16.3,
1.07,
1.07,
20.55,
20.55,
0.67,
0.67,
51.89,
51.89,
46.21,
46.21,
38.84,
38.84,
58.26,
58.26,
6.84,
6.84,
5.42,
5.42,
4.06,
4.06,
0.21,
0.21,
1.14,
1.14,
0.8,
0.8,
8.14,
8.14,
0.25,
0.25,
10.26,
10.26,
1.81,
1.81,
3.83,
3.83,
0.9,
0.9,
0.34,
0.34,
0.38,
0.38,
27.44,
27.44,
54.98,
54.98,
17.27,
17.27,
3.62,
3.62,
25.9,
25.9,
34.6,
34.6,
0.51,
0.51,
61.73,
61.73,
1.91,
1.91,
2.03,
2.03,
21.77,
21.77,
36.66,
36.66,
3.41,
3.41,
48.97,
48.97,
9.68,
9.68,
4.3,
4.3,
5.75,
5.75,
29.08,
29.08,
1.61,
1.61,
1.52,
1.52,
0.54,
0.54,
7.68,
7.68,
0.45,
0.45,
4.56,
4.56,
3.04,
3.04,
1.28,
1.28,
0.71,
0.71,
0.36,
0.36,
4.83,
4.83,
10.87,
10.87,
12.93,
12.93,
0.2,
0.2,
1.2,
1.2,
0.24,
0.24,
2.28,
2.28,
0.76,
0.76,
0.4,
0.4,
0.3,
0.3,
1.01,
1.01,
11.51,
11.51,
14.52,
14.52,
30.81,
30.81,
5.12,
5.12,
23.07,
23.07,
6.09,
6.09,
43.61,
43.61,
]

def __init__(
self, index, descr="Base script for taking PTC flats and darks."
) -> None:
Expand All @@ -247,6 +44,8 @@ def __init__(
self.instrument_setup_time = 0.0
self.extra_scan_time = 1.0

self.long_timeout = 30

@property
@abc.abstractmethod
def camera(self):
Expand All @@ -273,11 +72,7 @@ async def configure_electrometer(self, index):

@classmethod
def get_schema(cls):
default_flats_exp_times_str = ", ".join(
map(str, cls.DEFAULT_PTC_EXP_TIMES)
)

schema_yaml = f"""
schema_yaml = """
$schema: http://json-schema.org/draft-07/schema#
$id: https://github.com/lsst-ts/ts_externalscripts/base_take_ptc_flats.yaml
title: BaseTakePTCFlats
Expand All @@ -289,8 +84,8 @@ def get_schema(cls):
type: array
items:
type: number
minimum: 0
default: [{default_flats_exp_times_str}]
exclusiveMinimum: 0
minItems: 2
interleave_darks:
description: Darks interleave settings.
type: object
Expand Down Expand Up @@ -371,7 +166,9 @@ async def configure(self, config: types.SimpleNamespace):
await self.configure_camera()

if hasattr(config, "electrometer_scan"):
await self.configure_electrometer(config.electrometer_scan.index)
await self.configure_electrometer(
config.electrometer_scan["index"]
)

if hasattr(config, "ignore"):
for comp in config.ignore:
Expand Down Expand Up @@ -400,23 +197,23 @@ async def configure(self, config: types.SimpleNamespace):
# Handle interleave darks settings
if hasattr(config, "interleave_darks"):
if (
isinstance(config.interleave_darks.dark_exp_times, list)
and config.interleave_darks.n_darks
isinstance(config.interleave_darks["dark_exp_times"], list)
and config.interleave_darks["n_darks"]
):
raise ValueError(
"If 'n_darks' is provided, 'dark_exp_times' must "
"be a scalar."
)

if not isinstance(config.interleave_darks.dark_exp_times, list):
config.interleave_darks.dark_exp_times = (
[config.interleave_darks.dark_exp_times] * (
config.interleave_darks.n_darks
if not isinstance(config.interleave_darks["dark_exp_times"], list):
config.interleave_darks["dark_exp_times"] = (
[config.interleave_darks["dark_exp_times"]] * (
config.interleave_darks["n_darks"]
)
)
else:
config.interleave_darks.n_darks = len(
config.interleave_darks.dark_exp_times
config.interleave_darks["n_darks"] = len(
config.interleave_darks["dark_exp_times"]
)

self.config = config
Expand Down Expand Up @@ -511,7 +308,7 @@ def set_metadata(self, metadata: salobj.BaseMsgType) -> None:

# Calculate dark exposure time if interleaving darks
if hasattr(self.config, "interleave_darks"):
dark_exp_times = self.config.interleave_darks.dark_exp_times
dark_exp_times = self.config.interleave_darks["dark_exp_times"]
n_darks = (
n_flat_pairs * len(dark_exp_times) * 2
) # Two sets of darks per pair of flats
Expand Down Expand Up @@ -583,19 +380,35 @@ async def take_electrometer_scan(

async def take_ptc_flats(self):
if hasattr(self.config, "electrometer_scan"):
self.log.info(
f"Setting up electrometer wit mode: "
f"{self.config.electrometer_scan['mode']}, range: "
f"{self.config.electrometer_scan['range']} and "
f"integration_time: "
f"{self.config.electrometer_scan['integration_time']}."
)
await self.setup_electrometer(
mode=self.config.electrometer_scan.mode,
range=self.config.electrometer_scan.range,
mode=self.config.electrometer_scan["mode"],
range=self.config.electrometer_scan["range"],
integration_time=(
self.config.electrometer_scan.integration_time
self.config.electrometer_scan["integration_time"]
),
)

for i in range(0, len(self.config.flats_exp_times), 2):
exp_time_pair = self.config.flats_exp_times[i:i + 2]

for exp_time in exp_time_pair:
await self.checkpoint(
f"Taking pair {i // 2 + 1} of {len(self.config.flats_exp_times) // 2}."
)
for j, exp_time in enumerate(exp_time_pair):
if hasattr(self.config, "electrometer_scan"):
self.log.info(
f"Taking flat {j+1}/2 with exposure time: {exp_time} "
f"seconds and scanning electrometer for "
f"{exp_time + self.extra_scan_time} seconds."
)

electrometer_task = self.take_electrometer_scan(
exp_time + self.extra_scan_time
)
Expand All @@ -613,6 +426,10 @@ async def take_ptc_flats(self):
await asyncio.gather(electrometer_task, flat_task)

else:
self.log.info(
f"Taking flat {j+1}/2 with exposure time: {exp_time} "
f"seconds."
)
await self.camera.take_imgtype(
imgtype="FLAT",
exptime=exp_time,
Expand All @@ -624,7 +441,13 @@ async def take_ptc_flats(self):
)

if hasattr(self.config, "interleave_darks"):
for dark_exp_time in self.config.interleave_darks.dark_exp_times:
for k, dark_exp_time in enumerate(
self.config.interleave_darks["dark_exp_times"]
):
self.log.info(
f"Taking dark {k+1}/{len(self.config.interleave_darks['dark_exp_times'])} "
f"for pair {i // 2 + 1} of {len(self.config.flats_exp_times) // 2}."
)
await self.camera.take_imgtype(
imgtype="DARK",
exptime=dark_exp_time,
Expand Down
Loading

0 comments on commit 39436e2

Please sign in to comment.