Smoothed particle hydrodynamics analysis and visualization with Python.
Project description
Plonk
Smoothed particle hydrodynamics analysis and visualization with Python.
Description
Plonk is a Python tool for analysis and visualization of smoothed particle hydrodynamics data with a focus on astrophysical fluid dynamics.
With Plonk we aim to integrate the high quality SPH visualisation of Splash into the modern Python astronomer workflow, and provide a framework for analysis of smoothed particle hydrodynamics simulation data.
Usage
Plonk supports the following SPH file formats:
Note: you can convert Phantom non-HDF5 snapshots to HDF5. See the Phantom docs.
Accessing data
To read in a simulation with snapshot files like disc_00000.h5
, and global quantity time series files like disc01.ev
, in the current directory, and see what snapshots there are:
>>> import plonk
>>> simulation = plonk.load_sim(prefix='disc')
>>> simulation.snaps
[<plonk.Snap "disc_00000.h5">,
...
<plonk.Snap "disc_00030.h5">]
You can load individual snapshots and access the particle arrays:
>>> snap = plonk.load_snap(filename='disc_00030.h5')
>>> snap['position']
array([[-3.69505001e+12, 7.42032967e+12, -7.45096980e+11],
...,
[ 1.21421196e+12, 2.08618956e+13, 1.12998892e+12]]) <Unit('meter')>
The Snap objects contain the particle arrays, lazily loaded from the HDF5 file, as well as simulation metadata properties stored as a dictionary.
Visualization
To visualize the column density on a snapshot:
>>> snap.image(quantity='density')
<AxesSubplot:xlabel='x [m]', ylabel='y [m]'>
For a more complicated example, here is the deviation from Keplerian velocity around a planet embedded in a protoplanetary disc.
Deviation from Keplerian velocity around a planet: at the disc midplane (left), and 10 (middle) and 20 au (right) above the disc midplane. See here for details.
Analysis
Extra quantities not written to the snapshot file are available:
>>> snap['angular_momentum']
array([ ... ]) <Unit('kilogram * meter ** 2 / second')>
You can generate radial profiles on the snapshot. For example, to calculate the scale height in a disc:
>>> prof = plonk.load_profile(snap)
>>> prof['scale_height']
array([ ... ]) <Unit('meter')>
Physical units of array quantities and other properties allow for unit conversion:
>>> pos = snap['position'][0]
>>> pos
array([-3.69505001e+12, 7.42032967e+12, -7.45096980e+11]) <Unit('meter')>
>>> pos.to('au')
array([-24.6998837 , 49.60184016, -4.98066567]) <Unit('astronomical_unit')>
You can get a subset of particles as a SubSnap.
>>> subsnap = snap[:1000]
>>> subsnap = snap[snap['x'] > 0]
>>> subsnap = snap.family('gas')
More
For further usage, see documentation. The code is internally documented with docstrings. Try, for example, help(plonk.Snap)
or help(plonk.load_snap)
.
Install
Conda
You can install Plonk via the package manager Conda from conda-forge.
conda install plonk --channel conda-forge
This will install the required dependencies.
Note: You can simply use conda install plonk
if you add the conda-forge
channel with conda config --add channels conda-forge
. I also recommend strictly using conda-forge which you can do with conda config --set channel_priority true
. Both of these commands modify the Conda configuration file ~/.condarc
.
pip
You can also install Plonk from PyPI via pip.
python -m pip install plonk
This should install the required dependencies.
Source
You can install Plonk from source as follows.
# clone via HTTPS
git clone https://github.com/dmentipl/plonk.git
# or clone via SSH
git clone git@github.com:dmentipl/plonk
cd plonk
python -m pip install -e .
This assumes you have already installed the dependencies. One way to do this is by setting up a conda environment. The environment.yml file provided sets up a conda environment "plonk" for using or developing Plonk.
conda env create --file environment.yml
conda activate plonk
Requirements
Python 3.6+ with h5py, matplotlib, numba, numpy, pandas, pint, scipy, toml. Installing Plonk with conda or pip will install these dependencies.
Getting help
If you need help, please try the following:
- Check the documentation.
- Check the built-in help, e.g.
help(plonk.load_snap)
. - Raise an issue, as a bug report or feature request, using the issue tracker.
Please don't be afraid to raise an issue. Even if your issue is not a bug, it's nice to have the question and answer available in a public forum so we can all learn from it together.
If you don't get an immediate response, please be patient. Plonk is maintained by one person, @dmentipl.
Contributing
All types of contributions are welcome from all types of people with different skill levels.
Thank you for considering contributing to Plonk. There are many ways to contribute:
- If you find any bugs or cannot work out how to do something, please file a bug report in the issue tracker. Even if the issue is not a bug it may be that there is a lack of documentation.
- If you have any suggestions for new features, please raise a feature request in the issue tracker.
- If you use Plonk to do anything please consider contributing to the examples section in particular, or any other section, of the documentation.
- If you would like to contribute code, firstly thank you! We take code contributions via pull request.
See CONTRIBUTING.md for detailed guidelines on how to contribute.
Citation
If you use Plonk in a scientific publication, please cite the paper published in JOSS.
Plonk: Smoothed particle hydrodynamics analysis and visualization with Python
A BibTeX entry is available in CITATION.bib
If you use the interpolation to pixel grid component of Plonk please cite the Splash paper. You should also consider citing any other scientific software packages that you use.
Change log
The change log is available in CHANGELOG.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file plonk-0.7.4.tar.gz
.
File metadata
- Download URL: plonk-0.7.4.tar.gz
- Upload date:
- Size: 166.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff0824e49a993bd15884e696eb0ecd2b38a9f30a9f56bdf72f881b220ab8c53c |
|
MD5 | cae8a12e0b697df602842d3c07a861a4 |
|
BLAKE2b-256 | 380ed34e88770d2d7031c61dfaecac888b6851aa92fb7f6e15b55bc747a6c676 |
File details
Details for the file plonk-0.7.4-py3-none-any.whl
.
File metadata
- Download URL: plonk-0.7.4-py3-none-any.whl
- Upload date:
- Size: 191.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2fb4ca5c7aef9fff93cbfb8fd9c82c2a3b93b179fbf57716168ac33e081fe2a |
|
MD5 | 4725a3b7bd0be182fc76f4a76f7427e6 |
|
BLAKE2b-256 | b6f1c009de4d4d05960b6703764ff9da37bebf4efb82c183caa3eefa540a5e30 |