Skip to content

Commit

Permalink
Add GUI for plotting integrals per package (#26)
Browse files Browse the repository at this point in the history
* Add GUI for plotting integrals per package

* Fix docstring

* Add `integrals_packages` to documentation

- Fix typos in documentation of special functions
  • Loading branch information
trappitsch authored Mar 17, 2022
1 parent 8f28fc6 commit 2251210
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 3 deletions.
18 changes: 18 additions & 0 deletions docs/dev/api/guis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ Create a PyQt app and run it.

.. autofunction:: dt_ions

**************************
:func:`integrals_packages`
**************************

Create a PyQt app and run it.

.. autofunction:: integrals_packages

*************************
:func:`nof_ions_per_shot`
*************************
Expand Down Expand Up @@ -202,6 +210,16 @@ Matplotlib PyQt figure to plot histogram for arrival time differences between io
:members:
:undoc-members:

****************************
:class:`IntegralsPerPackage`
****************************

Matplotlib PyQt figure to integrals per package.

.. autoclass:: IntegralsPerPackage
:members:
:undoc-members:

********************
:class:`IonsPerShot`
********************
Expand Down
32 changes: 30 additions & 2 deletions docs/pkg/special.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The following code shows you how to do this:

.. code-block:: python
from typing import Path
from pathlib import Path
from rimseval import CRDFileProcessor
from rimseval.guis import hist_nof_shots
Expand Down Expand Up @@ -70,7 +70,7 @@ This number is of course user-defined and can be omitted.

.. code-block:: python
from typing import Path
from pathlib import Path
from rimseval import CRDFileProcessor
from rimseval.guis import dt_ions
Expand All @@ -80,3 +80,31 @@ This number is of course user-defined and can be omitted.
crd.spectrum_full()
dt_ions(crd, max_ns=100)
---------------------
Integrals per package
---------------------

If you have split your spectrum into packages
and have defined integrals,
this routine allows you to show a figure
of all integrals per package
versus the number of the package.
This is especially interesting to find bursts in your measurements,
i.e., when measuring with the desorption laser.

The following example shows how the plot is generated:

.. code-block:: python
from pathlib import Path
from rimseval import CRDFileProcessor
from rimseval.guis import integrals_packages
my_file = Path("path/to/my_file.crd")
crd = CRDFileProcessor(crd)
crd.spectrum_full()
integrals_packages(crd)
3 changes: 2 additions & 1 deletion rimseval/guis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from .integrals import define_backgrounds_app, define_integrals_app
from .mcal import create_mass_cal_app
from .plots import dt_ions, nof_ions_per_shot
from .plots import dt_ions, integrals_packages, nof_ions_per_shot

__all__ = [
"create_mass_cal_app",
"define_backgrounds_app",
"define_integrals_app",
"dt_ions",
"integrals_packages",
"nof_ions_per_shot",
]
74 changes: 74 additions & 0 deletions rimseval/guis/plots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Plotting capability for specialty functions."""

import itertools
import sys
from typing import Tuple

Expand All @@ -20,6 +21,10 @@
from rimseval.processor import CRDFileProcessor


# markers to cycle through
MARKERS = ("o", "^", "s", "v", "<", ">", "+", "x", "*", "1", "2", "3", "4")


class PlotFigure(QtWidgets.QMainWindow):
"""QMainWindow to plot a Figure."""

Expand Down Expand Up @@ -157,6 +162,60 @@ def calc_and_draw(self) -> None:
self.sc.draw()


class IntegralsPerPackage(PlotFigure):
"""Plot integrals of all packages versus package number."""

def __init__(
self, crd: CRDFileProcessor, logy: bool = False, theme: str = None
) -> None:
"""Initialize the class.
:param crd: CRD file to process.
:param logy: Plot with logarithmic y-axis? Defaults to ``True``
:param theme: Theme to plot in, defaults to ``None``.
:raises OSError: Packages are not defined
"""
super().__init__(logy=logy, theme=theme)

self.setWindowTitle("Integrals per package")

self.crd = crd

if crd.integrals_pkg is None:
raise OSError("Integrals for packages are not available.")

self.calc_and_draw()

def calc_and_draw(self) -> None:
"""Create the plot for all the defined integrals."""
int_names = self.crd.def_integrals[0]
integrals_pkg = self.crd.integrals_pkg

xdata = np.arange(len(integrals_pkg)) + 1 # start with 1
counts = integrals_pkg[:, :, 0]
errors = integrals_pkg[:, :, 1]

# plot
marker = itertools.cycle(MARKERS)
for it in range(counts.shape[1]): # loop through all defined integrals
dat = counts[:, it]
err = errors[:, it]
self.axes.errorbar(
xdata, dat, yerr=err, ls="--", label=int_names[it], marker=next(marker)
)

# labels
self.axes.set_xlabel("Package number")
self.axes.set_ylabel("Counts in integral")
self.axes.set_title(
f"Integrals per package - {self.crd.fname.with_suffix('').name}"
)
self.axes.legend()

self.sc.draw()


class IonsPerShot(PlotFigure):
"""Plot histogram for number of ions per shot."""

Expand Down Expand Up @@ -222,6 +281,21 @@ def dt_ions(
app.exec()


def integrals_packages(
crd: CRDFileProcessor, logy: bool = False, theme: str = None
) -> None:
"""Plot all the integrals versus package number for data split into packages.
:param crd: CRD file to process.
:param logy: Plot with logarithmic y axis? Defaults to ``True``
:param theme: Theme to plot in, defaults to ``None``.
"""
app = QtWidgets.QApplication(sys.argv)
window = IntegralsPerPackage(crd, logy=logy, theme=theme)
window.show()
app.exec()


def nof_ions_per_shot(
crd: CRDFileProcessor, logy: bool = False, theme: str = None
) -> None:
Expand Down

0 comments on commit 2251210

Please sign in to comment.