Skip to content

Commit b36dc43

Browse files
authored
Merge pull request #371 from RemiLehe/prepare_v2
Support reading of 'rt' lasy files
2 parents 88ab6e1 + dbd1cd5 commit b36dc43

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,23 @@ def read_field_circ( filename, iteration, field, coord,
198198
field_path = join_infile_path( field, coord )
199199
group, dset = find_dataset( dfile, iteration, field_path )
200200

201+
# Current simulation time
202+
time = (it.attrs['time'] + group.attrs['timeOffset']) * it.attrs['timeUnitSI']
203+
201204
# Extract the metainformation
202205
coord_labels = {ii: coord.decode() for (ii,coord) in
203206
enumerate(group.attrs['axisLabels'])}
204-
coord_label_str = ''.join(coord_labels.values())
205-
coord_label_str = 'm' + coord_label_str
206-
coord_order = RZorder[coord_label_str]
207-
208-
# Current simulation time
209-
time = (it.attrs['time'] + group.attrs['timeOffset']) * it.attrs['timeUnitSI']
210-
211-
if coord_order == RZorder.mrz:
207+
if coord_labels[0] == 'r':
208+
coord_order = RZorder.mrz
212209
Nm, Nr, Nz = get_shape( dset )
213210
N_pair = (Nr, Nz)
214-
elif coord_order == RZorder.mzr:
211+
elif coord_labels[1] == 'r':
215212
Nm, Nz, Nr = get_shape( dset )
216213
N_pair = (Nz, Nr)
214+
coord_order = RZorder.mzr
217215
else:
218216
raise Exception(order_error_msg)
217+
219218
info = FieldMetaInformation( coord_labels, N_pair,
220219
group.attrs['gridSpacing'], group.attrs['gridGlobalOffset'],
221220
group.attrs['gridUnitSI'], dset.attrs['position'], time,
@@ -287,12 +286,6 @@ def read_field_circ( filename, iteration, field, coord,
287286
else:
288287

289288
# Extract the modes and recombine them properly
290-
if coord_order is RZorder.mrz:
291-
F_total = np.zeros( (2 * Nr, Nz ), dtype=dset.dtype )
292-
elif coord_order is RZorder.mzr:
293-
F_total = np.zeros( (Nz, 2 * Nr ), dtype=dset.dtype )
294-
else:
295-
raise Exception(order_error_msg)
296289
if m == 'all':
297290
# Sum of all the modes
298291
# - Prepare the multiplier arrays
@@ -308,11 +301,13 @@ def read_field_circ( filename, iteration, field, coord,
308301
# - Sum the modes
309302
F = get_data( dset ) # (Extracts all modes)
310303
if coord_order is RZorder.mrz:
304+
F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype )
311305
F_total[Nr:, :] = np.tensordot( mult_above_axis,
312306
F, axes=(0, 0) )[:, :]
313307
F_total[:Nr, :] = np.tensordot( mult_below_axis,
314308
F, axes=(0, 0) )[::-1, :]
315309
elif coord_order is RZorder.mzr:
310+
F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype )
316311
F_total[:, Nr:] = np.tensordot( mult_above_axis,
317312
F, axes=(0, 0) )[:, :]
318313
F_total[:, :Nr] = np.tensordot( mult_below_axis,
@@ -321,9 +316,11 @@ def read_field_circ( filename, iteration, field, coord,
321316
# Extract mode 0
322317
F = get_data( dset, 0, 0 )
323318
if coord_order is RZorder.mrz:
319+
F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype )
324320
F_total[Nr:, :] = F[:, :]
325321
F_total[:Nr, :] = F[::-1, :]
326322
elif coord_order is RZorder.mzr:
323+
F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype )
327324
F_total[:, Nr:] = F[:, :]
328325
F_total[:, :Nr] = F[:, ::-1]
329326
else:
@@ -337,9 +334,11 @@ def read_field_circ( filename, iteration, field, coord,
337334
F_sin = get_data( dset, 2 * m, 0 )
338335
F = cos * F_cos + sin * F_sin
339336
if coord_order is RZorder.mrz:
337+
F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype )
340338
F_total[Nr:, :] = F[:, :]
341339
F_total[:Nr, :] = (-1) ** m * F[::-1, :]
342340
elif coord_order is RZorder.mzr:
341+
F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype )
343342
F_total[:, Nr:] = F[:, :]
344343
F_total[:, :Nr] = (-1) ** m * F[:, ::-1]
345344
else:

openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ def read_field_circ( series, iteration, field_name, component_name,
203203
# grid spacing/offset/position
204204

205205
coord_labels = {ii: coord for (ii, coord) in enumerate(field.axis_labels)}
206-
coord_label_str = ''.join(coord_labels.values())
207-
coord_label_str = 'm' + coord_label_str
208-
coord_order = RZorder[coord_label_str]
209-
if coord_order is RZorder.mrz:
206+
207+
if coord_labels[0] == 'r':
208+
coord_order = RZorder.mrz
210209
Nm, Nr, Nz = component.shape
211210
N_pair = (Nr, Nz)
212-
elif coord_order is RZorder.mzr:
211+
elif coord_labels[1] == 'r':
213212
Nm, Nz, Nr = component.shape
214213
N_pair = (Nz, Nr)
214+
coord_order = RZorder.mzr
215215
else:
216216
raise Exception(order_error_msg)
217217
time = (it.time + field.time_offset) * it.time_unit_SI
@@ -285,12 +285,6 @@ def read_field_circ( series, iteration, field_name, component_name,
285285
else:
286286

287287
# Extract the modes and recombine them properly
288-
if coord_order is RZorder.mrz:
289-
F_total = np.zeros( (2 * Nr, Nz ), dtype=component.dtype )
290-
elif coord_order is RZorder.mzr:
291-
F_total = np.zeros( (Nz, 2 * Nr ), dtype=component.dtype )
292-
else:
293-
raise Exception(order_error_msg)
294288
if m == 'all':
295289
# Sum of all the modes
296290
# - Prepare the multiplier arrays
@@ -306,11 +300,13 @@ def read_field_circ( series, iteration, field_name, component_name,
306300
# - Sum the modes
307301
F = get_data( series, component ) # (Extracts all modes)
308302
if coord_order is RZorder.mrz:
303+
F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype )
309304
F_total[Nr:, :] = np.tensordot( mult_above_axis,
310305
F, axes=(0, 0) )[:, :]
311306
F_total[:Nr, :] = np.tensordot( mult_below_axis,
312307
F, axes=(0, 0) )[::-1, :]
313308
elif coord_order is RZorder.mzr:
309+
F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype )
314310
F_total[:, Nr:] = np.tensordot( mult_above_axis,
315311
F, axes=(0, 0) )[:, :]
316312
F_total[:, :Nr] = np.tensordot( mult_below_axis,
@@ -321,9 +317,11 @@ def read_field_circ( series, iteration, field_name, component_name,
321317
# Extract mode 0
322318
F = get_data( series, component, 0, 0 )
323319
if coord_order is RZorder.mrz:
320+
F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype )
324321
F_total[Nr:, :] = F[:, :]
325322
F_total[:Nr, :] = F[::-1, :]
326323
elif coord_order is RZorder.mzr:
324+
F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype )
327325
F_total[:, Nr:] = F[:, :]
328326
F_total[:, :Nr] = F[:, ::-1]
329327
else:
@@ -336,9 +334,11 @@ def read_field_circ( series, iteration, field_name, component_name,
336334
F_sin = get_data( series, component, 2 * m, 0 )
337335
F = cos * F_cos + sin * F_sin
338336
if coord_order is RZorder.mrz:
337+
F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype )
339338
F_total[Nr:, :] = F[:, :]
340339
F_total[:Nr, :] = (-1) ** m * F[::-1, :]
341340
elif coord_order is RZorder.mzr:
341+
F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype )
342342
F_total[:, Nr:] = F[:, :]
343343
F_total[:, :Nr] = (-1) ** m * F[:, ::-1]
344344
else:

0 commit comments

Comments
 (0)