diff --git a/gridlock/read.py b/gridlock/read.py index 9df3e08..9be52b1 100644 --- a/gridlock/read.py +++ b/gridlock/read.py @@ -83,7 +83,7 @@ class GridReadMixin(GridPosMixin): else: w = [1] - c_min, c_max = (self.xyz[plane.axis][i] for i in [0, -1]) + c_min, c_max = (self.shifted_xyz(which_shifts)[plane.axis][i] for i in [0, -1]) if plane.pos < c_min or plane.pos > c_max: raise GridError('Coordinate of selected plane must be within simulation domain') diff --git a/gridlock/test/test_grid.py b/gridlock/test/test_grid.py index 9f2e4f3..c6c8ae7 100644 --- a/gridlock/test/test_grid.py +++ b/gridlock/test/test_grid.py @@ -226,6 +226,18 @@ def test_extent_accepts_scalar_like_inputs() -> None: assert_allclose([extent.center, extent.span, extent.min, extent.max], [3.0, 4.0, 1.0, 5.0]) +def test_get_slice_uses_shifted_grid_bounds() -> None: + grid = Grid([[0, 1, 2], [0, 1, 2], [0, 1, 2]], shifts=[[0.5, 0, 0]]) + cell_data = numpy.arange(numpy.prod(grid.cell_data_shape), dtype=float).reshape(grid.cell_data_shape) + + grid_slice = grid.get_slice(cell_data, Plane(x=2.0), which_shifts=0) + + assert_allclose(grid_slice, cell_data[0, 1, :, :]) + + with pytest.raises(GridError): + grid.get_slice(cell_data, Plane(x=2.1), which_shifts=0) + + def test_visualize_isosurface_sampling_uses_preview_lattice(monkeypatch: pytest.MonkeyPatch) -> None: