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

GridSpacing: Per-Component UnitSI & UnitDimension #7

Merged
merged 1 commit into from
Nov 13, 2018
Merged
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
5 changes: 3 additions & 2 deletions openpmd_updater/Updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""
import packaging.version
from openpmd_updater.backends.HDF5 import HDF5
from openpmd_updater.transforms.v2_0_0 import DataOrder, \
ExtensionString, Version, ParticleBoundary
from openpmd_updater.transforms.v2_0_0 import \
DataOrder, GridUnit, ParticleBoundary, ExtensionString, Version


class Updater(object):
Expand All @@ -30,6 +30,7 @@ def __init__(self, filename, verbose=False):
self.updates = {
"2.0.0" : [
DataOrder.DataOrder, # must be before move of particleBoundary
GridUnit.GridUnit,
ParticleBoundary.ParticleBoundary,
ExtensionString.ExtensionString,
Version.Version # must be last
Expand Down
73 changes: 73 additions & 0 deletions openpmd_updater/transforms/v2_0_0/GridUnit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
This file is part of the openPMD-updater.

Copyright 2018 openPMD contributors
Authors: Axel Huebl
License: ISC
"""

from openpmd_updater.transforms.ITransform import ITransform
import numpy as np


class GridUnit(ITransform):
"""
GridSpacing: Per-Component UnitSI & UnitDimension

In openPMD 1.*, mesh grid spacings were always spatial.
openPMD 2.0 introduces a notation to allow arbitrary axes on meshes.

openPMD standard: 1.*.* -> 2.0.0

Related openPMD-standard issues:
https://github.com/openPMD/openPMD-standard/pull/122
https://github.com/openPMD/openPMD-standard/pull/193
"""

"""Name and description of the transformation"""
name = "gridUnit", \
"allow non-spatial gridSpacing in meshes"

"""Minimum openPMD standard version that is supported by this transformation"""
min_version = "1.0.0"

"""openPMD standard version is fulfilled by this transformation"""
to_version = "2.0.0"

def __init__(self, backend):
"""Open a file"""
self.fb = backend

def transform(self, in_place=True):
"""Perform transformation"""
if not in_place:
raise NotImplementedError("Only in-place transformation implemented!")

self.fb.cd(None)
basePath = "/data/" # fixed in openPMD v1
meshes_path = self.fb.get_attr("meshesPath").decode()

iterations = self.fb.list_groups("/data/")

for it in iterations:
abs_meshes_path = "/data/" + str(it) + "/" + meshes_path
# vector/tensor and scalar meshes
all_meshes = self.fb.list_groups(abs_meshes_path) + self.fb.list_data(abs_meshes_path)

self.fb.cd(abs_meshes_path)

for mesh in all_meshes:
old_grid_unit_SI = self.fb.get_attr("gridUnitSI", mesh)

grid_ndim = len(self.fb.get_attr("gridSpacing", mesh))

new_grid_unit_SI = np.ones((grid_ndim, ), dtype=np.float64) * \
old_grid_unit_SI

self.fb.add_attr("gridUnitSI", new_grid_unit_SI, mesh)

# openPMD 1.* dimensions were spatial (L)
grid_unit_dimension = np.zeros((grid_ndim * 7, ), dtype=np.float64)
grid_unit_dimension[::7] = 1.0

self.fb.add_attr("gridUnitDimension", grid_unit_dimension, mesh)
Empty file.