Skip to content

Commit

Permalink
Add warning if trigger scaling changes in request (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
samaloney authored Apr 11, 2024
1 parent f5b77dc commit 9fd6fc7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
3 changes: 2 additions & 1 deletion stixcore/data/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self, data_dir):
self.DIR / "solo_L1_stix-ql-lightcurve_20210116_V01.fits"]
self.L1_fits = list(self.DIR.glob('solo_L1_stix-*.fits'))
self.LB_21_6_30_fits = self.DIR / "solo_LB_stix-21-6-30_0664156800_V01.fits"
self.LB_21_6_21_fits = self.DIR / "solo_LB_stix-21-6-21_0000000000-9999999999_V02_2312148821-53879.fits" # noqa
self.LB_21_6_21_fits_scaled = self.DIR / "solo_LB_stix-21-6-21_0000000000-9999999999_V02_2312148821-53879.fits" # noqa
self.LB_21_6_24_scale_change = self.DIR / "solo_LB_stix-21-6-24_0000000000-9999999999_V02_2402021788-59493.fits" # noqa
self.__doc__ = "\n".join([f'{str(k)}: {repr(v)}\n\n' for k, v in self.__dict__.items()])


Expand Down
Git LFS file not shown
4 changes: 2 additions & 2 deletions stixcore/data/test/publish/rid_lut.csv
Git LFS file not shown
4 changes: 2 additions & 2 deletions stixcore/data/test/publish/update_rid_lut.csv
Git LFS file not shown
13 changes: 12 additions & 1 deletion stixcore/processing/tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def packet():


def test_level_0_descaling_trigger(out_dir):
lb = test_data.products.LB_21_6_21_fits
lb = test_data.products.LB_21_6_21_fits_scaled
l0 = Level0(out_dir / 'LB', out_dir)
res = l0.process_fits_files(files=[lb])
assert len(res) == 1
Expand All @@ -70,6 +70,17 @@ def test_level_0_descaling_trigger(out_dir):
assert factor == 30


def test_level_0_descaling_warning(out_dir):
lb = test_data.products.LB_21_6_24_scale_change
l0 = Level0(out_dir / 'LB', out_dir)
res = l0.process_fits_files(files=[lb])
assert len(res) == 1
datawarn = fits.getval(res[0], 'DATAWARN')
comment = fits.getval(res[0], 'COMMENT')
assert datawarn == 1
assert "Multiple compression schemes detected, trigger values maybe incorrect." in comment


@pytest.mark.skip(reason="needs proper spice pointing kernels")
def test_level_2(out_dir, spicekernelmanager):
SOOPManager.instance = SOOPManager(Path(__file__).parent.parent.parent
Expand Down
26 changes: 20 additions & 6 deletions stixcore/products/level0/scienceL0.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def __init__(self, *, service_type, service_subtype, ssid, control, data,

@classmethod
def from_levelb(cls, levelb, parent=''):
header_comments = []
header_history = []
additional_header_keywords = []

packets, idb_versions, control = ScienceProduct.from_levelb(levelb, parent=parent)

c_skm, c_skm_meta = _get_compression_scheme(packets, 'NIX00260')
Expand All @@ -310,8 +314,10 @@ def from_levelb(cls, levelb, parent=''):
t_skm, t_skm_meta = _get_compression_scheme(packets, 'NIX00242')
control.add_data('compression_scheme_triggers_skm', (t_skm[0].reshape(1, 3), t_skm_meta))

header_history = []
additional_header_keywords = []
if np.unique(t_skm, axis=0).shape[0] != 1:
additional_header_keywords.append(('DATAWARN', 1, 'See comments'))
header_comments.append('Multiple compression schemes detected, '
'trigger values maybe incorrect')

data = Data()
try:
Expand Down Expand Up @@ -530,7 +536,8 @@ def from_levelb(cls, levelb, parent=''):
data=data,
idb_versions=idb_versions,
packets=packets,
history=header_history)
history=header_history,
comment=header_comments)

prod.add_additional_header_keywords(additional_header_keywords)
return prod
Expand Down Expand Up @@ -696,6 +703,10 @@ def __init__(self, *, service_type, service_subtype, ssid, control, data,

@classmethod
def from_levelb(cls, levelb, parent=''):
header_comments = []
header_history = []
additional_header_keywords = []

packets, idb_versions, control = ScienceProduct.from_levelb(levelb, parent=parent)

c_skm, c_skm_meta = _get_compression_scheme(packets, 'NIX00268')
Expand All @@ -704,8 +715,10 @@ def from_levelb(cls, levelb, parent=''):
t_skm, t_skm_meta = _get_compression_scheme(packets, 'NIX00267')
control.add_data('compression_scheme_triggers_skm', (t_skm[0].reshape(1, 3), t_skm_meta))

header_history = []
additional_header_keywords = []
if np.unique(t_skm, axis=0).shape[0] != 1:
additional_header_keywords.append(('DATAWARN', 1, 'See comments'))
header_comments.append('Multiple compression schemes detected, '
'trigger values maybe incorrect.')

control['detector_masks'] = np.unique(_get_detector_mask(packets)[0], axis=0)
control['detector_masks'] = fix_detector_mask(control, control['detector_masks'])
Expand Down Expand Up @@ -836,7 +849,8 @@ def from_levelb(cls, levelb, parent=''):
data=data,
idb_versions=idb_versions,
packets=packets,
history=header_history)
history=header_history,
comment=header_comments)

prod.add_additional_header_keywords(additional_header_keywords)
return prod
Expand Down

0 comments on commit 9fd6fc7

Please sign in to comment.