[yt-users] If statement for particles existing?

Matthew Turk matthewturk at gmail.com
Fri Apr 16 16:04:14 PDT 2010


Hi Libby,

One other option is to do something like:

if na.any(pf.h.grid_particle_count):

which should be True if any grid has > 0 particles and False if all have == 0.

-Matt

On Fri, Apr 16, 2010 at 12:12 PM, Britton Smith <brittonsmith at gmail.com> wrote:
> Hi Libby,
>
> You could also try getting the NumberOfParticles parameter from the
> parameter file with:
> pf.get_parameter('NumberOfParticles',type=int)
>
> Britton
>
> On Fri, Apr 16, 2010 at 10:04 AM, Elizabeth Harper-Clark
> <h-clark at astro.utoronto.ca> wrote:
>>
>> Hi guys,
>>
>> I sometimes have particles in my sims and when i do I want to plot them.
>> At the moment I have:
>>         if sp["ParticleMassMsun"].size > 0:
>>             p.modify["particles"](1.0, p_size=10.0, col='k')
>>
>> but if there are no particles I get this error message:
>>
>> yt         INFO       2010-04-16 11:58:29,408 Getting ParticleMassMsun
>> using ParticleIO
>> Traceback (most recent call last):
>>   File "Density_movie.py", line 29, in <module>
>>     if sp["ParticleMassMsun"].size > 0:
>>   File
>> "/scratch/YT-x86_64/lib/python2.5/site-packages/yt-2.0dev-py2.5-linux-x86_64.egg/yt/lagos/BaseDataTypes.py",
>> line 249, in __getitem__
>>     self.get_data(key)
>>   File
>> "/scratch/YT-x86_64/lib/python2.5/site-packages/yt-2.0dev-py2.5-linux-x86_64.egg/yt/lagos/BaseDataTypes.py",
>> line 1636, in get_data
>>     self[field] = self.particles[field]
>>   File
>> "/scratch/YT-x86_64/lib/python2.5/site-packages/yt-2.0dev-py2.5-linux-x86_64.egg/yt/lagos/ParticleIO.py",
>> line 45, in __getitem__
>>     return self.get_data(key)
>>   File
>> "/scratch/YT-x86_64/lib/python2.5/site-packages/yt-2.0dev-py2.5-linux-x86_64.egg/yt/lagos/ParticleIO.py",
>> line 91, in get_data
>>     conv_factors)
>>   File
>> "/scratch/YT-x86_64/lib/python2.5/site-packages/yt-2.0dev-py2.5-linux-x86_64.egg/yt/lagos/DataReadingFuncs.py",
>> line 206, in _read_particles
>>     filenames, ids, conv_factors = zip(*sorted(zip(filenames, ids,
>> conv_factors)))
>> ValueError: need more than 0 values to unpack
>>
>>
>> Can anyone think of a better if statement to check if i have particles
>> that doesn't crash YT if there isn't?
>>
>> Many thanks,
>>
>> Libby
>>
>>
>>
>> --
>> Elizabeth Harper-Clark MA MSci
>> PhD Candidate, Astrophysics, UofT
>>
>> www.astro.utoronto.ca/~h-clark
>> h-clark at cita.utoronto.ca
>> AIM: edphc1
>> MSN: edphc1 at hotmail.com
>> Skype: eharperclark
>> Office phone: 416-978-5759
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>
>
> _______________________________________________
> 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