Titania monitoring framework
Project description
Titania
This is framework made for VELO LHCb data visualization. It's made to be fully customizable.
Titania on PyHEP: (See video below)
Installation
You should start with downloading Titania framework through pip:
(recommended)
pip install git+https://gitlab.cern.ch/velo-calibration-software/titania
or with
pip install titania
Development installation
git clone https://gitlab.cern.ch/velo-calibration-software/titania
cd titania
pip install -r requirements.txt
Starting project
When you are ready to create skeleton for your monitoring project with command:
python -m titania start --name NAME
REMEMBER TO REPLACE "NAME" WITH YOUR APPLICATION NAME
Now you are ready to go! Look for Quick Guide to learn how to use this framework.
Running tests
To run tests from CI sometimes it is needed to add:
set PYTHONPATH=%PYTHONPATH%;src;tests
Run project
From main application folder u can run this script:
python main.py
first you need to fill your main(look in our examples)
Quick Guide:
Ok, so lets say that you want add new tab to the your titania project:
Right here:
First: Defining data
Thats very easy step. We store data related code at data
module. You can find some implementations in framework core.
If the thing that you are looking for is not there, you should add your own class there.
That is extending TitaniaDataInterface
and putting it in data
folder. It is very simple.
The only requirements are that your class have fetch()
method, that returns the actual data.
Lets implement it with an example:
import random
from titania.data.data_core import LovellDataInterface
class RandomNList(LovellDataInterface):
def __init__(self, n=10):
self.n = n
def fetch(self):
return [random.random() for i in range(self.n)]
And that's it!
(The RandomNList
class can be found in package titania.data
)
Creating the Plot
We need something that we want to look at, we can easilly implement some kind of plot by extending MplPlot
.
This class uses Matplotlib for plotting.
(If you would like to use any other plotting framework, you must at least extend PlotInterface
class.)
from titania.plots.base_plot import MplPlot
class OurPlot(MplPlot):
def draw_plot(self):
ax = self.figure.add_subplot()
ax.plot(self.view.data.fetch())
self.draw()
Very simple, we inherit from that class, and we only need to define draw_plot
.
We already have self.figure
as matplotlib object, as a property of MplPlot class.
We can save this as a python file in plot
module.
##Part three, the prestige: Implementation of tab
Creating new python file
We will create exemplary plot.
We will create file called exemplary_gui.py
, and put it in views -> VELOView -> Exemplary -> exemplary_gui.py
Notice, that the Exemplary
folder does not exist, yet.
This is because we are structuring the files used to create tabs, in similar way that we structure tabs themselves.
You can look around in views
folder to see that this is true.
Although this is not necessary, this is the convention that we choose.
Writing code
Now, we will create minimal implementation for new tab, line by line.
Tab class
from titania.QtGUI import SimpleTab
class Exemplary(SimpleTab):
pass
First we create tab class, in this case called Exemplary
.
All of the tab implementations need to implement at least class QtTabInterface
.
This interface requires the following components:
- data argument in constructor, as in
__init__(self, data)
. This object must inherit from LovellDataInterface. - plot_panel_grid - assigned in constructor
- lineLayout - assigned in constructor
- grid_layout- assigned in constructor
- Method create_control_panel - that creates panel for the tab
- Method set_title - that returns the string with the name of the tab.
- Method initiate - that is runned after the creation of tab object, when we want to draw it on gui. But our class is using sub-class that is already implementing
The QtTabInterface
class is inherited by SimpleTab
, QtBaseLayoutTab
, QtPlotTab
.
In most of the cases you should use them instead of inheriting directly from QtTabInterface
.
The recommended way is by subclassing QtBaseLayoutTab
.
The minimal requirements for inheriting from QtBaseLayoutTab
are as follows:
- call
QtBaseLayoutTab
constructor withdata
argument - implement method set_title
- implement method create_control_panel
- implement method set_plot
Lets go back to our example
Data
from titania.QtGUI import QtBaseLayoutTab
from titania.data.data_core import EmptyLovellData
class Exemplary(QtBaseLayoutTab):
def __init__(self, parent=None):
QtBaseLayoutTab.__init__(self, data=EmptyLovellData(), parent=parent)
We added EmptyLovellData
to the call of the constructor.
The data object must inherit from LovellDataInterface
.
This interface only requirec implementation of fetch()
method, that will return data.
Name
Next we add the name of the tab, by implementing method get_title
.
def get_title(self):
return "example"
control panel
We add control panel, that we will use to navigate through the data.
def create_control_panel(self):
return EmptyControlPanel()
For now we leave that empty, with EmptyControlPanel
.
Plotting
Now we must define set_plot
. It must return object that Inherits PlotInterface
. But we can also use partially implemented SimplePlot
that inherits from that interface.
def set_plot(self):
return OurPlot(view=self)
It all comes together
Finally your file should look something like this:
from titania.QtGUI import QtBaseLayoutTab
from titania.panels.main_control_panel import EmptyControlPanel
from titania.data.exemplary_generated_data import RandomNList
from titania.plots.our_plot import OurPlot
class Exemplary(QtBaseLayoutTab):
def __init__(self, parent=None):
QtBaseLayoutTab.__init__(self, data=RandomNList(), parent=parent)
def get_title(self):
return "example"
def create_control_panel(self):
return EmptyControlPanel()
def set_plot(self):
return OurPlot(view=self)
Save it in the file described in previous section.
Now run your application. Can you see the new Tab? Probably not, because we are missing one key factor. We need to add this class to the configuration.
Configuration file
Open up file Config -> config.py.
You can probably see something like this
from view.VELOView.AreaPlotTestTab.stacked_area_plot_gui import StackedAreaTestTab
# ...
# (Long list of imports)
# ...
config = {
"VELOView": [ThresholdsTab, BoxPlotTestTab, StackedAreaTestTab, ScatterWithHistogramPlotTestTab, ScatterPlotTestTab, CountPlotTestTab],
"RUNView": [PedestalsPlot, AnotherThresholdsPlot, PedestalsSingleMatrixPlot]
}
This is the actual place which decides about the tabs placement. So add line that imports the created class, and add it to the list, like this:
from view.VELOView.AreaPlotTestTab.stacked_area_plot_gui import StackedAreaTestTab
# ...
# (Long list of imports)
# ...
from view.VELOView.ExemplaryPlotTab.exemplary_gui import Exemplary
config = {
"VELOView": [ThresholdsTab, BoxPlotTestTab, StackedAreaTestTab, ScatterWithHistogramPlotTestTab, ScatterPlotTestTab, CountPlotTestTab, Exemplary],
"RUNView": [PedestalsPlot, AnotherThresholdsPlot, PedestalsSingleMatrixPlot]
}
Now when you run your application you should be able to see your tab.
Of course, everything is empty. But now, with all of the knowledge that you gained, it should be easy for you to implement anything that you want to view here.
New plot type
If you would like to create new plot, the easiest way is to inherit from SimplePlot
class, and reimplement draw_plot
method.
Remember to use self.view.data.fetch() to get data!
Then you can return your new plot object in set_plot
method in your tab.
Take a look at GUIWidget -> PlotWindow -> Plot to get inspiration.
Project details
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
File details
Details for the file titania-0.3.71.tar.gz
.
File metadata
- Download URL: titania-0.3.71.tar.gz
- Upload date:
- Size: 501.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d6fbb8d2f621908ef4e93b4aa589e550faf26634533e05b2acc007cff7622d6 |
|
MD5 | 0a4711192806018c374f6bb758a59c69 |
|
BLAKE2b-256 | 80dc1722741332af2b457483fbe589da2bd5573a8e299a560c2756b099e52240 |
File details
Details for the file titania-0.3.71-py3-none-any.whl
.
File metadata
- Download URL: titania-0.3.71-py3-none-any.whl
- Upload date:
- Size: 504.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da0d33abe9e888815801efb64fca0e806800e5f6957f57e1b0404de34b5dc342 |
|
MD5 | 3aadf3535a4872aa00b2efa8d129dd7d |
|
BLAKE2b-256 | 4283f192fe6c5507fbcf0645044f72b8cab4e86b2ad53ca0ce7febcbc9cc94b4 |