shyft.dashboard.time_series.ts_viewer

Classes

TsViewer(*, bokeh_document[, title, state, ...])

TsViewer class is the main class combining all components to view time series in bokeh.

Exceptions

exception shyft.dashboard.time_series.ts_viewer.TsViewerError[source]

Bases: RuntimeError

class shyft.dashboard.time_series.ts_viewer.TsViewer(*, bokeh_document, title='', state=States.ACTIVE, width=150, height=None, padding=None, sizing_mode=None, time_step_restrictions=None, zoom_in_interval=None, zoom_out_interval=None, init_view_range=None, auto_dt_multiple=None, thread_pool_executor=None, add_dt_selector=True, logger=None, unit_registry=None, tools=None, time_zone=None, reset_time_axis=True, full_view=True, should_wait_async_view_data=False)[source]

Bases: object

TsViewer class is the main class combining all components to view time series in bokeh.

Different ViewContainer (As figures, tables) can be added to the viewer.

Examples

# create our viewer app
viewer = TsViewer()

# create view container
table1 = Table(viewer=viewer)
fig1 = Figure(viewer=viewer)

All view container will be bound to the same time axis, controlled by a TimeAxisHandler. (i.e. linked x axis of all figures)

To view time series data one need to define the data or how it can be retrieved with a DataSource. In addition one need to define the View(s), i.e. how the data should be visualised in the different ViewContainer. For convenience, book-keeping and easy messaging between apps is the combination of a DataSource and a List[Views] defined as an ds_view_handle.

Examples (continued)

# define data source
data_source = DataSource(ts_adapter=”TsAdapter”, unit=’MW’)
# define views
percentile_view = PercentileView(view_container_uid=fig1.uid)
table_view = TableView(view_container_uid=table1.uid)

# add it to the viewer
ds_view_handle = viewer.create_ds_view_handle(data_source=data_source,
views=[percentile_view, table_view])
# OR create an ds_view_handle and add it to the viewer
dsviehandle = DsViewHandle(data_source=data_source,
views=[percentile_view, table_view])
viewer.add_ds_view_handle(ds_view_handle)
# OR send it using the port function (takes a List[DsViewHandles])
viewer.receive_ds_view_handles_to_add([ds_view_handle])

# the ds_view_handle can be removed by

viewer.remove_ds_view_handle(ds_view_handle)
# OR using the port function (takes a List[DsViewHandles])
viewer.receive_ds_view_handles_to_remove([ds_view_handle])
param bokeh_document:

the bokeh document it belongs to

param title:

title of the app

param time_step_restrictions:

list of time step restrictions

param zoom_in_interval:

the minimum visible interval

param zoom_out_interval:

the maximum visible interval

param init_view_range:

the period which should be the default period

param auto_dt_multiple:

sets the lowest resolution of the time series

param thread_pool_executor:

the thread pool executor used for async requests

param add_dt_selector:

switch to add a time step selector tool

param logger:

python logger

param unit_registry:

the unit registry used in the app

param tools:

list of tools to be part of the TsViewer

param state:

the initial state

param full_view:

if set to true, the time-series are not clipped to t_now (should be the default!)

__init__(*, bokeh_document, title='', state=States.ACTIVE, width=150, height=None, padding=None, sizing_mode=None, time_step_restrictions=None, zoom_in_interval=None, zoom_out_interval=None, init_view_range=None, auto_dt_multiple=None, thread_pool_executor=None, add_dt_selector=True, logger=None, unit_registry=None, tools=None, time_zone=None, reset_time_axis=True, full_view=True, should_wait_async_view_data=False)[source]
Parameters:
  • bokeh_document (Document) – the bokeh document it belongs to

  • title (str | None) – title of the app

  • time_step_restrictions (List[int | float] | ndarray | None) – list of time step restrictions

  • zoom_in_interval (int | float | None) – the minimum visible interval

  • zoom_out_interval (int | float | None) – the maximum visible interval

  • init_view_range (UtcPeriod) – the period which should be the default period

  • auto_dt_multiple (int | None) – sets the lowest resolution of the time series

  • thread_pool_executor (ThreadPoolExecutor | None) – the thread pool executor used for async requests

  • add_dt_selector (bool) – switch to add a time step selector tool

  • logger (Logger | None) – python logger

  • unit_registry (UnitRegistry | None) – the unit registry used in the app

  • tools (List[TsViewerTool]) – list of tools to be part of the TsViewer

  • state (States | None) – the initial state

  • full_view (bool) – if set to true, the time-series are not clipped to t_now (should be the default!)

  • width (int | None)

  • height (int | None)

  • padding (int | None)

  • sizing_mode (str | None)

  • time_zone (str | None)

  • reset_time_axis (bool)

  • should_wait_async_view_data (bool)

Return type:

None

property layout: column | None
init_view_range(intersection=False)[source]

This function intializes the view range

Parameters:

intersection (bool)

Return type:

None

plot(reset_time_axis=True)[source]

This function triggers the plotting of views

Parameters:

reset_time_axis (bool)

Return type:

None

clear()[source]

This function clears all views, view contianer etc.

Return type:

None

trigger_data_update()[source]

This function triggers the reloading of the sources with data, each source is requested for data currently that will result in a call to the function above, request_time_axis(min_dt, data_time_range) to get back a time-axis that is fitted to the current view-range and auto/dt selection .. and the particular data-source limitations min_dt, and data_time_range. (possibly in background thread) and when done they will eventually call the trigger_view_update(…) with the new data.

TODO: consider passing the current view_range, cal,delta-t .. that is: the view-timeaxis(padded or not)

down to the source so that it can make it’s own choices. That helps a lot..

Return type:

None

source_starting_async_data_update(source)[source]

This function must be called by the source before starting an asynchronous data update operation.

Parameters:

source (Source)

source_completed_async_data_update(source)[source]

This function must be called by the source after its asynchronous data update.

Parameters:

source (Source)

trigger_view_update(view_data)[source]

This function triggers the updating of the views, with given data, it’s usually called by the data-sources when they are finished extracting data from the TsAdapters.

This function merely dispatches the received values to the view-containers that performs the presentation.

Parameters:

view_data (Dict[BaseView, Quantity[TsVector]])

Return type:

None

add_view_container(view_container)[source]

This functions adds a view container to the TsViewer and assignes an uid to the view container

Raises:

BindableError if view container is already bound to a TsViewer

Parameters:

view_container (BaseViewContainer)

Return type:

None

remove_view_container(view_container)[source]

This functions removes a view container from the TsViewer.

Raises:

BindableError if view container is is not bound to the TsViewer

Parameters:

view_container (BaseViewContainer)

Return type:

None

connect_to_dt_selector(receive_dt)[source]

This function connects the a receiver port to receive the current dt to the dt selector box if available.

Parameters:

receive_dt (Receiver)

Return type:

None

add_ds_view_handles(ds_view_handles)[source]

This function add new ds_view_handles to the TsViewer

Parameters:

ds_view_handles (List[DsViewHandle]) – ds_view_handles defining data source and views of the data

Return type:

None

remove_ds_view_handles(ds_view_handles)[source]

This function remove ds_view_handles from the TsViewer

Parameters:

ds_view_handles (List[DsViewHandle]) – ds_view_handles defining data source and views of the data

Return type:

None

add_tool(tool)[source]
Parameters:

tool (TsViewerTool)

Return type:

None

set_layout(layout)[source]

Function to quickly define a layout

Use List[ViewContainer] -> columns Use List[List[ViewContainer]] -

Parameters:

layout (List[BaseViewContainer] | List[List[BaseViewContainer]] | Dict[str, BaseViewContainer])

Return type:

None

property layout_components

This property returns all layout components of the all sub components

Parameters:
  • bokeh_document (bokeh.document.Document)

  • title (str | None)

  • state (States | None)

  • width (int | None)

  • height (int | None)

  • padding (int | None)

  • sizing_mode (str | None)

  • time_step_restrictions (List[int | float] | ndarray | None)

  • zoom_in_interval (int | float | None)

  • zoom_out_interval (int | float | None)

  • init_view_range (UtcPeriod)

  • auto_dt_multiple (int | None)

  • thread_pool_executor (ThreadPoolExecutor | None)

  • add_dt_selector (bool)

  • logger (logging.Logger | None)

  • unit_registry (UnitRegistry | None)

  • tools (List[TsViewerTool])

  • time_zone (str | None)

  • reset_time_axis (bool)

  • full_view (bool)

  • should_wait_async_view_data (bool)