[yt-dev] Issue #1278: Unable to filter a dataset using a derived field (yt_analysis/yt)

Danielle Sponseller issues-reply at bitbucket.org
Fri Sep 16 09:26:12 PDT 2016


New issue 1278: Unable to filter a dataset using a derived field
https://bitbucket.org/yt_analysis/yt/issues/1278/unable-to-filter-a-dataset-using-a-derived

Danielle Sponseller:

When defining a particle filter, a derived field cannot be used to determine which particles to filter out. The example below shows a field defined to be equivalent to the "particle_position_x" field. When using "particle_position_x' in the filter definition, the filter works as expected, however when the derived field is used an error is returned saying that the field cannot be found.


```
#!python

import yt
import yt.units as units                                                                          

@yt.particle_filter(requires=["myField"], filtered_type='all')
def small_x(pfilter, data):
	filter = data[(pfilter.filtered_type, "myField")] < 0
	return filter
    
snap = 'GadgetDiskGalaxy'
ds = yt.load(snap, bounding_box = [[-8000, 8000], [-8000, 8000], [-8000, 8000]])
ds.add_particle_filter('small_x')

def myField(field, data):
	return data["particle_position_x"]
ds.add_field("myField", function=myField, units="kpc", particle_type = True)

ds_disk_angular_momentum = yt.ParticlePlot(ds, ('small_x', 'particle_position_x'), ('small_x', 'particle_position_y'), ('small_x', 'myField'), width=(2000, 'kpc'))
ds_disk_angular_momentum.save("Plot")
```




More information about the yt-dev mailing list