Skip to content

Commit

Permalink
Fix off-axis rendering when center is not [0.5, 0.5, 0.5]
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Nov 20, 2024
1 parent 9e483ce commit 80736ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 7 additions & 1 deletion yt/visualization/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions yt/visualization/volume_rendering/off_axis_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 80736ad

Please sign in to comment.