-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4414 from chrishavlin/gadget_header_array_reduction
- Loading branch information
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import numpy as np | ||
|
||
import yt | ||
from yt.testing import requires_file, requires_module | ||
from yt.utilities.on_demand_imports import _h5py as h5py | ||
|
||
|
||
@requires_file("snapshot_033/snap_033.0.hdf5") | ||
@requires_module("h5py") | ||
def test_gadget_header_array_reduction(tmp_path): | ||
# first get a real header | ||
ds = yt.load("snapshot_033/snap_033.0.hdf5") | ||
hvals = ds._get_hvals() | ||
hvals_orig = hvals.copy() | ||
# wrap some of the scalar values in nested arrays | ||
hvals["Redshift"] = np.array([hvals["Redshift"]]) | ||
hvals["Omega0"] = np.array([[hvals["Omega0"]]]) | ||
|
||
# drop those header values into a fake header-only file | ||
tmp_snpshot_dir = tmp_path / "snapshot_033" | ||
tmp_snpshot_dir.mkdir() | ||
tmp_header_only_file = str(tmp_snpshot_dir / "fake_gadget_header.hdf5") | ||
with h5py.File(tmp_header_only_file, mode="w") as f: | ||
headergrp = f.create_group("Header") | ||
for field, val in hvals.items(): | ||
headergrp.attrs[field] = val | ||
|
||
# trick the dataset into using the header file and make sure the | ||
# arrays are reduced | ||
ds._input_filename = tmp_header_only_file | ||
hvals = ds._get_hvals() | ||
for attr in ("Redshift", "Omega0"): | ||
assert hvals[attr] == hvals_orig[attr] | ||
assert isinstance(hvals[attr], np.ndarray) is False |