[yt-users] If statement for particles existing?

Elizabeth Harper-Clark h-clark at astro.utoronto.ca
Fri Apr 16 09:04:19 PDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20100416/2c783523/attachment.htm>


More information about the yt-users mailing list