Package: plutoplot
plutoplot - Plutocode data loading and plotting libraryplutoplotis a Python package for loading, analyzing and plotting data from theastrophysical gas dynamics simulation code PLUTO.
By handling simulations as a whole and loading data only when needed (lazy loading), it is fast and easy to use.It features:Loading on data actually needed (by lazy loading in memory mapping)easy slicing into large datasets (e.g. plotting 2D slice of 3D dataset)plotting non-cartesian coordinates projected into cartesian spaceinteractive plotting in Jupyter NotebooksCLI tool to quickly acquire information about simulationsAccess to parameters set indefinitions.handpluto.iniAccess to simulation metadata and grid propertiesIndexing withijk(likepyPLUTO) andkji(like PLUTO internally) schemesThere is currently no support for:ParticlesAdaptive grids (AMR)3D plotting (only plotting 2D slices of 3D data is supported.)To get started withplutoplotcheck out thedocumentationandexamples.Installationplutoplotrequires Python >=3.6. Make sure for installation to install in the right environment, and/or adapt the pip commands accordingly (e.g.pip3).The base version of plutoplot can be installed from Pypi with:pipinstall--upgradeplutoplotTo keep the installation size small the dependencies for interactive plotting and loading of HDF5 data are declared as optional dependencies.
To install the optional dependencies use either of the following, depeding on your needs:pipinstall--upgradeplutoplot[interactive]pipinstall--upgradeplutoplot[hdf5]pipinstall--upgradeplutoplot[interactive,hdf5]To install the current development version from this branch:pipinstall--upgrade"plutoplot @ git+https://github.com/simske/plutoplot"Quick StartCLI: check simulation infoTo quickly check the status of a PLUTO simulation, you can use thepluto-infocommand line tool:pluto-info/path/to/simulationSample:>> pluto-info test-problems/HD/Jet/01/
PLUTO simulation at 'test-problems/HD/Jet/01'
Polar grid with dimensions (160, 1, 640)
Domain: x1: 0.00e+00 .. 1.00e+01 (Lx1 = 1.00e+01)
        x2: 0.00e+00 .. 1.00e+00 (Lx2 = 1.00e+00)
        x2: 0.00e+00 .. 4.00e+01 (Lx3 = 4.00e+01)
Available variables: rho vx1 vx2 vx3 prs
Data files:
    Format dbl: 16 files, last time 15.0, data timestep 1.00e+00
    Format flt: 61 files, last time 15.0, data timestep 2.50e-01(note: depending on your Python environment, the entrypointpluto-infomight not be installed correctly. Check thedocumentation for more details).Quick start in Python scripts / Jupyter notebooksimportplutoplotasppBasicsSimulations can be loaded by just providing the path to the simulation directory (directory withdefinitions.handpluto.ini).
The data directory is the found automatically, as well as the grid geometry.
The formats are searched in the order (dbl, flt, vtk, dbl.h5, flt.h5) and the first found loaded, this can be overriden.sim=pp.Simulation("/path/to/simulation",format="flt")The simulation object provides access to all outputs (of this format), the grid and simulation metadata.
A few examples of accesible attributes:sim.dims# domain resolutionsim.x1,sim.x2,sim.x3# cell centered coordinates, redirect to sim.grid.x{1,2,3}sim.x1i,sim.x2i,sim.x3i# cell interface coordinatessim.Lx1,sim.Lx2,sim.Lx3sim.t# simulation output timessim.vars# simulation output variablesThe data at the specific output steps can be accessed with thesim[n]syntax.
This results in aPlutoDataobject, which can be used to access the data:sim[-1].rhoThe data object as well as the data array are generated when needed, and the data arrays are memory mapped, which means only data actually accessed is read from disk.
The names of the data variables can be found withsim.vars.Be aware that data arrays are always 3-dimensional, even if the domain has a resolution of 1 in some directions.
This is for clarity and consistency, so that an axis always has a direct correspondence to its coordinates in the grid.Simulations are iterable:forstepinsim:print("Total mean squared velocity at t={step.t}: ",(step.vx1**2+step.vx2**2+step.vx3**2).mean())And also provide areduce()function to run over the whole simulation:prs_mean=sim.reduce(lambdastep:step.prs.mean())This results in an array containing the output of the supplied function for each step, in the example the mean pressure.Working with simulation slicesTo only look at a part of a simulation we can slice into it.
This can be particularly useful for analyzing and plotting 2D slices of 3D data, as full 3D plotting is not supported yet.
To slice into a simulation the usual slicing syntax onSimulation.slicer:sliced_sim=sim.slicer[:,0,32:64]This sliced simulation object can now be used as the normal simulation object.
The grid and data arrays will automatically return the data for this slice.
(Note: for clarity a 3D slice is always required. The data arrays will still always be 3D, see above).Plottingplutoplotprovides automatic plotting for 1D & 2D simulations.
To plot slices of 3D simulations, first create a simulation slice (section above), then just follow normally.The PlutoData object provides aplot()function, which will automatically project the data onto a cartesian grid, and annotating the axes and colorbar correctly:sim[-1].plot('rho')The projection can also be turned off, an arbitrary options which will be passed to matplotlib can be given:sim[-1].plot('rho',projection=False)If a plot of a custom quantitity is needed, a array instead of a variable name can be given:step = sim[-1]
step.plot(step.prs / step.rho, label="T")In Jupyter Notebooks interactive plotting can be used to step through the simulation steps.Simulation.iplot()has the same interface asPlutoData.plot(), but it will show a slider to step through simulation steps:sim.iplot("rho")TestingThe test suite forplutoplotcan be found intest/and is run by Github actions usingtoxandpytest.The test suite is currently minimal and has low code coverage. It will be expanded in the future to ensure correctness.ContributingIf you have any questions, suggestions or find a bug, feel free to open anissueorPull Request, I am happy to accept contributions to make plutoplot better.plutoplotusespre-committo ensure a consistend code style, please use it when opening a Pull Request.LicenseGPLv3