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

Additional hotfix for the removed currsys #368

Merged
merged 7 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@
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")

Check warning on line 132 in scopesim/effects/data_container.py

View check run for this annotation

Codecov / codecov/patch

scopesim/effects/data_container.py#L132

Added line #L132 was not covered by tests

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
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that make_surface_dict_from_table() is now redundant and perhaps can be deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can. I did do that but get my branches confused, and they forgot to re-delete it from this branch. Thanks 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same can be done to make_surface_from_row

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
93 changes: 0 additions & 93 deletions scopesim/optics/radiometry.py

This file was deleted.

28 changes: 14 additions & 14 deletions scopesim/optics/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
from synphot.models import Empirical1D

from ..effects import ter_curves_utils as ter_utils
from .surface_utils import make_emission_from_emissivity,\
from .surface_utils import make_emission_from_emissivity, \
make_emission_from_array
from ..utils import (get_meta_quantity, quantify, extract_type_from_unit,
from_currsys, convert_table_comments_to_dict, find_file,
get_logger)


logger = get_logger(__name__)


Expand All @@ -43,13 +42,14 @@ class SpectralSurface:

"""

def __init__(self, filename=None, **kwargs):
def __init__(self, filename=None, cmds=None, **kwargs):
filename = find_file(filename)
self.meta = {"filename": filename,
"temperature": -270 * u.deg_C, # deg C
"emission_unit": "",
"wavelength_unit": u.um}

self.cmds = cmds
self.table = Table()
if filename is not None and Path(filename).exists():
self.table = ioascii.read(filename)
Expand All @@ -62,10 +62,10 @@ def __init__(self, filename=None, **kwargs):
@property
def area(self):
if "area" in self.meta:
the_area = self.from_meta("area", u.m**2)
the_area = self.from_meta("area", u.m ** 2)
elif "outer" in self.meta:
outer_diameter = self.from_meta("outer", u.m)
the_area = np.pi * (0.5 * outer_diameter)**2
the_area = np.pi * (0.5 * outer_diameter) ** 2
if "inner" in self.meta:
inner_diameter = self.from_meta("inner", u.m)
the_area -= np.pi * (0.5 * inner_diameter) ** 2
Expand Down Expand Up @@ -106,7 +106,7 @@ def reflection(self):
def emission(self):
"""
Look for an emission array in self.meta.

If it doesn't find this, it defaults to creating a blackbody and
multiplies this by the emissivity. Assumption is that
``self.meta["temperature"]`` is in ``deg_C``, unless it is a
Expand All @@ -118,8 +118,8 @@ def emission(self):
wave = self._get_array("wavelength")
flux = make_emission_from_array(flux, wave, meta=self.meta)
elif "temperature" in self.meta:
emiss = self.emissivity # SpectralElement [0..1]
temp = from_currsys(self.meta["temperature"])
emiss = self.emissivity # SpectralElement [0..1]
temp = from_currsys(self.meta["temperature"], self.cmds)
if not isinstance(temp, u.Quantity):
temp = quantify(temp, u.deg_C)
temp = temp.to(u.Kelvin, equivalencies=u.temperature())
Expand All @@ -133,11 +133,11 @@ def emission(self):
if flux is not None and has_solid_angle:
conversion_factor = flux.meta["solid_angle"].to(u.arcsec ** -2)
flux = flux * conversion_factor
flux.meta["solid_angle"] = u.arcsec**-2
flux.meta["solid_angle"] = u.arcsec ** -2
flux.meta["history"].append(f"Converted to arcsec-2: {conversion_factor}")

if flux is not None and "rescale_emission" in self.meta:
dic = from_currsys(self.meta["rescale_emission"])
dic = from_currsys(self.meta["rescale_emission"], self.cmds)
amplitude = dic["value"] * u.Unit(dic["unit"])
filter_name = dic["filter_name"]
if "filename_format" in dic:
Expand Down Expand Up @@ -226,11 +226,11 @@ def _compliment_array(self, colname_a, colname_b):
compliment_b = self._get_array(colname_b)

if compliment_a is not None and compliment_b is not None:
actual = 1*compliment_a.unit - (compliment_a + compliment_b)
actual = 1 * compliment_a.unit - (compliment_a + compliment_b)
elif compliment_a is not None and compliment_b is None:
actual = 1*compliment_a.unit - compliment_a
actual = 1 * compliment_a.unit - compliment_a
elif compliment_b is not None and compliment_a is None:
actual = 1*compliment_b.unit - compliment_b
actual = 1 * compliment_b.unit - compliment_b
elif compliment_b is None and compliment_a is None:
actual = None

Expand Down Expand Up @@ -261,7 +261,7 @@ def _get_array(self, colname):
colname, self.meta.get("name", self.meta["filename"]))
return None

col_units = colname+"_unit"
col_units = colname + "_unit"
if isinstance(val, u.Quantity):
units = val.unit
elif col_units in self.meta:
Expand Down
12 changes: 6 additions & 6 deletions scopesim/tests/test_utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def test_loads_ifu_optical_train_object(self):
assert isinstance(opt, OpticalTrain)
assert from_currsys(opt["ifu_spectral_traces"].include)

@pytest.mark.xfail
def test_loads_mos_optical_train_object(self):
opt = load_example_optical_train(set_modes=["mos"])

assert isinstance(opt, OpticalTrain)
assert from_currsys(opt["slit_wheel"].include)
# @pytest.mark.xfail
# def test_loads_mos_optical_train_object(self):
# opt = load_example_optical_train(set_modes=["mos"])
#
# assert isinstance(opt, OpticalTrain)
# assert from_currsys(opt["slit_wheel"].include)
Loading
Loading