Skip to content

Commit

Permalink
backing up
Browse files Browse the repository at this point in the history
  • Loading branch information
laspsandoval committed May 8, 2024
1 parent 6315472 commit 51254e5
Show file tree
Hide file tree
Showing 12 changed files with 7,056 additions and 73 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SHCOARSE,TIMESPINSTART,TIMESPINSTARTSUB,DURATION,SPINNUMBER,TIMESPINDATA,SPINPERIOD,SPINPHASE,SPINPERIODVALID,SPINPHASEVALID,SPINPERIODSOURCE,CATBEDHEATERFLAG,INTS,INTN1,INTN2,HWMODE,IMCENB,LEFTDEFLECTIONCHARGE,RIGHTDEFLECTIONCHARGE
445015650,445015650,0,15000,29667711,445015650,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015665,445015665,0,14999,29667712,445015665,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015680,445015680,0,14999,29667713,445015680,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015694,445015694,999,15001,29667714,445015695,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015710,445015710,1,14998,29667715,445015710,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015725,445015725,0,14999,29667716,445015725,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015739,445015739,999,15001,29667717,445015740,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015755,445015755,1,14998,29667718,445015755,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015770,445015770,0,14999,29667719,445015770,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015784,445015784,999,15001,29667720,445015785,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015800,445015800,1,14998,29667721,445015800,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015815,445015815,0,14999,29667722,445015815,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015829,445015829,999,15001,29667723,445015830,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015845,445015845,1,14998,29667724,445015845,46875,65535,1,1,0,0,1,1,1,0,1,0,0
445015860,445015860,0,14999,29667725,445015860,46875,65535,1,1,0,0,1,1,1,0,1,0,0

Large diffs are not rendered by default.

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions imap_processing/tests/ultra/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ def ccsds_path_events():
)


@pytest.fixture()
def ccsds_path_theta_0():
"""Returns the ccsds directory."""
return (
Path(sys.modules[__name__.split(".")[0]].__file__).parent
/ "tests"
/ "ultra"
/ "test_data"
/ "l0"
/ "FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00"
"_20240207T102740.CCSDS"
)


@pytest.fixture()
def ccsds_path_tof():
"""Returns the ccsds directory."""
Expand Down Expand Up @@ -90,6 +104,23 @@ def aux_test_path():
)


@pytest.fixture()
def aux_test_path_theta_0():
"""Returns the xtce auxiliary test data directory."""
filename = (
"FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00"
"_ULTRA_AUXILIARY_20240207T102753_.csv"
)
return (
Path(sys.modules[__name__.split(".")[0]].__file__).parent
/ "tests"
/ "ultra"
/ "test_data"
/ "l0"
/ filename
)


@pytest.fixture()
def events_test_path():
"""Returns the xtce auxiliary test data directory."""
Expand All @@ -107,6 +138,23 @@ def events_test_path():
)


@pytest.fixture()
def events_test_path_theta_0():
"""Returns the xtce auxiliary test data directory."""
filename = (
"FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00"
"_Ultra_Image_Raw_Event_20240207T102746_.csv"
)
return (
Path(sys.modules[__name__.split(".")[0]].__file__).parent
/ "tests"
/ "ultra"
/ "test_data"
/ "l0"
/ filename
)


@pytest.fixture()
def tof_test_path():
"""Returns the xtce auxiliary test data directory."""
Expand All @@ -122,3 +170,20 @@ def tof_test_path():
/ "l0"
/ filename
)


@pytest.fixture()
def events_fsw_comparison_theta_0():
"""Returns the xtce auxiliary test data directory."""
filename = (
"FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00"
"_Ultra_Image_Raw_Event_20240207T102746_withFSWcalcs.csv"
)
return (
Path(sys.modules[__name__.split(".")[0]].__file__).parent
/ "tests"
/ "ultra"
/ "test_data"
/ "l0"
/ filename
)
61 changes: 61 additions & 0 deletions imap_processing/tests/ultra/unit/test_decom_apid_880_theta_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import numpy as np
import pandas as pd
import pytest

from imap_processing import decom
from imap_processing.ultra.l0.decom_ultra import decom_ultra_apids
from imap_processing.ultra.l0.ultra_utils import ULTRA_AUX
from imap_processing.utils import group_by_apid


@pytest.fixture()
def decom_test_data(ccsds_path_theta_0, xtce_path):
"""Read test data from file"""
data_packet_list = decom.decom_packets(ccsds_path_theta_0, xtce_path)
return data_packet_list


def test_aux_enumerated(decom_test_data):
"""Test if enumerated values derived correctly"""

count = 0 # count number of packets with APID 880
total_packets = 15

grouped_data = group_by_apid(decom_test_data)
apid_data = grouped_data[880]

for packet in apid_data:
assert packet.data["SPINPERIODVALID"].derived_value == "VALID"
assert packet.data["SPINPHASEVALID"].derived_value == "VALID"
assert packet.data["SPINPERIODSOURCE"].derived_value == "SAFING"
assert packet.data["CATBEDHEATERFLAG"].derived_value == "UNFLAGGED"
count += 1

assert count == total_packets


def test_aux_mode(decom_test_data):
"""Test if enumerated values derived correctly"""

for packet in decom_test_data:
if packet.header["PKT_APID"].derived_value == 880:
assert packet.data["HWMODE"].derived_value == "MODE0"
assert packet.data["IMCENB"].derived_value == "MODE1"
assert packet.data["LEFTDEFLECTIONCHARGE"].derived_value == "MODE0"
assert packet.data["RIGHTDEFLECTIONCHARGE"].derived_value == "MODE0"


def test_aux_decom(ccsds_path_theta_0, xtce_path, aux_test_path_theta_0):
"""This function reads validation data and checks that
decom data matches validation data for auxiliary packet"""

decom_ultra = decom_ultra_apids(ccsds_path_theta_0, xtce_path, ULTRA_AUX.apid[0])
df = pd.read_csv(aux_test_path_theta_0, index_col="SHCOARSE")

np.testing.assert_array_equal(df.TIMESPINSTART, decom_ultra["TIMESPINSTART"])
np.testing.assert_array_equal(df.TIMESPINSTARTSUB, decom_ultra["TIMESPINSTARTSUB"])
np.testing.assert_array_equal(df.DURATION, decom_ultra["DURATION"])
np.testing.assert_array_equal(df.SPINNUMBER, decom_ultra["SPINNUMBER"])
np.testing.assert_array_equal(df.TIMESPINDATA, decom_ultra["TIMESPINDATA"])
np.testing.assert_array_equal(df.SPINPERIOD, decom_ultra["SPINPERIOD"])
np.testing.assert_array_equal(df.SPINPHASE, decom_ultra["SPINPHASE"])
59 changes: 59 additions & 0 deletions imap_processing/tests/ultra/unit/test_decom_apid_896_theta_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import numpy as np
import pandas as pd
import pytest

from imap_processing.cdf.defaults import GlobalConstants
from imap_processing.ultra.l0.decom_ultra import decom_ultra_apids
from imap_processing.ultra.l0.ultra_utils import ULTRA_EVENTS


@pytest.fixture()
def decom_ultra(ccsds_path_theta_0, xtce_path):
"""Data for decom_ultra"""
data_packet_list = decom_ultra_apids(
ccsds_path_theta_0, xtce_path, ULTRA_EVENTS.apid[0]
)
# Convert dictionary to DataFrame
decom_ultra_df = pd.DataFrame(data_packet_list)

# Now apply the filtering
filtered_decom_ultra = decom_ultra_df[
(decom_ultra_df["COIN_TYPE"] != GlobalConstants.INT_FILLVAL)
]
return filtered_decom_ultra


def test_image_raw_events_decom(decom_ultra, events_test_path_theta_0):
"""This function reads validation data and checks that decom data
matches validation data for image rate packet"""

df = pd.read_csv(events_test_path_theta_0, index_col="TimeTag")

np.testing.assert_array_equal(df["Spin"], decom_ultra["SPIN"])
np.testing.assert_array_equal(df["AbortFlag"], decom_ultra["ABORTFLAG"])
np.testing.assert_array_equal(df["StartDelay"], decom_ultra["STARTDELAY"])
np.testing.assert_array_equal(df["CoinType"], decom_ultra["COIN_TYPE"])
np.testing.assert_array_equal(df["StartType"], decom_ultra["START_TYPE"])
np.testing.assert_array_equal(df["StopType"], decom_ultra["STOP_TYPE"])
np.testing.assert_array_equal(df["StartPosTDC"], decom_ultra["START_POS_TDC"])
np.testing.assert_array_equal(df["StopNorthTDC"], decom_ultra["STOP_NORTH_TDC"])
np.testing.assert_array_equal(df["StopEastTDC"], decom_ultra["STOP_EAST_TDC"])
np.testing.assert_array_equal(df["StopSouthTDC"], decom_ultra["STOP_SOUTH_TDC"])
np.testing.assert_array_equal(df["StopWestTDC"], decom_ultra["STOP_WEST_TDC"])
np.testing.assert_array_equal(df["CoinNorthTDC"], decom_ultra["COIN_NORTH_TDC"])
np.testing.assert_array_equal(df["CoinSouthTDC"], decom_ultra["COIN_SOUTH_TDC"])
np.testing.assert_array_equal(df["CoinDiscrete"], decom_ultra["COIN_DISCRETE_TDC"])
np.testing.assert_array_equal(df["EnergyPH"], decom_ultra["ENERGY_PH"])
np.testing.assert_array_equal(df["PulseWidth"], decom_ultra["PULSE_WIDTH"])
np.testing.assert_array_equal(df["Bin"], decom_ultra["BIN"])


def test_image_raw_events_decom_flags(decom_ultra, events_test_path_theta_0):
"""This function reads validation data and checks that decom data
matches validation data for image rate packet"""

df = pd.read_csv(events_test_path_theta_0, index_col="TimeTag")

np.testing.assert_array_equal(df["PHCompSL"], decom_ultra["EVENT_FLAG_PHCMPSL"])
np.testing.assert_array_equal(df["PHCompSR"], decom_ultra["EVENT_FLAG_PHCMPSR"])
np.testing.assert_array_equal(df["PHCompCD"], decom_ultra["EVENT_FLAG_PHCMPCD"])
55 changes: 55 additions & 0 deletions imap_processing/tests/ultra/unit/test_ultra_l1a.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import dataclasses

import numpy as np
import pandas as pd
import pytest
from cdflib.xarray import cdf_to_xarray

from imap_processing.cdf.defaults import GlobalConstants
from imap_processing.ultra import ultra_cdf_attrs
from imap_processing.ultra.l0.decom_ultra import decom_ultra_apids
from imap_processing.ultra.l0.ultra_utils import (
Expand All @@ -21,6 +24,15 @@ def decom_ultra_aux(ccsds_path, xtce_path):
return data_packet_list


@pytest.fixture()
def decom_ultra_aux_theta_0(ccsds_path_theta_0, xtce_path):
"""Data for decom_ultra_events"""
data_packet_list = decom_ultra_apids(
ccsds_path_theta_0, xtce_path, ULTRA_AUX.apid[0]
)
return data_packet_list


@pytest.fixture()
def decom_ultra_rates(ccsds_path, xtce_path):
"""Data for decom_ultra_rates"""
Expand All @@ -37,6 +49,15 @@ def decom_ultra_events(ccsds_path_events, xtce_path):
return data_packet_list


@pytest.fixture()
def decom_ultra_events_theta_0(ccsds_path_theta_0, xtce_path):
"""Data for decom_ultra_events"""
data_packet_list = decom_ultra_apids(
ccsds_path_theta_0, xtce_path, ULTRA_EVENTS.apid[0]
)
return data_packet_list


@pytest.fixture()
def decom_ultra_tof(ccsds_path_tof, xtce_path):
"""Data for decom_ultra_tof"""
Expand Down Expand Up @@ -172,6 +193,40 @@ def test_xarray_events(decom_ultra_events, decom_ultra_aux, events_test_path):
assert cointype_attr == expected_cointype_attr


def test_xarray_events_theta_0(
decom_ultra_events_theta_0, decom_ultra_aux_theta_0, events_fsw_comparison_theta_0
):
"""This function checks that a xarray was
successfully created from the decom_ultra_events data."""

dataset = create_dataset(
{
ULTRA_EVENTS.apid[0]: decom_ultra_events_theta_0,
ULTRA_AUX.apid[0]: decom_ultra_aux_theta_0,
}
)

df = pd.read_csv(events_fsw_comparison_theta_0)
df.replace(-1, GlobalConstants.INT_FILLVAL, inplace=True)

np.testing.assert_array_equal(df["CoinType"], dataset.COIN_TYPE.data)
np.testing.assert_array_equal(df["StartType"], dataset.START_TYPE.data)
np.testing.assert_array_equal(df["StopType"], dataset.STOP_TYPE.data)
np.testing.assert_array_equal(df["StartPosTDC"], dataset.START_POS_TDC.data)
np.testing.assert_array_equal(df["StopNorthTDC"], dataset.STOP_NORTH_TDC.data)
np.testing.assert_array_equal(df["StopEastTDC"], dataset.STOP_EAST_TDC.data)
np.testing.assert_array_equal(df["StopSouthTDC"], dataset.STOP_SOUTH_TDC.data)
np.testing.assert_array_equal(df["StopWestTDC"], dataset.STOP_WEST_TDC.data)
np.testing.assert_array_equal(df["CoinNorthTDC"], dataset.COIN_NORTH_TDC.data)
np.testing.assert_array_equal(df["CoinSouthTDC"], dataset.COIN_SOUTH_TDC.data)
np.testing.assert_array_equal(df["CoinDiscreteTDC"], dataset.COIN_DISCRETE_TDC.data)
np.testing.assert_array_equal(df["EnergyOrPH"], dataset.ENERGY_PH.data)
np.testing.assert_array_equal(df["PulseWidth"], dataset.PULSE_WIDTH.data)
np.testing.assert_array_equal(df["PhaseAngle"], dataset.PHASE_ANGLE.data)
np.testing.assert_array_equal(df["Bin"], dataset.BIN.data)
np.testing.assert_array_equal(df["CnT"], dataset.EVENT_FLAG_CNT.data)


def test_cdf_aux(
ccsds_path,
xtce_path,
Expand Down
Loading

0 comments on commit 51254e5

Please sign in to comment.