Skip to content

Commit

Permalink
BUG: fix ds.all_data() for spherical AMReX datasets
Browse files Browse the repository at this point in the history
`ds.index.level_dds` was being overwritten in `_parse_index()`, which
breaks the `all_data()` region selector. This commit instead updates
`domain_right_edge` in `_parse_header_file()`, like we do for
cylindrical datasets.
  • Loading branch information
yut23 committed Oct 10, 2024
1 parent 8640daf commit 5b6763e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
11 changes: 6 additions & 5 deletions yt/frontends/amrex/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,9 @@ def _parse_index(self):
default_ybounds = (0.0, 1.0)
default_zbounds = (0.0, 1.0)
elif self.ds.geometry == "cylindrical":
self.level_dds[:, 2] = 2 * np.pi
default_ybounds = (0.0, 1.0)
default_zbounds = (0.0, 2 * np.pi)
elif self.ds.geometry == "spherical":
# BoxLib only supports 1D spherical, so ensure
# the other dimensions have the right extent.
self.level_dds[:, 1] = np.pi
self.level_dds[:, 2] = 2 * np.pi
default_ybounds = (0.0, np.pi)
default_zbounds = (0.0, 2 * np.pi)
else:
Expand Down Expand Up @@ -908,6 +903,12 @@ def _parse_header_file(self):
dre = self.domain_right_edge.copy()
dre[2] = 2.0 * np.pi
self.domain_right_edge = dre
if self.geometry == "spherical" and self.dimensionality < 3:
dre = self.domain_right_edge.copy()
dre[2] = 2.0 * np.pi
if self.dimensionality < 2:
dre[1] = np.pi
self.domain_right_edge = dre

header_file.close()

Expand Down
57 changes: 57 additions & 0 deletions yt/frontends/amrex/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,60 @@ def test_maestro_parameters():
# Check an int parameter
assert ds.parameters["s0_interp_type"] == 3
assert type(ds.parameters["s0_interp_type"]) is int # noqa: E721


# test loading non-Cartesian coordinate systems in different dimensionalities


def check_coordsys_data(ds):
# check that level_dds is consistent with domain_width
assert_allclose(
ds.index.level_dds[0] * ds.domain_dimensions,
ds.domain_width.to_value("code_length"),
rtol=1e-12,
atol=0.0,
)

# check that we get the expected number of data points when selecting the
# entire domain
expected_size = sum(np.count_nonzero(g.child_mask) for g in ds.index.grids)
ad = ds.all_data()
assert ad["boxlib", "Temp"].size == expected_size


cyl_1d = "castro_sedov_1d_cyl_plt00150"
cyl_2d = "castro_sedov_2d_sph_in_cyl_plt00130"
sph_1d = "sedov_1d_sph_plt00120"
sph_2d = "xrb_spherical_smallplt00010"


@requires_file(cyl_1d)
def test_coordsys_1d_cylindrical():
ds = data_dir_load(cyl_1d)
assert ds.geometry == "cylindrical"
assert ds.dimensionality == 1
check_coordsys_data(ds)


@requires_file(cyl_2d)
def test_coordsys_2d_cylindrical():
ds = data_dir_load(cyl_2d)
assert ds.geometry == "cylindrical"
assert ds.dimensionality == 2
check_coordsys_data(ds)


@requires_file(sph_1d)
def test_coordsys_1d_spherical():
ds = data_dir_load(sph_1d)
assert ds.geometry == "spherical"
assert ds.dimensionality == 1
check_coordsys_data(ds)


@requires_file(sph_2d)
def test_coordsys_2d_spherical():
ds = data_dir_load(sph_2d)
assert ds.geometry == "spherical"
assert ds.dimensionality == 2
check_coordsys_data(ds)
12 changes: 12 additions & 0 deletions yt/sample_data_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@
"load_name": null,
"url": "https://yt-project.org/data/castro_sedov_2d_cyl_in_cart_plt00150.tar.gz"
},
"castro_sedov_2d_sph_in_cyl_plt00130.tar.gz": {
"hash": "ef4d081a2a2f8e10afe132768725c573631b82021e91f07782f1c1fbe043e2b5",
"load_kwargs": {},
"load_name": null,
"url": "https://yt-project.org/data/castro_sedov_2d_sph_in_cyl_plt00130.tar.gz"
},
"castro_sod_x_plt00036.tar.gz": {
"hash": "3f0a586b41e7b54fa2b3cddd50f9384feb2efe1fe1a815e7348965ae7bf88f78",
"load_kwargs": {},
Expand Down Expand Up @@ -946,6 +952,12 @@
"load_name": "DD0045/DD0045.0.h5",
"url": "https://yt-project.org/data/tiny_fof_halos.tar.gz"
},
"xrb_spherical_smallplt00010.tar.gz": {
"hash": "27ede5ed03f7c89b2afac03a368beb56d5f25f0c7c95b81f14f071a54a795783",
"load_kwargs": {},
"load_name": null,
"url": "https://yt-project.org/data/xrb_spherical_smallplt00010.tar.gz"
},
"ytdata_test.tar.gz": {
"hash": "cafb2b06ab3190ba17909585b58a4724e25f27ac72f11d6dff1a482146eb8958",
"load_kwargs": {},
Expand Down

0 comments on commit 5b6763e

Please sign in to comment.