Pulse

Utilities for working with ECG/EKG data.
/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/docscrape.py:259: UserWarning: potentially wrong underline length... 
Example 
-------- in 
Function to create a temporary table in a database.
...
  else: warn(msg)
/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/docscrape.py:259: UserWarning: Unknown section Example
  else: warn(msg)

source

create_table_from_csv


def create_table_from_csv(
    cursor, connection, table_name:str, # Name of the table
    table_query:str, # Table creation query
    csv_path:str, # CSV path for table
):

Function to create a temporary table in a database.


source

connect_to_postgres


def connect_to_postgres(
    postgres_connection_path:str='/hpc/users/foxb02/.ecg_postgres.yaml', # Path of yaml file with configurations for postgres database
):

Function to connect to a postgres database


source

generate_plot


def generate_plot(
    waveform_array, figsize, dpi, save:bool=False, save_file_path:NoneType=None, return_figure:bool=False
):

Function to plot a


source

process_ecg


def process_ecg(
    waveform_array:list, # Array/list of waveform integer values,
    cutoff, # Length of array subset,
    random_index:bool=True, # Indicator of whether to randomly subset the waveform at a random start index
    random_cutoff:bool=False, # Indicator of whether to randomly generator a cutoff value
)->list: # Processed waveform array

High level function to process ecg data


source

subset_waveform


def subset_waveform(
    waveform_array:list, # Array/list of waveform integer values
    cutoff:int=5000, # Length of array subset
    random_index:bool=False, # Indicator of whether to randomly subset the waveform at a random start index
    random_cutoff:bool=False, # Indicator of whether to randomly generator a cutoff value
)->list: # subsetted waveform array

Function to take a subset of a waveform array


source

decode_waveform


def decode_waveform(
    waveform_string:str, # Waveform string
)->list: # List of int16 waveform values

Function to convert a waveform string from a buffer


source

ECG_Model_TST


def ECG_Model_TST(
    c_in, c_out, seq_len, n_layers:int=3, d_model:int=128, n_heads:int=16, d_ff:int=256, dropout:float=0.1,
    act:str='gelu', compression_channels:int=32, compression_rate:int=100
):

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call :meth:to, etc.

.. note:: As per the example above, an __init__() call to the parent class must be made before assignment on the child.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool


source

ECG_Model_TSAI


def ECG_Model_TSAI(
    c_in, d_model, c_out, n_head, dim_ff, n_layers, compression_channels:int=32, compression_rate:int=100,
    dropout:float=0.1, max_len:int=5000
):

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call :meth:to, etc.

.. note:: As per the example above, an __init__() call to the parent class must be made before assignment on the child.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool


source

ECG_Model


def ECG_Model(
    c_in, d_model, c_out, nhead, dim_ff, num_layers, compression_rate:int=100, dropout:float=0.1, max_len:int=5000
):

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call :meth:to, etc.

.. note:: As per the example above, an __init__() call to the parent class must be made before assignment on the child.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool


source

PositionalEncoding


def PositionalEncoding(
    d_model:int, dropout:float=0.1, max_len:int=5000
):

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call :meth:to, etc.

.. note:: As per the example above, an __init__() call to the parent class must be made before assignment on the child.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool