Fast H5 File Viewer
DataBrowserView
for .h5
files in ScopeFoundry.In the previous tutorial, you learned how to create a DataBrowserView
. Here, we provide tips for faster development after creating a ScopeFoundry.Measurement
.
Run a measurement, hit Analyze with ipynb, and copy the
.h5_dataloaders
file next to your viewer files. You may rename it to avoid conflicts.From your
ScopeFoundry.Measurement
, copy the following methods:setup_figure
update_display
However, slight modifications, mainly deletions, may still be required.
Ensure your
DataBrowserView
subclass is named the same as the measurement. Otherwise, override theon_change_filename
method.Link it with this boilerplate code.
def setup(self): self.setup_figure() def on_change_data_filename(self, fname): self.data = load(fname) self.update_display()
Add the viewer to your data browser app.
self.add_view(RandomNumberGenView(self))
Putting Everything Together
For the random_number_gen_simple.py
example from the previous tutorial, the code becomes:
# viewers/random_number_gen.py
from qtpy import QtWidgets
import pyqtgraph as pg
from ScopeFoundry.data_browser import DataBrowserView
# Import the load function from the h5_data_loader.py file generated by Analyze with ipynb.
from .random_number_gen_h5_data_loaders import load_number_gen_readout_simple
class RandomNumberGenView(DataBrowserView):
# This name is used in the GUI for the DataBrowser
name = "number_gen_readout_simple"
def setup(self):
self.setup_figure()
def on_change_data_filename(self, fname):
self.data = load_number_gen_readout_simple(fname)
self.update_display()
def setup_figure(self):
"""
Runs once during app initialization and is responsible
for creating the widget `self.ui`.
"""
self.ui = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout()
self.ui.setLayout(layout)
# Create a plot widget
self.graphics_widget = pg.GraphicsLayoutWidget(border=(100, 100, 100))
self.plot = self.graphics_widget.addPlot(title=self.name)
self.plot_lines = {"y": self.plot.plot(pen="g")}
layout.addWidget(self.graphics_widget)
def update_display(self):
self.plot_lines["y"].setData(self.data.y) # NEEDED MODIFICATION HERE
With following two lines in your app, the viewer will look like.
from viewers.random_number_gen import RandomNumberGenView
self.add_view(RandomNumberGenView(self))