Skip to content
Otto Akseli Hannuksela edited this page May 4, 2015 · 51 revisions

Analysator

User documentation

Features

Here is a quick list of features one can do with python tools:

  • Read VLSV files and do calculations with the data
  • Write VLSV files
  • Plot the real space from VLSV files with mayavi
  • Plot the velocity space (both blocks and iso surface) from VLSV files by clicking in real space
  • Take cut-throughs from VLSV files (both in mayavi plots and from the terminal for calculations) Note: Check the "Picker options" section.
  • Take pitch angle distributions (both in terminal from VLSV files and in Mayavi by clicking with the cursor)
  • Take gyrophase angle (both in terminal from VLSV files and in Mayavi by clicking with the cursor)
  • Take 3d slices (for making 2d or 3d fouriers, for example)
  • Take time evolution of specified variables for specified cells
  • Plot variables with sub plots in a clean format
  • Take fourier transforms in time (This can be done via scipy or numpy library too)
  • Fit 1d polynomials to data (Not used very much and this can be done via scipy)
  • Edit the code as you see fit and improve it (Python is easy)
  • Do python scripts and combine all of this

Installation

First make sure that you have the required dependencies: ipython numpy scipy matplotlib mayavi2

Add the main directory of vlsv python tools to your PYTHONPATH variable. Example assuming vlsv-python-tools folder is in your home folder: echo 'export PYTHONPATH=$PYTHONPATH:${HOME}/vlsv-python-tools' >> /home/example/.bashrc

Make sure you have MayaVi installed and up-to-date:

sudo apt-get install mayavi2 #Installs dependencies

mkdir $HOME/ETS

mkdir -p $HOME/mayavi_install/lib/python2.7/site-packages

cd $HOME/ETS

wget https://github.com/enthought/ets/raw/master/ets.py .

export PYTHONPATH=$PYTHONPATH:$HOME/mayavi_install/lib/python2.7/site-packages

echo "export PYTHONPATH=$PYTHONPATH:$HOME/mayavi_install/lib/python2.7/site-packages" >> $HOME/.bashrc

python ets.py clone

python ets.py develop --prefix=$HOME/mayavi_install

alias mayavi2=$HOME/mayavi_install/bin/mayavi2

echo "alias mayavi2=$HOME/mayavi_install/bin/mayavi2" >> $HOME/.bashrc

More documentation on Mayavi2 installation here: http://docs.enthought.com/mayavi/mayavi/installation.html

Sphinx documentation

The python tools have an automatically-generated sphinx documentation at:

http://ohannuks.github.io/sphinx_build/html/index.html Note: The website is currently not being automatically updated.

Usage notes

First import the pytools in python.

import pytools as pt

List of interesting classes

VlsvReader

This class is used to read a vlsv file. Usage:

f=pt.vlsvfile.VlsvReader(file_name="fullf.0000000.vlsv")

### VlsvWriter

This class is used to write vlsv files. Usage:
``` python
vlsvReader=pt.vlsvfile.VlsvReader(file_name="fullf.0000000.vlsv")
vlsvWriter=pt.vlsvfile.VlsvWriter(vlsvReader=vlsvReader, "new_file.vlsv")
# Read in rho:
rho = vlsvReader.read_variable('rho')
vlsvWriter.write( data=rho, name="rho", tag="VARIABLE", mesh="SpatialGrid")

MayaviGrid

This class is used to plot the data in a vlsv file as a mayavi grid The following will bring up a new window and plot the grid in the vlsv file:

grid = pt.grid.MayaviGrid(vlsvReader=f, variable="rho", operator='pass', threaded=False)

Once you have the window open you can use the picker tool in the right-upper corner and use various point-click tools for analyzing data.

Picker options:

None Does nothing upon clicking somewhere in the grid

Velocity_space Plots the velocity space at a specific position upon clicking somewhere in the grid Note: If the vlsv file does not have the velocity space at the position where you are clicking, this will not work

Velocity_space_iso_surface Plots the velocity space at a specific position upon clicking somewhere in the grid in iso-surface plotting style Note: If the vlsv file does not have the velocity space at the position where you are clicking, this will not work

Velocity_space_nearest_cellid Plots the velocity space of the closest cell id to the picking point Note: If the vlsv file does not have velocity space saved at all, this will not work

Velocity_space_nearest_cellid_iso_surface Plots the velocity space of the closest cell id to the picking point in iso-surface plotting style Note: If the vlsv file does not have velocity space saved at all, this will not work

Pitch_angle Plots the pitch angle distribution at the clicking position Note: If the vlsv file does not have the velocity space at the position where you are clicking, this will not work

Cut_through Is used to plot or save the cut-through between two clicking points. This option requires you to use the args section at top-left. To use the args section to plot variables you must write for example: plot rho B,x E,y Upon clicking at two points a new window would open with a cut-through plot of rho, x-component of B and y-component of E Alternatively, you can save the cut-through to a variable in the MayaviGrid class by typing instead: rho B,x E,y and then going to the terminal and typing

cut_through_data = grid.cut_through
print cut_through_data

VariableInfo

This class is used to hold variables with info (name, units) on them.

rho = f.read_variable_info(name='rho')
rho.units='1/m^3'
print rho
print rho.units
print rho.name
print rho.data
# Plot rho:
import numpy as np
length = len(rho.data)
figure = pt.plot.plot_variables(np.arange(length)*5, rho)
figure.show()

List of useful modules:

calculations

Includes various tools for doing calculations

pt.calculations.

plot

Includes a couple of quick plotting functions that support the VariableInfo class

pt.plot.

grid

Includes everything to do with plotting vlsv files with Mayavi

pt.grid.

vlsvfile

Includes everything to do with reading and writing vlsv files

pt.vlsvfile.

Examples

Plotting a cut-through from the command line

f=pt.vlsvfile.VlsvReader(file_name="trunk/distfunction.0000030.vlsv")
cut=pt.calculations.cut_through(f,[-1e7,0,0],[3e7,0,0]);
#read rho and B magnitude. cut[0] contains the cellids
rho = f.read_variable("rho",cut[0].data)
B = f.read_variable_info("B",cut[0].data,"magnitude")
#plot as function of distance in cut[1]
fig=pt.plot.plot_multiple_variables([cut[1],cut[1]],[rho,B])
fig.show()