Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better inheritance and more #264

Merged
merged 6 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions scopesim/effects/apertures.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,13 @@ class SlitWheel(Effect):
current_slit: "C"

"""
def __init__(self, **kwargs):
required_keys = ["slit_names", "filename_format", "current_slit"]
check_keys(kwargs, required_keys, action="error")

required_keys = {"slit_names", "filename_format", "current_slit"}
_current_str = "current_slit"

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

params = {"z_order": [80, 280, 580],
"path": "",
Expand All @@ -436,7 +438,7 @@ def __init__(self, **kwargs):
self.meta.update(params)
self.meta.update(kwargs)

path = Path(self.meta["path"], from_currsys(self.meta["filename_format"]))
path = self._get_path()
self.slits = {}
for name in from_currsys(self.meta["slit_names"]):
kwargs["name"] = name
Expand Down Expand Up @@ -483,12 +485,6 @@ def current_slit(self):
return False
return self.slits[currslit]

@property
def display_name(self):
return f"{self.meta['name']} : " \
f"[{from_currsys(self.meta['current_slit'])}]"


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

Expand Down
11 changes: 10 additions & 1 deletion scopesim/effects/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@

@property
def display_name(self):
return self.meta.get("name", self.meta.get("filename", "<empty>"))
name = self.meta.get("name", self.meta.get("filename", "<untitled>"))
if not hasattr(self, "_current_str"):
return name
return f"{name} : [{from_currsys(self.meta[self._current_str])}]"

@property
def meta_string(self):
Expand Down Expand Up @@ -321,3 +324,9 @@
raise ValueError(f"__getitem__ calls must start with '#': {item}")

return value

def _get_path(self):
if any(key not in self.meta for key in ("path", "filename_format")):
return None

Check warning on line 330 in scopesim/effects/effects.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/effects.py#L330

Added line #L330 was not covered by tests
return Path(self.meta["path"],
from_currsys(self.meta["filename_format"]))
2 changes: 1 addition & 1 deletion scopesim/effects/spectral_efficiency.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

ax.set_xlabel("Wavelength [um]")
ax.set_ylabel("Grating efficiency")
ax.set_title(f"Grating efficiencies from {self.filename}")
ax.set_title(f"Grating efficiencies {self.display_name}")

Check warning on line 125 in scopesim/effects/spectral_efficiency.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/spectral_efficiency.py#L125

Added line #L125 was not covered by tests
ax.legend()

return fig
18 changes: 7 additions & 11 deletions scopesim/effects/spectral_trace_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,14 @@ class SpectralTraceListWheel(Effect):
filter_names: "!INST.grism_names"

"""
def __init__(self, **kwargs):
required_keys = ["trace_list_names",
"filename_format",
"current_trace_list"]
check_keys(kwargs, required_keys, action="error")

required_keys = {"trace_list_names", "filename_format",
"current_trace_list"}
_current_str = "current_trace_list"

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

params = {"z_order": [70, 270, 670],
"path": "",
Expand All @@ -444,7 +445,7 @@ def __init__(self, **kwargs):
self.meta.update(params)
self.meta.update(kwargs)

path = Path(self.meta["path"], from_currsys(self.meta["filename_format"]))
path = self._get_path()
self.trace_lists = {}
for name in from_currsys(self.meta["trace_list_names"]):
kwargs["name"] = name
Expand All @@ -462,8 +463,3 @@ def current_trace_list(self):
if trace_list_name is not None:
trace_list_eff = self.trace_lists[trace_list_name]
return trace_list_eff

@property
def display_name(self):
name = self.meta.get("name", self.meta.get("filename", "<untitled>"))
return f"{name} : [{from_currsys(self.meta['current_trace_list'])}]"
4 changes: 2 additions & 2 deletions scopesim/effects/surface_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"x" plots throughput. "t","e","r" plot trans/emission/refl.
Can be a combination, e.g. "tr" or "tex" to plot each.
wavelength : array_like, optional
DESCRIPTION. The default is None.
Passed to TERCurve.plot() for each surface. The default is None.
axes : matplotlib axes, optional
If given, plot into existing axes. The default is None.

Expand All @@ -168,7 +168,7 @@
curve = TERCurve(**surface.meta)
curve.surface = surface
kwargs.update(plot_kwargs={"ls": "-", "label": key})
curve.plot(ter, axes=ax, **kwargs)
curve.plot(ter, wavelength, axes=ax, **kwargs)

Check warning on line 171 in scopesim/effects/surface_list.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/surface_list.py#L171

Added line #L171 was not covered by tests

# Plot the system surface
# TODO: self is a subclass of TERCurve, why create again??
Expand Down
Loading