Skip to content

Commit

Permalink
Merge pull request #368 from AstarVienna/kl/fix_currsys_surface_list
Browse files Browse the repository at this point in the history
DRAFT : Additional hotfix for the removed currsys
  • Loading branch information
hugobuddel committed Feb 14, 2024
2 parents 00c9922 + 804c2ef commit 3f76171
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 509 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ filterwarnings = [
# Should probably be fixed:
"ignore::ResourceWarning",
"ignore:The fit may be poorly conditioned:astropy.utils.exceptions.AstropyUserWarning",
"ignore::astropy.units.core.UnitsWarning",
# Perhaps fix?
"ignore:divide by zero encountered in scalar divide:RuntimeWarning",
"ignore:divide by zero encountered in double_scalars:RuntimeWarning",
"ignore:invalid value encountered in multiply:RuntimeWarning",
"ignore:invalid value encountered in divide:RuntimeWarning",
"ignore:Cannot merge meta key.*:astropy.utils.metadata.MergeConflictWarning",
"default:The fov_grid*:DeprecationWarning",
# Raised when saving fits files, not so important to fix:
Expand All @@ -102,7 +104,7 @@ filterwarnings = [
"ignore:datetime.datetime.utcfromtimestamp()*:DeprecationWarning",
# Pytest Notebook stuff
"ignore:The*:pytest.PytestRemovedIn8Warning",
"ignore:Proactor*:RuntimeWarning"
"ignore:Proactor*:RuntimeWarning",
]

[tool.coverage.report]
Expand Down
3 changes: 3 additions & 0 deletions scopesim/effects/data_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def _load_ascii(self):
self.meta.update(hdr_dict)
# self.table.meta.update(hdr_dict)
self.table.meta.update(self.meta)
if self.table.meta.get("cmds"):
self.table.meta.pop("cmds")

self.meta["history"] += ["ASCII table read from "
f"{self.meta['filename']}"]

Expand Down
24 changes: 0 additions & 24 deletions scopesim/effects/effects_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,6 @@
logger = get_logger(__name__)


def combine_surface_effects_OLD(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)]

if len(surflist_list) == 0:
surf = empty_surface_list()
surf.meta["name"] = "Radiometry Table"
surflist_list += [surf]

new_surflist = deepcopy(surflist_list[0])
for surflist in surflist_list[1:]:
new_surflist.add_surface_list(surflist)

for surf in surf_list:
position = surf.meta["position"] if "position" in surf.meta else -1
new_surflist.add_surface(surf, surf.meta["name"], position=position)

new_surflist.table = new_surflist.radiometry_table.table

return new_surflist


def combine_surface_effects(surface_effects):
surflist_list = [eff for eff in surface_effects
if isinstance(eff, efs.SurfaceList)]
Expand Down
10 changes: 5 additions & 5 deletions scopesim/effects/fits_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ExtraFitsKeywords(Effect):
"""

def __init__(self, **kwargs):
def __init__(self, cmds=None, **kwargs):
# don't pass kwargs, as DataContainer can't handle yaml files
super().__init__()
params = {"name": "extra_fits_keywords",
Expand Down Expand Up @@ -419,7 +419,7 @@ class EffectsMetaKeywords(ExtraFitsKeywords):
"""

def __init__(self, **kwargs):
def __init__(self, cmds=None, **kwargs):
super(ExtraFitsKeywords, self).__init__()
params = {"name": "effects_fits_keywords",
"description": "Effect Meta FITS headers",
Expand Down Expand Up @@ -453,7 +453,7 @@ def apply_to(self, hdul, **kwargs):
keys = list(eff_meta.keys())
for key in keys:
value = eff_meta[key]
if key in ["history", "notes", "changes"]:
if key in ["history", "notes", "changes", "cmds"]:
eff_meta.pop(key)
if isinstance(value, Table):
eff_meta[key] = f"Table object of length: {len(value)}"
Expand Down Expand Up @@ -506,7 +506,7 @@ class SourceDescriptionFitsKeywords(ExtraFitsKeywords):
"""

def __init__(self, **kwargs):
def __init__(self, cmds=None, **kwargs):
super(ExtraFitsKeywords, self).__init__()
params = {"name": "source_fits_keywords",
"description": "Source description FITS headers",
Expand Down Expand Up @@ -590,7 +590,7 @@ class SimulationConfigFitsKeywords(ExtraFitsKeywords):
"""

def __init__(self, **kwargs):
def __init__(self, cmds=None, **kwargs):
super(ExtraFitsKeywords, self).__init__()
params = {"name": "simulation_fits_keywords",
"description": "Simulation Config FITS headers",
Expand Down
2 changes: 1 addition & 1 deletion scopesim/effects/spectral_trace_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ def __init__(self, **kwargs):
self.trace_lists = {}
for name in from_currsys(self.meta["trace_list_names"], self.cmds):
kwargs["name"] = name
kwargs["cmds"] = self.cmds
fname = str(path).format(name)
self.trace_lists[name] = SpectralTraceList(filename=fname,
cmds=self.cmds,
**kwargs)

def apply_to(self, obj, **kwargs):
Expand Down
19 changes: 14 additions & 5 deletions scopesim/effects/surface_list.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""TBA."""
from collections import OrderedDict
from copy import deepcopy

import warnings
import numpy as np
from astropy import units as u

from .ter_curves import TERCurve, FilterWheelBase
from ..optics import radiometry_utils as rad_utils
from ..optics.surface import PoorMansSurface
from ..optics.surface import PoorMansSurface, SpectralSurface
from ..utils import quantify, from_currsys, figure_factory


Expand All @@ -21,11 +23,18 @@ def __init__(self, **kwargs):
self.meta.update(params)
self.meta.update(kwargs)

tbl = from_currsys(self.table, self.cmds)
self.surfaces = rad_utils.make_surface_dict_from_table(tbl)
self._surface = None
self._throughput = None
self._emission = None
self.surfaces = OrderedDict({})

if self.table is not None:
for row in self.table:
surf_kwargs = deepcopy(self.table.meta)
surf_kwargs.update(dict(row))
surf_kwargs["cmds"] = self.cmds
surf_kwargs["filename"] = from_currsys(surf_kwargs["filename"], self.cmds)
self.surfaces[surf_kwargs["name"]] = SpectralSurface(**surf_kwargs)

def fov_grid(self, which="waveset", **kwargs):
warnings.warn("The fov_grid method is deprecated and will be removed "
Expand Down Expand Up @@ -137,8 +146,8 @@ def add_surface(self, surface, name=None, position=-1, add_to_table=True):
def add_surface_list(self, surface_list, prepend=False):
if isinstance(surface_list, SurfaceList):
self.surfaces.update(surface_list.surfaces)
new_tbl = from_currsys(surface_list.table, self.cmds),
self.table = rad_utils.combine_tables(new_tbl, self.table, prepend)
# new_tbl = from_currsys(surface_list.table, self.cmds),
self.table = rad_utils.combine_tables(surface_list.table, self.table, prepend)

def plot(self, which="x", wavelength=None, *, axes=None, **kwargs):
"""Plot TER curves.
Expand Down
1 change: 0 additions & 1 deletion scopesim/optics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .surface import SpectralSurface
from . import surface_utils
from .radiometry import RadiometryTable
from . import radiometry_utils

from .fov import FieldOfView
Expand Down
2 changes: 1 addition & 1 deletion scopesim/optics/optics_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def load_effects(self, yaml_dicts, **kwargs):
"""
if not isinstance(yaml_dicts, Sequence):
yaml_dicts = [yaml_dicts]
self.optical_elements.extend(OpticalElement(dic, **kwargs)
self.optical_elements.extend(OpticalElement(dic, cmds=self.cmds, **kwargs)
for dic in yaml_dicts if "effects" in dic)

def add_effect(self, effect, ext=0):
Expand Down
93 changes: 0 additions & 93 deletions scopesim/optics/radiometry.py

This file was deleted.

25 changes: 0 additions & 25 deletions scopesim/optics/radiometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,3 @@ def add_surface_to_table(tbl, surf, name, position, silent=True):
new_tbl = change_table_entry(new_tbl, colname, name, position=position)

return new_tbl


def add_surface_to_dict(dic, surf, name, position=0):
new_entry = OrderedDict({name : surf})
dic = insert_into_ordereddict(dic, new_entry, position)

return dic


def make_surface_dict_from_table(tbl):
surf_dict = OrderedDict({})
if tbl is not None and len(tbl) > 0:
names = tbl[real_colname("name", tbl.colnames)]
for ii, row in enumerate(tbl):
surf_dict[names[ii]] = make_surface_from_row(row, **tbl.meta)

return surf_dict


def make_surface_from_row(row, **kwargs):
row_dict = {colname.lower(): row[colname] for colname in row.colnames}
kwargs.update(row_dict)
surface = SpectralSurface(**kwargs)

return surface
Loading

0 comments on commit 3f76171

Please sign in to comment.