Metadata-Version: 2.1
Name: foamgraph
Version: 0.2.0
Summary: Fast visualization library for interactive online analysis at scientific user facilities
Author-email: Jun Zhu <zhujun981661@gmail.com>
License: BSD 3-Clause License
        
        Copyright (c) 2022, Jun Zhu
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: repository, https://github.com/zhujun98/foamgraph
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy (>=1.21.5)
Provides-Extra: test
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: pytest-cov ; extra == 'test'

foamgraph
=========

[![PyPi](https://img.shields.io/pypi/v/foamgraph.svg)](https://pypi.org/project/foamgraph/)
![Build status](https://github.com/zhujun98/foamgraph/actions/workflows/python-package.yml/badge.svg)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/zhujun98/foamgraph.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/zhujun98/foamgraph/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/zhujun98/foamgraph.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/zhujun98/foamgraph/context:python)

![Language](https://img.shields.io/badge/language-python-blue)
[![Qt 5](https://img.shields.io/badge/Qt-5-brightgreen)](https://doc.qt.io/qt-5/)
[![Qt 6](https://img.shields.io/badge/Qt-6-brightgreen)](https://doc.qt.io/qt-6/)

`foamgraph` was originally developed as part of the online analysis framework 
[EXtra-foam](https://github.com/European-XFEL/EXtra-foam.git)
to provide fast display (10 Hz) and interactive data analysis for photon science
experiments at the state-of-art free-electron laser (FEL) facility - European XFEL.
It was implemented on top of the famous Python graphics and GUI library
[PyQtGraph](https://github.com/pyqtgraph/pyqtgraph). The following features make 
`foamgraph` stand out:

- The widgets and graphics objects are dedicated for photon science experiments.
- The performance has been significantly improved.
- It trades flexibility for an easy-to-use and unified API.

It must be emphasized that `foamgraph` is only a GUI library. It does not provide
any interfaces for data and metadata exchange between the backend and the GUI because
it is facility and experiment specific.

Nevertheless, when integrating GUI into a real-time data analysis pipeline, 
there are a couple of things to be taken into account:
- The GUI in principle should not perform any number crunching jobs, otherwise it 
will be slowed down because it is written in Python.
- Light computation tasks can be performed in a Python thread and the communication 
between the GUI and the processor can still be fulfilled using Qt's signal-slot connections.

## Getting started

Every plot widget should inherit from `PlotWidgetF`. The following code snippet
shows how to create a double-y plot with a title, axis labels and a legend:

```py
from foamgraph import FColor, PlotWidgetF


class DoubleYPlot(PlotWidgetF):
    def __init__(self, *, parent=None):
        super().__init__(parent=parent)

        self.setTitle('Double-y plot')
        self.setLabel('bottom', "x (arb. u.)")
        self.setLabel('left', "y (arb. u.)")
        self.setLabel('right', "y2 (arg. u.)")

        self._plot = self.plotCurve(name="Data", pen=FColor.mkPen('w'))
        self._plot2 = self.plotBar(
            name="Count", y2=True, brush=FColor.mkBrush('i', alpha=150))
        self.addLegend()

    def updateF(self, data):
        """Override."""
        self._plot.setData(data['x'], data['y'])
        self._plot2.setData(data['x'], data['y2'])
```

Every widget for image analysis should inherit from `ImageViewF`. The following
code snippet shows how to create a simple widget for displaying an image:

```py
from foamgraph import ImageViewF


class ImageAnalysis(ImageViewF):
    def updateF(self, data):
        """Override."""
        self.setImage(data['image']['data'])
```

## Examples

* Open a terminal and start the producer:

```sh
python examples/producer.py
```

* Open another terminal and start the plot gallery example

```sh
python examples/plot_gallery.py
```

![](examples/plot_gallery.gif)

* Open another terminal and start the image analysis example

```sh
python examples/image_analysis.py
```

![](examples/image_analysis.gif)
