yt-project / yt

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

BUG: defect in polar coordinate handler breaks fixed-resolution buffer #4789

Open neutrinoceros opened 9 months ago

neutrinoceros commented 9 months ago

Bug report

Bug summary

This was spotted by @forrestglines in https://github.com/yt-project/yt/pull/4323#discussion_r1465753748 I don't know yet if it's an issue with just polar coordinates or 2D dataset. Will investigate.

Code for reproduction

import yt

ds = yt.load_sample("bw_polar_2d")
slc = yt.SlicePlot(ds, "z", ("gas", "density"))
frb = slc.data_source.to_frb(width=(1, "cm"), resolution=(512, 512))
frb["r"]

Actual outcome

yt : [INFO     ] 2024-01-26 10:50:16,011 Sample dataset found in '/Users/clm/dev/yt-project/yt/bugs/parthenon/polar/bw_polar_2d/output0001.dat'
yt : [INFO     ] 2024-01-26 10:50:16,108 Parameters: current_time              = 0.05
yt : [INFO     ] 2024-01-26 10:50:16,108 Parameters: domain_dimensions         = [32 32  1]
yt : [INFO     ] 2024-01-26 10:50:16,108 Parameters: domain_left_edge          = [0. 0. 0.]
yt : [INFO     ] 2024-01-26 10:50:16,108 Parameters: domain_right_edge         = [2.         6.28318531 1.        ]
yt : [INFO     ] 2024-01-26 10:50:16,108 Parameters: cosmological_simulation   = 0
yt : [INFO     ] 2024-01-26 10:50:16,115 Using full MHD energy for thermal pressure.
yt : [INFO     ] 2024-01-26 10:50:16,202 xlim = -2.000000 2.000000
yt : [INFO     ] 2024-01-26 10:50:16,202 ylim = -2.000000 2.000000
yt : [INFO     ] 2024-01-26 10:50:16,202 Setting origin='native' for polar geometry.
yt : [INFO     ] 2024-01-26 10:50:16,203 xlim = -2.000000 2.000000
yt : [INFO     ] 2024-01-26 10:50:16,203 ylim = -2.000000 2.000000
yt : [INFO     ] 2024-01-26 10:50:16,206 Making a fixed resolution buffer of (('gas', 'density')) 800 by 800

Traceback (most recent call last):
  File "/Users/clm/dev/yt-project/yt/bugs/parthenon/polar/t.py", line 6, in <module>
    frb["r"]
    ~~~^^^^^
  File "/Users/clm/dev/yt-project/yt/yt/visualization/fixed_resolution.py", line 208, in __getitem__
    return self.get_image(item)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/clm/dev/yt-project/yt/yt/visualization/fixed_resolution.py", line 212, in get_image
    self._generate_image_and_mask(key)
  File "/Users/clm/dev/yt-project/yt/yt/visualization/fixed_resolution.py", line 600, in _generate_image_and_mask
    mask = pixelize_cylinder(
           ^^^^^^^^^^^^^^^^^^
  File "yt/utilities/lib/pixelization_routines.pyx", line 552, in yt.utilities.lib.pixelization_routines.pixelize_cylinder
ValueError: Buffer has wrong number of dimensions (expected 2, got 1)

Expected outcome

no exception

Version Information

forrestglines commented 9 months ago

I don't know yet if it's an issue with just polar coordinates or 2D dataset. Will investigate.

I think it's related to polar coordinates and not 2D datasets. In the PR where I came across this bug I also tested on a 3D polar dataset and got the same error.

neutrinoceros commented 9 months ago

Indeed, my patch (#4790) has nothing to do with dimensionality!