Skip to content

Commit

Permalink
MPL: ImpactXParticleContainer.plot_phasespace() (#469)
Browse files Browse the repository at this point in the history
* MPL: `ImpactXParticleContainer.plot_phasespace()`

Add an interactive plotter to quickly check the current phase
space of the particle bunch.

This is heavily inspired by Wake-T's `bunch.show()` functionality.

* CI: Update `dependencies/gcc.sh`

Install `requirements.txt`

Chain of `requirements.txt`: tests -> examples -> root
  • Loading branch information
ax3l authored Apr 8, 2024
1 parent bbe4b68 commit 73018ce
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dependencies/gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sudo apt-get install -y \
python3 -m pip install -U pip
python3 -m pip install -U build packaging setuptools wheel
python3 -m pip install -U cmake pytest
python3 -m pip install -U -r requirements.txt
python3 -m pip install -U -r examples/requirements.txt

python3 -m pip install -U openPMD-validator
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ In order to run our tests, you need to have a few Python packages installed:
```console
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade build packaging setuptools wheel pytest
python3 -m pip install --upgrade -r examples/requirements.txt
python3 -m pip install --upgrade -r tests/python/requirements.txt
```

You can run all our tests with:
Expand Down
38 changes: 38 additions & 0 deletions docs/source/dataanalysis/dataanalysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Data Analysis
=============

.. _dataanalysis-monitor:

Beam Monitor
------------

Expand All @@ -14,6 +16,8 @@ For data analysis of openPMD data, see examples of `many supported tools, Python

See also `WarpX' documentation on openPMD <https://warpx.readthedocs.io/en/latest/dataanalysis/formats.html>`__.

.. _dataanalysis-monitor-refparticle:

Additional Beam Attributes
""""""""""""""""""""""""""

Expand Down Expand Up @@ -49,6 +53,8 @@ Example to print the integrated orbit path length ``s`` at each beam monitor pos
print(f"step {k_i:>3}: s_ref={s_ref}")
.. _dataanalysis-beam-characteristics:

Reduced Beam Characteristics
----------------------------

Expand Down Expand Up @@ -78,3 +84,35 @@ The code writes out the values in an ASCII file prefixed ``reduced_beam_characte
Courant-Snyder (Twiss) beta (unit: meter)
* ``charge``
Cumulated beam charge (unit: Coulomb)


.. _dataanalysis-plot:

Interactive Analysis
--------------------

When steering ImpactX from Python, one can at any point visualize the beam phase space with:

.. code-block:: python
import matplotlib.pyplot as plt
from impactx import ImpactX, RefPart, distribution, elements
sim = ImpactX()
# ... setup and simulate ...
pc = sim.particle_container()
fig = pc.plot_phasespace()
# note: figure data available on MPI rank zero
if fig is not None:
fig.savefig("phase_space.png")
plt.show()
.. figure:: https://user-images.githubusercontent.com/1353258/295041638-8410ba76-9bd2-4dae-9810-5ec9f33dd372.png
:alt: In situ visualization of the beam phase space projections.

In situ visualization of the beam phase space projections.
7 changes: 4 additions & 3 deletions docs/source/install/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Optional dependencies include:

- `mpi4py <https://mpi4py.readthedocs.io>`__
- `numpy <https://numpy.org>`__
- `quantiphy <https://quantiphy.readthedocs.io/>`__
- `openPMD-api <https://github.com/openPMD/openPMD-api>`__
- see our ``requirements.txt`` file for compatible versions

Expand Down Expand Up @@ -66,7 +67,7 @@ Conda (Linux/macOS/Windows)

.. code-block:: bash
conda create -n impactx-cpu-mpich-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp "openpmd-api=*=mpi_mpich*" python numpy pandas scipy yt pkg-config matplotlib mamba ninja mpich pip virtualenv
conda create -n impactx-cpu-mpich-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp "openpmd-api=*=mpi_mpich*" python numpy pandas quantiphy scipy yt pkg-config matplotlib mamba ninja mpich pip virtualenv
conda activate impactx-cpu-mpich-dev
# compile ImpactX with -DImpactX_MPI=ON
Expand All @@ -76,7 +77,7 @@ Conda (Linux/macOS/Windows)

.. code-block:: bash
conda create -n impactx-cpu-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp openpmd-api python numpy pandas scipy yt pkg-config matplotlib mamba ninja pip virtualenv
conda create -n impactx-cpu-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp openpmd-api python numpy pandas quantiphy scipy yt pkg-config matplotlib mamba ninja pip virtualenv
conda activate impactx-cpu-dev
# compile ImpactX with -DImpactX_MPI=OFF
Expand Down Expand Up @@ -138,7 +139,7 @@ Now install the WarpX/ImpactX dependencies in a new development environment:
# installation
spack install
python3 -m pip install jupyter matplotlib numpy openpmd-api openpmd-viewer pandas scipy virtualenv yt
python3 -m pip install jupyter matplotlib numpy openpmd-api openpmd-viewer pandas quantiphy scipy virtualenv yt
In new terminal sessions, re-activate the environment with

Expand Down
1 change: 1 addition & 0 deletions examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r ../requirements.txt
matplotlib
numpy
openpmd-api
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
numpy~=1.15
quantiphy~=2.19
Loading

0 comments on commit 73018ce

Please sign in to comment.