Skip to content

Commit

Permalink
Make observe work with no source (empty field) (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
oczoske authored Oct 28, 2024
2 parents c33f0fe + 0905243 commit 60ca229
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions scopesim/optics/optical_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..detector import DetectorManager
from ..effects import ExtraFitsKeywords
from ..utils import from_currsys, top_level_catch, get_logger
from ..source.source_templates import empty_sky
from .. import __version__


Expand Down Expand Up @@ -69,6 +70,11 @@ class OpticalTrain:
>>> opt.observe(src)
>>> hdus = opt.readout()
If no Source is specified, an empty field is observe, so that the
following is equivalent to the commands above::
>>> opt.observe()
>>> hdus = opt.readout()
List the effects modelled in an OpticalTrain::
>>> print(opt.effects)
Expand Down Expand Up @@ -169,7 +175,7 @@ def update(self, **kwargs):
for det_list in opt_man.detector_setup_effects]

@top_level_catch
def observe(self, orig_source, update=True, **kwargs):
def observe(self, orig_source=None, update=True, **kwargs):
"""
Main controlling method for observing ``Source`` objects.
Expand All @@ -183,6 +189,9 @@ def observe(self, orig_source, update=True, **kwargs):
Notes
-----
When orig_source is None (e.g. when writing opt.observe()), an
empty field is observed (internally created with empty_sky()).
How the list of Effects is split between the 5 main tasks:
- Make a FOV list - z_order = 0..99
Expand All @@ -202,7 +211,11 @@ def observe(self, orig_source, update=True, **kwargs):

# Make a copy of the Source and prepare for observation (convert to
# internally used units, sample to internal wavelength grid)
source = orig_source.make_copy()
if orig_source is None:
source = empty_sky()
logger.info("Observing empty field")
else:
source = orig_source.make_copy()
source = self.prepare_source(source)

# [1D - transmission curves]
Expand Down
7 changes: 6 additions & 1 deletion scopesim/tests/tests_optics/test_OpticalTrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@ def test_ignore_effects_works(self, cmds_with_ignore):
@pytest.mark.usefixtures("patch_mock_path")
class TestObserve:
"""
All tests here are for visual inspection.
Almost all tests here are for visual inspection.
No asserts, this just to test that the puzzle gets put back together
after it is chopped up by the FOVs.
"""
def test_observe_works_for_none(self, cmds):
opt = OpticalTrain(cmds)
opt.observe()
empty = sim.source.source_templates.empty_sky()
assert(opt._last_source.fields[0].field == empty.fields[0].field)

def test_observe_works_for_table(self, cmds, tbl_src):
opt = OpticalTrain(cmds)
Expand Down

0 comments on commit 60ca229

Please sign in to comment.