Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] OpenPMD frontend update #4982

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ http-stream = ["requests>=2.20.0"]
idefix = ["yt_idefix[HDF5]>=2.3.0"] # externally packaged frontend
moab = ["yt[HDF5]"]
nc4-cm1 = ["yt[netCDF4]"]
open-pmd = ["yt[HDF5]"]
open-pmd = ["yt[openpmd_api]"]
owls = ["yt[HDF5]"]
owls-subfind = ["yt[HDF5]"]
ramses = ["yt[Fortran]"]
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/open_pmd/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import tests
from .data_structures import OpenPMDDataset, OpenPMDGrid, OpenPMDHierarchy
from .fields import OpenPMDFieldInfo
from .io import IOHandlerOpenPMDHDF5
from .io import IOHandlerOpenPMD
754 changes: 498 additions & 256 deletions yt/frontends/open_pmd/data_structures.py

Large diffs are not rendered by default.

35 changes: 16 additions & 19 deletions yt/frontends/open_pmd/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from yt.frontends.open_pmd.misc import is_const_component, parse_unit_dimension
from yt.units.yt_array import YTQuantity
from yt.utilities.logger import ytLogger as mylog
from yt.utilities.on_demand_imports import _h5py as h5py
from yt.utilities.physical_constants import mu_0, speed_of_light


Expand Down Expand Up @@ -141,20 +140,19 @@ class OpenPMDFieldInfo(FieldInfoContainer):

def __init__(self, ds, field_list):
f = ds._handle
bp = ds.base_path
mp = ds.meshes_path
pp = ds.particles_path

try:
fields = f[bp + mp]
for fname in fields.keys():
fields = f.meshes
for fname in list(fields):
field = fields[fname]
if isinstance(field, h5py.Dataset) or is_const_component(field):
if len(list(field)) == 1 or is_const_component(field):
# Don't consider axes.
# This appears to be a vector field of single dimensionality
ytname = str("_".join([fname.replace("_", "-")]))
ytname = str(
"_".join([fname.replace("_", "-")])
) # doesn't do anything for us
parsed = parse_unit_dimension(
np.asarray(field.attrs["unitDimension"], dtype="int64")
np.asarray(field.unit_dimension, dtype="int64")
)
unit = str(YTQuantity(1, parsed).units)
aliases = []
Expand All @@ -164,10 +162,10 @@ def __init__(self, ds, field_list):
self._mag_fields.append(ytname)
self.known_other_fields += ((ytname, (unit, aliases, None)),)
else:
for axis in field.keys():
for axis in list(field):
ytname = str("_".join([fname.replace("_", "-"), axis]))
parsed = parse_unit_dimension(
np.asarray(field.attrs["unitDimension"], dtype="int64")
np.asarray(field.unit_dimension, dtype="int64")
)
unit = str(YTQuantity(1, parsed).units)
aliases = []
Expand All @@ -182,29 +180,28 @@ def __init__(self, ds, field_list):
pass

try:
particles = f[bp + pp]
for pname in particles.keys():
particles = f.particles
for pname in list(particles):
species = particles[pname]
for recname in species.keys():
for recname in list(species):
try:
record = species[recname]
parsed = parse_unit_dimension(record.attrs["unitDimension"])
parsed = parse_unit_dimension(record.unit_dimension)
unit = str(YTQuantity(1, parsed).units)

ytattrib = str(recname).replace("_", "-")
if ytattrib == "position":
# Symbolically rename position to preserve yt's
# interpretation of the pfield particle_position is later
# derived in setup_absolute_positions in the way yt expects
ytattrib = "positionCoarse"
if isinstance(record, h5py.Dataset) or is_const_component(
record
):
if len(list(record)) == 1 or is_const_component(record):
name = ["particle", ytattrib]
self.known_particle_fields += (
(str("_".join(name)), (unit, [], None)),
)
else:
for axis in record.keys():
for axis in list(record):
aliases = []
name = ["particle", ytattrib, axis]
ytname = str("_".join(name))
Expand Down
Loading
Loading