[yt-users] Best way to count particles?

Matthew Turk matthewturk at gmail.com
Fri Oct 12 16:07:47 PDT 2012


On Fri, Oct 12, 2012 at 3:40 PM, Stephen Skory <s at skory.us> wrote:
> Hi Matt,
>
>> What's the best way to get the number of particles of a particular
>> type from a data object?
>>
>> i.e., the derived quantity way of doing:
>>
>> (dd["particle_type"] == something).sum()
>
> This should probably work, what do you think Matt?
>
> from yt.mods import *
>
> def _pcount(field, data):
>     return (data["particle_type"] == 0).sum()
>
> add_field("pcount", function=_pcount, particle_type=True)
>
> pf = load("DD0252")
>
> dd = pf.h.all_data()
>
> print dd.quantities['TotalQuantity']('pcount')

Thanks, Stephen -- that works great.

-Matt

>
>
>
> --
> Stephen Skory
> s at skory.us
> http://stephenskory.com/
> 510.621.3687 (google voice)
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org



More information about the yt-users mailing list