yt.data_objects.particle_filters module¶

This is a library for defining and using particle filters.

class yt.data_objects.particle_filters.DummyFieldInfo[source]

Bases: object

particle_type = True
class yt.data_objects.particle_filters.ParticleFilter(name, function, requires, filtered_type)[source]

Bases: object

apply(dobj)[source]
available(field_list)[source]
missing(field_list)[source]
wrap_func(field_name, old_fi)[source]
yt.data_objects.particle_filters.add_particle_filter(name, function, requires=None, filtered_type='all')[source]

Create a new particle filter in the global namespace of filters

A particle filter is a short name that corresponds to an algorithm for filtering a set of particles into a subset. This is useful for creating new particle types based on a cut on a particle field, such as particle mass, ID or type.

Note

Alternatively, you can make use of the particle_filter() decorator to define a new particle filter.

Parameters: name (string) – The name of the particle filter. New particle fields with particle type set by this name will be added to any dataset that enables this particle filter. function (reference to a function) – The function that defines the particle filter. The function should accept two arguments: a reference to a particle filter object and a reference to an abstract yt data object. See the example below. requires (a list of field names) – A list of field names required by the particle filter definition. filtered_type (string) – The name of the particle type to be filtered.

Example

>>> import yt

>>> def _stars(pfilter, data):
...     return data[(pfilter.filtered_type, 'particle_type')] == 2

>>> yt.add_particle_filter("stars", function=_stars, filtered_type='all',
...                        requires=["particle_type"])

>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
[  1.68243760e+38   1.65690882e+38   1.65813321e+38 ...,   2.04238266e+38
2.04523901e+38   2.04770938e+38] g

yt.data_objects.particle_filters.particle_filter(name=None, requires=None, filtered_type='all')[source]

A decorator that adds a new particle filter

A particle filter is a short name that corresponds to an algorithm for filtering a set of particles into a subset. This is useful for creating new particle types based on a cut on a particle field, such as particle mass, ID or type.

Note

Alternatively, you can make use of the add_particle_filter() function to define a new particle filter using a more declarative syntax.

Parameters: name (string) – The name of the particle filter. New particle fields with particle type set by this name will be added to any dataset that enables this particle filter. If not set, the name will be inferred from the name of the filter function. function (reference to a function) – The function that defines the particle filter. The function should accept two arguments: a reference to a particle filter object and a reference to an abstract yt data object. See the example below. requires (a list of field names) – A list of field names required by the particle filter definition. filtered_type (string) – The name of the particle type to be filtered.

Example

>>> import yt

>>> # define a filter named "stars"
>>> @yt.particle_filter(requires=["particle_type"], filtered_type='all')
>>> def stars(pfilter, data):
...     return data[(pfilter.filtered_type, 'particle_type')] == 2

>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')