aboutsummaryrefslogtreecommitdiff
path: root/Docs/source/dataanalysis/openpmdviewer.rst
blob: 39b550df7b7b5c0ea295c99b3acf9d99c7e39b6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
.. _dataanalysis-openpmd-viewer:

openPMD-viewer
==============

`openPMD-viewer <https://github.com/openPMD/openPMD-viewer>`__ is an open-source Python package to access openPMD data.

It allows to:

* Quickly browse through the data, with a GUI-type interface in the Jupyter notebook
* Have access to the data numpy array, for more detailed analysis

Installation
------------

openPMD-viewer can be installed via ``conda`` or ``pip``:

.. code-block:: bash

    conda install -c conda-forge openpmd-viewer openpmd-api

.. code-block:: bash

    pip install openPMD-viewer openPMD-api

Usage
-----

openPMD-viewer can be used either in simple Python scripts or in `Jupyter <https://jupyter.org>`__.
For interactive plots in Jupyter notebook, add this `"cell magic" <https://ipython.readthedocs.io/en/stable/interactive/magics.html>`__ to the first line of your notebook:

.. code-block:: python

   %matplotlib notebook

and for Jupyter Lab use this instead:

.. code-block:: python

   %matplotlib widget

If none of those work, e.g. because `ipympl <https://github.com/matplotlib/ipympl#installation>`__ is not properly installed, you can as a last resort always try ``%matplotlib inline`` for non-interactive plots.

In both interactive and scripted usage, you can import openPMD-viewer, and load the data with the following commands:

.. code-block:: python

    from openpmd_viewer import OpenPMDTimeSeries
    ts = OpenPMDTimeSeries('./diags/diag1/')

.. note::

    If you are using the Jupyter notebook, then you can start a pre-filled
    notebook, which already contains the above lines, by typing in a terminal:

    ::

        openPMD_notebook

When using the Jupyter notebook, you can quickly browse through the data
by using the command:

::

    ts.slider()

You can also access the particle and field data as numpy arrays with the methods ``ts.get_field`` and ``ts.get_particle``.
See the openPMD-viewer tutorials `here <https://github.com/openPMD/openPMD-viewer/tree/master/tutorials>`_ for more info.