lumicks.pylake.channel.Slice¶
-
class
Slice
(data_source, labels=None, calibration=None)¶ A lazily evaluated slice of a timeline/HDF5 channel
Users will only ever get these as a result of slicing a timeline/HDF5 channel or slicing another slice (via this class’
__getitem__
), i.e. the__init__
method will never be invoked by users.Parameters: - data_source : Any
A slice data source. Can be
Continuous
,TimeSeries
, ‘TimeTags’, or any other source which conforms to the same interface.- labels : Dict[str, str]
Plot labels: “x”, “y”, “title”.
- calibration: ForceCalibration
-
__init__
(data_source, labels=None, calibration=None)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(data_source[, labels, calibration])Initialize self. downsampled_by
(factor[, reduce])Return a copy of this slice which is downsampled by factor
downsampled_like
(other_slice[, reduce])Downsample high frequency data analogously to a low frequency channel in the same way that Bluelake does it. downsampled_over
(range_list[, reduce, where])Downsample channel data based on timestamp ranges. downsampled_to
(frequency[, reduce, where, …])Return a copy of this slice downsampled to a specified frequency plot
([start])A simple line plot to visualize the data over time range_selector
([show])Attributes
calibration
Calibration data slicing is deferred until calibration is requested to avoid slicing values that may be needed. data
The primary values of this channel slice sample_rate
The data frequency for continuous data sources or None
if it’s variableseconds
Relative time (in seconds) that corresponds to the channel data start
Starting timestamp of this time series in nanoseconds stop
End timestamp of this time series in nanoseconds timestamps
Absolute timestamps (since epoch) which correspond to the channel data -
__getitem__
(item)¶ All indexing is in timestamp units (ns)
-
downsampled_by
(factor, reduce=<function mean>)¶ Return a copy of this slice which is downsampled by
factor
Parameters: - factor : int
The size and sample rate of the data will be divided by this factor.
- reduce : callable
The
numpy
function which is going to reduce multiple samples into one. The default isnp.mean
, butnp.sum
could also be appropriate for some cases, e.g. photon counts.
-
downsampled_like
(other_slice, reduce=<function mean>)¶ Downsample high frequency data analogously to a low frequency channel in the same way that Bluelake does it.
Note: some data required to reconstruct the first low frequency time point can actually occur before the starting timestamp of the marker and is therefore missing from the exported
.h5
file. Therefore, it is not always possible to downsample to all of the data points in the low frequencyother_slice
. This function returns both the requested downsampled channel data and a copy of the input channel cropped such that both returnedSlice
objects have the same time points.Parameters: - other_slice : Slice
Timeline channel to downsample like. This should be a low frequency channel that provides the timestamps to downsample to.
- reduce : callable
The
numpy
function which is going to reduce multiple samples into one. The default isnp.mean
, butnp.sum
could also be appropriate for some cases, e.g. photon counts.
Returns: - downsampled_slice : Slice
This channel downsampled to the same timestamp ranges as
other_slice
.- cropped_other_slice : Slice
A copy of
other_slice
cropped such that the timestamps match those ofdownsampled_slice
.
-
downsampled_over
(range_list, reduce=<function mean>, where='center')¶ Downsample channel data based on timestamp ranges. The downsampling function (e.g. np.mean) is evaluated for the time between a start and end time of each block. A list is returned that contains the data corresponding to each block.
Parameters: - range_list : list of tuples
A list of (start, stop) tuples indicating over which ranges to apply the function. Start and stop have to be specified in nanoseconds.
- reduce : callable
The
numpy
function which is going to reduce multiple samples into one. The default isnp.mean
, butnp.sum
could also be appropriate for some cases, e.g. photon counts.- where : str
Where to put the final time point. ‘center’ time point is put at (timestamps_subset[0] + timestamps_subset[-1]) / 2, where timestamps_subset are the timestamps corresponding to the samples being downsampled over. ‘left’ time point is put at start
Examples
from lumicks import pylake file = pylake.File("example.h5") stack = pylake.CorrelatedStack("example.tiff") file.force1x.downsampled_over(stack.timestamps)
-
downsampled_to
(frequency, reduce=<function mean>, where='center', method='safe')¶ Return a copy of this slice downsampled to a specified frequency
Parameters: - frequency : int
The desired downsampled frequency downsampled (Hz)
- reduce : callable
The
numpy
function which is going to reduce multiple samples into one. The default isnp.mean
, butnp.sum
could also be appropriate for some cases, e.g. photon counts.- where : str
Where to put the final time point. ‘center’ time point is put at (timestamps_subset[0] + timestamps_subset[-1]) / 2, where timestamps_subset are the timestamps corresponding to the samples being downsampled over. ‘left’ time point is put at start
- method : str
How to handle target sample times that are not exact multiples of the current sample time.
- ‘safe’ new sample time must be an exact multiple of the current sample time,
else an exception is raised.
‘ceil’ rounds the sample rate up to the nearest frequency which fulfills this condition ‘force’ downsample data with the target input frequency; this will result in variable
sample times and a variable number of sampling contributing to each target sample, but must be used for variable-frequency data
-
plot
(start=None, **kwargs)¶ A simple line plot to visualize the data over time
Parameters: - start : int64
Origin timestamp. This can be used to plot two slices starting at different times on the same axis.
- **kwargs
Forwarded to
matplotlib.pyplot.plot()
.
-
calibration
¶ Calibration data slicing is deferred until calibration is requested to avoid slicing values that may be needed.
-
data
¶ The primary values of this channel slice
-
sample_rate
¶ The data frequency for continuous data sources or
None
if it’s variable
-
seconds
¶ Relative time (in seconds) that corresponds to the channel data
-
start
¶ Starting timestamp of this time series in nanoseconds
-
stop
¶ End timestamp of this time series in nanoseconds
-
timestamps
¶ Absolute timestamps (since epoch) which correspond to the channel data