Skip to content

Commit

Permalink
Merge pull request #148 from sot/imgtype-3
Browse files Browse the repository at this point in the history
Prevent crash when IMGTYPE==3 when using blobs
  • Loading branch information
javierggt authored Jun 5, 2023
2 parents 1b07bfe + dab9388 commit 51e9070
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
13 changes: 6 additions & 7 deletions chandra_aca/maude_decom.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _aca_image_msid_list(pea):
# - Type 0 is 4x4,
# - Types 1 (first batch of 6x6) and 4 (first batch of 8x8) use the same pixel IDs as 4x4.
# - Type 3 is not a real image type. It occurs when the image telemetry is used to download
# engineering data. In this case, the image is treated as 4x4, but the values will be giberish.
# memory dump data. In this case, the image is treated as 4x4, but the values might be giberish.
# - Types 2 (second batch of 6x6) and 5 (second batch of 8x8) use the same pixel IDs.
_IMG_INDICES = [
np.array([PIXEL_MAP_INV["4x4"][f"{k}1"] for k in _a2p]).T,
Expand Down Expand Up @@ -521,12 +521,11 @@ def _combine_aca_packets(aca_packets):
pixels = np.ma.masked_all((8, 8))
pixels.data[:] = np.nan
for f in aca_packets:
i0, i1 = _IMG_INDICES[f["IMGTYPE"]]
pixels[i0, i1] = f["pixels"]
# IMGTYPE 3 is not a real image. It means the pixels are used to download engineering data
# We set the pixel values to the values in telemetry, but mask them.
if f["IMGTYPE"] == 3:
pixels.mask[i0, i1] = True
# IMGTYPE 3 is not a real image. It means the pixels are used to download memory dump data
# if IMGTYPE == 3, do nothing. All pixels will be masked
if f["IMGTYPE"] != 3:
i0, i1 = _IMG_INDICES[f["IMGTYPE"]]
pixels[i0, i1] = f["pixels"]

for f in aca_packets:
res.update(f)
Expand Down
36 changes: 17 additions & 19 deletions chandra_aca/tests/test_maude_decom.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,29 +753,27 @@ def test_get_aca_packets_blobs():
assert blobs == ref_blobs


def test_imgtype_dnld():
@pytest.mark.parametrize("source", ["blobs", "frames"])
def test_imgtype_dnld(source):
"""
Tests for the case when IMGTYPE is DNLD
Tests for the case when IMGTYPE is DNLD.
"""

start = "2023:047:02:58:13.213"
stop = "2023:047:02:58:14.239"
maude_result = maude.get_frames(start, stop, channel="FLIGHT")
raw_aca_packets = maude_decom.get_raw_aca_packets(
start, stop, maude_result=maude_result
)
# decom_packets = [maude_decom.unpack_aca_telemetry(a) for a in raw_aca_packets["packets"]]
# assert 3 not in [p['IMGTYPE'] for packet in decom_packets for p in packet]

img = maude_decom._get_aca_packets(
raw_aca_packets,
start,
stop,
combine=False,
adjust_time=False,
calibrate=False,
from cxotime import CxoTime

start = CxoTime("2023:047:02:57")
stop = CxoTime("2023:047:02:58")
if source == "blobs":
maude_result = maude.get_blobs(start, stop, channel="FLIGHT")
args = {"blobs": maude_result}
else:
maude_result = maude.get_frames(start, stop, channel="FLIGHT")
args = {"frames": maude_result}

img = maude_decom.get_aca_packets(
start, stop, combine=False, adjust_time=False, calibrate=False, **args
)

all_masked = np.array([np.all(row["IMG"].mask) for row in img])
img_dnld = img["IMGTYPE"] == 3
assert img_dnld.shape[0] > 0
assert np.all(all_masked == img_dnld)

0 comments on commit 51e9070

Please sign in to comment.