<spanid="the-libutil-module"></span><h1>the libutil module<aclass="headerlink"href="#module-pNbody.libutil"title="Permalink to this headline">¶</a></h1>
<dlclass="function">
<dtid="pNbody.libutil.Extract1dMeanFrom2dMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">Extract1dMeanFrom2dMap</tt><big>(</big><em>x</em>, <em>y</em>, <em>mass</em>, <em>val</em>, <em>kx</em>, <em>ky</em>, <em>nmin</em>, <em>momentum=0</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.Extract1dMeanFrom2dMap"title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the mean along one axis, from a 2d mean or sigma matrix</p>
<p>x : pos in first dim. (beetween 0 and 1)
y : pos in sec dim. (beetween 0 and 1)
mass : mass of particles
val : value to compute</p>
<p>kx : number of bins in x
ky : number of bins in y</p>
<p>nmin : min number of particles needed to compute value</p>
<p>momentum : 0,1,2 (-1=number)</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.GetMassMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">GetMassMap</tt><big>(</big><em>pos</em>, <em>mass</em>, <em>shape</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.GetMassMap"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.GetMeanMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">GetMeanMap</tt><big>(</big><em>m0</em>, <em>m1</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.GetMeanMap"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a MeanMap using the 0 and 1 momentum</p>
<p>m0 : zero momentum
m1 : first momentum</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.GetMeanValMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">GetMeanValMap</tt><big>(</big><em>pos</em>, <em>mass</em>, <em>val</em>, <em>shape</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.GetMeanValMap"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.GetNumberMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">GetNumberMap</tt><big>(</big><em>pos</em>, <em>shape</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.GetNumberMap"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.GetSigmaMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">GetSigmaMap</tt><big>(</big><em>m0</em>, <em>m1</em>, <em>m2</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.GetSigmaMap"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a MeanMap using the 0 and 1 and 2 momentum</p>
<p>m0 : zero momentum
m1 : first momentum
m2 : second momentum</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.GetSigmaValMap">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">GetSigmaValMap</tt><big>(</big><em>pos</em>, <em>mass</em>, <em>val</em>, <em>shape</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.GetSigmaValMap"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.RotateAround">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">RotateAround</tt><big>(</big><em>angle</em>, <em>axis</em>, <em>point</em>, <em>ObsM</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.RotateAround"title="Permalink to this definition">¶</a></dt>
<dd><p>this should be C</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.add_box">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">add_box</tt><big>(</big><em>matint</em>, <em>shape=(256</em>, <em>256)</em>, <em>size=(30.0</em>, <em>30.0)</em>, <em>center=None</em>, <em>box_opts=(1</em>, <em>None</em>, <em>None</em>, <em>255)</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.add_box"title="Permalink to this definition">¶</a></dt>
<dd><p>add a box on the frame</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.apply_filter">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">apply_filter</tt><big>(</big><em>mat</em>, <em>name=None</em>, <em>opt=None</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.apply_filter"title="Permalink to this definition">¶</a></dt>
<dd><p>Apply a filter to an image</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.compress_from_lst">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">compress_from_lst</tt><big>(</big><em>x</em>, <em>num</em>, <em>lst</em>, <em>reject=False</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.compress_from_lst"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the compression of x</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.contours">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">contours</tt><big>(</big><em>m</em>, <em>matint</em>, <em>nl</em>, <em>mn</em>, <em>mx</em>, <em>kx</em>, <em>ky</em>, <em>color</em>, <em>crush='no'</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.contours"title="Permalink to this definition">¶</a></dt>
<dd><p>Compute iso-contours on a n x m float array.
If “l_min” equal “l_max”, levels are automatically between the minimum and
maximum values of the matrix “mat”.</p>
<p>m = matrice (real values)
matint = matrice (interger values)
kx = num of sub-boxes
ky = num of sub-boxes
nl = # of levels
mn = min
mx = max
color = color of contours</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.drawxticks">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">drawxticks</tt><big>(</big><em>matint</em>, <em>m0</em>, <em>d0</em>, <em>n0</em>, <em>h0</em>, <em>shape</em>, <em>size</em>, <em>center</em>, <em>color</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.drawxticks"title="Permalink to this definition">¶</a></dt>
<dd><p>draw x ticks in a matrix</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.drawyticks">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">drawyticks</tt><big>(</big><em>matint</em>, <em>m0</em>, <em>d0</em>, <em>n0</em>, <em>h0</em>, <em>shape</em>, <em>size</em>, <em>center</em>, <em>color</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.drawyticks"title="Permalink to this definition">¶</a></dt>
<dd><p>draw x ticks in a matrix</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.extract_parameters">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">extract_parameters</tt><big>(</big><em>arg</em>, <em>kw</em>, <em>defaultparams</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.extract_parameters"title="Permalink to this definition">¶</a></dt>
<dd><p>this function extract parameters given to a function
it returns a dictionary of parameters with respective value</p>
<p>defaultparams : dictionary of default parameters</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.get_eyes">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">get_eyes</tt><big>(</big><em>x0</em>, <em>xp</em>, <em>alpha</em>, <em>dr</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.get_eyes"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the position of two eyes.</p>
<p>x0 : position of the head
xp : looking point
theta : rotation of the head
dr : distance of the eyes</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.get_image">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">get_image</tt><big>(</big><em>mat</em>, <em>name=None</em>, <em>palette_name='light'</em>, <em>mode='RGB'</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.get_image"title="Permalink to this definition">¶</a></dt>
<dd><p>Return an image (PIL object).</p>
<p>data : numpy 2x2 object
name : name of the output
palette_name : name of a palette</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.geter">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">geter</tt><big>(</big><em>n</em>, <em>rmin</em>, <em>rmax</em>, <em>g</em>, <em>gm</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.geter"title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a one dimentional non linear array of r</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.geter2">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">geter2</tt><big>(</big><em>n</em>, <em>rmin</em>, <em>rmax</em>, <em>g</em>, <em>gm</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.geter2"title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a one dimentional non linear array of r</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.getr">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">getr</tt><big>(</big><em>nr=31</em>, <em>nt=32</em>, <em>rm=100.0</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.getr"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a sequence of number (n x 1 array),
where n=nr+1 defined by: Pfenniger & Friedli (1994)</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.getval">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">getval</tt><big>(</big><em>nb</em>, <em>mode='m'</em>, <em>obs=None</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.getval"title="Permalink to this definition">¶</a></dt>
<dd><p>For each point, return a specific value linked to this point</p>
<p>0 : moment 0
m : moment 0</p>
<p>x : first moment in x
y : first moment in y
z : first moment in z
y2 : second moment in x
y2 : second moment in y
z2 : second moment in z</p>
<p>vx : first velocity moment in x
vy : first velocity moment in y
vz : first velocity moment in z
vx2 : second velocity moment in x
vy2 : second velocity moment in y
vz2 : second velocity moment in z</p>
<p>Lx : kinetic momemtum in x
Ly : kinetic momemtum in y
Lz : kinetic momemtum in z
lx : specific kinetic momemtum in x
ly : specific kinetic momemtum in y
lz : specific kinetic momemtum in z</p>
<p>u : specific energy
rho : density
T : temperature
A : entropy
P : pressure
Tcool : cooling time
Lum : luminosity
Ne : local electro density</p>
<p># depends on projection</p>
<p>r : first momemtum of radial distance
r2 : second momemtum of radial distance</p>
<p>vr : first momemtum of radial velocity
vr2 : second momemtum of radial velocity</p>
<p>vxyr : first momemtum of radial velocity in the plane
vxyr2 : second momemtum of radial velocity in the plane</p>
<p>vtr : first momemtum of tangential velocity in the plane
vtr2 : second momemtum of tangential velocity in the plane</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.getvaltype">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">getvaltype</tt><big>(</big><em>mode='m'</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.getvaltype"title="Permalink to this definition">¶</a></dt>
<dd><p>list values that depends on projection</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.invgetr">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">invgetr</tt><big>(</big><em>r</em>, <em>nr=31</em>, <em>nt=32</em>, <em>rm=100.0</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.invgetr"title="Permalink to this definition">¶</a></dt>
<dd><p>From r, return the corresponding indexes.
Inverse of getr function.</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.log_filter">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">log_filter</tt><big>(</big><em>x</em>, <em>xmin</em>, <em>xmax</em>, <em>xc</em>, <em>kx=1.0</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.log_filter"title="Permalink to this definition">¶</a></dt>
<dd><p>map a value between 0 and kx</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.log_filter_inv">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">log_filter_inv</tt><big>(</big><em>k</em>, <em>xmin</em>, <em>xmax</em>, <em>xc</em>, <em>kx=1.0</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.log_filter_inv"title="Permalink to this definition">¶</a></dt>
<dd><p>map a value betwen xmin and xmax</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.mplot">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">mplot</tt><big>(</big><em>mat</em>, <em>palette='light'</em>, <em>save=None</em>, <em>marker=None</em>, <em>header=None</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.mplot"title="Permalink to this definition">¶</a></dt>
<dd><p>plot a 2d array</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.myhistogram">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">myhistogram</tt><big>(</big><em>a</em>, <em>bins</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.myhistogram"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the histogram (n x 1 float array) of the
n x 1 array “a”.
“bins” (m x 1 array) specify the bins of the histogram.</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.phys2img">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">phys2img</tt><big>(</big><em>shape</em>, <em>size</em>, <em>center</em>, <em>x</em>, <em>y</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.phys2img"title="Permalink to this definition">¶</a></dt>
<dd><p>convert physical position into the image pixel</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.sbox">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">sbox</tt><big>(</big><em>shape</em>, <em>size</em>, <em>lweight=1</em>, <em>xticks=None</em>, <em>yticks=None</em>, <em>color=255</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.sbox"title="Permalink to this definition">¶</a></dt>
<dd><p>simple box</p>
<p>return a matrix of integer, containing a box with labels</p>
<p>xticks = (m0,d0,h0,m1,d1,h1)</p>
<p>0 = big
1 = small</p>
<p>m0,m1 = dist between ticks
d0,d1 = first tick
h0,h1 = height of the ticks</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.set_ranges">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">set_ranges</tt><big>(</big><em>mat</em>, <em>scale='log'</em>, <em>mn=None</em>, <em>mx=None</em>, <em>cd=None</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.set_ranges"title="Permalink to this definition">¶</a></dt>
<dd><p>Transform an n x m float array into an n x m int array that will be
used to create an image. The float values are rescaled and cutted in order to range
between 0 and 255.</p>
<p>mat : the matrice
scale : lin or log
mn : lower value for the cutoff
mx : higer value for the cutoff
cd : parameter</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.tranfert_functions">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">tranfert_functions</tt><big>(</big><em>rmin</em>, <em>rmax</em>, <em>g=None</em>, <em>gm=None</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.tranfert_functions"title="Permalink to this definition">¶</a></dt>
<dd><p>This function computes the normalized tranfer fonction from g and gm
It is very usefull to tranform a linear vetor in a non linear one</p>
<p>example of g:</p>
<blockquote>
g = lambda r:log(r/rc+1)
gm = lambda r:rc*(exp(r)-1)</blockquote>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.vel_cart2cyl">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">vel_cart2cyl</tt><big>(</big><em>pos</em>, <em>vel</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.vel_cart2cyl"title="Permalink to this definition">¶</a></dt>
<dd><p>Transform velocities in carthesian coordinates vx,vy,vz into cylindrical
coodinates vr,vz,vz.
Pos is the position of particles in cart. coord.
Vel is the velocity in cart. coord.
Return a 3xn float array.</p>
</dd></dl>
<dlclass="function">
<dtid="pNbody.libutil.vel_cyl2cart">
<ttclass="descclassname">pNbody.libutil.</tt><ttclass="descname">vel_cyl2cart</tt><big>(</big><em>pos=None</em>, <em>vel=None</em><big>)</big><aclass="headerlink"href="#pNbody.libutil.vel_cyl2cart"title="Permalink to this definition">¶</a></dt>
<dd><p>Transform velocities in cylindrical coordinates vr,vt,vz into carthesian