Post-processing & visualization toolkit for the Entity PIC code
Project description
nt2.py
Python package for visualization and post-processing of the Entity simulation data. For usage, please refer to the documentation. The package is distributed via PyPI:
pip install nt2py
Usage
The Library works both with single-file output as well as with separate files. In either case, the location of the data is passed via path keyword argument.
import nt2
data = nt2.Data(path="path/to/data")
# example:
# data = nt2.Data(path="path/to/shock.h5") : for single-file
# data = nt2.Data(path="path/to/shock") : for multi-file
The data is stored in specialized containers which can be accessed via corresponding attributes:
data.fields # < xr.Dataset
data.particles # < dict[int : xr.Dataset]
data.spectra # < xr.Dataset
Examples
Plot a field (in cartesian space) at a specific time (or output step):
data.fields.Ex.sel(t=10.0, method="nearest").plot() # time ~ 10
data.fields.Ex.isel(t=5).plot() # output step = 5
Plot a slice or time-averaged field quantities:
data.fields.Bz.mean("t").plot()
data.fields.Bz.sel(t=10.0, x=0.5, method="nearest").plot()
Plot in spherical coordinates (+ combine several fields):
e_dot_b = (data.fields.Er * data.fields.Br +\
data.fields.Eth * data.fields.Bth +\
data.fields.Eph * data.fields.Bph)
bsqr = data.fields.Br**2 + data.fields.Bth**2 + data.fields.Bph**2
# only plot radial extent of up to 10
(e_dot_b / bsqr).sel(t=50.0, method="nearest").sel(r=slice(None, 10)).polar.pcolor()
You can also quickly plot the fields at a specific time using the handy .inspect accessor:
data.fields\
.sel(t=3.0, method="nearest")\
.sel(x=slice(-0.2, 0.2))\
.inspect.plot(only_fields=["E", "B"])
# Hint: use `<...>.plot?` to see all options
Or if no time is specified, it will create a quick movie (need to also provide a name in that case):
data.fields\
.sel(x=slice(-0.2, 0.2))\
.inspect.plot(name="inspect", only_fields=["E", "B", "N"])
You can also create a movie of a single field quantity (can be custom):
(data.fields.Ex * data.fields.Bx).sel(x=slice(None, 0.2)).movie.plot(name="ExBx", vmin=-0.01, vmax=0.01, cmap="BrBG")
You may also combine different quantities and plots (e.g., fields & particles) to produce a more customized movie:
def plot(t, data):
fig, ax = mpl.pyplot.subplots()
data.fields.Ex.sel(t=t, method="nearest").sel(x=slice(None, 0.2)).plot(
ax=ax, vmin=-0.001, vmax=0.001, cmap="BrBG"
)
for sp in range(1, 3):
ax.scatter(
data.particles[sp].sel(t=t, method="nearest").x,
data.particles[sp].sel(t=t, method="nearest").y,
c="r" if sp == 1 else "b",
)
ax.set_aspect(1)
data.makeMovie(plot)
If using Jupyter notebook, you can quickly preview the loaded metadata by simply running a cell with just
datain it (or in regular python, by doingprint(data)).
Dashboard
Support for the dask dashboard is still in beta, but you can access it by first launching the dashboard client:
import nt2
nt2.Dashboard()
This will output the port where the dashboard server is running, e.g., Dashboard: http://127.0.0.1:8787/status. Click on it (or enter in your browser) to open the dashboard.
Features
- Lazy loading and parallel processing of the simulation data with
dask. - Context-aware data manipulation with
xarray. - Parellel plotting and movie generation with
multiprocessingandffmpeg.
TODO
- Unit tests
- Plugins for other simulation data formats
- Usage examples
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nt2py-0.5.0.tar.gz.
File metadata
- Download URL: nt2py-0.5.0.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
125c4db1eb8669afea0450ba8b31796ad698ee55aecf9b3b02c090a6191b2a52
|
|
| MD5 |
ce406bf92379defa2999e49d284d47a1
|
|
| BLAKE2b-256 |
ad3f2f50c8f92141c4dc9f5a86c16116b6143eba044bf8e6b3680be7d08859da
|
File details
Details for the file nt2py-0.5.0-py3-none-any.whl.
File metadata
- Download URL: nt2py-0.5.0-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94ca62cd5b1c4f3c594f057f26d4c48d8176dbb3bff7cef304801364649ddfab
|
|
| MD5 |
20ec885a5f86d1435feeb9b888f6dce6
|
|
| BLAKE2b-256 |
bcb7edde7cd3a5ae62c703d0e970a819762bfd7af5ab4807534054df2193928d
|