Notebook display#
Instruments and publishers display as cards in Jupyter, VS Code and Colab notebooks. A card needs no setup and never talks to the hardware.
Overview#
In Jupyter, VS Code and Colab, an instrument or publisher at the end of a cell displays as a card. Outside a notebook, repr() gives a one-line summary.
from instro import InstroPSU
from instro.drivers import VirtualPSU
psu = InstroPSU(name="bench", driver=VirtualPSU(), num_channels=2, dataset_rid="<dataset RID>")
psu.start()
psu # shows the card
An instrument’s card shows its driver, background daemon, publishers, default tags and, once start() has been called, the latest value of every channel. A card shows only what instro already holds in memory, so displaying an instrument never talks to the hardware.
Each publisher has a card too. A NominalCorePublisher card links its dataset in Nominal.
The notebook display example shows each card and needs no hardware or Nominal credentials. From a clone of the repository, just notebook opens it in JupyterLab: open notebook_display.md with Open With → Jupytext Notebook.
Display options#
instro.lib.set_display_options() changes every card, as a call or for the length of a with block:
from instro.lib import set_display_options
set_display_options(timezone="America/Los_Angeles", time_precision="ms")
with set_display_options(show_link=False):
psu # no request to resolve the Nominal workspace
Option |
Default |
Effect |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Link datasets to Nominal. The first link for a client makes one request to resolve its workspace. |
|
|
Sections with more items start collapsed |
|
|
Items listed per section |
Custom instruments and publishers#
A custom Instrument subclass gets a default card automatically. To customize the card, override _display_fields() and return (label, html) pairs built from in-memory state only. Start from super()._display_fields() to keep the rows of the class you extend:
To replace the whole card, override _repr_html_().
An instrument’s card describes each publisher in one line. A publisher without _display_summary() shows its class name. Define _display_summary(), returning one line of HTML, to describe it there; a subclass of a built-in publisher can extend the built-in line with super()._display_summary().