[yt-users] Particles in volume rendering

Charles Hansen chansen at astro.berkeley.edu
Mon Aug 2 10:45:24 PDT 2010


Orion particles aren't in yt properly yet to my knowledge, but anyone 
using them has their own particle readers by this point.  I've just 
started adding the particles to the density field by hand lately (code 
below).  They look blocky and their size depends on the cell width, but 
the bigger problem is that the particles still aren't visible unless I 
am extremely careful with the color scheme of the contours.  Even if 
alpha is set to 1, any given contour is mostly transparent.  Is there a 
way to tell the renderer that some particular cell (where a sink 
particle is) is completely opaque?

Charles

def _partden(field, 
data):                                                     
    starlist = particles.readParticles(data.pf)     #not part of yt 
                         
    x = 
data["x"]                                                              
    y = 
data["y"]                                                              
    z = 
data["z"]                                                              
    partm = 
0                                                                  
    if starlist != 
None:                                                       
        dx = 
data["dx"]                                                        
        dy = 
data["dy"]                                                        
        dz = 
data["dz"]                                                        
        for i in range(0, 
len(starlist)):                                      
            dxp = 
abs(x-starlist[i]['x'][0])                                   
            dyp = 
abs(y-starlist[i]['x'][1])                                   
            dzp = 
abs(z-starlist[i]['x'][2])                                   
                                                                                

            mass = starlist[i]['m']*(dxp < dx/2)*(dyp < dy/2)*(dzp < 
dz/2)     
            partm = partm + 
mass                                               
    partden = 
partm/data["CellVolume"]                                         
    return 
partden                                                             
add_field("partden", function=_partden)     

def _dentot(field, 
data):                                                      
    return 
(data["density"]+data["partden"])                                   
add_field("dentot", function=_dentot)          
                                  

Stella Offner wrote:
> Thanks, Matt and Stephen! The issue here is that I only have a small 
> number of stars (< 100), so calculating a particle density would 
> probably cause problems.
>
> It might be possible to use what you suggest below if I don't start 
> with a blank field filled with zeros (I also will likely plot in log 
> space). I will play around with some of these things and let you know 
> if I find something useful...
> Stella
>
>>
>>
>> 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!
>>
>
> _______________________________________________
> 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