Py3D package

Submodules

Py3D.dump module

class Py3D.dump.Dump(num=None, param_file=None, path='./')

Bases: object

class that reads and stores dump file data

TODO: submit my complaint through github
add version switch for _proc_to_dumpindex Debug 3d for old code write code for box to procs to load
Maybies:
optimize _pop_particles with seek to location?
read_fields(index=None)
read_particles(index, wanted_procs=None, tags=False)

# Method : read_dump_parts

set_dump_num(num)

Py3D.dumpID module

class Py3D.dumpID.DumpID(num=None, param_file=None, path='./')

Bases: object

Write better doc strings!

TODO: Debug for differnet simulations

get_part_in_box(r=[1.0, 1.0], dx=[0.5, 0.5], par=False, species=None, tags=False)

Takes a box defined by its center position r and it’s widths dx and gets the particle data

read_fields()

Wrapper for the Dump mehtod read_fields Args: None Returns:

dict: dictionary containing E and B fields read from the
dump files
NOTE: We include this it is common to call only DumpID, when
we still need the field values

Py3D.movie module

class Py3D.movie.Movie(num=None, param_file=None, path='./')

Bases: object

Class to load p3d movie data

get_fields(vars, time=None, slice=None)

Loads the field(s) var at for a given time(s)

var (string, [strings]) ::
a single string field name a list of string field names or simply ‘all’

time (int, None) :: what time you want to read, if None it will ask

slice (None, tuple(0-2, int)) :: if you want to load only a slice
of a 3D movie file (to save time?) the first int it what plane that you dont want, and the second is the off set
class Py3D.movie.UnfinishedMovie(param=None, path='./')

Bases: Py3D.movie.Movie

Class to load p3d movie data

Py3D.movie.load_movie(vars=None, time=None, movie_num=None)

Py3D.sub module

Py3D.sub.set_local(d, loc, overwrite=False)

Sets the contents of a dictory d to the local namespace loc

Parameters:
  • d (dict) – Typicly the field values for a simulation
  • loc (dict (local namespace)) – Dictionary that keeps track of the namespace
  • overwrite (bool) – If true will overwrite values in loc
Returns:

None

Py3D.sub.ims(d, k, ax=None, extent=None, cbar=None, cont=None, no_draw=None, ctargs={}, **kwargs)

A wrapper function for imshow to do most tedious stuff for P3D simulations

Parameters:
  • d (dict) – A dictionary with relevent simualtion information. d must contain xx and yy so it will know the dimensions to plot
  • k (str or np.array) – Either a str of a varible contained within d or a 2D numpy array of size (len(d[‘xx’]), len(d[‘yy’])) that will be plotted.
  • cbar (bool) – If true, then auto generate a colorbar.
  • cont (bool) – If true, then auto generate contours
  • no_draw (bool) – If ture, do not call matplotlib.pylab.draw(), can speed up the plotting process
  • ctargs (dict) – A dictonary to pass extra argumens to the contour call, so you can add more lines or set the elvels explicitly.
Py3D.sub.find_xpt(d)
Py3D.sub.var_at(fdic, key, r0, ordflg='idl')
Py3D.sub.ims_subplot(d, var, ax, window, **kwargs)
ims, but for a sub region, plots faster and get auto max and min
colors right
Args:

d (dict): Typicly the field values for a simulation k (str (key of d) or numpy.array): the string of field that you want

to plot.

ax (matplotlib.pyplot.axis): MPL axis to plot to window (4*[float]): List of corners of the window to plot

Py3D.sub.load_movie(num=None, param=None, path='./', vars='all', time=None, slice=None)
num : int
Moving number to load. If None it will ask
param : str
name of param file, If None it will ask.
path : str
where movie files are. (Assumese in local dir)
vars : str or array of strs
what varibles to load [‘bx’, ‘by’, ‘bz’, ..], Assumes that you want to load ‘all’
time : int
what time to load the move from. If None it will ask
Py3D.sub.check_energy_conservation(mov_num=0, init_time=0, final_time=-1, ims_var='pexx', use_UFM=False)

A simpile method that plots how well the total energy is conserved Parameters ———- mov_num

Py3D.sub.multi_color(slice=None, draw=False)

A method for Mike!. It coppies his multi gray IDL code.

slice : None || (axis, offset)

Only relevent for 3D data. Which slice (plane) to plot. axis : int 0,1,2

Which plane do you want to see? 0 -> (y,z), 1 -> (x,z), 2 -< (x,y)
offset : float
What value do you want to use in the 3rd direction?
draw : bool
if True it will plot and draw every subplot in real time Note: if set to True it is VERY slow
Py3D.sub.show_energy(fname=None)
Grabs the energy values from a p3d.stdout file and returns them
as a numpy array.
Args:
fname (str, optional): Name of the p3d.stdout file to grab.
If None it will ask.
Py3D.sub.calc_psi(d)

Calculated the magnetic scaler potential for a 2D simulation

Args:
d (dict): Dictionary containing the fields of the simulation
d must contain bx, by, xx and yy
Retruns:
psi (numpy.array(len(d[‘xx’], len(d[‘yy’]))) ): Magnetic scaler
potential
Py3D.sub.readsave(restore_fname)

read an idl .sav(.dat) file or a python npy file

Py3D.sub.date_file_prefix()

returns a string with the current date

Py3D.sub.rs3d(arr)

Reshape an array as a 3D array (for Tulasi’s stupid code)

Py3D.sub.rotate_ten(d, var='pi', av='av', overwrite=False, full_rotate=False)

Py3D.vdist module

class Py3D.vdist.VDist

Bases: object

velocity distribution fucntion calculator

eflux(v1, v2, v3, mass, v_light=None, **kwargs)

Function that makes an energy flux distrobution ToDo: add an eflux_autobin funciton

spec1d(pts, dir, pa, dpa, mass, v0_frame=False, v_light=None, **kwargs)

core program for calculating the energy spectrum along a direction

vdist2d(v1, v2, v3=None, dz=None, v0_frame=False, v_light=None, **kwargs)

Simple 2D velocity histogram

vdist2d_pitch(v1, v2, v3, pa=90.0, dpa=20.0, v0_frame=False, **kwargs)

Pitch party!!!!

pa = pitch angle dpa = angular width around pa (Delta Pitch Angle)

Py3D.vdist_plotter module

class Py3D.vdist_plotter.VDistPlotter(r0=None, dx=None, **dumpargs)

Bases: object

velocity distribution fucntion plotter

plot2d(d1, d2, sp, ax=None, dz=None, par=False, v0_frame=False, smooth=0.0, ctargs=None, pcmargs={}, **kwargs)

Plots a 2D distro Args:

d1 (int 0-2): The velocity space direction coresponding to the x
axis
d2 (int 0-2): The velocity space direction coresponding to the y

axis Note that if par == False:

0 -> x, 1 -> y, 2 -> z
And if par == True:
0 -> b, 1 -> exb, 2 -> bx(exb)
ax (Matplotlib axes obj, optional): the subplot you want this to
be plotted to. If left as None, the code grabs the current axes

sp (str ‘i’ or ‘e’): the species that you want plotted

dz (float, optional): The width of integrated “pizza” in the 3rd
velocity space direction. Default is None (All space)
v0_frame (boo, optional): If true, this shifts the center of the
pizza to the mean velocity in the 3rd direction. Default is set to False
smooth (float, optional) the std for the guassian filter to smooth
the histogram

ctargs (dict): Keyword arguments for the contour function

pcmargs (dict): Keyword arguments for the pcolormesh function

**kwargs: Keyword arguments that will ultimtily be passed to the
numpy histogram2d function, so look there for more details
Returns:
ax: Retuns matplotlib AxesSubplot of coresponding to plotted fig
spec1d(dir, pitch_angle, delta_pitch, species, mass=None, ax=None, v0_frame=False, v_light=None, smooth=0.0, ctargs=None, pcmargs={}, **kwargs)

Plots a 2D distro Args:

pitch angle (int 0-2): The velocity space direction coresponding to the x
axis
dpitch_angle (Matplotlib axes obj, optional): the subplot you want this to
be plotted to. If left as None, the code grabs the current axes

species (str ‘i’ or ‘e’): the species that you want plotted dz (float, optional): The width of integrated “pizza” in the 3rd

velocity space direction. Default is None (All space)
v0_frame (bool, optional): If true, this shifts the center of the
pizza to the mean velocity in the 3rd direction. Default is set to False

ctargs (dict): Keyword arguments for the contour function pcmargs (dict): Keyword arguments for the pcolormesh function **kwargs: Keyword arguments that will ultimtily be passed to the

numpy histogram2d function, so look there for more details
Returns:
ax: Retuns matplotlib AxesSubplot of coresponding to plotted fig
update_box(r0, dx)

Module contents