Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GDF] Grids cell width is wrongly set to 1.0 for inappropriate dimension for 2D datasets. #3629

Closed
Xarthisius opened this issue Oct 30, 2021 · 3 comments · Fixed by #3630
Closed
Labels
bug code frontends Things related to specific frontends

Comments

@Xarthisius
Copy link
Member

Xarthisius commented Oct 30, 2021

Bug report

Bug summary

I'm trying to create a simple plot for a dataset with a specific orientation: 2d, where x-axis is reduced, y-axis is horizontal and z-axis is vertical. It turns out to be pretty impossible (unless I'm missing something obvious).

Data: http://use.yt/upload/d1b9ac33

Note, you can use different data. 3D even. Just try non-standard axis orientation.

Code for reproduction

What I want to achieve (roughly):

import matplotlib.pyplot as plt
import h5py as h5
import numpy as np

with h5.File("crwind_tst_0001.h5", "r") as h5f:
    data = h5f["/data/grid_0000000000/density"][:].swapaxes(0, 2)
    data = np.squeeze(data)

fig = plt.figure(num=1, figsize=(4, 6.5))
ax = fig.add_subplot(111)
ax.set_ylim(-1000, 1000)
ax.set_xlim(-500, 500)
c = ax.imshow(
    np.log10(data.T),
    aspect="equal",
    extent=[-500, 500, -1000, 1000],
    origin="lower",
)
plt.colorbar(c)
plt.tight_layout()
fig.savefig("manual.png")

which yields:

manual

Actual outcome aka Code I've tried

  1. Default SlicePlot
import yt
from yt.visualization.image_writer import write_image

ds = yt.load("crwind_tst_0001.h5")
slc = yt.SlicePlot(ds, "x", "density")
slc.save()  ### so wrong

crwind_tst_0001_Slice_x_density

  1. Manual slicing:
import numpy as np
import yt
from yt.visualization.image_writer import write_image

ds = yt.load("crwind_tst_0001.h5")
slc = ds.slice(0, 0.0)
ds.coordinates.x_axis["x"] = 2
ds.coordinates.x_axis[0] = 2
ds.coordinates.y_axis["x"] = 1
ds.coordinates.y_axis[0] = 1
frb = slc.to_frb(ds.domain_width[1], (480, 960), center=ds.domain_center, height=ds.domain_width[2])
print(frb["gas", "density"])  ## zeros...
write_image(np.log10(frb["gas", "density"]), "semi_manual.png")  ## fails...

Expected Outcome
Having this at least documented somewhere, if somebody know how to do that... This has been asked at least twice in past week at #help @ yt-project slack.

Version Information

  • Operating System: Ubuntu 18.04
  • Python Version: 3.8
  • yt version: 4.0.1
@Xarthisius
Copy link
Member Author

@neutrinoceros (re: viz:2D label) as I mentioned in the description, I don't think the fact the dataset is 2D is relevant. I can provide 3D dataset that behaves the same way.

@neutrinoceros
Copy link
Member

I think the "2D" part of the label relates to the kind of visualisation, i.e. almost everything we do with matplotlib, and is meant to be opposed to "viz: 3D" as in volume rendering. It doesn't say anything about the dimensionality of the data itself. That's how I've been understanding and using it at least.

@Xarthisius
Copy link
Member Author

Turns out it's a frontend problem after all...

@Xarthisius Xarthisius changed the title Controlling data orientation on plots/frbs is too complicated (if even possible) [GDF] Grids cell width is wrongly set to 1.0 for inappropriate dimension for 2D datasets. Oct 31, 2021
@neutrinoceros neutrinoceros added bug code frontends Things related to specific frontends and removed viz: 2D labels Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug code frontends Things related to specific frontends
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants