Skip to content

Plotting helper routines

Markus Battarbee edited this page Jan 27, 2021 · 4 revisions

Plotting helper routines

The file pyPlots/plot_helpers.py contains a selection of small scripts and examples to be used in conjunction with the plot_colormap and plot_colormap3dslice routines. They can be used to evaluate variables which require e.g. spatial or temporal derivatives. The file also includes some parameters which can be defined in other routines in order to ensure correct output for e.g. derivatives:

PLANE = 'XY' # or alternatively, 'XZ'
CELLSIZE = 300000.0 # cell size
DT = 0.5 # time step

These can be edited by calling e.g. pt.plot.plot_helpers.DT=1.0

Basic usage:

The simplest method of using these helpers is, for example, to use call pt.plot.plot_colormap() with the keyword expression=pt.plot.plot_helpers.expr_J

Temporal derivatives, time averaging etc

If you wish to calculate temporal derivatives or averages, multiple timesteps must be passed to the expression or external function. This is activated with the keyword pass_times which can be either a single value Y where Y timesteps before and after the main step are passed, or a list of two nymbers [Z,W] where Z steps before and W steps after the main argument are included and passed to the external function or expression.

Selecting variables to be used by the function:

Functions can be given variables read from the vlsv files for use in computation of derived variables and physical quantities. The variables used by the function are added to the beginning of it as follows:

def expression(pass_maps, requestvariables=False):
    if requestvariables==True:
        return ['variable1', 'variable2', 'variable3']

If the function is called using plot_colormap3dslice, by default the function receives a 2D slice of requested variables. If the variable list also includes the identifier '3d', the function instead receives the full upsampled 3D data set.

Accessing the variables within the function

The function receives a dictionary. Each entry in the dictionary is a map of a given variable. Additionally, there can be an entry with name dstep which indicates the step offset in time from the main argument. E.g. the preceding timestep will have a dictionary in which there is an entry dstep:-1.

If several timesteps are requested, the external function or expression is passed not a dictionary but a list of dictionaries, one dictionary for each timestep.

Numerical helper functions:

def numjacobian(inputarray):
def numgradscalar(inputarray):
def numdiv(inputarray):
def numdivtensor(inputtensor):
def numcrossproduct(inputvector1, inputvector2):
def numcurl(inputarray):
def vanleer(left, cent, right):
def limitedgradient(inputarray, *varargs):
def numcurllimited(inputarray):
def numvecdotdelvec(inputarray1, inputarray2):
def numvecdottensor(inputarray, inputtensor):
def TransposeVectorArray(inputarray):
def rotateTensorArrayToVectorArray(inputtensor, inputvector):
def TensorArrayParallelComponent(inputtensor):
def TensorArrayPerpendicularComponent(inputtensor):
def TensorArrayAnisotropy(inputtensor):
def VectorArrayParallelComponent(inputvector, directionvector):
def VectorArrayPerpendicularComponent(inputvector, directionvector):
def VectorArrayPerpendicularVector(inputvector, directionvector):
def VectorArrayAnisotropy(inputvector, directionvector):

Some extended physical parameters

def vec_MagneticPressureForce(inputarray):
def vec_MagneticTensionForce(inputarray):
def vec_ThermalPressureForce(inputarray):
def vec_currentdensity(inputarray):
def vec_currentdensity_lim(inputarray):
def vec_Hallterm(currentdensity, magneticfield, numberdensity):
def vec_ElectricFieldForce(electricfield, numberdensity):
def expr_Hall(pass_maps, requestvariables=False):
def expr_Hall_aniso(pass_maps, requestvariables=False):
def expr_J(pass_maps, requestvariables=False):

...and plenty more!

Special helper used for differencing two .vlsv files:

def expr_Diff(pass_maps, requestvariables=False):