Skip to content

Commit

Permalink
PupilMaskWheel
Browse files Browse the repository at this point in the history
  • Loading branch information
oczoske committed Nov 25, 2024
1 parent 5c0a141 commit 4725735
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions scopesim/effects/ter_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,80 @@ def __init__(self, transmission, cmds=None, **kwargs):
emissivity=[0., 0.], **self.params)

def update_transmission(self, transmission, **kwargs):
"""Set a new transmission value"""
self.__init__(transmission, **kwargs)


class PupilMaskWheel(Effect):
"""
Wheel holding a selection of predefined pupil masks
Currently, changing the PupilMask only changes the relative transmission.
Eventually, the change should also affect the total PSF of the OpticalTrain.
Example
-------
::
name : pupil_masks
class : PupilMaskWheel
kwargs:
pupil_masks: [("name1", transmission1),
("name2", transmission2)]
current_mask: "open"
"""
required_keys = {"pupil_masks", "current_mask"}
z_order: ClassVar[tuple[int, ...]] = (126, 226, 526)
report_plot_include: ClassVar[bool] = False
report_table_include: ClassVar[bool] = True
report_table_rounding: ClassVar[int] = 4
_current_str = "current_mask"

def __init__(self, cmds=None, **kwargs):
super().__init__(cmds=cmds, **kwargs)
check_keys(kwargs, self.required_keys, action="error")

Check warning on line 930 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L929-L930

Added lines #L929 - L930 were not covered by tests

self.meta.update(kwargs)
mask_dict = from_currsys(self.meta["pupil_masks"], cmds=self.cmds)
names = mask_dict['names']
transmissions = mask_dict['transmissions']
self.masks = {}
for name, trans in zip(names, transmissions):
kwargs["name"] = name
self.masks[name] = PupilTransmission(transmission=trans,

Check warning on line 939 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L932-L939

Added lines #L932 - L939 were not covered by tests
cmds=cmds,
**kwargs)
self.table = self.get_table(mask_dict)

Check warning on line 942 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L942

Added line #L942 was not covered by tests

def apply_to(self, obj, **kwargs):
"""Use ``apply_to`` of current pupil mask."""
return self.current_mask.apply_to(obj, **kwargs)

Check warning on line 946 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L946

Added line #L946 was not covered by tests

def change_mask(self, maskname=None):
"""Change the current pupil mask."""
if not maskname or maskname in self.masks:
self.meta["current_mask"] = maskname
self.include = maskname

Check warning on line 952 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L950-L952

Added lines #L950 - L952 were not covered by tests
else:
raise ValueError(f"Unknown pupil mask requested: {maskname}")

Check warning on line 954 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L954

Added line #L954 was not covered by tests

@property
def current_mask(self):
"""Return the currently used pupil mask."""
currmask = from_currsys(self.meta['current_mask'], cmds=self.cmds)
if not currmask:
return False
return self.masks[currmask]

Check warning on line 962 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L959-L962

Added lines #L959 - L962 were not covered by tests

def __getattr__(self, item):
return getattr(self.current_mask, item)

Check warning on line 965 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L965

Added line #L965 was not covered by tests

def get_table(self, maskdict):
"""Create a table of pupil masks with throughput."""
tbl = Table(maskdict)
return tbl

Check warning on line 970 in scopesim/effects/ter_curves.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L969-L970

Added lines #L969 - L970 were not covered by tests


class ADCWheel(Effect):
"""
Wheel holding a selection of predefined atmospheric dispersion correctors.
Expand Down

0 comments on commit 4725735

Please sign in to comment.