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

Resolve recursive bang-strings #351

Merged
merged 12 commits into from
Jan 31, 2024
2 changes: 1 addition & 1 deletion scopesim/effects/effects_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def combine_surface_effects(surface_effects):
surflist_list = [eff for eff in surface_effects
if isinstance(eff, efs.SurfaceList)]
surf_list = [eff for eff in surface_effects
if isinstance(eff, (efs.TERCurve, efs.FilterWheel))
if isinstance(eff, (efs.TERCurve, efs.FilterWheelBase))
and not isinstance(eff, efs.SurfaceList)]

if not surflist_list:
Expand Down
4 changes: 2 additions & 2 deletions scopesim/effects/surface_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from astropy import units as u

from .ter_curves import TERCurve
from .ter_curves import TERCurve, FilterWheelBase
from ..optics import radiometry_utils as rad_utils
from ..optics.surface import PoorMansSurface
from ..utils import quantify, from_currsys, figure_factory
Expand Down Expand Up @@ -119,7 +119,7 @@ def is_empty(self):
def add_surface(self, surface, name=None, position=-1, add_to_table=True):
if name is None:
name = surface.meta.get("name", "<unknown surface>")
if isinstance(surface, TERCurve):
if isinstance(surface, (TERCurve, FilterWheelBase)):
ter_meta = surface.meta
surface = surface.surface
surface.meta.update(ter_meta)
Expand Down
21 changes: 19 additions & 2 deletions scopesim/effects/ter_curves.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Transmission, emissivity, reflection curves."""

from collections.abc import Collection

import numpy as np
Expand All @@ -26,6 +25,9 @@ class TERCurve(Effect):
"""
Transmission, Emissivity, Reflection Curve.

note:: This is basically an ``Effect`` wrapper for the
``SpectralSurface`` object

Must contain a wavelength column, and one or more of the following:
``transmission``, ``emissivity``, ``reflection``.
Additionally, in the header there
Expand Down Expand Up @@ -201,7 +203,12 @@ def plot(self, which="x", wavelength=None, *, axes=None, **kwargs):
if wavelength is None:
wunit = params["wave_unit"]
# TODO: shouldn't need both, make sure they're equal
assert wunit == wave_unit
if wunit != wave_unit:
logger.warning(f"wavelength units in the meta dict of "
f"{self.meta.get('name')} are inconsistent: \n"
f"- wavelength_unit : {wave_unit} \n"
f"- wave_unit : {wunit}")
astronomyk marked this conversation as resolved.
Show resolved Hide resolved

wave = np.arange(quantify(params["wave_min"], wunit).value,
quantify(params["wave_max"], wunit).value,
quantify(params["wave_bin"], wunit).value)
Expand All @@ -213,6 +220,8 @@ def plot(self, which="x", wavelength=None, *, axes=None, **kwargs):
abbrs = {"t": "transmission", "e": "emission",
"r": "reflection", "x": "throughput"}

if not isinstance(axes, list):
astronomyk marked this conversation as resolved.
Show resolved Hide resolved
axes = [axes]
for ter, ax in zip(which, axes):
y_name = abbrs.get(ter, "throughput")
y = getattr(self.surface, y_name)
Expand Down Expand Up @@ -581,6 +590,14 @@ def apply_to(self, obj, **kwargs):
"""Use apply_to of current filter."""
return self.current_filter.apply_to(obj, **kwargs)

@property
def surface(self):
return self.current_filter.surface

@property
def throughput(self):
return self.current_filter.throughput

def fov_grid(self, which="waveset", **kwargs):
return self.current_filter.fov_grid(which=which, **kwargs)

Expand Down
18 changes: 14 additions & 4 deletions scopesim/optics/optics_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,20 @@ def fov_setup_effects(self):
@property
def surfaces_table(self):
"""Get combined surface table from effects with z_order = 100...199."""
if self._surfaces_table is None:
surface_like_effects = self.get_z_order_effects(100)
self._surfaces_table = combine_surface_effects(surface_like_effects)
return self._surfaces_table
from copy import deepcopy
sle_list = self.get_z_order_effects(100)
sle_list_copy = []
for eff in sle_list:
if isinstance(eff, efs.SurfaceList):
eff_copy = deepcopy(eff)
eff_copy.table = from_currsys(eff.table)
else:
# Avoid infinite recursion in Wheel effects (filter, adc)
eff_copy = eff
sle_list_copy += [eff_copy]
astronomyk marked this conversation as resolved.
Show resolved Hide resolved

comb_table = combine_surface_effects(sle_list_copy)
teutoburg marked this conversation as resolved.
Show resolved Hide resolved
return comb_table

@property
def all_effects(self):
Expand Down
11 changes: 9 additions & 2 deletions scopesim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,18 @@ def from_currsys(item):
if isinstance(item, str) and len(item) and item.startswith("!"):
if item in rc.__currsys__:
item = rc.__currsys__[item]
if isinstance(item, str) and item.startswith("!"):
item = from_currsys(item)
astronomyk marked this conversation as resolved.
Show resolved Hide resolved
else:
raise ValueError(f"{item} was not found in rc.__currsys__")

if isinstance(item, str) and item.lower() == "none":
item = None
if isinstance(item, str):
if item.lower() == "none":
item = None
try:
item = float(item)
except TypeError:
teutoburg marked this conversation as resolved.
Show resolved Hide resolved
pass

return item

Expand Down
Loading