@@ -155,9 +155,9 @@ def create_dataset(
155
155
packet_files = [packet_files ]
156
156
157
157
# Set up containers to store our data
158
- # We are getting a packet file that may contain multiple apids
159
- # Each apid is expected to contain consistent data fields, so we want to create a
160
- # dataset per apid .
158
+ # We are getting a packet file that may contain multiple APIDs
159
+ # Each APID is expected to contain consistent data fields, so we want to create a
160
+ # dataset per APID .
161
161
# {apid1: dataset1, apid2: dataset2, ...}
162
162
data_dict : dict [int , dict ] = {}
163
163
# Also keep track of the datatype mapping for each field
@@ -167,38 +167,38 @@ def create_dataset(
167
167
168
168
for packet_file in packet_files :
169
169
with open (packet_file , "rb" ) as f :
170
- packet_generator = list (xtce_packet_definition .packet_generator (f , ** packet_generator_kwargs ))
171
-
172
- for packet in packet_generator :
173
- apid = packet .raw_data .apid
174
- if apid not in data_dict :
175
- # This is the first packet for this APID
176
- data_dict [apid ] = collections .defaultdict (list )
177
- datatype_mapping [apid ] = {}
178
- variable_mapping [apid ] = packet .keys ()
179
-
180
- if variable_mapping [apid ] != packet .keys ():
181
- raise ValueError (
182
- f"Packet fields do not match for APID { apid } . This could be "
183
- f"due to a conditional (polymorphic) packet definition in the XTCE, while this "
184
- f"function currently only supports flat packet definitions."
185
- f"\n Expected: { variable_mapping [apid ]} ,\n got: { list (packet .keys ())} "
186
- )
187
-
188
- for key , value in packet .items ():
189
- if use_raw_values :
190
- # Use the derived value if it exists, otherwise use the raw value
191
- val = value .raw_value
192
- else :
193
- val = value
194
-
195
- data_dict [apid ][key ].append (val )
196
- if key not in datatype_mapping [apid ]:
197
- # Add this datatype to the mapping
198
- datatype_mapping [apid ][key ] = _get_minimum_numpy_datatype (
199
- key , xtce_packet_definition , use_raw_value = use_raw_values
170
+ packet_generator = xtce_packet_definition .packet_generator (f , ** packet_generator_kwargs )
171
+
172
+ for packet in packet_generator :
173
+ apid = packet .raw_data .apid
174
+ if apid not in data_dict :
175
+ # This is the first packet for this APID
176
+ data_dict [apid ] = collections .defaultdict (list )
177
+ datatype_mapping [apid ] = {}
178
+ variable_mapping [apid ] = set (packet .keys ())
179
+
180
+ if variable_mapping [apid ] != packet .keys ():
181
+ raise ValueError (
182
+ f"Packet fields do not match for APID { apid } . This could be "
183
+ f"due to a conditional (polymorphic) packet definition in the XTCE, while this "
184
+ f"function currently only supports flat packet definitions."
185
+ f"\n Expected: { variable_mapping [apid ]} ,\n got: { list (packet .keys ())} "
200
186
)
201
187
188
+ for key , value in packet .items ():
189
+ if use_raw_values :
190
+ # Use the derived value if it exists, otherwise use the raw value
191
+ val = value .raw_value
192
+ else :
193
+ val = value
194
+
195
+ data_dict [apid ][key ].append (val )
196
+ if key not in datatype_mapping [apid ]:
197
+ # Add this datatype to the mapping
198
+ datatype_mapping [apid ][key ] = _get_minimum_numpy_datatype (
199
+ key , xtce_packet_definition , use_raw_value = use_raw_values
200
+ )
201
+
202
202
# Turn the dict into an xarray dataset
203
203
dataset_by_apid = {}
204
204
0 commit comments