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
23 changes: 21 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 @@
"""
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,14 @@
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("wavelength units in the meta dict of "

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

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L206-L207

Added lines #L206 - L207 were not covered by tests
"%s are inconsistent:\n"
"- wavelength_unit : %s\n"
"- wave_unit : %s",
{self.meta.get("name")},
wave_unit, wunit)

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 +222,8 @@
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]

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

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L225-L226

Added lines #L225 - L226 were not covered by tests
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 +592,14 @@
"""Use apply_to of current filter."""
return self.current_filter.apply_to(obj, **kwargs)

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

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

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L597

Added line #L597 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/ter_curves.py#L601

Added line #L601 was not covered by tests

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.append(eff_copy)

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 @@
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:

Check warning on line 874 in scopesim/utils.py

View check run for this annotation

Codecov / codecov/patch

scopesim/utils.py#L874

Added line #L874 was not covered by tests
item = float(item)
except (TypeError, ValueError):
pass

return item

Expand Down
Loading