labcore.analysis.hvplotting#

HoloViews-based plotting for labstack. Contains a set of classes and functions that can be used to plot labstack-style data.

Important Classes:
  • Nodes:
    • Node: a base class for all nodes. Nodes are the basic blocks we use for

      processing data. They can be chained together to form a pipeline.

    • LoaderNode: a node that loads and preprocesses data.

    • ReduxNode: a node that reduces data dimensionality (e.g. by averaging).

    • ValuePlot: plots data values.

    • ComplexHist: plots histograms of complex data (‘IQ readout histograms’).

  • Widgets:
    • XYSelect: a widget for selecting x and y axes.

#TODO:

  • When fitting real and imaginary data, the color of the dot and line between data crosses. For example if the imaginary line is red with dots red, after adding a fit to the real data, the dots of imaginary will remain red, but the lines will be orange and the dots of the fit will orange but the lines red

  • Program refuses to open if it cannot find the config file.

  • Program refuses to open if it cannot find data properly formatted. This might be ok but a nice error message should appear.

Module Attributes

Data

Type alias for valid data.

DataDisplay

Type alias for displaying raw data.

Functions

labeled_widget(w[, lbl])

plot_data(data)

plot_df_as_2d(df, x, y[, dim_labels, graph_axes])

plot_xr_as_2d(ds, x, y[, dim_labels, graph_axes])

Classes

ComplexHist(*args, **kwargs)

MagnitudePhasePlot(*args, **kwargs)

Node([path, data_in])

Node base class.

PlotNode([path])

PlotNode, Node subclass

ReduxNode(*args, **kwargs)

ValuePlot(*args, **kwargs)

XYSelect()

class labcore.analysis.hvplotting.ComplexHist(*args, **kwargs)[source]#

Bases: PlotNode

fit_axis_options()[source]#

Returns a list of the different axes you can make a fit for in this node.

Should be overridden by subclasses to return the appropriate object.

get_plot()[source]#

Returns the plot as a holoviews object

Used for saving the plot as html or png.

Can/Should be overridden by subclasses to return the appropriate object.

name = 'ComplexHist'#
plot_panel()[source]#

Creates and returns a panel with the class’s plot

Should be overridden by subclasses to return the desired plot.

labcore.analysis.hvplotting.Data#

Type alias for valid data. Can be either a pandas DataFrame or an xarray Dataset.

alias of Dataset | DataFrame

labcore.analysis.hvplotting.DataDisplay#

Type alias for displaying raw data.

alias of DataFrame | Dataset | str | None

class labcore.analysis.hvplotting.MagnitudePhasePlot(*args, **kwargs)[source]#

Bases: PlotNode

fit_axis_options()[source]#

Returns a list of the different axes you can make a fit for in this node.

Should be overridden by subclasses to return the appropriate object.

get_data_fit_names(axis_name)[source]#
name = 'MagnitudePhasePlot'#
plot_options_panel()[source]#
plot_panel()[source]#

Creates and returns a panel with the class’s plot

Should be overridden by subclasses to return the desired plot.

process()[source]#

Make a copy of the data so that changes (added fits) don’t carry to other graphs/other analysis. Add saved arguments for all fits/axes.

class labcore.analysis.hvplotting.Node(path=None, data_in: Dataset | DataFrame | None = None, *args: Any, **kwargs: Any)[source]#

Bases: Viewer

Node base class.

A simple wrapper class that we use to standardize the way we process data. Aim: whenever input data is set/updated, Node.process is called (in the base class it simply sets output equal to input). User-defined nodes may watch data_in and data_out to update UI or anything else. Pipelines are formed by appending nodes to each other using Node.append.

Nodes with graphs must implement a get_plot() function that returns a holoviews graph object in order for that graph to be able to be saved as either an html or png file.

Params#

data_in

input data. Must be either a pandas DataFrame or an xarray Dataset.

data_out

processed output data. Must be either a pandas DataFrame or an xarray Dataset.

units_in

units of input data. Must be a dictionary with keys corresponding to dimensions, and values corresponding to units.

units_out

units of output data. Must be a dictionary with keys corresponding to dimensions, and values corresponding to units.

meta_in

any input metadata. Arbitrary keys/value.

meta_out

any output metadata. Arbitrary keys/value.

append(other: Node) None[source]#
static complex_dependents(data: Dataset | DataFrame | None) dict[str, dict[str, str]][source]#

Returns a dictionary of complex dependents and their real/imaginary parts.

Requires that complex data has already been split.

Parameters:

data – input data.

Returns:

dependent”: {“real”: “dependent_Re”, “imag”: “dependent_Im”}} dependent_Re and dependent_Im are the dimensions actually present in the data.

Return type:

dictionary of the form

static data_dims(data: Dataset | DataFrame | None) tuple[list[str], list[str]][source]#

Returns the dimensions of the data.

Format: (independents, dependents); both as lists of strings.

Raises:

NotImplementedError – if data is not a pandas DataFrame or an xarray Dataset.

data_in = None#
data_in_view() DataFrame | Dataset | str | None[source]#

Updating view of input data (as table; as provided by the data type).

Updates on change of data_in.

data_out = None#
data_out_view() DataFrame | Dataset | str | None[source]#

Updating view of output data (as table; as provided by the data type).

Updates on change of data_out.

detach(other: Node) None[source]#
dim_label(dim: str, which: str = 'out') str[source]#

Generate dimension label for use in plots.

Parameters:
  • dim – dimension name.

  • which – Either “in” or “out”, depending on whether we want the input or output data of the Node. Default is “out”.

Return type:

dimension label, including units if available.

dim_labels(which: str = 'out') dict[str, str][source]#

Generate dimension labels for use in plots.

Generates all dimension labels for the data. See Node.dim_label for more information.

fit_obj()[source]#
static mean(data: Dataset | DataFrame, *dims: str) Dataset | DataFrame[source]#

Takes the mean of data along the given dimensions.

Parameters:
  • data – input data.

  • *dims – dimensions to take the mean along

Return type:

data after taking the mean

Raises:

NotImplementedError – if data is not a pandas DataFrame or an xarray Dataset.

meta_in = {}#
meta_out = {}#
name = 'Node'#
plot() Viewable[source]#

A reactive panel object that allows selecting a plot type, and shows the plot.

Updates on change of data_out.

plot_obj() Node | None[source]#

The actual plot object.

Updates on change of data_out or the selection of the plot value.

Return type:

A dedicated plotting node.

process() None[source]#

Process data.

By default, simply sets data_out equal to data_in.

Can/Should be overridden by subclasses to do more complicated things.

static render_data(data: Dataset | DataFrame | None) DataFrame | Dataset | str | None[source]#

Shows data as renderable object.

Raises:

NotImplementedError – if data is not a pandas DataFrame or an xarray Dataset.

static split_complex(data: Dataset | DataFrame) Dataset | DataFrame[source]#

Split complex dependents into real and imaginary parts.

TODO: should update units as well

Parameters:

data – input data.

Return type:

data with complex dependents split into real and imaginary parts.

Raises:

NotImplementedError – if data is not a pandas DataFrame or an xarray Dataset.

units_in = {}#
units_out = {}#
update(*events: Event) None[source]#

Update the node using external events.

If event contains data_out, units_out, or meta_out, will set them as data_in, units_in, or meta_in respectively.

class labcore.analysis.hvplotting.PlotNode(path=None, *args, **kwargs)[source]#

Bases: Node

PlotNode, Node subclass

A superclass of all nodes that make plots of some sort. Mostly deals with define/creating fits for whatever graph subnode is instantiated.

FITS = None#
add_fit_box(selected=None, fitted=False)[source]#

Create a widget box for creating a fit.

fit_axis_options() list[source]#

Returns a list of the different axes you can make a fit for in this node.

Should be overridden by subclasses to return the appropriate object.

get_ansatz()[source]#
get_arguments()[source]#

Gets argument values for the currently selected fit and fit axis. Pulls data from the json if one exists, otherwise runs fit.guess and takes those values.

get_data_fit_names(axis_name, omit_axes=None)[source]#
get_fit_panel()[source]#
get_plot()[source]#

Returns the plot as a holoviews object

Used for saving the plot as html or png.

Can/Should be overridden by subclasses to return the appropriate object.

get_values(axis: str)[source]#

Gets a dictionary of values from the result of the FitResult’s params_to_dict() function.

indep_dims() int[source]#
static load_fits_from_config()[source]#
model_fit(*events: Event)[source]#

Models the fit starting with the arguments already created

name = 'PlotNode'#
plot_panel()[source]#

Creates and returns a panel with the class’s plot

Should be overridden by subclasses to return the desired plot.

process()[source]#

Make a copy of the data so that changes (added fits) don’t carry to other graphs/other analysis. Add saved arguments for all fits/axes.

refresh_graph = None#
reguess_fit(event)[source]#

Resets the current args to the results of the Fit.guess() function for the current fit class.

remove_fit_box()[source]#
save_fit(*events: Event)[source]#

Saves only the currently selected fit axis to the json file

set_fit_box(*events: Event, fitted: bool | None = None)[source]#
set_fit_box_helper(new_box: bool, fit_func_name: str, fitted: bool = False)[source]#

Removes and/or creates a fit box. If new_box == True this will (re)create the fit box.

update_dataset_by_data(fit_data: ndarray, name: str)[source]#
update_dataset_by_fit_and_axis(fit_class: Fit, model_args: dict[str, float], model_axis_name: str, saved: bool = False)[source]#

Updates the data for fit in the self.data_out dataset based on the given arguments.

update_fit_args(event)[source]#

Updates the temporary saved value for all of the fit’s starting arguments.

Called whenever a float input’s value is changed, when the fitbox is created, or when the fit_axis changes.

class labcore.analysis.hvplotting.ReduxNode(*args, **kwargs)[source]#

Bases: Node

OPTS = ['None', 'Mean']#
coordinates = []#
name = 'ReduxNode'#
on_input_update()[source]#
on_operations_change()[source]#
on_widget_change(*events)[source]#
operations = []#
process()[source]#

Process data.

By default, simply sets data_out equal to data_in.

Can/Should be overridden by subclasses to do more complicated things.

class labcore.analysis.hvplotting.ValuePlot(*args, **kwargs)[source]#

Bases: PlotNode

fit_axis_options()[source]#

Returns a list of the different axes you can make a fit for in this node.

Should be overridden by subclasses to return the appropriate object.

name = 'ValuePlot'#
plot_options_panel()[source]#
plot_panel()[source]#

Creates and returns a panel with the class’s plot

Should be overridden by subclasses to return the desired plot.

class labcore.analysis.hvplotting.XYSelect[source]#

Bases: Viewer

name = 'XYSelect'#
on_option_change()[source]#
options = ['None']#
value = ('None', 'None')#
labcore.analysis.hvplotting.labeled_widget(w, lbl=None)[source]#
labcore.analysis.hvplotting.plot_data(data: DataFrame | Dataset) Viewable[source]#
labcore.analysis.hvplotting.plot_df_as_2d(df, x, y, dim_labels=None, graph_axes=None)[source]#
labcore.analysis.hvplotting.plot_xr_as_2d(ds, x, y, dim_labels=None, graph_axes=None)[source]#