Skip to content

Commit

Permalink
Merge pull request #56 from AngelFP/update_openpmd_viewer
Browse files Browse the repository at this point in the history
Update attributes in `FieldMetaInformation`
  • Loading branch information
AngelFP authored Aug 12, 2023
2 parents 70e4e35 + caa398c commit 5709264
Showing 1 changed file with 62 additions and 27 deletions.
89 changes: 62 additions & 27 deletions visualpic/data_reading/openpmd_data_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from openpmd_viewer.openpmd_timeseries.data_reader.h5py_reader import (
field_reader as fr)
from openpmd_viewer.openpmd_timeseries import FieldMetaInformation
from openpmd_viewer import __version__
viewer_version = __version__.split('.')
viewer_version = [int(v) for v in viewer_version]
new_metainformation = (viewer_version[0] > 1) or (viewer_version[1] >= 8)


class OpenPMDDataReader(DataReader):
Expand Down Expand Up @@ -66,7 +70,8 @@ def read_field_metadata(self, iteration, field_name, component_name):
# Axis metadata.
md['axis'] = {}
info = self.get_field_meta_info(
iteration, field_name, component_name, axis_labels, field_geometry)
iteration, field_name, component_name, axis_labels, field_geometry,
t)
for axis in axis_labels:
md['axis'][axis] = {}
md['axis'][axis]['units'] = 'm'
Expand All @@ -78,27 +83,27 @@ def read_field_metadata(self, iteration, field_name, component_name):
return md

def get_field_meta_info(self, iteration, field, comp, axis_labels,
geometry):
geometry, t):
""" Get the `FieldMetaInformation` of the field. """
if self.backend == 'h5py':
filename = self.iteration_to_file[iteration]
if geometry in ['thetaMode']:
return read_circ_field_metadata_h5py(
filename, iteration, field, comp)
filename, iteration, field, comp, t)
elif geometry in ["1dcartesian", "2dcartesian", "3dcartesian"]:
return read_cartesian_field_metadata_h5py(
filename, iteration, field, comp, axis_labels)
filename, iteration, field, comp, axis_labels, t)
elif self.backend == 'openpmd-api':
if geometry in ['thetaMode']:
return read_circ_field_metadata_io(
self.series, iteration, field, comp)
self.series, iteration, field, comp, t)
elif geometry in ["1dcartesian", "2dcartesian", "3dcartesian"]:
return read_cartesian_field_metadata_io(
self.series, iteration, field, comp, axis_labels)
self.series, iteration, field, comp, axis_labels, t)


def read_cartesian_field_metadata_h5py(filename, iteration, field_name,
component_name, axis_labels):
component_name, axis_labels, t):
"""
Get `FieldMetaInformation` of cartesian field using `h5py` backend.
Expand Down Expand Up @@ -127,15 +132,22 @@ def read_cartesian_field_metadata_h5py(filename, iteration, field_name,
# Extract the metainformation
shape = list(fr.get_shape(dset))
axes = {i: axis_labels[i] for i in range(len(axis_labels))}
info = FieldMetaInformation(
axes, shape, group.attrs['gridSpacing'],
group.attrs['gridGlobalOffset'], group.attrs['gridUnitSI'],
dset.attrs['position'])

if new_metainformation:
info = FieldMetaInformation(
axes, shape, group.attrs['gridSpacing'],
group.attrs['gridGlobalOffset'], group.attrs['gridUnitSI'],
dset.attrs['position'], t, iteration)
else:
info = FieldMetaInformation(
axes, shape, group.attrs['gridSpacing'],
group.attrs['gridGlobalOffset'], group.attrs['gridUnitSI'],
dset.attrs['position'])
return info


def read_cartesian_field_metadata_io(series, iteration, field_name,
component_name, axis_labels):
component_name, axis_labels, t):
"""
Get `FieldMetaInformation` of cartesian field using `io` backend.
Expand Down Expand Up @@ -164,15 +176,22 @@ def read_cartesian_field_metadata_io(series, iteration, field_name,
# Extract the metainformation
shape = component.shape
axes = {i: axis_labels[i] for i in range(len(axis_labels))}
info = FieldMetaInformation(
axes, shape,
field.grid_spacing, field.grid_global_offset,
field.grid_unit_SI, component.position)
if new_metainformation:
info = FieldMetaInformation(
axes, shape,
field.grid_spacing, field.grid_global_offset,
field.grid_unit_SI, component.position,
t, iteration)
else:
info = FieldMetaInformation(
axes, shape,
field.grid_spacing, field.grid_global_offset,
field.grid_unit_SI, component.position)
return info


def read_circ_field_metadata_h5py(filename, iteration, field_name,
component_name):
component_name, t):
"""
Get `FieldMetaInformation` of thetaMode field using `h5py` backend.
Expand All @@ -198,15 +217,23 @@ def read_circ_field_metadata_h5py(filename, iteration, field_name,

# Extract the metainformation
Nm, Nr, Nz = fr.get_shape(dset)
info = FieldMetaInformation(
{0: 'r', 1: 'z'}, (Nr, Nz),
group.attrs['gridSpacing'], group.attrs['gridGlobalOffset'],
group.attrs['gridUnitSI'], dset.attrs['position'], thetaMode=True)
if new_metainformation:
info = FieldMetaInformation(
{0: 'r', 1: 'z'}, (Nr, Nz),
group.attrs['gridSpacing'], group.attrs['gridGlobalOffset'],
group.attrs['gridUnitSI'], dset.attrs['position'], t, iteration,
thetaMode=True)
else:
info = FieldMetaInformation(
{0: 'r', 1: 'z'}, (Nr, Nz),
group.attrs['gridSpacing'], group.attrs['gridGlobalOffset'],
group.attrs['gridUnitSI'], dset.attrs['position'], thetaMode=True)

return info


def read_circ_field_metadata_io(series, iteration, field_name, component_name):
def read_circ_field_metadata_io(series, iteration, field_name, component_name,
t):
"""
Get `FieldMetaInformation` of thetaMode field using `io` backend.
Expand All @@ -232,11 +259,19 @@ def read_circ_field_metadata_io(series, iteration, field_name, component_name):

# Extract the metainformation
Nm, Nr, Nz = component.shape
info = FieldMetaInformation(
{0: 'r', 1: 'z'}, (Nr, Nz),
field.grid_spacing, field.grid_global_offset,
field.grid_unit_SI, component.position, thetaMode=True)
return info
if new_metainformation:
info = FieldMetaInformation(
{0: 'r', 1: 'z'}, (Nr, Nz),
field.grid_spacing, field.grid_global_offset,
field.grid_unit_SI, component.position, t, iteration,
thetaMode=True)
return info
else:
info = FieldMetaInformation(
{0: 'r', 1: 'z'}, (Nr, Nz),
field.grid_spacing, field.grid_global_offset,
field.grid_unit_SI, component.position, thetaMode=True)
return info


def determine_field_units(field_name):
Expand Down

0 comments on commit 5709264

Please sign in to comment.