[yt-users] If statement for particles existing?

Britton Smith brittonsmith at gmail.com
Fri Apr 16 09:12:14 PDT 2010


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 <http://www.astro.utoronto.ca/%7Eh-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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20100416/9e4c3dc6/attachment.htm>


More information about the yt-users mailing list