Simulation¶
- class plonk.Simulation¶
Smoothed particle hydrodynamics simulation object.
This class aggregates snapshot files, global quantity and sink time series data. Snapshot files contain a complete snapshot of the simulation at a particular time. Other files contain time series of global quantities on particles such as energy and momentum, and time series data for sink particles.
Examples
Reading simulation data into a Simulation object.
>>> sim = plonk.load_simulation('prefix', path_to_directory)
Accessing the snapshots.
>>> sim.snaps
Accessing the properties.
>>> sim.properties
Accessing the global quantity and sink time series data.
>>> sim.time_series['global'] >>> sim.time_series['sinks']
- load_simulation(prefix, directory=None, data_source='Phantom')¶
Load Simulation.
- Parameters
prefix (str) – Simulation prefix, e.g. ‘disc’, if files are named like disc_00000.h5, disc01.ev, discSink0001N01.ev, etc.
directory (optional) – Directory containing simulation snapshot files and auxiliary files. Default is None.
data_source (optional) – The SPH code used to produce the simulation data. Default is ‘Phantom’.
- Return type
- set_units_on_time_series(config=None)¶
Set physical units on time series data.
- Parameters
config (optional) – The path to a Plonk config.toml file.
- property time_series: pandas.core.frame.DataFrame¶
Time series data.
- to_array(quantity, indices=None)¶
Generate an array of a quantity over all snapshots.
Warning: this can be very memory intensive and slow.
- Parameters
- Returns
- Return type
An array with units.
Examples
Get the position of every particle during the whole simulation.
>>> pos = sim.to_array(quantity='position') >>> pos.shape (31, 1100000, 3)
- unset_units_on_time_series(config=None)¶
Un-set physical units on time series data.
- Parameters
config (optional) – The path to a Plonk config.toml file.
- visualize(kind, **kwargs)¶
Visualize a simulation.
- Parameters
sim (Simulation) – The Simulation object.
kind (str) – The kind of plot: ‘particle’, ‘image’, ‘vector’.
**kwargs – Keyword arguments to pass to plotting methods such as plonk.image, plonk.plot, and plonk.vector.
- Returns
- Return type
VisualizeSimulation
Examples
Visualize a simulation by density projection images.
>>> viz = visualize_sim(sim=sim, kind='image', quantity='density')
Alternatively.
>>> sim.visualize(kind='image', quantity='density')
Go forwards and backwards through snaps.
>>> viz.next() >>> viz.prev()
Go to a particular snap, or skip ahead.
>>> viz.goto(10) >>> viz.next(5)
- plonk.load_simulation(prefix, directory=None, data_source='Phantom')¶
Load Simulation.
- Parameters
prefix (str) – Simulation prefix, e.g. ‘disc’, if files are named like disc_00000.h5, disc01.ev, discSink0001N01.ev, etc.
directory (optional) – Directory containing simulation snapshot files and auxiliary files. Default is None.
data_source (optional) – The SPH code used to produce the simulation data. Default is ‘Phantom’.
- Return type
- plonk.load_time_series(filenames, data_source='Phantom', config=None)¶
Load time series data from file(s).
Time series files track global quantities, such as energy, momentum, and density, over time. The time increments in these files is smaller than the snapshot file output time. These files are typically stored as text files.
The data is stored as a pandas DataFrame.
- Parameters
filename(s) – Collection of paths to time series file(s) in chronological order. These should all contain the same columns.
data_source (optional) – The code used to produce the data. Default is ‘Phantom’.
config (optional) – The path to a Plonk config.toml file.
filenames (Union[str, pathlib.Path, Tuple[str], Tuple[pathlib.Path], List[str], List[pathlib.Path]]) –
- Returns
A pandas DataFrame with the time series data.
- Return type
dataframe
Examples
Reading a single time series file into a pandas DataFrame.
>>> file_name = 'simulation.ev' >>> ts = plonk.load_time_series(file_name)
Reading a collection of time series files into a pandas DataFrame.
>>> file_names = ('sim01.ev', 'sim02.ev', 'sim03.ev') >>> ts = plonk.load_time_series(file_names)