Skip to content

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")
Additionally the coordinates system and indexing can be set manually. If no format is given, the first existing format is used (in the order 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 pluto.ini, definitions.h, etc)

data_path pathlib.Path

path to data directory (with *.out and data files)

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
or use the Jupyter Notebook formatting
sim

PLUTO Simulation path: /home/simeon/masterproject/PLUTO/test-problems/HD/Disk_Planet/03_0, 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

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 or get() functions
    step_data = sim[10]
    step_data = sim.get(10, keep=False)
    
  • iteration
    for step in sim:
        # process data
    
  • reduced data with reduce() and reduce_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:dict of :obj:str): mapping from coordinate system variable name to PLUTO variable names. (e.g. for spherical coordinates r->x1, theta->x2, phi->x3, )

mapping_vars

obj:dict of :obj:str): mapping from coordinate system variable attribute name to PLUTO variable names. (e.g. for spherical coordinates vr->vx1, vtheta->vx2, vphi->vx3)

mapping_tex

obj:dict of :obj:str): mapping from variable name to LaTeX names.

dims

obj:tuple of :obj:int): domain dimensions

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 coordinates == 'cylindrical', maps to x1, x2

ri, zi (numpy.ndarray

available if coordinates == 'cylindrical', maps to x1i, x2i

dr, dz (numpy.ndarray

available if coordinates == 'cylindrical', maps to dx1, dx2

r, phi, z (numpy.ndarray

available if coordinates == 'polar', maps to x1, x2, x3

ri, phii, zi (numpy.ndarray

available if coordinates == 'polar', maps to x1i, x2i, x3i

dr, dphi, dz (numpy.ndarray

available if coordinates == 'polar', maps to dx1, dx2, dx3

r, theta, phi (numpy.ndarray

available if coordinates == 'spherical', maps to x1, x2, x3

ri, thetai, phii (numpy.ndarray

available if coordinates == 'spherical', maps to x1i, x2i, x3i

dr, dtheta, dphi (numpy.ndarray

available if coordinates == 'spherical', maps to dx1, dx2, dx3

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:str or :obj:Pathlike): path to gridfile

required
coordinates

obj:str, optional): name of coordinate system (cartesian, polar, cylindrical, spherical). If not set this will be read from gridfile.

None
indexing

obj:str, optional): index order for arrays. 'ijk' or 'kji'

'ijk'

read_gridfile(self, gridfile_path, coordinates=None)

Read and parse gridfile

Parameters:

Name Type Description Default
gridfile_path

obj:str or :obj:Pathlike): Path to PLUTO gridfile grid.out

required
coordinates

obj:str, optional): coordinate system name If not set this will be read from gridfile

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