Skip to content

Commit

Permalink
a little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
StokesMIDE committed Feb 14, 2024
1 parent 1fb56b6 commit 86157a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
48 changes: 21 additions & 27 deletions idelib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import struct
import sys
from time import sleep
from typing import List, Optional

from ebmlite.core import loadSchema
import numpy as np
Expand Down Expand Up @@ -140,6 +141,8 @@ class Transformable(Cascading):
Note: The object's `transform` attribute will not change; it will
just be ignored.
"""
dataset: "Dataset"
children: list

def setTransform(self, transform, update=True):
""" Set the transforming function/object. This does not change the
Expand Down Expand Up @@ -187,7 +190,7 @@ def getTransforms(self, id_=None, _tlist=None):
"""
_tlist = [] if _tlist is None else _tlist
if getattr(self, "_transform", None) is not None:
if isinstance(self._transform, Iterable) and id_ is not None:
if isinstance(self._transform, Sequence) and id_ is not None:
x = self._transform[id_]
else:
x = self._transform
Expand Down Expand Up @@ -707,7 +710,7 @@ def __init__(self, dataset, channelId=None, parser=None, sensor=None,
self._unitsStr = None

self.cache = bool(cache)
self.singleSample = singleSample
self.singleSample: Optional[bool] = singleSample

if isinstance(sensor, int):
sensor = self.dataset.sensors.get(sensor, None)
Expand Down Expand Up @@ -1042,7 +1045,7 @@ def __init__(self, parent, subchannelId, name=None, units=('', ''),

self.allowMeanRemoval = parent.allowMeanRemoval
self.removeMean = False
self.singleSample = parent.singleSample
self.singleSample: Optional[bool] = parent.singleSample

# Is `color` a set of R/G/B values? Check for `__getitem__` instead of
# using `instance`, since various things (bytearray, wx.Colour, etc.)
Expand Down Expand Up @@ -1619,16 +1622,7 @@ def __getitem__(self, idx, display=False):
pairs.
"""
# TODO: Cache this; a Channel's SubChannels will often be used together.
if not self.useAllTransforms:
xform = self._comboXform
elif display:
xform = self._displayXform or self._fullXform
else:
xform = self._fullXform

if isinstance(idx, (int, np.integer)):


if idx >= len(self):
raise IndexError("EventArray index out of range")

Expand Down Expand Up @@ -2651,39 +2645,39 @@ def exportCsv(self, stream, start=None, stop=None, step=1, subchannels=True,
""" Export events as CSV to a stream (e.g. a file).
:param stream: The stream object to which to write CSV data.
:keyword start: The first event index to export.
:keyword stop: The last event index to export.
:keyword step: The number of events between exported lines.
:keyword subchannels: A sequence of individual subchannel numbers
:param start: The first event index to export.
:param stop: The last event index to export.
:param step: The number of events between exported lines.
:param subchannels: A sequence of individual subchannel numbers
to export. Only applicable to objects with subchannels.
`True` (default) exports them all.
:keyword callback: A function (or function-like object) to notify
:param callback: A function (or function-like object) to notify
as work is done. It should take four keyword arguments:
`count` (the current line number), `total` (the total number
of lines), `error` (an exception, if raised during the
export), and `done` (will be `True` when the export is
complete). If the callback object has a `cancelled`
attribute that is `True`, the CSV export will be aborted.
The default callback is `None` (nothing will be notified).
:keyword callbackInterval: The frequency of update, as a
:param callbackInterval: The frequency of update, as a
normalized percent of the total lines to export.
:keyword timeScalar: A scaling factor for the event times.
:param timeScalar: A scaling factor for the event times.
The default is 1 (microseconds).
:keyword raiseExceptions:
:keyword dataFormat: The number of decimal places to use for the
:param raiseExceptions:
:param dataFormat: The number of decimal places to use for the
data. This is the same format as used when formatting floats.
:keyword useUtcTime: If `True`, times are written as the UTC
:param useUtcTime: If `True`, times are written as the UTC
timestamp. If `False`, times are relative to the recording.
:keyword useIsoFormat: If `True`, the time column is written as
:param useIsoFormat: If `True`, the time column is written as
the standard ISO date/time string. Only applies if `useUtcTime`
is `True`.
:keyword headers: If `True`, the first line of the CSV will contain
:param headers: If `True`, the first line of the CSV will contain
the names of each column.
:keyword removeMean: Overrides the EventArray's mean removal for the
:param removeMean: Overrides the EventArray's mean removal for the
export.
:keyword meanSpan: The span of the mean removal for the export.
:param meanSpan: The span of the mean removal for the export.
-1 removes the total mean.
:keyword display: If `True`, export using the EventArray's 'display'
:param display: If `True`, export using the EventArray's 'display'
transform (e.g. unit conversion).
:return: Tuple: The number of rows exported and the elapsed time.
"""
Expand Down
2 changes: 1 addition & 1 deletion idelib/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def dataParser(cls):
#===============================================================================

def renameKeys(d, renamed, exclude=True, recurse=True,
mergeAttributes=True):
mergeAttributes=True) -> dict:
""" Create a new dictionary from and old one, using different keys. Used
primarily for converting EBML element names to function keyword
arguments.
Expand Down

0 comments on commit 86157a7

Please sign in to comment.