1 Using pNbody with the python interpreter

In this section, we assume that pNbody in installed in /usr/lib/python2.4/site-packages/pNbody/. First move to the examples directory and start python :

[lunix@lunix ~]$ cd /usr/lib/python2.4/site-packages/pNbody/examples
[lunix@lunix examples]$ python
Python 2.4.2 (#2, Jul 13 2006, 15:26:48)
[GCC 4.0.1 (4.0.1-5mdk for Mandriva Linux release 2006.0)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now, you can load the pNbody module :
>>> from pNbody import *
At this point, we cas start by creating an pNbody objet, by opening the snapshot gadget file gadget_z00.dat :
>>> nb = Nbody('gadget_z00.dat',ftype='gadget')
At this point, the all the content of the information contained in the snapshot file is transfered in the object nb. Informatins on this object may be obtained using the instance info() :
>>> nb.info()
-----------------------------------
particle file    : ['gadget_z00.dat']
ftype            : 'Nbody_gadget'
nbody            : 20560
nbody_tot        : 20560
npart            : array([ 9160, 10280,     0,     0,  1120,     0])
npart_tot        : array([ 9160, 10280,     0,     0,  1120,     0])
mtot             : 79.717887878417969
byteorder        : 'little'
pio              : 'no'

len pos             : 20560
pos[0]              : array([-1294.48828125, -2217.09765625, -9655.49609375], type=Float32)
pos[-1]             : array([ -986.0625    , -2183.83203125,  4017.04296875], type=Float32)
len vel             : 20560
vel[0]              : array([ -69.80491638,   60.56475067, -166.32981873], type=Float32)
vel[-1]             : array([-140.59715271,  -66.44669342,  -37.01613235], type=Float32)
len mass            : 20560
mass[0]             : 0.0010856521548703313
mass[-1]            : 0.0010856521548703313
len num             : 20560
num[0]              : 21488
num[-1]             : 1005192
len rsp            : 20560
rsp[0]             : 909.027587890625
rsp[-1]           : 0.0

nzero               : 20560
npart               : [ 9160 10280     0     0  1120     0]
massarr             : [ 0.  0.  0.  0.  0.  0.]
atime               : 1.0
redshift            : 2.22044604925e-16
flag_sfr            : 1
flag_feedback       : 1
nall                : [ 9160 10280     0     0  1120     0]
flag_cooling        : 1
num_files           : 1
boxsize             : 100000.0
omega0              : 0.3
omegalambda         : 0.7
hubbleparam         : 0.7
flag_age            : 0
flag_metals         : 0
nallhw              : [0 0 0 0 0 0]
flag_entr_ic        : 0
critical_energy_spec: 0.0

len u               : 20560
u[0]                : 6606.63037109
u[-1]               : 0.0
len rho             : 20560
rho[0]              : 7.05811936674e-11
rho[-1]             : 0.0
len rsp             : 20560
rsp[0]              : 909.027587891
rsp[-1]             : 0.0
len erd             : 20560
erd[0]              : 446292.5625
erd[-1]             : 0.0
The content of single variables associated to the nb object (like positions or number of particles ) are simply obtained by typing :
>>> nb.pos
array([[-1294.48828125, -2217.09765625, -9655.49609375],
       [-4272.2734375 , -1574.39453125, -6895.22265625],
       [-4192.90234375, -2828.90625   , -7032.86328125],
       ...,
       [-1269.9921875 , -1017.7890625 ,   300.4453125 ],
       [-1271.2890625 , -1018.8828125 ,   300.6640625 ],
       [ -986.0625    , -2183.83203125,  4017.04296875]], type=Float32)
>>> nb.nbody
20560
You can obtain informations on physical values, like the center of mass or the total angular momentum vector by typing :
>>> nb.cm()
array([-1649.92650646,   609.98258649, -1689.04021837])
>>> nb.Ltot()
array([-1112071.75 ,  -755970.625, -1536666.25 ], type=Float32)
In order to visualise the model in position space, it is possible to generate a surface density map of it using the display instance :
>>> nb.display(size=(10000,10000),shape=(256,256),palette='light')
You can now performe some operations on the model in order to explore a specific region. First, translate the model in position space :
>>> nb.translate([3125,-4690,1720])
>>> nb.display(size=(10000,10000),shape=(256,256),palette='light')
>>> nb.display(size=(1000,1000),shape=(256,256),palette='light')
Ou can now rotate around
>>> nb.rotate(angle=pi)
>>> nb.display(size=(1000,1000),shape=(256,256),palette='light')
You can now try to display a temperature map of the model. First, create a new object with only the gas particles.
>>> nb_gas = nb.select('gas')
>>> nb_gas.display(size=(1000,1000),shape=(256,256),palette='light')
now, display the temparture mass weighted map :
>>> nb_gas.display(size=(1000,1000),shape=(256,256),palette='rainbow4',mode='T',filter_name='convol')
You can select only particles within a radius smaller tha 500 with respect to the center
>>> nb_sub = nb.selectc((nb.rxyz()<500))
>>> nb_sub.display(size=(1000,1000),shape=(256,256),palette='light')
Now, rename the new model and save it.
>>> nb_sub.rename('gadget_z00_sub.dat')
>>> nb_sub.write()
Select particles as a function of the temperature
>>> log10(max(nb_gas.T()))
12.870792505729391
>>> nb_sub = nb_gas.selectc( (nb_gas.T()>1e11) )
>>> nb_sub.write_num('T11.num')
Now open a new file and find the particles in previous snapshot with temperature higher than :
>>> nb = Nbody('gadget_z40.dat',ftype='gadget')
>>> nb.display(size=(10000,10000),shape=(256,256),palette='light')
>>> nb_sub = nb.selectp(file='T11.num')
>>> nb_sub.display(size=(10000,10000),shape=(256,256),palette='light')
An the last example, change the type of the file and save it :
>>> nb = nb.set_ftype('binary')
>>> nb.rename('binary.dat')
>>> nb.write()
The last example show how two pNbody models can be easyly merged with only 11 lines.
>>> nb1 = Nbody('disk.gad',ftype='gadget')
>>> nb2 = Nbody('disk.gad',ftype='gadget')
>>> nb1.rotate2(angle=pi/4,axis=[0,1,0])
>>> nb1.translate([-150,0,0])
>>> nb1.vel = nb1.vel + [50,0,0]
>>> nb2.rotate2(angle=pi/4,axis=[1,0,0])
>>> nb2.translate([+150,0,50])
>>> nb2.vel = nb2.vel - [50,0,0]
>>> nb3 = nb1 + nb2
>>> nb3.rename('merge.gad')
>>> nb3.write()

See About this document... for information on suggesting changes.