Skip to content

Commit

Permalink
if sequence counters don't increase properly, call it a bad image (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbhughes authored Jan 3, 2025
1 parent 71cb591 commit bc4e9bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 13 additions & 3 deletions punchpipe/flows/level0.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def level0_form_images(session=None, pipeline_config_path=None):
distinct_times = session.query(SciPacket.timestamp).filter(~SciPacket.is_used).distinct().all()
distinct_spacecraft = session.query(SciPacket.spacecraft_id).filter(~SciPacket.is_used).distinct().all()


already_parsed_tlms = {} # tlm_path maps to the parsed contents

skip_count, success_count = 0, 0
Expand Down Expand Up @@ -104,20 +103,31 @@ def level0_form_images(session=None, pipeline_config_path=None):

# Form the image packet stream for decompression
ordered_image_content = []
sequence_counter = []
for packet_entry in image_packets_entries:
tlm_content_index = needed_tlm_paths.index(tlm_id_to_tlm_path[packet_entry.source_tlm_file])
selected_tlm_contents = tlm_contents[tlm_content_index]
ordered_image_content.append(selected_tlm_contents[0x20]['SCI_XFI_IMG_DATA'][packet_entry.packet_num])
sequence_counter.append(selected_tlm_contents[0x20]['SCI_XFI_HDR_GRP'][packet_entry.packet_num])

# Get the proper image
skip_image = False
sequence_counter_diff = np.diff(np.array(sequence_counter))
if not np.all(np.isin(sequence_counter_diff, [1, 255])):
skip_image = True
error = {'start_time': image_packets_entries[0].timestamp.isoformat(),
'start_block': image_packets_entries[0].flash_block,
'replay_length': image_packets_entries[-1].flash_block
- image_packets_entries[0].flash_block}
errors.append(error)

if image_compression[0]['CMP_BYP'] == 0 and image_compression[0]['JPEG'] == 1: # this assumes the image compression is static for an image
try:
ordered_image_content = np.concatenate(ordered_image_content)
image = form_from_jpeg_compressed(ordered_image_content)
except (RuntimeError, ValueError):
skip_image = True
error = {'start_time': image_packets_entries[0].timestamp.strftime("%Y-%m-%d %h:%m:%s"),
error = {'start_time': image_packets_entries[0].timestamp.isoformat(),
'start_block': image_packets_entries[0].flash_block,
'replay_length': image_packets_entries[-1].flash_block
- image_packets_entries[0].flash_block}
Expand All @@ -129,7 +139,7 @@ def level0_form_images(session=None, pipeline_config_path=None):
image = form_from_raw(ordered_image_content)
except (RuntimeError, ValueError):
skip_image = True
error = {'start_time': image_packets_entries[0].timestamp.strftime("%Y-%m-%d %h:%m:%s"),
error = {'start_time': image_packets_entries[0].timestamp.isoformat(),
'start_block': image_packets_entries[0].flash_block,
'replay_length': image_packets_entries[-1].flash_block
- image_packets_entries[0].flash_block}
Expand Down
3 changes: 1 addition & 2 deletions punchpipe/level0/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,9 @@ def form_from_jpeg_compressed(packets):

def form_from_raw(flat_image):
"""Form a raw image from packets"""
np.save("experiment.npy", flat_image)
pixel_values = unpack_Nbit_values(flat_image, byteorder=">", N=16)
nvals = pixel_values.size
width = 2176
width = 2048
if nvals % width == 0:
image = pixel_values.reshape((-1, width))
else:
Expand Down

0 comments on commit bc4e9bf

Please sign in to comment.