The readplt
project is a Python library for reading and parsing
SWMF/BATSRUS
output files in .dat
and .plt
format. The library may also be able to read other .plt
files but only a core subset of the .plt
format specification is supported. The project also includes a use case in the form of a 'quicklook' command sw-quick
that can visualise two-dimensional SWMF/BATSRUS output.
After cloning this repository, the project may be installed with pip
in the regular way:
cd <project>
pip install .
This code reads a dataset named <file>
and stores the dataset variable named Rho [g/cm^3]
in a local variable named density_g_cm3
.
from starwinds_readplt.dataset import Dataset
ds = Dataset.from_file('<file>')
print(ds)
density_g_cm3 = ds('Rho [g/cm^3]')
A simple 'quicklook' shell command is included which permits plotting of two-dimensional slices of the SWMF/BATSRUS results. Irregularly gridded data is accepted. The quicklook command uses the plot function in basicplot.py
but this may be extended by the user.
To create a quicklook .png
file from the included file examples/x=0_var_2_n00000000.plt
run
cd examples
sw-quick x=0_var_2_n00000000.plt
This will create a file named ql-x-0-var-2-n00000000-plt-rho-g-cm-3.png
; the name comprises the prefix ql
, the file name, and the name of the plotted variable. The name is sanitised using slugify
to replace spaces and other problematic characters in the output file name with dashes.
A wildcard pattern may be used; in this case one .png
file is created for each file matching the wildcard pattern:
sw-quick x*.plt
To install the project in editable mode and enable testing do
cd <project>
pip install --editable .[tests]
Now it is possible to run the test suite by typing
pytest