From 30834e98328fdd024e6a74e869155c6528677d2b Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Wed, 27 Nov 2024 08:24:20 -0700 Subject: [PATCH] fully tested level 0 --- punchpipe/control/db.py | 96 +++++++++++----------- punchpipe/flows/level0.py | 79 ++++++++++++------ punchpipe/level0/ccsds.py | 109 +++++++++++++++---------- punchpipe/level0/core.py | 47 ++++++----- punchpipe/level0/defs/ENG_BOOT.csv | 1 - punchpipe/level0/defs/ENG_CEB.csv | 1 - punchpipe/level0/defs/ENG_COMSEC.csv | 1 - punchpipe/level0/defs/ENG_DNLD.csv | 1 - punchpipe/level0/defs/ENG_EVT.csv | 1 - punchpipe/level0/defs/ENG_FDC.csv | 1 - punchpipe/level0/defs/ENG_FILL.csv | 1 - punchpipe/level0/defs/ENG_HI.csv | 1 - punchpipe/level0/defs/ENG_HYD.csv | 1 - punchpipe/level0/defs/ENG_LED.csv | 7 +- punchpipe/level0/defs/ENG_LO.csv | 1 - punchpipe/level0/defs/ENG_LZ.csv | 1 - punchpipe/level0/defs/ENG_PFW.csv | 1 - punchpipe/level0/defs/ENG_SEQ.csv | 1 - punchpipe/level0/defs/ENG_SSV.csv | 1 - punchpipe/level0/defs/ENG_STM_DIAG.csv | 1 - punchpipe/level0/defs/ENG_STM_DUMP.csv | 1 - punchpipe/level0/defs/ENG_STM_ECHO.csv | 1 - punchpipe/level0/defs/ENG_STM_HK.csv | 1 - punchpipe/level0/defs/ENG_STM_LOG.csv | 1 - punchpipe/level0/defs/ENG_XACT.csv | 1 - punchpipe/level0/defs/ENG_XTS.csv | 1 - punchpipe/level0/meta.py | 2 +- 27 files changed, 194 insertions(+), 167 deletions(-) diff --git a/punchpipe/control/db.py b/punchpipe/control/db.py index 1cef4e4..8286d1d 100644 --- a/punchpipe/control/db.py +++ b/punchpipe/control/db.py @@ -2,6 +2,7 @@ from sqlalchemy import TEXT, Boolean, Column, DateTime, Float, Integer, String from sqlalchemy.orm import declarative_base +from sqlalchemy.dialects.mysql import INTEGER from punchpipe.error import MissingCCSDSDataError @@ -134,54 +135,53 @@ class ENGPFWPacket(Base): flash_block = Column(Integer, nullable=False) timestamp = Column(DateTime, nullable=False, index=True) packet_num = Column(Integer, nullable=False) - source_tlm_file = Column(Integer, nullable=False) - - PFW_STATUS =Column(Integer, nullable=False) # Current PFW Status (0 - no error, else error) - STEP_CALC = Column(Integer, nullable=False) # Calculated step (0-1199) - LAST_CMD_N_STEPS = Column(Integer, nullable=False) # Commanded number of steps (1-1199) - HOME_POSITION_OVRD = Column(Integer, nullable=False) # HOME Position OVERRIDE - POSITION_CURR = Column(Integer, nullable=False) # Current position (1-5, 0 - manual stepping) - POSITION_CMD = Column(Integer, nullable=False) # Commanded position (1-5, 0 - manual stepping) - RESOLVER_POS_RAW = Column(Integer, nullable=False) # Resolver position - raw resolver counts (0-65000) - RESOLVER_POS_CORR = Column(Integer, nullable=False) # Resolver position - error correction applied (0-65000) - RESOLVER_READ_CNT = Column(Integer, nullable=False) # Accumulative # of resolver reads (resets on boot) - LAST_MOVE_N_STEPS = Column(Integer, nullable=False)# Number of steps on last move (1-1199) + source_tlm_file = Column(INTEGER(unsigned=True), nullable=False) + + PFW_STATUS =Column(INTEGER(unsigned=True), nullable=False) # Current PFW Status (0 - no error, else error) + STEP_CALC = Column(INTEGER(unsigned=True), nullable=False) # Calculated step (0-1199) + LAST_CMD_N_STEPS = Column(INTEGER(unsigned=True), nullable=False) # Commanded number of steps (1-1199) + POSITION_CURR = Column(INTEGER(unsigned=True), nullable=False) # Current position (1-5, 0 - manual stepping) + POSITION_CMD = Column(INTEGER(unsigned=True), nullable=False) # Commanded position (1-5, 0 - manual stepping) + RESOLVER_POS_RAW = Column(INTEGER(unsigned=True), nullable=False) # Resolver position - raw resolver counts (0-65000) + RESOLVER_POS_CORR = Column(INTEGER(unsigned=True), nullable=False) # Resolver position - error correction applied (0-65000) + RESOLVER_READ_CNT = Column(INTEGER(unsigned=True), nullable=False) # Accumulative # of resolver reads (resets on boot) + LAST_MOVE_N_STEPS = Column(INTEGER(unsigned=True), nullable=False)# Number of steps on last move (1-1199) LAST_MOVE_EXECUTION_TIME = Column(Float, nullable=False) # Current move execution time - LIFETIME_STEPS_TAKEN = Column(Integer, nullable=False) # Lifetime accumulative number of steps taken + LIFETIME_STEPS_TAKEN = Column(INTEGER(unsigned=True), nullable=False) # Lifetime accumulative number of steps taken LIFETIME_EXECUTION_TIME = Column(Float, nullable=False) # Lifetime accumulative execution time - FSM_CTRL_STATE = Column(Integer, nullable=False) # Controller FSM State - READ_SUB_STATE = Column(Integer, nullable=False) # READ Sub-FSM State - MOVE_SUB_STATE = Column(Integer, nullable=False) # MOVE Sub-FSM State - HOME_SUB_STATE = Column(Integer, nullable=False) # HOME Sub-FSM State - HOME_POSITION = Column(Integer, nullable=False) # Home Position (1-5) - RESOLVER_SELECT = Column(Integer, nullable=False) # Resolver Select - RESOLVER_TOLERANCE_HOME = Column(Integer, nullable=False) # Resolver Tolerance - RESOLVER_TOLERANCE_CURR = Column(Integer, nullable=False) # Resolver Tolerance - STEPPER_SELECT= Column(Integer, nullable=False) # Stepper Motor Select - STEPPER_RATE_DELAY = Column(Integer, nullable=False) # Stepper Motor Rate Delay + FSM_CTRL_STATE = Column(INTEGER(unsigned=True), nullable=False) # Controller FSM State + READ_SUB_STATE = Column(INTEGER(unsigned=True), nullable=False) # READ Sub-FSM State + MOVE_SUB_STATE = Column(INTEGER(unsigned=True), nullable=False) # MOVE Sub-FSM State + HOME_SUB_STATE = Column(INTEGER(unsigned=True), nullable=False) # HOME Sub-FSM State + HOME_POSITION = Column(INTEGER(unsigned=True), nullable=False) # Home Position (1-5) + RESOLVER_SELECT = Column(INTEGER(unsigned=True), nullable=False) # Resolver Select + RESOLVER_TOLERANCE_HOME = Column(INTEGER(unsigned=True), nullable=False) # Resolver Tolerance + RESOLVER_TOLERANCE_CURR = Column(INTEGER(unsigned=True), nullable=False) # Resolver Tolerance + STEPPER_SELECT= Column(INTEGER(unsigned=True), nullable=False) # Stepper Motor Select + STEPPER_RATE_DELAY = Column(INTEGER(unsigned=True), nullable=False) # Stepper Motor Rate Delay STEPPER_RATE = Column(Float, nullable=False) # Stepper Motor Rate - SHORT_MOVE_SETTLING_TIME_MS = Column(Integer, nullable=False) # Short Move(1-4 steps) Settling time before reading resolver - LONG_MOVE_SETTLING_TIME_MS = Column(Integer, nullable=False) # Long Move(5-1199 steps) Setting time before reading resolver - PRIMARY_STEP_OFFSET_1 = Column(Integer, nullable=False) # Primary Step Offset 1 - PRIMARY_STEP_OFFSET_2 = Column(Integer, nullable=False) # Short Move(1-4 steps) Delay before reading resolver - PRIMARY_STEP_OFFSET_3 = Column(Integer, nullable=False) # Primary Step Offset 3 - PRIMARY_STEP_OFFSET_4 = Column(Integer, nullable=False) # Primary Step Offset 4 - PRIMARY_STEP_OFFSET_5 = Column(Integer, nullable=False) # Primary Step Offset 5 - REDUNDANT_STEP_OFFSET_1 = Column(Integer, nullable=False) # Redundant Step Offset 1 - REDUNDANT_STEP_OFFSET_2 = Column(Integer, nullable=False) # Redundant Step Offset 2 - REDUNDANT_STEP_OFFSET_3 = Column(Integer, nullable=False) # Redundant Step Offset 3 - REDUNDANT_STEP_OFFSET_4 = Column(Integer, nullable=False) # Redundant Step Offset 4 - REDUNDANT_STEP_OFFSET_5 = Column(Integer, nullable=False) # Redundant Step Offset 5 - PRIMARY_RESOLVER_POSITION_1 = Column(Integer, nullable=False) # Primary Resolver Position 1 - PRIMARY_RESOLVER_POSITION_2 = Column(Integer, nullable=False) # Primary Resolver Position 2 - PRIMARY_RESOLVER_POSITION_3 = Column(Integer, nullable=False) # Primary Resolver Position 3 - PRIMARY_RESOLVER_POSITION_4 = Column(Integer, nullable=False) # Primary Resolver Position 4 - PRIMARY_RESOLVER_POSITION_5 = Column(Integer, nullable=False) # Primary Resolver Position 5 - REDUNDANT_RESOLVER_POSITION_1 = Column(Integer, nullable=False) # Redundant Resolver Position 1 - REDUNDANT_RESOLVER_POSITION_2 = Column(Integer, nullable=False) # Redundant Resolver Position 2 - REDUNDANT_RESOLVER_POSITION_3 = Column(Integer, nullable=False) # Redundant Resolver Position 3 - REDUNDANT_RESOLVER_POSITION_4 = Column(Integer, nullable=False) # Redundant Resolver Position 4 - REDUNDANT_RESOLVER_POSITION_5 = Column(Integer, nullable=False) # Redundant Resolver Position 5 + SHORT_MOVE_SETTLING_TIME_MS = Column(INTEGER(unsigned=True), nullable=False) # Short Move(1-4 steps) Settling time before reading resolver + LONG_MOVE_SETTLING_TIME_MS = Column(INTEGER(unsigned=True), nullable=False) # Long Move(5-1199 steps) Setting time before reading resolver + PRIMARY_STEP_OFFSET_1 = Column(INTEGER(unsigned=True), nullable=False) # Primary Step Offset 1 + PRIMARY_STEP_OFFSET_2 = Column(INTEGER(unsigned=True), nullable=False) # Short Move(1-4 steps) Delay before reading resolver + PRIMARY_STEP_OFFSET_3 = Column(INTEGER(unsigned=True), nullable=False) # Primary Step Offset 3 + PRIMARY_STEP_OFFSET_4 = Column(INTEGER(unsigned=True), nullable=False) # Primary Step Offset 4 + PRIMARY_STEP_OFFSET_5 = Column(INTEGER(unsigned=True), nullable=False) # Primary Step Offset 5 + REDUNDANT_STEP_OFFSET_1 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Step Offset 1 + REDUNDANT_STEP_OFFSET_2 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Step Offset 2 + REDUNDANT_STEP_OFFSET_3 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Step Offset 3 + REDUNDANT_STEP_OFFSET_4 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Step Offset 4 + REDUNDANT_STEP_OFFSET_5 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Step Offset 5 + PRIMARY_RESOLVER_POSITION_1 = Column(INTEGER(unsigned=True), nullable=False) # Primary Resolver Position 1 + PRIMARY_RESOLVER_POSITION_2 = Column(INTEGER(unsigned=True), nullable=False) # Primary Resolver Position 2 + PRIMARY_RESOLVER_POSITION_3 = Column(INTEGER(unsigned=True), nullable=False) # Primary Resolver Position 3 + PRIMARY_RESOLVER_POSITION_4 = Column(INTEGER(unsigned=True), nullable=False) # Primary Resolver Position 4 + PRIMARY_RESOLVER_POSITION_5 = Column(INTEGER(unsigned=True), nullable=False) # Primary Resolver Position 5 + REDUNDANT_RESOLVER_POSITION_1 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Resolver Position 1 + REDUNDANT_RESOLVER_POSITION_2 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Resolver Position 2 + REDUNDANT_RESOLVER_POSITION_3 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Resolver Position 3 + REDUNDANT_RESOLVER_POSITION_4 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Resolver Position 4 + REDUNDANT_RESOLVER_POSITION_5 = Column(INTEGER(unsigned=True), nullable=False) # Redundant Resolver Position 5 class TLMFiles(Base): @@ -202,10 +202,10 @@ class Health(Base): num_pids = Column(Integer, nullable=False) -def get_closest_eng_packets(table, timestamp, spacecraft_id): +def get_closest_eng_packets(table, timestamp, spacecraft_id, session): # find the closest events which are greater/less than the timestamp - gt_event = table.query.filter(table.spacecraft_id == spacecraft_id).filter(table.timestamp > timestamp).order_by(table.timestamp.asc()).first() - lt_event = table.query.filter(table.spacecraft_id == spacecraft_id).filter(table.timestamp < timestamp).order_by(table.timestamp.desc()).first() + gt_event = session.query(table).filter(table.spacecraft_id == spacecraft_id).filter(table.timestamp > timestamp).order_by(table.timestamp.asc()).first() + lt_event = session.query(table).filter(table.spacecraft_id == spacecraft_id).filter(table.timestamp < timestamp).order_by(table.timestamp.desc()).first() if gt_event is None and lt_event is None: msg = "Could not find packet near that time." diff --git a/punchpipe/flows/level0.py b/punchpipe/flows/level0.py index e635888..b2c4748 100644 --- a/punchpipe/flows/level0.py +++ b/punchpipe/flows/level0.py @@ -27,24 +27,28 @@ ) from punchpipe.level0.meta import POSITIONS_TO_CODES, convert_pfw_position_to_polarizer +from prefect.blocks.fields import SecretDict +from prefect.blocks.core import Block + +class SpacecraftMapping(Block): + mapping: SecretDict @flow -def level0_ingest_raw_packets(session=None): +def level0_ingest_raw_packets(pipeline_config_path: str | None = None, session=None): if session is None: session = get_database_session() + config = load_pipeline_configuration(pipeline_config_path) - paths = detect_new_tlm_files(session=session) + paths = detect_new_tlm_files(config, session=session) for path in paths: packets = parse_new_tlm_files(path) - update_tlm_database(packets, path) - - # update the database with this tlm file new_tlm_file = TLMFiles(path=path, is_processed=True) session.add(new_tlm_file) session.commit() + update_tlm_database(packets, new_tlm_file.tlm_id) @flow -def level0_form_images(session=None, pipeline_config_path="config.yaml"): +def level0_form_images(session=None, pipeline_config_path=None): if session is None: session = get_database_session() @@ -54,10 +58,13 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): distinct_spacecraft = session.query(SciPacket.spacecraft_id).filter(~SciPacket.is_used).distinct().all() + already_parsed_tlms = {} # tlm_path maps to the parsed contents + for spacecraft in distinct_spacecraft: errors = [] for t in distinct_times: + print(t) image_packets_entries = session.query(SciPacket).where(and_(SciPacket.timestamp == t[0], SciPacket.spacecraft_id == spacecraft[0])).all() image_compression = [unpack_compression_settings(packet.compression_settings) @@ -65,10 +72,18 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): # Read all the relevant TLM files needed_tlm_ids = set([image_packet.source_tlm_file for image_packet in image_packets_entries]) - tlm_id_to_tlm_path = {tlm_id: session.query(TLMFiles.path).where(TLMFiles.tlm_id == tlm_id) + tlm_id_to_tlm_path = {tlm_id: session.query(TLMFiles.path).where(TLMFiles.tlm_id == tlm_id).one().path for tlm_id in needed_tlm_ids} needed_tlm_paths = list(session.query(TLMFiles.path).where(TLMFiles.tlm_id.in_(needed_tlm_ids)).all()) - tlm_contents = [process_telemetry_file(tlm_path) for tlm_path in needed_tlm_paths] + needed_tlm_paths = [p.path for p in needed_tlm_paths] + + # parse any new TLM files needed + for tlm_path in needed_tlm_paths: + if tlm_path not in already_parsed_tlms: + already_parsed_tlms[tlm_path] = process_telemetry_file(tlm_path) + + # make it easy to grab the right TLM files + tlm_contents = [already_parsed_tlms[tlm_path] for tlm_path in needed_tlm_paths] # Form the image packet stream for decompression ordered_image_content = [] @@ -84,14 +99,15 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): try: image = form_from_jpeg_compressed(ordered_image_content) except ValueError: + print("jpeg failed") + skip_image = True error = {'start_time': image_packets_entries[0].timestamp.strftime("%Y-%m-%d %h:%m:%s"), '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) - else: - skip_image = True else: + print("not jpeg compressed") skip_image = True error = {'start_time': image_packets_entries[0].timestamp.strftime("%Y-%m-%d %h:%m:%s"), 'start_block': image_packets_entries[0].flash_block, @@ -101,6 +117,7 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): # check the quality of the image if not skip_image and not image_is_okay(image, config): + print("image isn't okay") skip_image = True error = {'start_time': image_packets_entries[0].timestamp.strftime("%Y-%m-%d %h:%m:%s"), 'start_block': image_packets_entries[0].flash_block, @@ -109,17 +126,24 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): errors.append(error) if not skip_image: - spacecraft_secrets = Secret.load("spacecraft-ids") - spacecraft_id_mapper = spacecraft_secrets.get() - spacecraft_id = spacecraft_id_mapper[image_packets_entries[0].spacecraft_id] - - metadata_contents = get_fits_metadata(image_packets_entries[0].timestamp, spacecraft_id) + print("NOT SKIPPING") + spacecraft_secrets = SpacecraftMapping.load("spacecraft-ids").mapping.get_secret_value() + moc_index = spacecraft_secrets["moc"].index(image_packets_entries[0].spacecraft_id) + spacecraft_id = spacecraft_secrets["soc"][moc_index] + # spacecraft_id = spacecraft_id_mapper[image_packets_entries[0].spacecraft_id] + print("TO HERE") + + metadata_contents = get_fits_metadata(image_packets_entries[0].timestamp, + image_packets_entries[0].spacecraft_id, + session) file_type = POSITIONS_TO_CODES[convert_pfw_position_to_polarizer(metadata_contents['POSITION_CURR'])] - preliminary_wcs = form_preliminary_wcs(metadata_contents, config['plate_scale'][spacecraft_id]) - meta = NormalizedMetadata.load_template(file_type + spacecraft_id, "0") - for meta_key, meta_value in metadata_contents.items(): - meta[meta_key] = meta_value - cube = NDCube(data=image, metadata=meta, wcs=preliminary_wcs) + preliminary_wcs = form_preliminary_wcs(metadata_contents, float(config['plate_scale'][spacecraft_id])) + meta = NormalizedMetadata.load_template(file_type + str(spacecraft_id), "0") + # TODO : activate later + # for meta_key, meta_value in metadata_contents.items(): + # meta[meta_key] = meta_value + meta['DATE-OBS'] = str(t[0]) + cube = NDCube(data=image, meta=meta, wcs=preliminary_wcs) l0_db_entry = File(level="0", file_type=file_type, @@ -127,13 +151,14 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): file_version="1", # TODO: increment the file version software_version=software_version, date_created=datetime.now(), - date_obs=t, - date_beg=t, - date_end=t, + date_obs=t[0], + date_beg=t[0], + date_end=t[0], state="created") - write_ndcube_to_fits(cube, os.path.join(l0_db_entry.directory(config['data_path']), - get_base_file_name(cube))) + out_path = os.path.join(l0_db_entry.directory(config['root']), get_base_file_name(cube)) + ".fits" + os.makedirs(os.path.dirname(out_path), exist_ok=True) + write_ndcube_to_fits(cube,out_path) # TODO: write a jp2 for image_packets_entries in image_packets_entries: image_packets_entries.is_used = True @@ -141,6 +166,6 @@ def level0_form_images(session=None, pipeline_config_path="config.yaml"): session.commit() df_errors = pd.DataFrame(errors) date_str = datetime.now().strftime("%Y_%j") - df_path = os.path.join(config['root'], 'REPLAY', f'PUNCH_{spacecraft}_REPLAY_{date_str}.csv') - os.makedirs(df_path, exist_ok=True) + df_path = os.path.join(config['root'], 'REPLAY', f'PUNCH_{str(spacecraft[0])}_REPLAY_{date_str}.csv') + os.makedirs(os.path.dirname(df_path), exist_ok=True) df_errors.to_csv(df_path, index=False) diff --git a/punchpipe/level0/ccsds.py b/punchpipe/level0/ccsds.py index 0bab2bf..47bc901 100644 --- a/punchpipe/level0/ccsds.py +++ b/punchpipe/level0/ccsds.py @@ -7,6 +7,8 @@ from ccsdspy.utils import split_by_apid from matplotlib import pyplot as plt +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + PACKET_NAME2APID = { "ENG_LZ": 0x60, "ENG_BOOT": 0x61, @@ -33,6 +35,8 @@ "ENG_FILL": 0x71, } +SKIP_APIDS = [96, 0x64, 0x6B, 0x70, 0x6A, 0x67] + PACKET_APID2NAME = {v: k for k, v in PACKET_NAME2APID.items()} @@ -44,16 +48,17 @@ def open_and_split_packet_file(path: str) -> dict[int, io.BytesIO]: def load_packet_def(packet_name) -> ccsdspy.VariableLength | ccsdspy.FixedLength: if packet_name == "SCI_XFI": - return ccsdspy.VariableLength.from_file(os.path.join("./defs", f"{packet_name}.csv")) + return ccsdspy.VariableLength.from_file(os.path.join(THIS_DIR, "defs", f"{packet_name}.csv")) else: - return ccsdspy.FixedLength.from_file(os.path.join("./defs", f"{packet_name}.csv")) + return ccsdspy.FixedLength.from_file(os.path.join(THIS_DIR, "defs", f"{packet_name}.csv")) def process_telemetry_file(telemetry_file_path): apid_separated_tlm = open_and_split_packet_file(telemetry_file_path) parsed_data = {} for apid, stream in apid_separated_tlm.items(): - if apid not in PACKET_APID2NAME or apid in [96]: + print(apid) + if apid not in PACKET_APID2NAME or apid in SKIP_APIDS: print(f"skipping {apid}") else: print(apid, PACKET_APID2NAME[apid]) @@ -113,37 +118,40 @@ def unpack_acquisition_settings(acq_set_val: "bytes|int"): "TABLE2": acquire_config & 0b1111} return settings_dict - -if __name__ == "__main__": - from punchbowl.data.visualize import cmap_punch - - path = "/Users/jhughes/new_results/nov17-0753/PUNCH_EM-01_RAW_2024_320_22_36_V01.tlm" - # path = "/Users/jhughes/Desktop/data/PUNCH_CCSDS/RAW_CCSDS_DATA/PUNCH_WFI01_RAW_2024_117_22_00_V01.tlm" - parsed = process_telemetry_file(path) - print(parsed[0x20].keys()) - for i in range(len(parsed[0x20])): - print(i) - print(unpack_compression_settings(parsed[0x20]['SCI_XFI_COM_SET'][i])) - print(unpack_acquisition_settings(parsed[0x20]['SCI_XFI_COM_SET'][i])) - print("-"*80) - # - # fig, ax = plt.subplots() - # ax.plot(parsed[0x20]['SCI_XFI_HDR_SEC']) - # plt.show() - - print({k: len(parsed[k]) for k in parsed}) - - print(parsed[0x20]['CCSDS_PACKET_LENGTH']) - print(parsed[0x20]['SCI_XFI_HDR_SCID']) - - img = np.concatenate(parsed[0x20]['SCI_XFI_IMG_DATA'][5:24]) - # img = parsed[0x20]['SCI_XFI_IMG_DATA'][0] - img = pylibjpeg.decode(img.tobytes()) - - from punchbowl.data.io import load_ndcube_from_fits - cube = load_ndcube_from_fits("/Users/jhughes/new_results/nov17-0753/PUNCH_L0_PZ2_20241002142916_v1.fits") - - # vmin, vmax = 0, 1_000 +def get_single_packet(apid_contents: dict[str, np.ndarray], i: int): + return {k: v[i] for k, v in apid_contents.items()} + + +# if __name__ == "__main__": +# from punchbowl.data.visualize import cmap_punch +# +# path = "/Users/jhughes/new_results/nov17-0753/PUNCH_EM-01_RAW_2024_320_22_36_V01.tlm" +# # path = "/Users/jhughes/Desktop/data/PUNCH_CCSDS/RAW_CCSDS_DATA/PUNCH_WFI01_RAW_2024_117_22_00_V01.tlm" +# parsed = process_telemetry_file(path) +# print(parsed[0x20].keys()) +# for i in range(len(parsed[0x20])): +# print(i) +# print(unpack_compression_settings(parsed[0x20]['SCI_XFI_COM_SET'][i])) +# print(unpack_acquisition_settings(parsed[0x20]['SCI_XFI_COM_SET'][i])) +# print("-"*80) +# # +# # fig, ax = plt.subplots() +# # ax.plot(parsed[0x20]['SCI_XFI_HDR_SEC']) +# # plt.show() +# +# print({k: len(parsed[k]) for k in parsed}) +# +# print(parsed[0x20]['CCSDS_PACKET_LENGTH']) +# print(parsed[0x20]['SCI_XFI_HDR_SCID']) +# +# img = np.concatenate(parsed[0x20]['SCI_XFI_IMG_DATA'][5:24]) +# # img = parsed[0x20]['SCI_XFI_IMG_DATA'][0] +# img = pylibjpeg.decode(img.tobytes()) +# +# from punchbowl.data.io import load_ndcube_from_fits +# cube = load_ndcube_from_fits("/Users/jhughes/new_results/nov17-0753/PUNCH_L0_PZ2_20241002142916_v1.fits") +# +# # vmin, vmax = 0, 1_000 # fig, axs = plt.subplots(ncols=2, sharex=True, sharey=True) # im0 = axs[0].imshow(img, vmin=np.sqrt(vmin*8), vmax=np.sqrt(8*vmax), interpolation="none") # im1 = axs[1].imshow(cube.data, vmin=vmin, vmax=vmax, interpolation="none") @@ -163,15 +171,26 @@ def unpack_acquisition_settings(acq_set_val: "bytes|int"): # # ax.legend() # plt.show() + # + # vmin, vmax = 0, 1_600 + # fig, axs = plt.subplots(ncols=2, sharex=True, sharey=True, figsize=(12, 6)) + # im0 = axs[1].imshow(img, vmin=np.sqrt(vmin * 8), vmax=np.sqrt(8 * vmax), interpolation="none", cmap=cmap_punch()) + # im1 = axs[0].imshow(np.sqrt(cube.data*8), vmin=np.sqrt(vmin * 8), vmax=np.sqrt(8 * vmax), interpolation="none", cmap=cmap_punch()) + # axs[1].set_title("Output test image") + # axs[0].set_title("Input test image") + # # fig.colorbar(im0, ax=axs[0]) + # # fig.colorbar(im1, ax=axs[1]) + # fig.tight_layout() + # fig.savefig("mmr_image.png", dpi=300) + # plt.show() - vmin, vmax = 0, 1_600 - fig, axs = plt.subplots(ncols=2, sharex=True, sharey=True, figsize=(12, 6)) - im0 = axs[1].imshow(img, vmin=np.sqrt(vmin * 8), vmax=np.sqrt(8 * vmax), interpolation="none", cmap=cmap_punch()) - im1 = axs[0].imshow(np.sqrt(cube.data*8), vmin=np.sqrt(vmin * 8), vmax=np.sqrt(8 * vmax), interpolation="none", cmap=cmap_punch()) - axs[1].set_title("Output test image") - axs[0].set_title("Input test image") - # fig.colorbar(im0, ax=axs[0]) - # fig.colorbar(im1, ax=axs[1]) - fig.tight_layout() - fig.savefig("mmr_image.png", dpi=300) - plt.show() +if __name__ == "__main__": + from punchpipe.level0.core import update_tlm_database + from punchpipe.flows.level0 import level0_form_images, level0_ingest_raw_packets + # path = "/Users/jhughes/dropzone/PUNCH_WFI01_RAW_2024_325_16_23_V01.tlm" + # level0_ingest_raw_packets() + # packets = process_telemetry_file(path) + # print(packets) + # update_tlm_database(packets, 0) + + level0_form_images() \ No newline at end of file diff --git a/punchpipe/level0/core.py b/punchpipe/level0/core.py index 1e1bb02..0ab8454 100644 --- a/punchpipe/level0/core.py +++ b/punchpipe/level0/core.py @@ -5,6 +5,7 @@ from glob import glob from datetime import datetime, timedelta +import astropy.time import numpy as np import pylibjpeg import pymysql @@ -17,7 +18,7 @@ from punchpipe.control.db import ENGPFWPacket, EngXACTPacket, SciPacket, TLMFiles, get_closest_eng_packets from punchpipe.control.util import get_database_session, load_pipeline_configuration from punchpipe.error import CCSDSPacketConstructionWarning, CCSDSPacketDatabaseUpdateWarning -from punchpipe.level0.ccsds import PACKET_APID2NAME, process_telemetry_file +from punchpipe.level0.ccsds import PACKET_APID2NAME, process_telemetry_file, get_single_packet from punchpipe.level0.meta import eci_quaternion_to_ra_dec software_version = importlib.metadata.version("punchpipe") @@ -37,11 +38,11 @@ def default(self, obj): @task -def detect_new_tlm_files(session=None) -> [str]: +def detect_new_tlm_files(pipeline_config: dict, session=None) -> [str]: if session is None: session = get_database_session() - tlm_directory = load_pipeline_configuration()['tlm_directory'] + tlm_directory = pipeline_config['tlm_directory'] found_tlm_files = set(glob(tlm_directory + '/*.tlm')) database_tlm_files = set(session.query(TLMFiles.path).distinct().all()) return list(found_tlm_files - database_tlm_files) @@ -137,7 +138,6 @@ def form_packet_entry(apid, packet, packet_num, source_tlm_file_id): PFW_STATUS=packet['PFW_STATUS'], STEP_CALC=packet['STEP_CALC'], LAST_CMD_N_STEPS=packet['LAST_CMD_N_STEPS'], - HOME_POSITION_OVRD=packet['HOME_POSITION_OVRD'], POSITION_CURR=packet['POSITION_CURR'], POSITION_CMD=packet['POSITION_CMD'], RESOLVER_POS_RAW=packet['RESOLVER_POS_RAW'], @@ -183,9 +183,10 @@ def form_packet_entry(apid, packet, packet_num, source_tlm_file_id): ) case _: warnings.warn("Unable to add packet to database.", CCSDSPacketDatabaseUpdateWarning) + return None @task -def update_tlm_database(packets, telemetry_file_path: str, session=None): +def update_tlm_database(packets, tlm_id: int, session=None): if session is None: session = get_database_session() @@ -193,8 +194,10 @@ def update_tlm_database(packets, telemetry_file_path: str, session=None): for i in range(len(this_apid_packets['CCSDS_APID'])): if apid in PACKET_APID2NAME: try: - this_packet = form_packet_entry(apid, this_apid_packets[i], i, telemetry_file_path) - session.add(this_packet) + this_packet = form_packet_entry(apid, get_single_packet(this_apid_packets, i), + i, tlm_id) + if this_packet is not None: + session.add(this_packet) except (sqlalchemy.exc.DataError, pymysql.err.DataError) as e: warnings.warn(f"Unable to add packet to database, {e}.", CCSDSPacketDatabaseUpdateWarning) session.commit() @@ -205,34 +208,36 @@ def interpolate_value(query_time, before_time, before_value, after_time, after_v return before_value elif query_time == after_time: return after_value + elif before_time == after_time: + return after_value else: return ((after_value - before_value) - * (query_time - before_time) / (after_time - before_value) + * (query_time - before_time) / (after_time - before_time) + before_value) -def get_fits_metadata(observation_time, spacecraft_id): - before_xact, after_xact = get_closest_eng_packets(EngXACTPacket, observation_time, spacecraft_id) +def get_fits_metadata(observation_time, spacecraft_id, session): + before_xact, after_xact = get_closest_eng_packets(EngXACTPacket, observation_time, spacecraft_id, session) ATT_DET_Q_BODY_WRT_ECI1 = interpolate_value(observation_time, - before_xact.timestamp, before_xact['ATT_DET_Q_BODY_WRT_ECI1'], - after_xact.timestam, after_xact['ATT_DET_Q_BODY_WRT_ECI1']) + before_xact.timestamp, before_xact.ATT_DET_Q_BODY_WRT_ECI1, + after_xact.timestamp, after_xact.ATT_DET_Q_BODY_WRT_ECI1) ATT_DET_Q_BODY_WRT_ECI2 = interpolate_value(observation_time, - before_xact.timestamp, before_xact['ATT_DET_Q_BODY_WRT_ECI2'], - after_xact.timestam, after_xact['ATT_DET_Q_BODY_WRT_ECI2']) + before_xact.timestamp, before_xact.ATT_DET_Q_BODY_WRT_ECI2, + after_xact.timestamp, after_xact.ATT_DET_Q_BODY_WRT_ECI2) ATT_DET_Q_BODY_WRT_ECI3 = interpolate_value(observation_time, - before_xact.timestamp, before_xact['ATT_DET_Q_BODY_WRT_ECI3'], - after_xact.timestam, after_xact['ATT_DET_Q_BODY_WRT_ECI3']) + before_xact.timestamp, before_xact.ATT_DET_Q_BODY_WRT_ECI3, + after_xact.timestamp, after_xact.ATT_DET_Q_BODY_WRT_ECI3) ATT_DET_Q_BODY_WRT_ECI4 = interpolate_value(observation_time, - before_xact.timestamp, before_xact['ATT_DET_Q_BODY_WRT_ECI4'], - after_xact.timestam, after_xact['ATT_DET_Q_BODY_WRT_ECI4']) + before_xact.timestamp, before_xact.ATT_DET_Q_BODY_WRT_ECI4, + after_xact.timestamp, after_xact.ATT_DET_Q_BODY_WRT_ECI4) - before_pfw, _ = get_closest_eng_packets(ENGPFWPacket, observation_time, spacecraft_id) + before_pfw, _ = get_closest_eng_packets(ENGPFWPacket, observation_time, spacecraft_id, session) return {'spacecraft_id': spacecraft_id, 'datetime': observation_time, 'ATT_DET_Q_BODY_WRT_ECI1': ATT_DET_Q_BODY_WRT_ECI1, 'ATT_DET_Q_BODY_WRT_ECI2': ATT_DET_Q_BODY_WRT_ECI2, 'ATT_DET_Q_BODY_WRT_ECI3': ATT_DET_Q_BODY_WRT_ECI3, 'ATT_DET_Q_BODY_WRT_ECI4': ATT_DET_Q_BODY_WRT_ECI4, - 'POSITION_CURR': before_pfw['POSITION_CURR']} + 'POSITION_CURR': before_pfw.POSITION_CURR} def form_preliminary_wcs(metadata, plate_scale): @@ -252,7 +257,7 @@ def form_preliminary_wcs(metadata, plate_scale): celestial_wcs.wcs.ctype = f"RA--{projection}", f"DEC-{projection}" celestial_wcs.wcs.cunit = "deg", "deg" - return calculate_helio_wcs_from_celestial(celestial_wcs, metadata['datetime'], (2048, 2048)) + return calculate_helio_wcs_from_celestial(celestial_wcs, astropy.time.Time(metadata['datetime']), (2048, 2048))[0] def image_is_okay(image, pipeline_config): """Check that the formed image conforms to image quality expectations""" diff --git a/punchpipe/level0/defs/ENG_BOOT.csv b/punchpipe/level0/defs/ENG_BOOT.csv index b879dd8..14bb5ca 100644 --- a/punchpipe/level0/defs/ENG_BOOT.csv +++ b/punchpipe/level0/defs/ENG_BOOT.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_BOOT_HDR_LEN,uint,16 ENG_BOOT_HDR_SCID,uint,8 ENG_BOOT_HDR_FILL1,uint,1 ENG_BOOT_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_CEB.csv b/punchpipe/level0/defs/ENG_CEB.csv index 236df5e..a833005 100644 --- a/punchpipe/level0/defs/ENG_CEB.csv +++ b/punchpipe/level0/defs/ENG_CEB.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_CEB_HDR_LEN,uint,16 ENG_CEB_HDR_SCID,uint,8 ENG_CEB_HDR_FILL1,uint,1 ENG_CEB_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_COMSEC.csv b/punchpipe/level0/defs/ENG_COMSEC.csv index 78a65af..e2dd250 100644 --- a/punchpipe/level0/defs/ENG_COMSEC.csv +++ b/punchpipe/level0/defs/ENG_COMSEC.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_COMSEC_HDR_LEN,uint,16 ENG_COMSEC_HDR_SCID,uint,8 ENG_COMSEC_HDR_FILL1,uint,1 ENG_COMSEC_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_DNLD.csv b/punchpipe/level0/defs/ENG_DNLD.csv index 6b3fc1b..524fd91 100644 --- a/punchpipe/level0/defs/ENG_DNLD.csv +++ b/punchpipe/level0/defs/ENG_DNLD.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_DNLD_HDR_LEN,uint,16 ENG_DNLD_HDR_SCID,uint,8 ENG_DNLD_HDR_FILL1,uint,1 ENG_DNLD_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_EVT.csv b/punchpipe/level0/defs/ENG_EVT.csv index 2ff7abb..14d7db3 100644 --- a/punchpipe/level0/defs/ENG_EVT.csv +++ b/punchpipe/level0/defs/ENG_EVT.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_EVT_HDR_LEN,uint,16 ENG_EVT_HDR_SCID,uint,8 ENG_EVT_HDR_FILL1,uint,1 ENG_EVT_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_FDC.csv b/punchpipe/level0/defs/ENG_FDC.csv index 442e7a2..ef0123f 100644 --- a/punchpipe/level0/defs/ENG_FDC.csv +++ b/punchpipe/level0/defs/ENG_FDC.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_FDC_HDR_LEN,uint,16 ENG_FDC_HDR_SCID,uint,8 ENG_FDC_HDR_FILL1,uint,1 ENG_FDC_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_FILL.csv b/punchpipe/level0/defs/ENG_FILL.csv index f44c01c..21d143e 100644 --- a/punchpipe/level0/defs/ENG_FILL.csv +++ b/punchpipe/level0/defs/ENG_FILL.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_FILL_HDR_LEN,uint,16 ENG_FILL_HDR_SCID,uint,8 ENG_FILL_HDR_FILL1,uint,1 ENG_FILL_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_HI.csv b/punchpipe/level0/defs/ENG_HI.csv index 6746989..759f899 100644 --- a/punchpipe/level0/defs/ENG_HI.csv +++ b/punchpipe/level0/defs/ENG_HI.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_HI_HDR_LEN,uint,16 ENG_HI_HDR_SCID,uint,8 ENG_HI_HDR_FILL1,uint,1 ENG_HI_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_HYD.csv b/punchpipe/level0/defs/ENG_HYD.csv index 213141c..75e85b8 100644 --- a/punchpipe/level0/defs/ENG_HYD.csv +++ b/punchpipe/level0/defs/ENG_HYD.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_HYD_HDR_LEN,uint,16 ENG_HYD_HDR_SCID,uint,8 ENG_HYD_HDR_FILL1,uint,1 ENG_HYD_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_LED.csv b/punchpipe/level0/defs/ENG_LED.csv index 611e22f..d86ad6f 100644 --- a/punchpipe/level0/defs/ENG_LED.csv +++ b/punchpipe/level0/defs/ENG_LED.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_LED_HDR_LEN,uint,16 ENG_LED_HDR_SCID,uint,8 ENG_LED_HDR_FILL1,uint,1 ENG_LED_HDR_FLASH_BLOCK,uint,15 @@ -12,9 +11,9 @@ LED_CFG_NUM_PLS,uint,7 LED2_ACTIVE_STATE,uint,1 LED_CFG_PLS_DLY,uint,7 LED_CFG_PLS_WIDTH,uint,16 -LED1_AVG_CURRENT,uint,4064 -LED2_AVG_CURRENT,uint,4064 -LED_SAMPLE_COUNT,uint,1016 +LED1_AVG_CURRENT,fill,4064 +LED2_AVG_CURRENT,fill,4064 +LED_SAMPLE_COUNT,fill,1016 LED_PLS_START_SEC,uint,32 LED_PLS_START_USEC,uint,20 LED_PLS_START_RSVD,uint,12 diff --git a/punchpipe/level0/defs/ENG_LO.csv b/punchpipe/level0/defs/ENG_LO.csv index 4beabf7..f2f987f 100644 --- a/punchpipe/level0/defs/ENG_LO.csv +++ b/punchpipe/level0/defs/ENG_LO.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_LO_HDR_LEN,uint,16 ENG_LO_HDR_SCID,uint,8 ENG_LO_HDR_FILL1,uint,1 ENG_LO_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_LZ.csv b/punchpipe/level0/defs/ENG_LZ.csv index 9eb9854..7d54c56 100644 --- a/punchpipe/level0/defs/ENG_LZ.csv +++ b/punchpipe/level0/defs/ENG_LZ.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_LZ_HDR_LEN,uint,16 ENG_LZ_HDR_SCID,uint,8 ENG_LZ_HDR_FILL1,uint,1 ENG_LZ_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_PFW.csv b/punchpipe/level0/defs/ENG_PFW.csv index 41f5025..e88c42b 100644 --- a/punchpipe/level0/defs/ENG_PFW.csv +++ b/punchpipe/level0/defs/ENG_PFW.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_PFW_HDR_LEN,uint,16 ENG_PFW_HDR_SCID,uint,8 ENG_PFW_HDR_FILL1,uint,1 ENG_PFW_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_SEQ.csv b/punchpipe/level0/defs/ENG_SEQ.csv index c31c652..1e75f34 100644 --- a/punchpipe/level0/defs/ENG_SEQ.csv +++ b/punchpipe/level0/defs/ENG_SEQ.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_SEQ_HDR_LEN,uint,16 ENG_SEQ_HDR_SCID,uint,8 ENG_SEQ_HDR_FILL1,uint,1 ENG_SEQ_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_SSV.csv b/punchpipe/level0/defs/ENG_SSV.csv index b0501e8..51f0a98 100644 --- a/punchpipe/level0/defs/ENG_SSV.csv +++ b/punchpipe/level0/defs/ENG_SSV.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_SSV_HDR_LEN,uint,16 ENG_SSV_HDR_SCID,uint,8 ENG_SSV_HDR_FILL1,uint,1 ENG_SSV_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_STM_DIAG.csv b/punchpipe/level0/defs/ENG_STM_DIAG.csv index 3448e70..954b4a6 100644 --- a/punchpipe/level0/defs/ENG_STM_DIAG.csv +++ b/punchpipe/level0/defs/ENG_STM_DIAG.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_STM_DIAG_HDR_LEN,uint,16 ENG_STM_DIAG_HDR_SCID,uint,8 ENG_STM_DIAG_HDR_FILL1,uint,1 ENG_STM_DIAG_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_STM_DUMP.csv b/punchpipe/level0/defs/ENG_STM_DUMP.csv index 4896566..1e4ee02 100644 --- a/punchpipe/level0/defs/ENG_STM_DUMP.csv +++ b/punchpipe/level0/defs/ENG_STM_DUMP.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_STM_DUMP_HDR_LEN,uint,16 ENG_STM_DUMP_HDR_SCID,uint,8 ENG_STM_DUMP_HDR_FILL1,uint,1 ENG_STM_DUMP_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_STM_ECHO.csv b/punchpipe/level0/defs/ENG_STM_ECHO.csv index 213e89c..1611db8 100644 --- a/punchpipe/level0/defs/ENG_STM_ECHO.csv +++ b/punchpipe/level0/defs/ENG_STM_ECHO.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_STM_ECHO_HDR_LEN,uint,16 ENG_STM_ECHO_HDR_SCID,uint,8 ENG_STM_ECHO_HDR_FILL1,uint,1 ENG_STM_ECHO_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_STM_HK.csv b/punchpipe/level0/defs/ENG_STM_HK.csv index 9bacf97..5a5cdaa 100644 --- a/punchpipe/level0/defs/ENG_STM_HK.csv +++ b/punchpipe/level0/defs/ENG_STM_HK.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_STM_HK_HDR_LEN,uint,16 ENG_STM_HK_HDR_SCID,uint,8 ENG_STM_HK_HDR_FILL1,uint,1 ENG_STM_HK_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_STM_LOG.csv b/punchpipe/level0/defs/ENG_STM_LOG.csv index 982fc4d..baf4e34 100644 --- a/punchpipe/level0/defs/ENG_STM_LOG.csv +++ b/punchpipe/level0/defs/ENG_STM_LOG.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_STM_LOG_HDR_LEN,uint,16 ENG_STM_LOG_HDR_SCID,uint,8 ENG_STM_LOG_HDR_FILL1,uint,1 ENG_STM_LOG_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_XACT.csv b/punchpipe/level0/defs/ENG_XACT.csv index 8595bf8..4a846de 100644 --- a/punchpipe/level0/defs/ENG_XACT.csv +++ b/punchpipe/level0/defs/ENG_XACT.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_XACT_HDR_LEN,uint,16 ENG_XACT_HDR_SCID,uint,8 ENG_XACT_HDR_FILL1,uint,1 ENG_XACT_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/defs/ENG_XTS.csv b/punchpipe/level0/defs/ENG_XTS.csv index 0ed01de..f1b6ab5 100644 --- a/punchpipe/level0/defs/ENG_XTS.csv +++ b/punchpipe/level0/defs/ENG_XTS.csv @@ -1,5 +1,4 @@ name,data_type,bit_length -ENG_XTS_HDR_LEN,uint,16 ENG_XTS_HDR_SCID,uint,8 ENG_XTS_HDR_FILL1,uint,1 ENG_XTS_HDR_FLASH_BLOCK,uint,15 diff --git a/punchpipe/level0/meta.py b/punchpipe/level0/meta.py index 2384661..dc9d168 100644 --- a/punchpipe/level0/meta.py +++ b/punchpipe/level0/meta.py @@ -43,7 +43,7 @@ def eci_quaternion_to_ra_dec(q): z_body = R @ z_eci # Calculate RA and Dec from the rotated z-vector - c = SkyCoord(z_body[0], z_body[1], z_body[2], representation_type='cartesian', unit='m') + c = SkyCoord(z_body[0], z_body[1], z_body[2], representation_type='cartesian', unit='m').fk5 ra = c.ra.deg dec = c.dec.deg roll = np.arctan2(q[1] * q[2] - q[0] * q[3], 1 / 2 - (q[2] ** 2 + q[3] ** 2))