[yt-users] Particles in volume rendering

Stephen Skory stephenskory at yahoo.com
Mon Aug 2 08:55:13 PDT 2010


Hi Stella,


>    Does anyone know an easy way to include particles positions  (i.e. as small 
>spheres) in a volume rendering? It occurred to me that I could  add high values 
>to the locations of the particles within the field that is being  rendered and 
>then define the transfer function in order to pick them out.   However, I'm not 
>sure how to modify the field data to do this. Any  suggestions?


I've been doing something similar to this with some (but not great) success, but 
not exactly the same as you've described. Instead of plotting the particles as 
small spheres, I translate them into a density using the Cloud In Cell code 
included in yt, which is then treated like any other density field (like 
'Density').

The main is to define a new field that translates particles to density. This 
example picks out star particles; it should be easy to remove this if you like 
by eliminating the 'sel' stuff below.

import yt.lagos.UniversalFields as uf

def _pdensity_pyx(field, data):
    blank = na.zeros(data.ActiveDimensions, dtype='float32')
    if data.NumberOfParticles == 0: return blank
    uf.CICDeposit_3(data["particle_position_x"].astype(na.float64),
                 data["particle_position_y"].astype(na.float64),
                 data["particle_position_z"].astype(na.float64),
                 data["particle_mass"].astype(na.float32),
                 na.int64(data["particle_mass"].size),
                 blank, na.array(data.LeftEdge).astype(na.float64),
                 na.array(data.ActiveDimensions).astype(na.int32),
                 na.float64(data['dx']))
    return blank

add_field("particle_density_pyx", function=_pdensity_pyx,
          validators=[uf.ValidateSpatial(0)], 
convert_function=uf._convertDensity,
          display_name=r"\mathrm{Particle\ Density})")

Then you can use the field "particle_density_pyx" as you would "Density". The 
one thing to worry about in the case of stars, is there can be cells with no 
stars in them, which creates problems if you're doing the volume rendering in 
log space. Let me know if you have problems!

 _______________________________________________________
sskory at physics.ucsd.edu o__ Stephen Skory
http://physics.ucsd.edu/~sskory/ _.>/ _Graduate Student
________________________________(_)_\(_)_______________




More information about the yt-users mailing list