Skip to content

Commit 6af8925

Browse files
maxinelasptech3371
andauthored
* update telemetry_generator to be more generic * first pass at glows xtce * updated generator to use correct IntegerParameterType * First pass at GLOWS decom * Updating glows decom to properly process data into dictionary * Updating decom to include direct events * Finalizing code, adding smaller test data file and combined XML, updating documentation and tests * Updating data classes to use attributes, and changing names * Removing keys from data class and getting attribute names from the packet * Move INT to SINT in telemetry_generator Co-authored-by: Tenzin Choedon <36522642+tech3371@users.noreply.github.com> * Addressing code review comments --------- Co-authored-by: Tenzin Choedon <tenzin.choedon@lasp.colorado.edu>
1 parent b41fac9 commit 6af8925

14 files changed

Lines changed: 921 additions & 40 deletions

File tree

docs/source/reference/glows.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. _glows:
2+
3+
GLOWS (Global Solar Wind Structure)
4+
===================================
5+
6+
.. currentmodule:: imap_processing.glows
7+
8+
This is the GLOWS Instrument module, which contains the code for processing
9+
data from the GLOWS instrument.
10+
11+
The L0 code to decommutate the CCSDS packet data can be found below.
12+
13+
.. autosummary::
14+
:toctree: generated/
15+
:template: autosummary.rst
16+
:recursive:
17+
18+
imap_processing.glows.l0.decom_glows
19+
imap_processing.glows.l0.glows_l0_data

docs/source/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Instruments
1515
.. toctree::
1616
:maxdepth: 1
1717

18+
glows
1819
swe
1920

2021

imap_processing/glows/__init__.py

Whitespace-only changes.

imap_processing/glows/l0/__init__.py

Whitespace-only changes.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from enum import Enum
2+
from pathlib import Path
3+
4+
from bitstring import ReadError
5+
from space_packet_parser import parser, xtcedef
6+
7+
from imap_processing import imap_module_directory
8+
from imap_processing.glows.l0.glows_l0_data import DirectEventL0, HistogramL0
9+
10+
11+
class GlowsParams(Enum):
12+
"""Enum class for Glows packet data.
13+
14+
Attributes
15+
----------
16+
HIST_APID : int
17+
Histogram packet APID
18+
DE_APID : int
19+
Direct event APID
20+
"""
21+
22+
HIST_APID = 1480
23+
DE_APID = 1481
24+
25+
26+
def decom_packets(
27+
packet_file_path: str,
28+
) -> tuple[list[HistogramL0], list[DirectEventL0]]:
29+
"""Decom GLOWS data packets using GLOWS packet definition.
30+
31+
Parameters
32+
----------
33+
packet_file_path : str
34+
Path to data packet path with filename.
35+
36+
Returns
37+
-------
38+
data : tuple[list[HistogramL0], list[DirectEventL0]]
39+
A tuple with two pieces: one list of the GLOWS histogram data, in GlowsHistL0
40+
instances, and one list of the GLOWS direct event data, in GlowsDeL0 instance
41+
"""
42+
# Define paths
43+
xtce_document = Path(
44+
f"{imap_module_directory}/glows/packet_definitions/GLX_COMBINED.xml"
45+
)
46+
47+
packet_definition = xtcedef.XtcePacketDefinition(xtce_document)
48+
glows_parser = parser.PacketParser(packet_definition)
49+
50+
histdata = []
51+
dedata = []
52+
53+
with open(packet_file_path, "rb") as binary_data:
54+
try:
55+
glows_packets = glows_parser.generator(
56+
binary_data,
57+
buffer_read_size_bytes=5790778,
58+
)
59+
60+
for packet in glows_packets:
61+
apid = packet.header["PKT_APID"].derived_value
62+
# Do something with the packet data
63+
if apid == GlowsParams.HIST_APID.value:
64+
hist_l0 = HistogramL0(packet)
65+
histdata.append(hist_l0)
66+
67+
if apid == GlowsParams.DE_APID.value:
68+
de_l0 = DirectEventL0(packet)
69+
dedata.append(de_l0)
70+
71+
except ReadError as e:
72+
print(e)
73+
print("This may mean reaching the end of an incomplete packet.")
74+
75+
return histdata, dedata
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
class HistogramL0:
2+
"""Data structure for storing GLOWS histogram packet data.
3+
4+
Parameters
5+
----------
6+
packet : tuple[list]
7+
Histogram packet yielded from space_packet_parser.generate_packets.
8+
9+
Attributes
10+
----------
11+
packet_keys : tuple[str]
12+
Data names from the packet
13+
SHCOARSE : int
14+
CCSDS Packet Time Stamp (coarse time)
15+
STARTID : int
16+
Histogram Start ID
17+
ENDID : int
18+
Histogram End ID
19+
FLAGS : int
20+
Histogram flags
21+
SWVER : int
22+
Version of SW used for generation
23+
SEC : int
24+
Block start time (IMAP), seconds
25+
SUBSEC : int
26+
Block start time (IMAP), subseconds
27+
OFFSETSEC : int
28+
Block end time (IMAP), seconds
29+
OFFSETSUBSEC : int
30+
Block end time (IMAP), subseconds
31+
GLXSEC : int
32+
Block start time (GLOWS), seconds
33+
GLXSUBSEC : int
34+
Block start time (GLOWS), Subseconds
35+
GLXOFFSEC : int
36+
Block end time (GLOWS), seconds
37+
GLXOFFSUBSEC : int
38+
Block end time (GLOWS), subseconds
39+
SPINS : int
40+
Number of spins
41+
NBINS : int
42+
Number of bins
43+
TEMPAVG : int
44+
Mean filter temperature
45+
TEMPVAR : int
46+
Variance of filter temperature
47+
HVAVG : int
48+
Mean CEM voltage
49+
HVVAR : int
50+
Variance of CEM voltage
51+
SPAVG : int
52+
Mean spin period
53+
SPVAR : int
54+
Variance of spin period
55+
ELAVG : int
56+
Mean length of event impulse
57+
ELVAR : int
58+
Variance of event-impulse length
59+
EVENTS : int
60+
Number of events
61+
HISTOGRAM_DATA : int
62+
List of histogram data values
63+
"""
64+
65+
def __repr__(self):
66+
"""Print the data.
67+
68+
Returns
69+
-------
70+
String representation of GlowsHistL0
71+
"""
72+
output = "{"
73+
for key in self.packet_keys:
74+
output += f"{key}: {getattr(self, key)}, "
75+
return output + "}"
76+
77+
def __init__(self, packet):
78+
self.packet_keys = []
79+
for key, value in packet.data.items():
80+
if key != "HISTOGRAM_DATA":
81+
setattr(self, key, value.derived_value)
82+
else:
83+
setattr(self, key, self._convert_histogram_data(value.raw_value))
84+
85+
self.packet_keys.append(key)
86+
87+
def _convert_histogram_data(self, binary_hist_data: str) -> list[int]:
88+
"""Convert the raw histogram data into a list.
89+
90+
This method converts a binary number into a list of histogram values by
91+
splitting up the raw binary value into 8-bit segments.
92+
93+
Parameters
94+
----------
95+
binary_hist_data : str
96+
Raw data read from the packet, in binary format.
97+
98+
Returns
99+
-------
100+
histograms: list[int]
101+
List of binned histogram data
102+
"""
103+
# Convert the histogram data from a large raw string into a list of 8 bit values
104+
histograms = []
105+
for i in range(8, len(binary_hist_data), 8):
106+
histograms.append(int(binary_hist_data[i - 8 : i], 2))
107+
108+
if len(histograms) != 3599:
109+
raise ValueError(
110+
f"Histogram packet is lacking bins. Expected a count of 3599, "
111+
f"actually received {len(histograms)}"
112+
)
113+
114+
return histograms
115+
116+
117+
class DirectEventL0:
118+
"""Data structure for storing GLOWS direct event packet data.
119+
120+
Parameters
121+
----------
122+
packet : tuple[list]
123+
Direct event packet yielded from space_packet_parser.generate_packets.
124+
125+
Attributes
126+
----------
127+
packet_keys : tuple[str]
128+
Data names from the packet
129+
SHCOARSE : int
130+
CCSDS Packet Time Stamp (coarse time)
131+
SEC : int
132+
Data timestamp, seconds counter.
133+
LEN : int
134+
Number of packets in data set.
135+
SEQ : int
136+
Packet sequence in data set.
137+
138+
"""
139+
140+
def __repr__(self):
141+
"""Print the data.
142+
143+
Returns
144+
-------
145+
String representation of GlowsDeL0
146+
"""
147+
output = "{"
148+
for key in self.packet_keys:
149+
output += f"{key}: {getattr(self, key)}, "
150+
return output + "}"
151+
152+
def __init__(self, packet):
153+
self.packet_keys = []
154+
for key, value in packet.data.items():
155+
setattr(self, key, value.derived_value)
156+
self.packet_keys.append(key)

0 commit comments

Comments
 (0)