Morelia.Stream.Collect package

Submodules

Morelia.Stream.Collect.DataBucket module

class Morelia.Stream.Collect.DataBucket.Bucket(podDevice: Pod8206HR | Pod8401HR | Pod8274D, filterMethod: str = 'TakePast', filterInsert: float = nan)

Bases: object

Class to collect the data and timestamps when streaming from a POD device.

dataHose

Hose used to stream data from the POD device.

Type:

Hose

drops

Queue of the drops (timestamps and data) collected from the Hose.

Type:

Queue[ tuple[ list[float], list[Packet|None] ] ]

totalDropsCollected

Counts the total number of Drops collected from the Hose.

Type:

int

isCollecting

True when collecting drops from the Hose, False otherwise.

Type:

bool

DripDrop() tuple[list[float], list[Morelia.Packets.Packet.Packet | None]]

Dequeues the first point (timestamp, data) in the drops queue.

Raises:

Exception – No drops left to dequeue.

Returns:

Tuple (x,y) with ~1 sec of timestamps (x) and data (y) .

Return type:

tuple[ list[float], list[Packet|None] ]

EmptyBucket()

Resets the class.

GetVolumeOfDrops() int

Get the number of data drops currently in the queue.

Returns:

Size of the drops queue.

Return type:

int

StartCollecting(duration_sec: float | None = None) Thread

Start collecting stream data into the Bucket.

Parameters:

duration_sec (float | None, optional) – How long to stream data in seconds. Defaults to None.

Returns:

Started Thread for data collection.

Return type:

Thread

StopCollecting()

Tells the POD device to stop streaming data.

_CollectDrop()

Adds a point to the drops queue. Each point is a tuple (x,y) of the timestamps list (x) and the data list (y) for one drop (values from ~1 sec of streaming, or the number of values approximatly equal to the sample rate).

_CollectForDuration(duration_sec: float)

Collect streaming data for a given duration.

Parameters:

duration_sec (float) – How long to stream data in seconds.

_CollectWhileOpen()

Collect streaming data until the Hose is finished dripping.

_IsDropAvailableInHose() bool

Checks if the Hose has any uncollected drops.

Returns:

True if there is a drop to be collected, False otherwise.

Return type:

bool

Morelia.Stream.Collect.DataHose module

class Morelia.Stream.Collect.DataHose.Hose(podDevice: Pod8206HR | Pod8401HR | Pod8274D, filterMethod: str = 'TakePast', filterInsert: float = nan)

Bases: object

Collects streaming data from an 8206-HR or 8401-HR POD device. The data and timestamps are updated about every 1 second when streaming.

sampleRate

Sample rate of the POD device.

Type:

int

deviceValve

To open or close the data stream.

Type:

Valve

data

List of streaming binary data packets.

Type:

list[Packet|None]

timestamps (list[float]

List of timestamps for each data packet.

numDrops

Number of drops, or number of times the data and timestamps have been updated.

Type:

int

corruptedPointsRemoved

Total number of corrupted data points removed from the data and timestamps lists.

Type:

int

filterMethod

Method used to filter out corrupted data.

Type:

str

filterInsert

Value to replace corrupted data with if using the ‘InsertValue’ filter method. Defaults to np.nan.

Type:

float

EmptyHose()

Empties the hose and resets the attributes.

static GetSampleRate(podDevice: Pod8206HR | Pod8401HR | Pod8274D) int

Writes a command to the POD device to get its sample rate in Hz.

Parameters:

podDevice (Pod8206HR | Pod8401HR | Pod8274D) – POD device to get the sample rate for.

Raises:
  • Exception – Cannot get the sample rate for this POD device.

  • Exception – Could not connect to this POD device.

Returns:

Sample rate in Hz.

Return type:

int

PickFilterMethod(filterMethod: str)

Set the method used to filter corrupted data when streaming. The filter methods include ‘RemoveEntry’, ‘InsertValue’, ‘TakePast’, ‘TakeFuture’, or ‘DoNothing’. The default method is ‘DoNothing’.

Parameters:

filterMethod (str) – Filter method, which can be ‘RemoveEntry’, ‘InsertValue’, ‘TakePast’, ‘TakeFuture’, or ‘DoNothing’/other.

SetFilterInsertValue(insert: float)

Sets the value to insert in place of currupted data. This is only used if the filter method is ‘InsertValue’.

Parameters:

insert (float) – Numerical value to insert.

StartStream()

Start a thread to start streaming data from the POD device.

StopStream()

Writes a command to the POD device to stop streaming data.

_Drop(currentTime: float, ti: float, data: list[Morelia.Packets.Packet.Packet | None]) float

Updates the instance variables that store the streaming data. The data drops about every 1 second.

Parameters:
  • currentTime (float) – Current start time in seconds.

  • ti (float) – Computer clock time at the start of the ~1 second drop.

  • data (list[Packet | None]) – Packets recieved when streaming.

Returns:

updated current time in seconds for the next drop.

Return type:

float

_Filter(data: list[Morelia.Packets.Packet.Packet | None], timestamps: list[float]) bool

Searches the data list for corrupted points, and deals with them according to the set filter method.

Parameters:
  • data (list[Packet | None]) – List of Packets read from the POD device.

  • timestamps (list[float]) – List of timestamps in seconds for each Packet in the data list.

Returns:

True when the corrupted data is filtered, False otherwise. A list containing only None cannot be filtered.

Return type:

bool

_Filter_DoNothing(i: int, data: list[Morelia.Packets.Packet.Packet | None], timestamps: list[float])

Does nothing to the data and timestamps lists.

Parameters:
  • i (int) – Index of corrupted data.

  • data (list[Packet | None]) – List of Packets read from the POD device.

  • timestamps (list[float]) – List of timestamps in seconds for each Packet in the data list.

_Filter_InsertValue(i: int, timestamps: list[float], data: list[Morelia.Packets.Packet.Packet | None])

Replaces the data value at index i with a set value (class defaults to np.nan).

Parameters:
  • i (int) – Index of corrupted data.

  • data (list[Packet | None]) – List of Packets read from the POD device.

  • timestamps (list[float]) – List of timestamps in seconds for each Packet in the data list.

_Filter_RemoveEntry(i: int, data: list[Morelia.Packets.Packet.Packet | None], timestamps: list[float])

Removes a datapoint at index i from the data and timestamps lists.

Parameters:
  • i (int) – Index of corrupted data.

  • data (list[Packet | None]) – List of Packets read from the POD device.

  • timestamps (list[float]) – List of timestamps in seconds for each Packet in the data list.

_Filter_TakeFuture(i: int, data: list[Morelia.Packets.Packet.Packet | None], timestamps: list[float])

Replaces the data value at index i with the next Packet. If the index points to the last value in the data list, the data will be replaced with the previous Packet instead. If there are multiple currupted points in a row (data value is None), then all points will be replaced with the same future Packet.

Parameters:
  • i (int) – Index of corrupted data.

  • data (list[Packet | None]) – List of Packets read from the POD device.

  • timestamps (list[float]) – List of timestamps in seconds for each Packet in the data list.

_Filter_TakePast(i: int, data: list[Morelia.Packets.Packet.Packet | None], timestamps: list[float])

Replaces the data value at index i with the previous Packet. If the index points to the first value in the data list, the data will be replaced with the next Packet instead.

Parameters:
  • i (int) – Index of corrupted data.

  • data (list[Packet | None]) – List of Packets read from the POD device.

  • timestamps (list[float]) – List of timestamps in seconds for each Packet in the data list.

_Flow(stopAfterXfails: int = 3)

Streams data from the POD device. The data drops about every 1 second. Streaming will continue until a “stop streaming” packet is recieved.

Parameters:

stopAfterXfails (int) – The number of successive failed attempts of reading data before stopping the streaming.

Morelia.Stream.Collect.DeviceValve module

class Morelia.Stream.Collect.DeviceValve.Valve(podDevice: Pod8206HR | Pod8401HR | Pod8274D)

Bases: object

Simple class to start and stop streaming data from a POD device.

podDevice

POD device, such as an 8206-HR/8401-HR/8274D.

Type:

Pod8206HR | Pod8401HR | Pod8274D

streamCmd

Command name/number for streaming data.

Type:

str | int

streamPldStart

Payload to start streaming data.

Type:

int | bytes | tuple[int | bytes]

streamPldStop

Payload to stop streaming data.

Type:

int | bytes | tuple[int | bytes]

Close()

Write command to stop streaming

Drip() Packet

Reads one packet from the POD device.

Returns:

POD packet beginning with STX and ending with ETX. This may be a standard packet, binary packet, or an unformatted packet (STX+something+ETX).

Return type:

Packet

EmptyValve()

Reset the serial port buffer.

GetStartBytes() bytes

Gets the bytes string represeting a “start streaming data” packet.

Returns:

Bytes string for a self.streamCmd command and a self.streamPldStart payload.

Return type:

bytes

GetStopBytes() bytes

Gets the bytes string represeting a “stop streaming data” packet.

Returns:

Bytes string for a self.streamCmd command and a self.streamPldStop payload.

Return type:

bytes

Open()

Write command to start streaming.

Raises:

Exception – Could not connect to this POD device.

Morelia.Stream.Collect.DrainBucketToFile module

class Morelia.Stream.Collect.DrainBucketToFile.DrainBucket(dataBucket: Bucket, fileName: str, preampDevice: str | None = None)

Bases: object

This class is used to save the streaming data from a POD device that was collected by a Bucket into a file.

self.drainToFile

Class to to drain the data drops collected by a Bucket into a text or EDF file.

Type:

DrainToTXT, DrainToEDF

DrainBucketToFile(timeout_sec: float = 10.0, sleep: float = 0.25) Thread

Starts a thread that starts draining data drops into the save file.

Parameters:
  • timeout_sec (float, optional) – Quit saving data if no new data is recieved after timeout_sec time (in seconds). Defaults to 10.0.

  • sleep (float, optional) – Time duration in seconds to wait for the Bucket to collect more data before checking agian. Defaults to 0.25.

Returns:

Started thread where data is being saved to a file.

Return type:

Thread

IsCollecting() bool

Checks if the Bucket is collected data from the Hose.

Returns:

True if the Bucket is collecting data, False otherwise.

Return type:

bool

IsDataAvailable() bool

Checks if data is available in the Bucket.

Returns:

True if there are any drops in the Bucket, False otherwise.

Return type:

bool

_DrainDropToFile(timeoutTicker: float, timeout_sec: float = 10.0, sleep: float = 0.25) float

When data is available in the bucket, write one drop of data to the save file.

Parameters:
  • timeoutTicker (float) – Counts the amout of time passed since the last drop was recieved.

  • timeout_sec (float, optional) – Quit saving data if no new data is recieved after timeout_sec time (in seconds). Defaults to 10.0.

  • sleep (float, optional) – Time duration in seconds to wait for the Bucket to collect more data before checking agian. Defaults to 0.25.

Raises:

Exception – Timeout: no data found to be saved to file.

Returns:

Updated timeoutTicker.

Return type:

float

_ThreadedDrainBucketToFile(timeout_sec: float = 10.0, sleep: float = 0.25)

Opens a save file and starts saving data to it. The file is updated about every 1 sec. After the POD device stops streaming data, the file will close.

Parameters:
  • timeout_sec (float, optional) – Quit saving data if no new data is recieved after timeout_sec time (in seconds). Defaults to 10.0.

  • sleep (float, optional) – Time duration in seconds to wait for the Bucket to collect more data before checking agian. Defaults to 0.25.

Module contents