Skip to content

Commit 1b7aee2

Browse files
authored
Merge pull request #5112 from yut23/fix-slice-frb
BUG: fix NaNs in off-center FRB slices from ds.r
2 parents b090a4a + decac2e commit 1b7aee2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: yt/data_objects/region_expression.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ def _create_slice(self, slice_tuple):
138138
height = source.right_edge[yax] - source.left_edge[yax]
139139
# Make a resolution tuple with
140140
resolution = (int(new_slice[xax].step.imag), int(new_slice[yax].step.imag))
141-
sl = sl.to_frb(width=width, resolution=resolution, height=height)
141+
# Use the center of the slice, not the entire domain
142+
center = source.center
143+
sl = sl.to_frb(
144+
width=width, resolution=resolution, height=height, center=center
145+
)
142146
return sl
143147

144148
def _slice_to_edges(self, ax, val):

Diff for: yt/data_objects/tests/test_dataset_access.py

+13
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ def test_slice_from_r():
112112
frb4 = ds.r[0.5, 0.25:0.75:1024j, 0.25:0.75:512j]
113113
assert_equal(frb3["gas", "density"], frb4["gas", "density"])
114114

115+
# Test off-center slice
116+
offset_box = ds.box([0.0, 0.0, 0.4], [1.0, 0.5, 0.9])
117+
118+
sl5 = ds.r[0.5, 0:0.5, 0.4:0.9]
119+
sl6 = ds.slice("x", 0.5, data_source=offset_box)
120+
assert_equal(sl5["gas", "density"], sl6["gas", "density"])
121+
122+
frb5 = sl5.to_frb(
123+
width=0.5, height=0.5, resolution=(1024, 512), center=(0.5, 0.25, 0.65)
124+
)
125+
frb6 = ds.r[0.5, 0.0:0.5:1024j, 0.4:0.9:512j]
126+
assert_equal(frb5["gas", "density"], frb6["gas", "density"])
127+
115128

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

0 commit comments

Comments
 (0)