Skip to content

Commit

Permalink
Backport PR #5112: BUG: fix NaNs in off-center FRB slices from ds.r
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin authored and meeseeksmachine committed Feb 4, 2025
1 parent e98ec49 commit dc64e4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit dc64e4e

Please sign in to comment.