Skip to content
Markus Battarbee edited this page Jan 27, 2021 · 6 revisions

Access to Vlasiator output .vlsv files is handled through the Vlsvreader class. There are a number of useful plotting routines which do not require editing the data directly, but for any in-depth scripting, direct access routines are likely necessary.

VlsvReader

Open a file for access by creating a VlsvReader object.

f=pt.vlsvfile.VlsvReader("/path/to/simulation/bulk.0001234.vlsv")

Listing available variables

Within python, you can list available variables with

f.list()

You can also print additional information such as all available data reducers and operators by adding those keywords:

f.list(datareducer=True,operator=True)

Also, from the operating system command line, it can sometimes be useful to look directly at the XML footer information which contains information on all variables included in the file, e.g. tail -n 60 bulk.0001234.vlsv |less. You can adjust the line count until you have the information you need. Adding too many lines will result in human-unreadable binary output.

Reading in vlasov grid (MPIgrid) variables

In older Vlasiator versions (before 5.0, simulation identifier second letter A through F) most variables are saved on the MPIgrid and there is no identifying naming convention. Since version 5.0, with simulation version identifier letters starting from G, vlasov grid variables are prepended with vg_. Note that for per-population variables, this is placed after the population name.

Variables are read and returned as numpy arrays. MPIgrid (Vlasov grid) cell scalar variables are returned as a simple 1-dimensional array. Vectors, tensors and so on have additional dimensions tacked on. Note that the ordering of CellIDs (and thus, the corresponding order of proton number densities and all other MPIgrid variables) will vary between files. The list of MPIgrid CellIDs and the corresponding proton number densities can be found with

cellids = f.read_variable('cellid')
rho = f.read_variable('proton/vg_rho')

In order to use the read data, it needs to be sorted and rearranged to correspond with the spatial grid structure. If the grid is 2-D and AMR was not used, this is relatively straightforward. Select the coordinate sizes to match the simulation domain.

[xsize, ysize, zsize] = f.get_spatial_mesh_size()   
rho_shaped = rho[cellids.argsort()].reshape([ysize,xsize])

For vector data, use

bvol = f.read_variable('vg_b_vol')
bvol_shaped = bvol[cellids.argsort()].reshape([ysize,xsize,3])

Reading in vlasov grid (MPIgrid) AMR variables

This is a bit more complex and requires the use of helper functions. To be added.

Reading in field solver grid (FSgrid) variables

Since Vlasiator version 5.0, field solver grid (FSgrid) variables are prepended with fg_. FSgrid variables are returned as a numpy array, pre-sorted by the reading routine, with dimensions matching the spatial dimensions and, if applicable, vector size. For example, reading volumetric B-fields might yield an array of shape (1024, 736, 736, 3). There is a separate routine for reading FSgrid variables, but the standard read_variable() routine will redirect to the FSgrid routine if an FSgrid variable is requested.

fg_b = f.read_fsgrid_variable('fg_b')

Please note that FSgrid variables do not support reading via CellID. CellID to coordinate to FSgrid index access has not yet been implemented in Analysator but shall be at a later date.

Reading variables with metadata

Since Vlasiator 5.0, metadata is included for stored variables. The function read_variable_info returns an object with the following fields: data (as per the read_variable or read_fsgrid_variable call), name, units, latex (LaTeX-formatted name), latexunits (LaTeX-formatted unit)

vg_b_vol_with_info = f.read_variable_info('vg_b_vol')

Reading spatial cut-throughs

Reading a spatial profile through the simulation can be achieved with the cut_through() method. This supports only Vlasov grid data, not FSgrid data. AMR support is not yet included. Select the starting and final positions and read the line profile with

cut=pt.calculations.cut_through(f,pos1,pos2);

here f is the .vlsv file used for reading, pos1 and pos2 are XYZ coordinates (in metres) and the returned structure contains the relevant cellIDs (cut[0]) and position along the cut [cut[1], in metres). You can read the actual cut data with

variable=get_data(f.read_variable("vg_variablename",cut[0].data))

Plot the data with

ax.plot(cut[1].data/Re, variable)

Alternative stepped cut-through

Instead of reading all cells along a cut, this alternative function proceeds along the cut in the dominant cartesian direction and returns one cellID per row/column.

cut = pt.calculations.cut_through_step(f, pos1, pos2)