Data Access
After creating the simulation object all simulation data can be accessed via this object. Here the different ways to access data are explored.
If not explicitly specified, all examples assume an simulation object sim is available
import plutoplot as pp
sim = pp.Simulation("path/to/simulation")
The data for the individual timesteps is encapsulated in PlutoData-object, which the Simulation-object will create on demand.
The data arrays for the variables can be accessed from there.
Accessing Steps
Direct access
To get the PlutoData-object for a specific step can be accessed using the []-operator or get() function like this:
step_data = sim[10]
step_data = sim.get(10, keep=False)
# or direct acces to variables:
sim[10].rho
get() also has an additional parameter keep, which chooses if the resulting object should be kept im memory after use.
Simulation.get() docs
plutoplot.simulation.Simulation.get(self, key, keep=True)
Get PLUTO output
Access individual data frames as PlutoData object. If keep=True the object is cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
int |
Output number |
required |
keep |
obj: |
True |
Returns:
| Type | Description |
|---|---|
obj: |
Iteration and reduce
It is also possible to iterate over all (or some steps for processing)
for step_data in sim:
# process data here
# or for more control over the range
for step_data in sim.iter(start, stop, step):
# process data
Simulation.iter() reference
plutoplot.simulation.Simulation.iter(self, *range_, *, keep=False)
Iterate over simulation
Range argument definition the same as range().
Attributes:
| Name | Type | Description |
|---|---|---|
simulation |
plutoplot.simulation.Simulation |
Simulation to iterate |
keep |
bool |
Whether to keep the PlutoData objects in memory |
start |
int |
Iteration start |
stop |
int |
Iteration stop (exclusive) |
step |
int |
Iteration step |
Returns:
| Type | Description |
|---|---|
SimulationIterator |
SimulationIterator |
If each step should be reduced to into an array of values the reduce and reduce_parallel helpers can be used.
For example, if the mean density of each step is needed:
mean_rho = sim.reduce(lambda step: step.rho.mean())
# result: mean_rho.shape == len(sim)
column_density = sim.reduce(lambda step: step.rho.sum(axis=2))
# Result: column_density.shape == (n1, n2)
reduce_parallel is equivalent, but will use multiprocessing to parallelise this operation. Be aware that because of the overhead of multiprocessing this is not necessarily faster than a serial reduce(), especially with an optimized numpy-installation.
reduce() reference
plutoplot.simulation.Simulation.reduce(self, func, range=(), dtype=None)
Reduce all simulation steps with function.
Shape and dtype are implied from return value of func().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
function |
function which takes a PlutoData object and returns scalar or numpy array. |
required |
dtype |
numpy.dtype |
forced data type for result array (if None func() implies dtype) |
None |
range |
tuple |
range tuple for iterator. |
() |
Returns:
| Type | Description |
|---|---|
numpy.ndarray |
reduced data array |
reduce_parallel() reference
plutoplot.simulation.Simulation.reduce_parallel(self, func, range=(), processes=None, dtype=None)
Reduce all simulation steps with function in parallel
Shape and dtype are implied from return value of func().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
function |
function which takes a PlutoData object and returns scalar or numpy array. |
required |
dtype |
numpy.dtype |
forced data type for result array (if None func() implies dtype) |
None |
range |
tuple |
range tuple for iterator. |
() |
Returns:
| Type | Description |
|---|---|
numpy.ndarray |
reduced data array |
Accessing data
The available data variables of a simulation can be accessed from simulation.vars or plutodata.vars: