Skip to content

Commit

Permalink
Fix units for older versions of unyt
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Nov 20, 2024
1 parent 80736ad commit 28143f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions yt/visualization/volume_rendering/off_axis_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,22 @@ def temp_weightfield(field, data):
# i.e. we ignore the z-component
wmax = width[:2].max()
# Recenter positions w.r.t. center of the plot window
xyz = np.stack(
[data_source["index", k] - center[i] for i, k in enumerate("xyz")], axis=-1
xyz = data_source.ds.arr(
np.zeros((len(data_source[vol.field]), 3)), "code_length"
)

# If we have periodic boundaries, we need to wrap the positions
for idim, periodic in enumerate(data_source.ds.periodicity):
axis = "xyz"[idim]
xyz[..., idim] = data_source["index", axis] - center[idim]
if not periodic:
continue
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
xyz = (xyz / wmax).to("1").d

dx = (data_source["index", "dx"] / wmax).to("1").d

Expand Down

0 comments on commit 28143f8

Please sign in to comment.