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

Backport PR #5112 on branch yt-4.4.x (BUG: fix NaNs in off-center FRB slices from ds.r) #5113

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
6 changes: 5 additions & 1 deletion yt/data_objects/region_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def _create_slice(self, slice_tuple):
height = source.right_edge[yax] - source.left_edge[yax]
# Make a resolution tuple with
resolution = (int(new_slice[xax].step.imag), int(new_slice[yax].step.imag))
sl = sl.to_frb(width=width, resolution=resolution, height=height)
# Use the center of the slice, not the entire domain
center = source.center
sl = sl.to_frb(
width=width, resolution=resolution, height=height, center=center
)
return sl

def _slice_to_edges(self, ax, val):
Expand Down
13 changes: 13 additions & 0 deletions yt/data_objects/tests/test_dataset_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def test_slice_from_r():
frb4 = ds.r[0.5, 0.25:0.75:1024j, 0.25:0.75:512j]
assert_equal(frb3["gas", "density"], frb4["gas", "density"])

# Test off-center slice
offset_box = ds.box([0.0, 0.0, 0.4], [1.0, 0.5, 0.9])

sl5 = ds.r[0.5, 0:0.5, 0.4:0.9]
sl6 = ds.slice("x", 0.5, data_source=offset_box)
assert_equal(sl5["gas", "density"], sl6["gas", "density"])

frb5 = sl5.to_frb(
width=0.5, height=0.5, resolution=(1024, 512), center=(0.5, 0.25, 0.65)
)
frb6 = ds.r[0.5, 0.0:0.5:1024j, 0.4:0.9:512j]
assert_equal(frb5["gas", "density"], frb6["gas", "density"])


def test_point_from_r():
ds = fake_amr_ds(fields=["density"], units=["g/cm**3"])
Expand Down
Loading