diff --git a/yt/visualization/plot_window.py b/yt/visualization/plot_window.py index 78f96f14a28..5ce9bd790ea 100644 --- a/yt/visualization/plot_window.py +++ b/yt/visualization/plot_window.py @@ -26,6 +26,7 @@ validate_moment, ) from yt.geometry.api import Geometry +from yt.geometry.oct_geometry_handler import OctreeIndex from yt.units.unit_object import Unit # type: ignore from yt.units.unit_registry import UnitParseError # type: ignore from yt.units.yt_array import YTArray, YTQuantity @@ -2494,7 +2495,12 @@ def __init__( is_sph_field = finfo.is_sph_field particle_datasets = (ParticleDataset, StreamParticlesDataset) - if isinstance(data_source.ds, particle_datasets) and is_sph_field: + dom_width = data_source.ds.domain_width + cubic_domain = dom_width.max() == dom_width.min() + + if (isinstance(data_source.ds, particle_datasets) and is_sph_field) or ( + isinstance(data_source.ds.index, OctreeIndex) and cubic_domain + ): center_use = parse_center_array(center, ds=data_source.ds, axis=None) else: center_use = center_rot diff --git a/yt/visualization/volume_rendering/off_axis_projection.py b/yt/visualization/volume_rendering/off_axis_projection.py index 3c2359a3f80..f31919de196 100644 --- a/yt/visualization/volume_rendering/off_axis_projection.py +++ b/yt/visualization/volume_rendering/off_axis_projection.py @@ -444,21 +444,22 @@ def temp_weightfield(field, data): # We need the width of the plot window in projected coordinates, # i.e. we ignore the z-component wmax = width[:2].max() - - # Normalize the positions & dx so that they are in the range [-0.5, 0.5] + # Recenter positions w.r.t. center of the plot window xyz = np.stack( - [ - ((data_source["index", k] - center[i]) / wmax).to("1").d - for i, k in enumerate("xyz") - ], - axis=-1, + [data_source["index", k] - center[i] for i, k in enumerate("xyz")], axis=-1 ) + # If we have periodic boundaries, we need to wrap the positions for idim, periodic in enumerate(data_source.ds.periodicity): if not periodic: continue - # Wrap into [-0.5, +0.5] - xyz[..., idim] = (xyz[..., idim] + 0.5) % 1 - 0.5 + w = data_source.ds.domain_width[idim] + # Wrap into [-w/2, +w/2] + xyz[..., idim] = (xyz[..., idim] + w / 2) % w - w / 2 + + # Rescale to [-0.5, +0.5] + xyz /= wmax + xyz = xyz.to("1").d dx = (data_source["index", "dx"] / wmax).to("1").d