Skip to content

Commit

Permalink
Merge pull request #312 from sot/better-dark-date
Browse files Browse the repository at this point in the history
Pickle dark_date always and use it if existing for selecting dark map
  • Loading branch information
taldcroft authored Nov 19, 2019
2 parents b22b4cf + 168cc36 commit 00f708e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 0 additions & 1 deletion proseco/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ class ACATable(ACACatalogTable):
optimize = MetaAttribute(default=True)
call_args = MetaAttribute(default={})
version = MetaAttribute()
dark_date = MetaAttribute()

# For validation with get_aca_catalog(obsid), store the starcheck
# catalog in the ACATable meta.
Expand Down
29 changes: 25 additions & 4 deletions proseco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pickle
import inspect
import time
import warnings
from copy import copy
from pathlib import Path

Expand Down Expand Up @@ -540,6 +541,7 @@ class ACACatalogTable(BaseCatalogTable):
t_ccd_acq = MetaAttribute()
t_ccd_guide = MetaAttribute()
date = MetaAttribute()
dark_date = MetaAttribute()
dither_acq = MetaAttribute()
dither_guide = MetaAttribute()
detector = MetaAttribute()
Expand All @@ -561,16 +563,35 @@ def dark(self):
if hasattr(self, '_dark'):
return self._dark

# If self.dark_date is already set (most likely after unpickling an existing
# catalog), then use that instead of the observation date for getting the dark map.
if self.dark_date:
dark_id = get_dark_cal_id(date=self.dark_date, select='nearest')
self.log(f'Found dark cal image {dark_id} nearest self.dark_date={self.dark_date}')

# Warn if the pickled dark_date is not the same as we would have gotten based
# on the observation date.
dark_id_for_date = get_dark_cal_id(date=self.date, select='before')
if dark_id != dark_id_for_date:
warnings.warn(f'Unexpected dark_date: '
f'dark_id nearest dark_date={self.dark_date} is {dark_id} '
f'but dark_id before obs date={self.date} is {dark_id_for_date}')
else:
dark_id = get_dark_cal_id(date=self.date, select='before')
self.log(f'Found dark cal image {dark_id} before self.date={self.date}')

# In all cases set self.dark_date to be the actual date of the dark cal
# we are using, not what might have been set on input.
self.dark_date = dark_id[:4] + ':' + dark_id[4:]

# Dark current map handling. If asking for `dark` attribute without having set
# it then auto-fetch from mica. Note that get_dark_cal_image caches returned values
# using LRU cache on all params, so this is efficient for the different
# catalog tables.
self.log(f'Getting dark cal image at date={self.date} t_ccd={self.t_ccd:.1f}')
self.dark = get_dark_cal_image(date=self.date, select='before',
self.log(f'Getting dark cal image at date={self.dark_date} t_ccd={self.t_ccd:.1f} ')
self.dark = get_dark_cal_image(date=self.dark_date, select='nearest',
t_ccd_ref=self.t_ccd,
aca_image=False)
dark_id = get_dark_cal_id(date=self.date, select='before')
self.dark_date = dark_id[:4] + ':' + dark_id[4:]

return self._dark

Expand Down
14 changes: 14 additions & 0 deletions proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,17 @@ def test_includes_for_obsid():

out = includes_for_obsid(8008)
assert out == exp


def test_dark_date_warning():
aca = get_aca_catalog(**STD_INFO)
acap = pickle.loads(pickle.dumps(aca))
assert acap.dark_date == '2017:272'

# Fudge date forward, after the 2018:002 dark cal
acap.date = '2018:010'
with pytest.warns(None) as warns:
acap.dark # Accessing the `dark` property triggers code to read it (and warn)

assert len(warns) == 1
assert 'Unexpected dark_date: dark_id nearest dark_date' in str(warns[0].message)

0 comments on commit 00f708e

Please sign in to comment.