Loading simulations
Loading data from simulations is the central function plutoplot serves.
The central object to interact with a PLUTO simulation is the plutoplot.Simulation object.
In loads the simulation metadata, the grid and creates the objects for the individual output files.
Simulation
To load a simulation from disk create a plutoplot.Simulation object:
import plutoplot as pp
sim = pp.Simulation("path/to/simulation", format="flt")
dbl, flt, vtk, dbl.h5, flt.h5).
The coordinate system will be read from the gridfile if not specified. More information on the coordinate system can be found in the Grid section.
plutoplot.Simulation initialization reference
plutoplot.simulation.Simulation.__init__(self, path='.', format=None, coordinates=None, indexing='ijk')
special
Create Simulation object from PLUTO output directory
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path or str |
Path to simulation directory / data directory |
'.' |
format |
str |
PLUTO output format to load. Currently supported: 'dbl', 'flt', 'vtk', 'dbl.h5', 'flt.h5'. By default uses the first {format}.out file found. |
None |
coordinates |
str |
name of coordinates system of simulation. Will be read from gridfile by default Supported: (') |
None |
indexing |
str |
Array index convention. Supports ("ijk", "kji"). |
'ijk' |
Exceptions:
| Type | Description |
|---|---|
FileNotFoundError |
if no metadata or grid files are found. |
NotImplementedError |
if unsupported format is requested |
After loading the Simulation-object has the following attributes:
Simulation attributes
plutoplot.simulation.Simulation
Container class for PLUTO (http://plutocode.ph.unito.it/) output. Reads the metadata of all files in working directory (wdir), and loads individual files when needed. Simulation is subscriptable and iterable.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
pathlib.Path |
Path to simulation directory
(directory with |
data_path |
pathlib.Path |
path to data directory (with |
format |
str |
simulation format |
metadata |
plutoplot.io.SimulationMetadata |
Simulation metadata |
grid |
plutoplot.grid.Grid |
Simulation grid |
To show information about the simulation, just use the string representation:
Example
print(sim)
PLUTO Simulation: path: 'path/to/simulation', data directory '$sim_path/.'
Data vars: rho, vx1, vx2, vx3
Data files: Format `flt`: 2 files, last time 1.0, data timestep 1.00e+00
PLUTO Grid Dimensions: (128, 1, 384), spherical coordinate system
r: 0.40..2.50, Lx1=2.10, N1=128
theta: 1.45..1.57, Lx1=0.12, N1=1
phi: 0.00..6.28, Lx1=6.28, N1=384
sim
PLUTO Simulation path:
/home/simeon/masterproject/PLUTO/test-problems/HD/Disk_Planet/03_0, data directory$sim_path/.
Data vars:rhovx1vx2vx3
Data files: Formatflt: 2 files,last time 1.0, data timestep 1.00e+00
PLUTO Grid Dimensions (128, 1, 384), spherical coordinate system
L N \(r\) 0.40 2.50 2.10 128 \(\theta\) 1.45 1.57 0.12 1 \(\phi\) 0.00 6.28 6.28 384
Slicing simulations
Accessing simulation steps
Each simulation output step is represented by a PlutoData object, which will be generated on demand by the Simulation. The PlutoData-object then gives access to the actual data arrays.
The data from the simulation output steps can be accessed from the Simulation-object with:
- direct access using the
[]-operator orget()functionsstep_data = sim[10] step_data = sim.get(10, keep=False) - iteration
for step in sim: # process data - reduced data with
reduce()andreduce_parallel()(over each time step)mean_density = sim.reduce(lambda step: step.rho.mean())
More details in Data Access
Grid
The Grid object contains all the information of the simulation grid.
Grid reference
plutoplot.grid.Grid
Grid datastructure to be initialized from gridfile
Attributes:
| Name | Type | Description |
|---|---|---|
gridfile_path |
Path |
Path to gridfile |
coordinates |
str |
Name of coordinate system |
mapping_grid |
obj: |
|
mapping_vars |
obj: |
|
mapping_tex |
obj: |
|
dims |
obj: |
|
size |
int |
total size of data arrays (product of dims) |
x1, |
x2, x3 (numpy.ndarray |
cell centered grid (1d, not as mesh) |
x1i, |
x2i, x3i (numpy.ndarray |
cell interface coordinates (1d, not as mesh) |
dx1, |
dx2, dx3 (numpy.ndarray |
cell sizes (1d, not as mesh) |
r, |
z (numpy.ndarray |
available if |
ri, |
zi (numpy.ndarray |
available if |
dr, |
dz (numpy.ndarray |
available if |
r, |
phi, z (numpy.ndarray |
available if |
ri, |
phii, zi (numpy.ndarray |
available if |
dr, |
dphi, dz (numpy.ndarray |
available if |
r, |
theta, phi (numpy.ndarray |
available if |
ri, |
thetai, phii (numpy.ndarray |
available if |
dr, |
dtheta, dphi (numpy.ndarray |
available if |
Todo
- Generalize and document meshgrid functions
__init__(self, gridfile, coordinates=None, indexing='ijk')
special
Initialize Grid from gridfile
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gridfile |
obj: |
required | |
coordinates |
obj: |
None |
|
indexing |
obj: |
'ijk' |
read_gridfile(self, gridfile_path, coordinates=None)
Read and parse gridfile
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gridfile_path |
obj: |
required | |
coordinates |
obj: |
None |
Sets Attributes:
x1, x2, x3 (numpy.ndarray): cell centered grid (1d, not as mesh)
x1i, x2i, x3i (numpy.ndarray): cell interfaces (1d, not as mesh)
dx1, dx2, dx3 (numpy.ndarray): cell sizes (1d, not as mesh)
Lx1, Lx2, Lx3 (numpy.ndarray): Domain width
dims (:obj:tuple of :obj:int): domain dimensions
data_shape (:obj:tuple of :obj:int): shape of data array.
Depends on index order
size (int): total size of data arrays (product of dims)
set_coordinate_system(self, coordinates)
Set coordinate system of grid and get name mapping
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates |
str |
name of coordinate system (cartesian, polar, cylindrical, spherical) |
required |