Skip to content

Commit 49896b0

Browse files
authored
Merge pull request #87 from AstarVienna/mb/usedframes
Converted inputs to sets + fixed inputs
2 parents 1c485e5 + 8f2f7ee commit 49896b0

24 files changed

+142
-69
lines changed

metisp/pymetis/src/pymetis/base/product.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ def __str__(self):
100100

101101
def save(self):
102102
""" Save this Product to a file """
103-
Msg.info(self.__class__.__qualname__, f"Saving product file as {self.output_file_name!r}:")
104-
Msg.info(self.__class__.__qualname__, f"All frames: {self.recipe.frameset!s}")
105-
Msg.info(self.__class__.__qualname__, f"Used frames: {self.recipe.used_frames!s}")
103+
Msg.info(self.__class__.__qualname__,
104+
f"Saving product file as {self.output_file_name!r}:")
105+
Msg.info(self.__class__.__qualname__,
106+
f"All frames ({len(self.recipe.frameset)}): {sorted([frame.tag for frame in self.recipe.frameset])}")
107+
Msg.info(self.__class__.__qualname__,
108+
f"Used frames ({len(self.recipe.used_frames)}): {sorted([frame.tag for frame in self.recipe.used_frames])}")
106109
# At least one frame in the recipe frameset must be tagged as RAW!
107110
# Otherwise, it *will not* save (rite of passage)
108111
cpl.dfs.save_image(

metisp/pymetis/src/pymetis/inputs/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@ class WavecalInput(SinglePipelineInput):
103103

104104
class PinholeTableInput(SinglePipelineInput):
105105
_title: str = "pinhole table"
106-
_tags: Pattern = re.compile(r"WCU_PINHOLE_TABLE")
106+
_tags: Pattern = re.compile(r"PINHOLE_TABLE")
107107
_group: cpl.ui.Frame.FrameGroup = cpl.ui.Frame.FrameGroup.CALIB

metisp/pymetis/src/pymetis/inputs/inputset.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def __init__(self, frameset: cpl.ui.FrameSet, **kwargs):
5252
Filter the input frameset, capture frames that match criteria and assign them to your own attributes.
5353
By default, there is nothing: no inputs, no tag_parameters.
5454
"""
55-
self.inputs: list[PipelineInput] = [] # A list of all inputs for this InputSet.
56-
self.tag_parameters: dict[str, str] = {} # A set of all tunable parameters determined from tags
55+
self.inputs: set[PipelineInput] = set() # A set of all inputs for this InputSet.
56+
self.tag_parameters: dict[str, str] = {} # A dict of all tunable parameters determined from tags
5757
self.frameset = frameset
5858

5959
def validate(self) -> None:
@@ -85,7 +85,7 @@ def validate_detectors(self) -> None:
8585
raise ValueError(f"More than one detector found in inputset: {detectors}")
8686

8787
def print_debug(self, *, offset: int = 0) -> None:
88-
Msg.debug(self.__class__.__qualname__, f"{' ' * offset} -- Detailed class info ---")
88+
Msg.debug(self.__class__.__qualname__, f"{' ' * offset}--- Detailed class info ---")
8989
Msg.debug(self.__class__.__qualname__, f"{' ' * offset}{len(self.inputs)} inputs:")
9090
Msg.debug(self.__class__.__qualname__, str(self.inputs))
9191

metisp/pymetis/src/pymetis/inputs/mixins.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,26 @@
1919

2020
import cpl.ui
2121

22-
from pymetis.inputs import PersistenceMapInput, PipelineInputSet
22+
from pymetis.inputs import PersistenceMapInput, PipelineInputSet, GainMapInput, LinearityInput
2323

2424

2525
class PersistenceInputSetMixin(PipelineInputSet):
2626
def __init__(self, frameset: cpl.ui.FrameSet):
2727
super().__init__(frameset)
2828

29-
self.persistence_map = PersistenceMapInput(frameset)
30-
self.inputs += [self.persistence_map]
29+
self.persistence_map = PersistenceMapInput(frameset, required=False)
30+
self.inputs |= {self.persistence_map}
31+
32+
33+
class GainMapInputSetMixin(PipelineInputSet):
34+
def __init__(self, frameset: cpl.ui.FrameSet):
35+
super().__init__(frameset)
36+
self.gain_map = GainMapInput(frameset)
37+
self.inputs |= {self.gain_map}
38+
39+
40+
class LinearityInputSetMixin(PipelineInputSet):
41+
def __init__(self, frameset: cpl.ui.FrameSet):
42+
super().__init__(frameset)
43+
self.linearity = LinearityInput(frameset)
44+
self.inputs |= {self.linearity}

metisp/pymetis/src/pymetis/prefab/darkimage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ class InputSet(RawImageProcessor.InputSet):
4444
def __init__(self, frameset: cpl.ui.FrameSet):
4545
super().__init__(frameset)
4646
self.master_dark = self.MasterDarkInput(frameset)
47-
self.inputs += [self.master_dark]
47+
self.inputs |= {self.master_dark}

metisp/pymetis/src/pymetis/prefab/flat.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class RawInput(RawInput):
4646

4747
def __init__(self, frameset: cpl.ui.FrameSet):
4848
super().__init__(frameset)
49-
self.persistence = PersistenceMapInput(frameset)
50-
self.linearity = LinearityInput(frameset)
51-
self.gain_map = GainMapInput(frameset)
52-
self.inputs += [self.persistence, self.linearity, self.gain_map]
49+
#self.persistence = PersistenceMapInput(frameset)
50+
#self.linearity = LinearityInput(frameset)
51+
#self.gain_map = GainMapInput(frameset)
52+
#self.inputs |= {self.persistence, self.linearity, self.gain_map}
5353

5454
class Product(PipelineProduct):
5555
group = cpl.ui.Frame.FrameGroup.PRODUCT

metisp/pymetis/src/pymetis/prefab/rawimage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class InputSet(PipelineInputSet):
4040
def __init__(self, frameset: cpl.ui.FrameSet):
4141
super().__init__(frameset)
4242
self.raw = self.RawInput(frameset)
43-
self.inputs += [self.raw]
43+
self.inputs |= {self.raw}
4444

4545
def load_raw_images(self) -> cpl.core.ImageList:
4646
"""

metisp/pymetis/src/pymetis/recipes/cal/metis_cal_chophome.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from pymetis.base.product import PipelineProduct
3232
from pymetis.prefab.rawimage import RawImageProcessor
3333

34+
3435
class MetisCalChophomeImpl(RawImageProcessor): # TODO replace parent class?
3536
"""Implementation class for metis_cal_chophome"""
3637
target = "LM_CHOPHOME"
@@ -50,11 +51,11 @@ def __init__(self, frameset: cpl.ui.FrameSet):
5051
self.linearity = LinearityInput(frameset)
5152
self.gain_map = GainMapInput(frameset)
5253
self.persistence = PersistenceMapInput(frameset, required=False)
53-
self.badpixmap = BadpixMapInput(frameset, required=False)
54+
self.badpix_map = BadpixMapInput(frameset, required=False)
5455
self.pinhole_table = PinholeTableInput(frameset, required=True)
5556

56-
self.inputs += [self.background, self.linearity, self.gain_map,
57-
self.badpixmap, self.persistence]
57+
self.inputs |= {self.background, self.linearity, self.gain_map,
58+
self.badpix_map, self.persistence, self.pinhole_table}
5859

5960

6061
class ProductCombined(PipelineProduct):

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_calibrate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, frameset: cpl.ui.FrameSet):
5050
self.telluric = self.TelluricInput(frameset)
5151
self.fluxcal = self.FluxcalTabInput(frameset)
5252

53-
self.inputs += [self.sci_reduced, self.telluric, self.fluxcal]
53+
self.inputs |= {self.sci_reduced, self.telluric, self.fluxcal}
5454

5555
class ProductSciCubeCalibrated(PipelineProduct):
5656
tag = rf"IFU_SCI_CUBE_CALIBRATED"

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_distortion.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,25 @@
2525

2626
from pymetis.base.recipe import MetisRecipe
2727
from pymetis.base.product import PipelineProduct
28-
from pymetis.inputs import RawInput, SinglePipelineInput
28+
from pymetis.inputs import RawInput, SinglePipelineInput, MasterDarkInput
29+
from pymetis.inputs.common import PinholeTableInput
30+
from pymetis.inputs.mixins import PersistenceInputSetMixin, LinearityInputSetMixin, GainMapInputSetMixin
31+
from pymetis.prefab.darkimage import DarkImageProcessor
2932
from pymetis.prefab.rawimage import RawImageProcessor
3033

3134

32-
class MetisIfuDistortionImpl(RawImageProcessor):
33-
class InputSet(RawImageProcessor.InputSet):
35+
class MetisIfuDistortionImpl(DarkImageProcessor):
36+
class InputSet(LinearityInputSetMixin, GainMapInputSetMixin, PersistenceInputSetMixin, DarkImageProcessor.InputSet):
37+
MasterDarkInput = MasterDarkInput
38+
3439
class RawInput(RawInput):
3540
_tags = re.compile(r"IFU_DISTORTION_RAW")
3641

37-
class PinholeTableInput(SinglePipelineInput):
38-
_tags = re.compile(r"PINHOLE_TABLE")
39-
_title = "pinhole table"
40-
_group: cpl.ui.Frame.FrameGroup = cpl.ui.Frame.FrameGroup.CALIB
41-
4242
def __init__(self, frameset: cpl.ui.FrameSet):
4343
super().__init__(frameset)
44-
self.pinhole_table = SinglePipelineInput(frameset,
45-
tags=re.compile(r"PINHOLE_TABLE"),
46-
title="pinhole table",
47-
group=cpl.ui.Frame.FrameGroup.CALIB)
48-
self.inputs += [self.pinhole_table]
44+
self.pinhole_table = PinholeTableInput(frameset)
45+
46+
self.inputs |= {self.pinhole_table}
4947

5048

5149
class ProductIfuDistortionTable(PipelineProduct):

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_postprocess.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class SciCubeCalibratedInput(SinglePipelineInput):
3838
def __init__(self, frameset: cpl.ui.FrameSet):
3939
super().__init__(frameset)
4040
self.sci_cube_calibrated = self.SciCubeCalibratedInput(frameset)
41-
self.inputs += [self.sci_cube_calibrated]
41+
self.inputs |= {self.sci_cube_calibrated}
4242

4343
class ProductSciCoadd(PipelineProduct):
4444
level = cpl.ui.Frame.FrameLevel.FINAL

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_reduce.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@
2626
from pymetis.base.product import PipelineProduct, TargetSpecificProduct
2727
from pymetis.inputs import SinglePipelineInput
2828
from pymetis.inputs.common import RawInput, MasterDarkInput, LinearityInput, PersistenceMapInput
29+
from pymetis.inputs.mixins import PersistenceInputSetMixin, GainMapInputSetMixin
2930

3031
from pymetis.prefab.darkimage import DarkImageProcessor
3132

3233

3334
class MetisIfuReduceImpl(DarkImageProcessor):
3435
target: Literal["SCI"] | Literal["STD"] = None
3536

36-
class InputSet(DarkImageProcessor.InputSet):
37+
class InputSet(GainMapInputSetMixin, PersistenceInputSetMixin, DarkImageProcessor.InputSet):
3738
detector = "IFU"
3839

3940
class RawInput(RawInput):
4041
_tags = re.compile(r"IFU_(?P<target>SCI|STD)_RAW")
4142

43+
class RawSkyInput(RawInput):
44+
_tags = re.compile(r"IFU_SKY_RAW")
45+
_title = "blank sky image"
46+
4247
class MasterDarkInput(MasterDarkInput):
4348
_group: cpl.ui.Frame.FrameGroup = cpl.ui.Frame.FrameGroup.RAW
4449

@@ -52,18 +57,24 @@ class DistortionTableInput(SinglePipelineInput):
5257
_group = cpl.ui.Frame.FrameGroup.CALIB
5358
_title = "Distortion table"
5459

60+
class RsrfInput(SinglePipelineInput):
61+
_tags = re.compile(r"RSRF_IFU")
62+
_group = cpl.ui.Frame.FrameGroup.CALIB
63+
_title = "RSRF"
64+
5565
def __init__(self, frameset: cpl.ui.FrameSet):
5666
"""
5767
Here we also define all input frames specific for this recipe, except those handled by mixins.
5868
"""
5969
super().__init__(frameset)
6070
self.raw = self.RawInput(frameset)
71+
self.sky = self.RawSkyInput(frameset)
6172
self.linearity_map = LinearityInput(frameset)
62-
self.persistence_map = PersistenceMapInput(frameset)
6373
self.master_dark = self.MasterDarkInput(frameset)
6474
self.ifu_wavecal = self.WavecalInput(frameset)
75+
self.rsrf = self.RsrfInput(frameset)
6576
self.ifu_distortion_table = self.DistortionTableInput(frameset)
66-
self.inputs += [self.linearity_map, self.persistence_map, self.master_dark, self.ifu_wavecal, self.ifu_distortion_table]
77+
self.inputs |= {self.sky, self.linearity_map, self.rsrf, self.ifu_wavecal, self.ifu_distortion_table}
6778

6879
class ProductReduced(TargetSpecificProduct):
6980
level = cpl.ui.Frame.FrameLevel.FINAL

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_rsrf.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
class MetisIfuRsrfImpl(DarkImageProcessor):
38-
class InputSet(DarkImageProcessor.InputSet):
38+
class InputSet(PersistenceInputSetMixin, DarkImageProcessor.InputSet):
3939
class RawInput(RawInput):
4040
_tags = re.compile(r"IFU_RSRF_RAW")
4141
_title = "IFU rsrf raw"
@@ -57,12 +57,11 @@ def __init__(self, frameset: cpl.ui.FrameSet):
5757
self.gain_map = GainMapInput(frameset)
5858
self.distortion_table = DistortionTableInput(frameset)
5959
self.wavecal = WavecalInput(frameset)
60-
self.persistence = PersistenceMapInput(frameset, required=False)
6160
self.badpixmap = BadpixMapInput(frameset, required=False)
6261

63-
self.inputs += [self.background, self.linearity,
62+
self.inputs |= {self.background, self.linearity,
6463
self.gain_map, self.distortion_table,
65-
self.wavecal, self.persistence, self.badpixmap]
64+
self.wavecal, self.badpixmap}
6665

6766
class ProductBackground(PipelineProduct):
6867
"""

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_telluric.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,29 @@ class CombinedInput(SinglePipelineInput):
4242
_group = cpl.ui.Frame.FrameGroup.CALIB
4343
_tags = re.compile(r"IFU_(?P<target>SCI|STD)_COMBINED")
4444

45+
class LsfKernelInput(SinglePipelineInput):
46+
_title = "LSF kernel"
47+
_group = cpl.ui.Frame.FrameGroup.CALIB
48+
_tags = re.compile(r"LSF_KERNEL")
49+
50+
class AtmProfileInput(SinglePipelineInput):
51+
_title = "atmospheric profile"
52+
_group = cpl.ui.Frame.FrameGroup.CALIB
53+
_tags = re.compile(r"ATM_PROFILE")
54+
55+
class FluxStdCatalogInput(SinglePipelineInput):
56+
_title = "flux std catalog"
57+
_group = cpl.ui.Frame.FrameGroup.CALIB
58+
_tags = re.compile(r"FLUXSTD_CATALOG")
59+
4560
def __init__(self, frameset: cpl.ui.FrameSet):
4661
super().__init__(frameset)
4762
self.combined = self.CombinedInput(frameset)
48-
self.inputs += [self.combined]
63+
self.lsf_kernel = self.LsfKernelInput(frameset)
64+
self.atmospheric_profile = self.AtmProfileInput(frameset)
65+
self.fluxstd_catalog = self.FluxStdCatalogInput(frameset)
66+
67+
self.inputs |= {self.combined, self.lsf_kernel, self.atmospheric_profile, self.fluxstd_catalog}
4968

5069

5170
class ProductSciReduced1D(ProductTelluric):

metisp/pymetis/src/pymetis/recipes/ifu/metis_ifu_wavecal.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from pymetis.base import MetisRecipe
2525
from pymetis.base.product import PipelineProduct
26-
from pymetis.inputs.common import MasterDarkInput, GainMapInput, RawInput, DistortionTableInput
26+
from pymetis.inputs.common import MasterDarkInput, GainMapInput, RawInput, DistortionTableInput, LinearityInput
2727
from pymetis.inputs.mixins import PersistenceInputSetMixin
2828
from pymetis.prefab.darkimage import DarkImageProcessor
2929

@@ -39,8 +39,9 @@ def __init__(self, frameset: cpl.ui.FrameSet):
3939
super().__init__(frameset)
4040
self.gain_map = GainMapInput(frameset)
4141
self.distortion_table = DistortionTableInput(frameset)
42+
self.linearity = LinearityInput(frameset)
4243

43-
self.inputs += [self.gain_map, self.distortion_table]
44+
self.inputs |= {self.gain_map, self.distortion_table, self.linearity}
4445

4546
class ProductIfuWavecal(PipelineProduct):
4647
category = rf"IFU_WAVECAL"

metisp/pymetis/src/pymetis/recipes/img/metis_lm_img_background.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, frameset: cpl.ui.FrameSet):
3939
self.basic_reduced = self.LmBasicReducedInput(frameset)
4040

4141
# We need to register the inputs (just to be able to do `for x in self.inputs:`)
42-
self.inputs += [self.basic_reduced]
42+
self.inputs |= {self.basic_reduced}
4343

4444
class ProductBkg(PipelineProduct):
4545
tag: str = "LM_{target}_BKG"

metisp/pymetis/src/pymetis/recipes/img/metis_lm_img_basic_reduce.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self, frameset: cpl.ui.FrameSet):
8181
self.gain_map = GainMapInput(frameset)
8282

8383
# We need to register the inputs (just to be able to say `for x in self.inputs:`)
84-
self.inputs += [self.master_flat, self.linearity, self.persistence, self.gain_map]
84+
self.inputs |= {self.master_flat, self.linearity, self.persistence, self.gain_map}
8585

8686
class Product(TargetSpecificProduct):
8787
"""

metisp/pymetis/src/pymetis/recipes/instrument/metis_pupil_imaging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, frameset: cpl.ui.FrameSet):
9090
self.gain_map = GainMapInput(frameset, det=self.detector)
9191

9292
# We need to register the inputs (just to be able to do `for x in self.inputs:`)
93-
self.inputs += [self.master_flat, self.linearity, self.persistence, self.gain_map]
93+
self.inputs |= {self.master_flat, self.linearity, self.persistence, self.gain_map}
9494

9595
class Product(PipelineProduct):
9696
"""

metisp/pymetis/src/pymetis/recipes/metis_det_dark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, frameset: cpl.ui.FrameSet):
4343
self.persistence_map = PersistenceMapInput(frameset, required=False) # But should be
4444
self.gain_map = GainMapInput(frameset, required=False) # But should be
4545

46-
self.inputs += [self.linearity, self.badpix_map, self.persistence_map, self.gain_map]
46+
self.inputs |= {self.linearity, self.badpix_map, self.persistence_map, self.gain_map}
4747

4848
class Product(DetectorSpecificProduct):
4949
group = cpl.ui.Frame.FrameGroup.PRODUCT

metisp/pymetis/src/pymetis/recipes/metis_det_lingain.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ class InputSet(RawImageProcessor.InputSet):
4343
class RawInput(RawInput):
4444
_tags = re.compile(r"DETLIN_(?P<detector>2RG|GEO|IFU)_RAW")
4545

46-
class WcuOffInput(RawInput):
47-
_title = "WCU off raw"
48-
_tags = re.compile(r"(?P<band>LM|N|IFU)_WCU_OFF_RAW")
46+
#class WcuOffInput(RawInput):
47+
# _title = "WCU off raw"
48+
# _tags = re.compile(r"(?P<band>LM|N|IFU)_WCU_OFF_RAW")
4949

5050
def __init__(self, frameset: cpl.ui.FrameSet):
5151
super().__init__(frameset)
52-
self.wcu_off = self.WcuOffInput(frameset)
52+
# self.wcu_off = self.WcuOffInput(frameset)
5353
self.badpix_map = BadpixMapInput(frameset, required=False)
54-
self.inputs += [self.badpix_map, self.wcu_off]
54+
# self.inputs |= {self.badpix_map, self.wcu_off}
55+
self.inputs |= {self.badpix_map}
5556

5657
class ProductGain(LinGainProduct):
5758
@property

0 commit comments

Comments
 (0)