From 0a14180c7cbeb3078d272c15363146a726f3c16c Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 17 May 2023 09:45:26 -0700 Subject: [PATCH 1/2] Support time axes in RZ --- .../data_reader/h5py_reader/field_reader.py | 11 +++++------ .../data_reader/io_reader/field_reader.py | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py b/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py index d1431574..47617550 100644 --- a/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py +++ b/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py @@ -188,18 +188,17 @@ def read_field_circ( filename, iteration, field, coord, # Extract the metainformation coord_labels = {ii: coord.decode() for (ii,coord) in enumerate(group.attrs['axisLabels'])} - coord_label_str = ''.join(coord_labels.values()) - coord_label_str = 'm' + coord_label_str - coord_order = RZorder[coord_label_str] - - if coord_order == RZorder.mrz: + if coord_labels[0] == 'r': + coord_order = RZorder.mrz Nm, Nr, Nz = get_shape( dset ) N_pair = (Nr, Nz) - elif coord_order == RZorder.mzr: + elif coord_labels[1] == 'r': Nm, Nz, Nr = get_shape( dset ) N_pair = (Nz, Nr) + coord_order = RZorder.mzr else: raise Exception(order_error_msg) + info = FieldMetaInformation( coord_labels, N_pair, group.attrs['gridSpacing'], group.attrs['gridGlobalOffset'], group.attrs['gridUnitSI'], dset.attrs['position'], thetaMode=True ) diff --git a/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py b/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py index d69f7b37..a0ef5cb6 100644 --- a/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py +++ b/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py @@ -192,15 +192,15 @@ def read_field_circ( series, iteration, field_name, component_name, # grid spacing/offset/position coord_labels = {ii: coord for (ii, coord) in enumerate(field.axis_labels)} - coord_label_str = ''.join(coord_labels.values()) - coord_label_str = 'm' + coord_label_str - coord_order = RZorder[coord_label_str] - if coord_order is RZorder.mrz: + + if coord_labels[0] == 'r': + coord_order = RZorder.mrz Nm, Nr, Nz = component.shape N_pair = (Nr, Nz) - elif coord_order is RZorder.mzr: + elif coord_labels[1] == 'r': Nm, Nz, Nr = component.shape N_pair = (Nz, Nr) + coord_order = RZorder.mzr else: raise Exception(order_error_msg) From eb4e5a8d6cb0b671d196726b712ec7510f257f48 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 17 May 2023 09:52:53 -0700 Subject: [PATCH 2/2] Support complex files --- .../data_reader/h5py_reader/field_reader.py | 12 ++++++------ .../data_reader/io_reader/field_reader.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py b/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py index 47617550..8f27ca59 100644 --- a/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py +++ b/openpmd_viewer/openpmd_timeseries/data_reader/h5py_reader/field_reader.py @@ -268,12 +268,6 @@ def read_field_circ( filename, iteration, field, coord, else: # Extract the modes and recombine them properly - if coord_order is RZorder.mrz: - F_total = np.zeros( (2 * Nr, Nz ) ) - elif coord_order is RZorder.mzr: - F_total = np.zeros( (Nz, 2 * Nr ) ) - else: - raise Exception(order_error_msg) if m == 'all': # Sum of all the modes # - Prepare the multiplier arrays @@ -289,11 +283,13 @@ def read_field_circ( filename, iteration, field, coord, # - Sum the modes F = get_data( dset ) # (Extracts all modes) if coord_order is RZorder.mrz: + F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype ) F_total[Nr:, :] = np.tensordot( mult_above_axis, F, axes=(0, 0) )[:, :] F_total[:Nr, :] = np.tensordot( mult_below_axis, F, axes=(0, 0) )[::-1, :] elif coord_order is RZorder.mzr: + F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype ) F_total[:, Nr:] = np.tensordot( mult_above_axis, F, axes=(0, 0) )[:, :] F_total[:, :Nr] = np.tensordot( mult_below_axis, @@ -302,9 +298,11 @@ def read_field_circ( filename, iteration, field, coord, # Extract mode 0 F = get_data( dset, 0, 0 ) if coord_order is RZorder.mrz: + F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype ) F_total[Nr:, :] = F[:, :] F_total[:Nr, :] = F[::-1, :] elif coord_order is RZorder.mzr: + F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype ) F_total[:, Nr:] = F[:, :] F_total[:, :Nr] = F[:, ::-1] else: @@ -318,9 +316,11 @@ def read_field_circ( filename, iteration, field, coord, F_sin = get_data( dset, 2 * m, 0 ) F = cos * F_cos + sin * F_sin if coord_order is RZorder.mrz: + F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype ) F_total[Nr:, :] = F[:, :] F_total[:Nr, :] = (-1) ** m * F[::-1, :] elif coord_order is RZorder.mzr: + F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype ) F_total[:, Nr:] = F[:, :] F_total[:, :Nr] = (-1) ** m * F[:, ::-1] else: diff --git a/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py b/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py index a0ef5cb6..bf02afa0 100644 --- a/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py +++ b/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/field_reader.py @@ -271,12 +271,6 @@ def read_field_circ( series, iteration, field_name, component_name, else: # Extract the modes and recombine them properly - if coord_order is RZorder.mrz: - F_total = np.zeros( (2 * Nr, Nz ) ) - elif coord_order is RZorder.mzr: - F_total = np.zeros( (Nz, 2 * Nr ) ) - else: - raise Exception(order_error_msg) if m == 'all': # Sum of all the modes # - Prepare the multiplier arrays @@ -292,11 +286,13 @@ def read_field_circ( series, iteration, field_name, component_name, # - Sum the modes F = get_data( series, component ) # (Extracts all modes) if coord_order is RZorder.mrz: + F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype ) F_total[Nr:, :] = np.tensordot( mult_above_axis, F, axes=(0, 0) )[:, :] F_total[:Nr, :] = np.tensordot( mult_below_axis, F, axes=(0, 0) )[::-1, :] elif coord_order is RZorder.mzr: + F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype ) F_total[:, Nr:] = np.tensordot( mult_above_axis, F, axes=(0, 0) )[:, :] F_total[:, :Nr] = np.tensordot( mult_below_axis, @@ -307,9 +303,11 @@ def read_field_circ( series, iteration, field_name, component_name, # Extract mode 0 F = get_data( series, component, 0, 0 ) if coord_order is RZorder.mrz: + F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype ) F_total[Nr:, :] = F[:, :] F_total[:Nr, :] = F[::-1, :] elif coord_order is RZorder.mzr: + F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype ) F_total[:, Nr:] = F[:, :] F_total[:, :Nr] = F[:, ::-1] else: @@ -322,9 +320,11 @@ def read_field_circ( series, iteration, field_name, component_name, F_sin = get_data( series, component, 2 * m, 0 ) F = cos * F_cos + sin * F_sin if coord_order is RZorder.mrz: + F_total = np.zeros( (2 * Nr, Nz ), dtype=F.dtype ) F_total[Nr:, :] = F[:, :] F_total[:Nr, :] = (-1) ** m * F[::-1, :] elif coord_order is RZorder.mzr: + F_total = np.zeros( (Nz, 2 * Nr ), dtype=F.dtype ) F_total[:, Nr:] = F[:, :] F_total[:, :Nr] = (-1) ** m * F[:, ::-1] else: