nwbwidgets.utils package

Submodules

nwbwidgets.utils.cmaps module

Taken from https://github.com/maartenbreddels/ipyvolume/pull/178

nwbwidgets.utils.cmaps.linear_transfer_function(color, min_opacity=0, max_opacity=0.05, reverse_opacity=False, n_elements=256)[source]

Transfer function of a single color and linear opacity. :param color: List-like RGB, or string with hexadecimal or named color.

RGB values should be within 0-1 range.

Parameters
  • min_opacity (float, int) – Minimum opacity, default value is 0.0. Lowest possible value is 0.0, optional.

  • max_opacity (float, int) – Maximum opacity, default value is 0.05. Highest possible value is 1.0, optional.

  • reverse_opacity (bool) – Linearly decrease opacity, optional.

  • n_elements (int) – Length of rgba array transfer function attribute.

Returns

transfer_function

Return type

ipyvolume TransferFunction

Example

>>> import ipyvolume as ipv
>>> green_tf = ipv.transfer_function.linear_transfer_function('green')
>>> ds = ipv.datasets.aquariusA2.fetch()
>>> ipv.volshow(ds.data[::4,::4,::4], tf=green_tf)
>>> ipv.show()
.. seealso:: matplotlib_transfer_function()
nwbwidgets.utils.cmaps.matplotlib_transfer_function(colormap_name, min_opacity=0, max_opacity=0.05, reverse_colormap=False, reverse_opacity=False, n_elements=256)[source]

Transfer function from matplotlib colormaps. :param colormap_name: name of matplotlib colormap :param min_opacity: Minimum opacity, default value is 0.

Lowest possible value is 0, optional.

Parameters
  • max_opacity (float, int) – Maximum opacity, default value is 0.05. Highest possible value is 1.0, optional.

  • reverse_colormap (bool) – reversed matplotlib colormap, optional.

  • reverse_opacity (bool) – Linearly decrease opacity, optional.

  • n_elements (int) – Length of rgba array transfer function attribute.

Returns

transfer_function

Return type

ipyvolume TransferFunction

Example

>>> import ipyvolume as ipv
>>> rgb = (0, 255, 0)  # RGB value for green
>>> green_tf = ipv.transfer_function.matplotlib_transfer_function('bone')
>>> ds = ipv.datasets.aquariusA2.fetch()
>>> ipv.volshow(ds.data[::4,::4,::4], tf=green_tf)
>>> ipv.show()
.. seealso:: linear_transfer_function()

nwbwidgets.utils.dandi module

nwbwidgets.utils.dandi.get_all_dandisets_metadata()[source]
nwbwidgets.utils.dandi.get_dandiset_metadata(dandiset_id: str)[source]
nwbwidgets.utils.dandi.list_dandiset_files(dandiset_id: str)[source]
nwbwidgets.utils.dandi.get_file_url(dandiset_id: str, file_path: str)[source]

nwbwidgets.utils.dynamictable module

nwbwidgets.utils.dynamictable.extract_data_from_intervals(dynamic_table: DynamicTable)[source]
nwbwidgets.utils.dynamictable.infer_categorical_columns(dynamic_table: DynamicTable, region: Optional[Iterable] = None)[source]
Parameters
  • dynamic_table (DynamicTable) –

  • region (Iterable) – row indices to select

Returns

categorical_cols – keys: as columns that are categorical, values as the unique values

Return type

dict()

nwbwidgets.utils.dynamictable.infer_columns_to_plot(dynamic_table: DynamicTable)[source]

Infer which columns can be plotted in summary widgets

Parameters

dynamic_table (DynamicTable) –

Returns

column_names_to_plot – Columns that can be plotted with the dynamic table summary

Return type

list

nwbwidgets.utils.dynamictable.group_and_sort(group_vals=None, group_select=None, order_vals=None, keep_rows=None, limit=None)[source]

Logical flow: 0) Apply discard_rows - throw out any listed rows 1) Apply group select - Return only values that are within this group 2) Apply order - If group is provided, items are sorted first by group and then by order 3) Apply limit - Applied per group 4) Apply window - Return only items [int] through [int]. Useful for plotting

Parameters
  • group_vals (array-like of str) – [‘a’, ‘b’, ‘b’, ‘a’, ‘a’, ‘b’, ‘b’, ‘c’]

  • group_select (array-like of str) – [‘a’, ‘b’]

  • order_vals (array-like of ints) – [0, 3, 4, 1, 2, 5, 6, 7]

  • limit (int) –

nwbwidgets.utils.functional module

class nwbwidgets.utils.functional.MemoizeMutable(fn)[source]

Bases: object

nwbwidgets.utils.mpl module

nwbwidgets.utils.mpl.create_big_ax(fig)[source]
nwbwidgets.utils.mpl.grid_sps(shape, subplot_spec=None, fig=None)[source]

Create subplot_spec from pandas.DataFrame

Parameters
  • shape (tuple) –

  • subplot_spec (GridSpec, optional) –

  • fig (matplotlib.pyplot.Figure, optional) –

nwbwidgets.utils.plotly module

nwbwidgets.utils.plotly.multi_trace(x, y, color, label=None, fig=None, insert_nans=False)[source]

Create multiple traces that are associated with a single legend label

Parameters
  • x (array-like) –

  • y (array-like) –

  • color (str) –

  • label (str, optional) –

  • fig (go.FigureWidget) –

nwbwidgets.utils.plotly.event_group(times_list, offset=0, color='Black', label=None, fig=None, marker=None, line_width=None)[source]

Create an event raster that are all associated with a single legend label

Parameters
  • times_list (list of array-like) –

  • offset (float, optional) –

  • label (str, optional) –

  • fig (go.FigureWidget) –

  • optional

  • go.Scatter.marker (passed to) –

  • marker (str) –

  • line_width (str) –

  • color (str) – default: Black

nwbwidgets.utils.pynwb module

nwbwidgets.utils.pynwb.robust_unique(a)[source]

nwbwidgets.utils.testing module

nwbwidgets.utils.testing.dicts_exact_equal(first, second)[source]

Return whether two dicts of arrays are exactly equal

nwbwidgets.utils.testing.dicts_approximate_equal(first, second)[source]

Return whether two dicts of arrays are roughly equal

nwbwidgets.utils.timeseries module

nwbwidgets.utils.timeseries.get_timeseries_tt(node: TimeSeries, istart=0, istop=None) ndarray[source]

For any TimeSeries, return timestamps. If the TimeSeries uses starting_time and rate, the timestamps will be generated.

Parameters
  • node (pynwb.TimeSeries) –

  • istart (int, optional) – Optionally sub-select the returned times - lower bound

  • istop (int, optional) – Optionally sub-select the returned times - upper bound

Return type

numpy.ndarray

nwbwidgets.utils.timeseries.get_timeseries_maxt(node: TimeSeries) float[source]

Returns the maximum time of any TimeSeries

Parameters

node (pynwb.TimeSeries) –

Return type

float

nwbwidgets.utils.timeseries.get_timeseries_mint(node: TimeSeries) float[source]

Returns the minimum time of any TimeSeries

Parameters

node (pynwb.TimeSeries) –

Return type

float

nwbwidgets.utils.timeseries.get_timeseries_in_units(node: TimeSeries, istart=None, istop=None)[source]

Convert data into the designated units

Parameters
  • node (pynwb.TimeSeries) –

  • istart (int) –

  • istop (int) –

Return type

numpy.ndarray, str

nwbwidgets.utils.timeseries.timeseries_time_to_ind(node: TimeSeries, time, ind_min=None, ind_max=None) int[source]

Get the index of a certain time for any TimeSeries. For TimeSeries that use timestamps, bisect is used. You can optionally provide ind_min and ind_max to constrain the search.

Parameters
  • node (pynwb.TimeSeries) –

  • time (float) –

  • ind_min (int, optional) –

  • ind_max (int, optional) –

nwbwidgets.utils.timeseries.bisect_timeseries_by_times(timeseries: TimeSeries, starts, duration: float, traces=None)[source]
Parameters
  • timeseries (TimeSeries) –

  • starts (iterable) – time at which to bisect

  • duration (float) – duration of window after start

  • traces (int) – index into the second dim of data

Returns

out – list with bisected arrays from data

Return type

list

nwbwidgets.utils.timeseries.align_by_times_with_timestamps(timeseries: TimeSeries, starts, duration: float, traces=None)[source]
Parameters
  • timeseries (TimeSeries) – timeseries with variable timestamps

  • starts (array-like) – starts in seconds

  • duration (float) – duration in seconds

Returns

out – list: length=(n_trials); list[0]: array, shape=(n_time, …)

Return type

list

nwbwidgets.utils.timeseries.align_by_times_with_rate(timeseries: TimeSeries, starts, duration: float, traces=None)[source]
Parameters
  • timeseries (TimeSeries) – timeseries with variable timestamps

  • starts (array-like) – starts in seconds

  • duration (float) – duration in seconds

Returns

out – list: length=(n_trials); list[0]: array, shape=(n_time, …)

Return type

list

nwbwidgets.utils.timeseries.align_timestamps_by_trials(timeseries: TimeSeries, starts, before: float, after: float)[source]
Parameters
  • timeseries (TimeSeries) – timeseries with variable timestamps

  • starts (array-like) – starts in seconds

  • duration (float) – duration in seconds

Returns

out – list: length=(n_trials); list[0]: array, shape=(n_time, …)

Return type

list

nwbwidgets.utils.timeseries.align_by_trials(timeseries: TimeSeries, start_label='start_time', before=0.0, after=1.0)[source]
Parameters
  • timeseries – TimeSeries

  • start_label – str default: ‘start_time’

  • before – float time after start_label in secs (positive goes back in time)

  • after – float time after stop_label in secs (positive goes forward in time)

Returns

np.array(shape=(n_trials, n_time, …))

nwbwidgets.utils.timeseries.align_by_time_intervals(timeseries: TimeSeries, intervals, start_label='start_time', before=0.0, after=0.0, traces=None)[source]
Parameters
  • timeseries – pynwb.TimeSeries

  • intervals – pynwb.epoch.TimeIntervals

  • start_label – str default: ‘start_time’

  • before – float time after start_label in secs (positive goes back in time)

  • after – float time after stop_label in secs (positive goes forward in time)

  • timestamps – bool if alignment uses timestamps or constant rate and starting time in TimeSeries

Returns

np.array(shape=(n_trials, n_time, …))

nwbwidgets.utils.units module

nwbwidgets.utils.units.get_spike_times(units: Units, index, in_interval)[source]

Use bisect methods to efficiently retrieve spikes from a given unit in a given interval

Parameters
  • units (pynwb.misc.Units) –

  • index (int) –

  • in_interval (start and stop times) –

nwbwidgets.utils.units.get_min_spike_time(units: Units)[source]

Efficiently retrieve the first spike time across all units

Parameters

units (pynwb.misc.Units) –

nwbwidgets.utils.units.get_max_spike_time(units: Units)[source]

Efficiently retrieve the last spike time across all units

Parameters

units (pynwb.misc.Units) –

nwbwidgets.utils.units.align_by_times(units: Units, index, starts, stops)[source]
Parameters
  • units – pynwb.misc.Units

  • index – int

  • starts – array-like

  • stops – array-like

Returns

np.array

nwbwidgets.utils.units.align_by_trials(units: Units, index, start_label='start_time', stop_label=None, start=-0.5, end=1.0)[source]
Parameters
  • units

  • start_label – str default: ‘start_time’

  • stop_label – str default: None (just align to start_time)

  • start – float Start time for calculation before or after (negative or positive) the reference point (aligned to).

  • end – float End time for calculation before or after (negative or positive) the reference point (aligned to).

Returns

np.array(shape=(n_trials, n_time, …))

nwbwidgets.utils.units.align_by_time_intervals(units: Units, index, intervals, start_label='start_time', stop_label='stop_time', start=0.0, end=0.0, rows_select=(), progress_bar=None)[source]
Parameters
  • units – time-aware neurodata_type

  • index – int

  • intervals – pynwb.epoch.TimeIntervals

  • start_label – str default: ‘start_time’

  • stop_label – str default: ‘stop_time’

  • start – float Start time for calculation before or after (negative or positive) the reference point (aligned to).

  • end – float End time for calculation before or after (negative or positive) the reference point (aligned to).

  • rows_select – array_like, optional sub-selects specific rows

  • progress_bar – FloatProgress, optional Proved a progress bar object to have this method automatically update the progress bar

Returns

np.array(shape=(n_trials, n_time, …))

nwbwidgets.utils.units.get_unobserved_intervals(units, time_window, units_select=())[source]

nwbwidgets.utils.widgets module

nwbwidgets.utils.widgets.clean_axes(axes)[source]

Removes top and right spines from axes

Parameters

axes (iterable) –

nwbwidgets.utils.widgets.unpack_controls(controls, process_controls=<function <lambda>>)[source]
nwbwidgets.utils.widgets.interactive_output(f, controls, process_controls=<function <lambda>>, fixed=None)[source]

Connect widget controls to a function.

This function does not generate a user interface for the widgets (unlike interact). This enables customisation of the widget user interface layout. The user interface layout must be defined and displayed manually.

nwbwidgets.utils.widgets.set_plotly_callbacks(f, controls, process_controls=<function <lambda>>)[source]
class nwbwidgets.utils.widgets.Timer(timeout, callback)[source]

Bases: object

cancel()[source]
nwbwidgets.utils.widgets.debounce(wait)[source]

Decorator that will postpone a function’s execution until after wait seconds have elapsed since the last time it was invoked.

Module contents