yt-project / yt

Main yt repository
http://yt-project.org
Other
469 stars 280 forks source link

[BUG] Fix off-axis rendering when center is not [0.5, 0.5, 0.5], fix periodicity #5059

Open cphyc opened 2 days ago

cphyc commented 2 days ago

PR Summary

The off-axis renderer introduced in #4741 has an issue when the center and the center in rotated frame do not coincide (which happens when it isn't 0.5, 0.5, 0.5 afaik).

In addition, it wraps around the boundaries of the width of the plotting window rather than the simulation domain (if required).

This PR fixes both.

PR Checklist

Bug reproduction:

import numpy as np
import yt

ds = yt.load_sample("output_00080")
ad = ds.all_data()

center = ds.arr(ad.argmax("density"))

sp = ds.sphere(center, (200, "kpc"))

n = np.array([1, 1, 1.])
n /= np.linalg.norm(n)
p = yt.ProjectionPlot(ds, n, "density", center=center, data_source=sp, width=(400, "kpc"), weight_field=("gas", "density"))
p.set_zlim(("gas", "density"), 1e-4, 5)
p.save("frames/")
Before With this PR
info_00080_OffAxisProjection_density_density info_00080_OffAxisProjection_density_density
cphyc commented 1 day ago

@yt-fido test this please