Skip to content

Commit

Permalink
add NetCDF Postprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Rykath committed May 10, 2023
1 parent ab6e84f commit 7cc5427
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions profit/run/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,21 @@ def HDF5Postprocessor(self, data):
for key in f.keys():
if key in data.dtype.names:
data[key] = f[key][:]


# --- netCDF Postprocessor --- #


@Postprocessor.wrap("netcdf", config=dict(path="stdout"))
def NetCDFPostprocessor(self, data):
"""Postprocessor to read output from a HDF5 file
- variables are assumed to be stored with the correct key and able to be converted immediately
- not extensively tested
"""
import xarray as xr

ds = xr.open_dataset(self.path)
for key in ds.keys():
if key in data.dtype.names:
data[key] = ds[key]
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ install_requires =
tqdm
zmq
f90nml
xarray
importlib_metadata; python_version<'3.8'
importlib_metadata; python_version>='3.10' # required by chaospy
tests_require = pytest
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added tests/unit_tests/run/post.nc
Binary file not shown.
File renamed without changes.
7 changes: 5 additions & 2 deletions tests/unit_tests/run/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ def chdir_pytest():
# === initialization === #


POSTPROCESSORS = ["numpytxt", "json", "hdf5"]
POSTPROCESSORS = ["numpytxt", "json", "hdf5", "netcdf"]
INPUT_DTYPE = [("u", float), ("v", float)]
OUTPUTS = {"f": [1.4, 1.3, 1.2], "g": 10}
OUTPUT_DTYPE = [("f", float, (3,)), ("g", float)]
OPTIONS = {"numpytxt": {"names": ["f", "g"]}}
POST_EXTENSION = {"netcdf": "nc"}


@pytest.fixture
Expand All @@ -43,7 +44,9 @@ def postprocessor(request, logger):
from profit.run.command import Postprocessor

return Postprocessor[label](
path=f"{label}.post", **OPTIONS.get(label, {}), logger_parent=logger
path=f"post.{POST_EXTENSION.get(label, label)}",
**OPTIONS.get(label, {}),
logger_parent=logger,
)


Expand Down

0 comments on commit 7cc5427

Please sign in to comment.