yt-project / yt

Main yt repository
http://yt-project.org
Other
461 stars 276 forks source link

Cut Regions fail for particle-based fields #1976

Open chummels opened 6 years ago

chummels commented 6 years ago

Bug report

Bug summary

Cut regions, a method for filtering on fields, fail for particle-based fields. See yt docs here: http://yt-project.org/docs/dev/analyzing/filtering.html#cut-regions

Code for reproduction

import yt
ds = yt.load('FIRE_M12i_ref11/snapshot_600.hdf5')
ad = ds.all_data()
cool = ad.cut_region(["obj['temperature'] < 1e5"])
yt.ProjectionPlot(ds, 'x', ('gas', 'density'), data_source=cool).save()

Actual outcome

python ~/src/yt-data/test_cut_region.py
/Users/chummels/src/yt-conda/lib/python3.6/site-packages/cmocean/tools.py:76: MatplotlibDeprecationWarning: The is_string_like function was deprecated in version 2.1.
  if not mpl.cbook.is_string_like(rgbin[0]):
yt : [INFO     ] 2018-08-15 16:18:08,198 Calculating time from 1.000e+00 to be 4.355e+17 seconds
yt : [INFO     ] 2018-08-15 16:18:08,198 Assuming length units are in kpc/h (comoving)
yt : [INFO     ] 2018-08-15 16:18:08,221 Parameters: current_time              = 4.3545571088051386e+17 s
yt : [INFO     ] 2018-08-15 16:18:08,221 Parameters: domain_dimensions         = [1 1 1]
yt : [INFO     ] 2018-08-15 16:18:08,222 Parameters: domain_left_edge          = [ 0.  0.  0.]
yt : [INFO     ] 2018-08-15 16:18:08,222 Parameters: domain_right_edge         = [ 60000.  60000.  60000.]
yt : [INFO     ] 2018-08-15 16:18:08,222 Parameters: cosmological_simulation   = 1
yt : [INFO     ] 2018-08-15 16:18:08,223 Parameters: current_redshift          = 0.0
yt : [INFO     ] 2018-08-15 16:18:08,223 Parameters: omega_lambda              = 0.728
yt : [INFO     ] 2018-08-15 16:18:08,223 Parameters: omega_matter              = 0.272
yt : [INFO     ] 2018-08-15 16:18:08,223 Parameters: hubble_constant           = 0.702
yt : [INFO     ] 2018-08-15 16:18:08,426 Allocating for 4.787e+06 particles
Initializing coarse index : 100%|██████████████████████████████████████████████████████| 10/10 [00:00<00:00, 18.73it/s]
Initializing refined index: 100%|██████████████████████████████████████████████████████| 10/10 [00:01<00:00, 17.05it/s]
yt : [INFO     ] 2018-08-15 16:18:11,421 Loading KDTree from snapshot_600.hdf5.kdtree
yt : [INFO     ] 2018-08-15 16:18:11,676 Detected hash mismatch, regenerating KDTree
yt : [INFO     ] 2018-08-15 16:18:11,810 Allocating KDTree for 753678 particles
yt : [INFO     ] 2018-08-15 16:18:12,664 xlim = 0.000000 60000.000000
yt : [INFO     ] 2018-08-15 16:18:12,665 ylim = 0.000000 60000.000000
yt : [INFO     ] 2018-08-15 16:18:12,665 xlim = 0.000000 60000.000000
yt : [INFO     ] 2018-08-15 16:18:12,665 ylim = 0.000000 60000.000000
yt : [INFO     ] 2018-08-15 16:18:12,668 Making a fixed resolution buffer of (('gas', 'density')) 800 by 800
Traceback (most recent call last):
  File "/Users/chummels/src/yt-data/test_cut_region.py", line 5, in <module>
    yt.ProjectionPlot(ds, 'x', ('gas', 'density'), data_source=cool).save()
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/visualization/plot_window.py", line 1483, in __init__
    aspect=aspect)
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/visualization/plot_window.py", line 670, in __init__
    PlotWindow.__init__(self, *args, **kwargs)
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/visualization/plot_window.py", line 229, in __init__
    self._setup_plots()
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/visualization/plot_window.py", line 789, in _setup_plots
    image = self.frb[f]
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/visualization/fixed_resolution.py", line 135, in __getitem__
    int(self.antialias))
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/geometry/coordinates/cartesian_coordinates.py", line 180, in pixelize
    antialias, dimension, periodic)
  File "/Users/chummels/src/yt-conda/src/yt-git/yt/geometry/coordinates/cartesian_coordinates.py", line 274, in _ortho_pixelize
    le = data_source.data_source.left_edge.in_units('code_length')
AttributeError: 'YTCutRegion' object has no attribute 'left_edge'

Expected outcome

To make a projection

chummels commented 5 years ago

Maybe it's OK that this doesn't work? You can get much of the same functionality with particle filters, which do work in yt4. Not sure what it would take to get this working. At the very least, before this is closed we should document that cut regions do not work for particle-based datasets on the Filtering docs page: http://yt-project.org/docs/dev/analyzing/filtering.html

jzuhone commented 3 years ago

So I'm coming back to this. We're always trying to make sure that operations and scripts are as the same as possible between different frontends. In the past, we always thought about trying to make a cut region work for particles, but @ngoldbaum always argued that it didn't make sense (I can't remember his reasoning--if you have a chance Nathan I'd love to see you comment on this).

But what if we applied the logic the other way around? What if instead we generalized the particle filter to the grid-based data? So you would end up creating a new field type corresponding to the filter. This would seem to have the following benefits:

  1. We could have one operation across frontends to do the same thing.
  2. Using a function to define a field filter would be much better than the awkward string-based way of doing cut regions.

Thoughts?