From b8947e72ab13f6feec9bf19f1a2b9f26016e46c5 Mon Sep 17 00:00:00 2001 From: teutoburg Date: Tue, 26 Nov 2024 17:10:57 +0100 Subject: [PATCH 1/2] Don't fail when no modes supplied, add tests for that --- scopesim/commands/user_commands.py | 2 +- scopesim/tests/tests_commands/test_scopesimple.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scopesim/commands/user_commands.py b/scopesim/commands/user_commands.py index eaba04e0..9549e3fc 100644 --- a/scopesim/commands/user_commands.py +++ b/scopesim/commands/user_commands.py @@ -291,7 +291,7 @@ def update(self, other=None, /, **kwargs): mode_yaml = self.modes_dict[mode_name] self._load_yaml_dict(mode_yaml) - if modes := kwargs.get("set_modes"): + if modes := list(kwargs.get("set_modes", [])): self.set_modes(*modes) # Calling underlying NestedMapping's update method to avoid recursion diff --git a/scopesim/tests/tests_commands/test_scopesimple.py b/scopesim/tests/tests_commands/test_scopesimple.py index c194edf8..9a1acfe4 100644 --- a/scopesim/tests/tests_commands/test_scopesimple.py +++ b/scopesim/tests/tests_commands/test_scopesimple.py @@ -19,6 +19,14 @@ def test_instrument_name_in_str(self): simple = Simulation("basic_instrument") assert "basic_instrument" in str(simple) + def test_default_mode_works(self): + simple = Simulation("basic_instrument") + assert simple.mode == "imaging" + + def test_init_mode_works(self): + simple = Simulation("basic_instrument", "spectroscopy") + assert simple.mode == "spectroscopy" + @pytest.mark.xfail(reason="DIT, NDIT currently broken") def test_full_workflow_runs(self): simple = Simulation("basic_instrument") From 97305a7661b3e8fdc8e1091bf7b1ba7f3d5701d0 Mon Sep 17 00:00:00 2001 From: teutoburg Date: Tue, 26 Nov 2024 17:12:04 +0100 Subject: [PATCH 2/2] Finally fix last dit/ndit bug --- scopesim/commands/scopesimple.py | 9 --------- scopesim/effects/fits_headers.py | 2 +- scopesim/tests/tests_commands/test_scopesimple.py | 1 - 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/scopesim/commands/scopesimple.py b/scopesim/commands/scopesimple.py index 8517cf59..3812395c 100644 --- a/scopesim/commands/scopesimple.py +++ b/scopesim/commands/scopesimple.py @@ -181,15 +181,6 @@ def readout( List of HDUs containing simulation results. """ - # If we have AutoExposure in the optical train and no dit or ndit was - # passed, assume the user wants to re-estimate them from given exptime. - if "auto_exposure" in self.optical_train: - kwargs["dit"] = kwargs.get("dit") - kwargs["ndit"] = kwargs.get("ndit") - else: - # Without AutoExposure, we need to get dit, ndit into !OBS - self.settings["!OBS.dit"] = kwargs.get("dit") - self.settings["!OBS.ndit"] = kwargs.get("ndit") self._last_readout = self.optical_train.readout(filename, **kwargs) return self.last_readout[0] diff --git a/scopesim/effects/fits_headers.py b/scopesim/effects/fits_headers.py index 7fc6de56..779f2c87 100644 --- a/scopesim/effects/fits_headers.py +++ b/scopesim/effects/fits_headers.py @@ -459,7 +459,7 @@ def apply_to(self, hdul, **kwargs): eff_name = eff_name.split()[0] # get a resolved meta dict from the effect - eff_meta = deepcopy(opt_train[f"#{eff_name}.!"]) + eff_meta = deepcopy(opt_train[eff_name].meta) if self.meta["add_excluded_effects"] and not eff_meta["include"]: continue diff --git a/scopesim/tests/tests_commands/test_scopesimple.py b/scopesim/tests/tests_commands/test_scopesimple.py index 9a1acfe4..f63b9872 100644 --- a/scopesim/tests/tests_commands/test_scopesimple.py +++ b/scopesim/tests/tests_commands/test_scopesimple.py @@ -27,7 +27,6 @@ def test_init_mode_works(self): simple = Simulation("basic_instrument", "spectroscopy") assert simple.mode == "spectroscopy" - @pytest.mark.xfail(reason="DIT, NDIT currently broken") def test_full_workflow_runs(self): simple = Simulation("basic_instrument") src = st.star(flux=15)