{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reading SB\n", "Length of SB: 16559\n", "Reading AFIB\n", "Length of AFIB: 9839\n", "Reading GSVT\n", "Length of GSVT: 948\n", "Reading SR\n", "Length of SR: 9720\n" ] } ], "source": [ "import pickle\n", "# read pickle files and check len and print first record and first record keys\n", "\n", "path = \"C:/Studium/dsa/data\"\n", "\n", "categories_dict = {\n", "'SB': [426177001],\n", "'AFIB': [164889003, 164890007],\n", "'GSVT': [426761007, 713422000, 233896004, 233897008, 713422000],\n", "'SR': [426783006, 427393009]\n", "}\n", "\n", "\n", "data = {}\n", "for cat_name in categories_dict.keys():\n", " print(f\"Reading {cat_name}\")\n", " with open(f'{path}/{cat_name}.pkl', 'rb') as f:\n", " records = pickle.load(f)\n", " data[cat_name] = records\n", " print(f\"Length of {cat_name}: {len(records)}\")" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Keys of first record of SB: dict_keys(['record_name', 'n_sig', 'fs', 'counter_freq', 'base_counter', 'sig_len', 'base_time', 'base_date', 'comments', 'sig_name', 'p_signal', 'd_signal', 'e_p_signal', 'e_d_signal', 'file_name', 'fmt', 'samps_per_frame', 'skew', 'byte_offset', 'adc_gain', 'baseline', 'units', 'adc_res', 'adc_zero', 'init_value', 'checksum', 'block_size'])\n", "Number of records with p_signal: 9720\n", "Number of records with e_p_signal: 0\n", "Number of records with d_signal: 0\n", "Number of records with e_d_signal: 0\n", "{'record_name': 'JS00002', 'n_sig': 12, 'fs': 500, 'counter_freq': None, 'base_counter': None, 'sig_len': 5000, 'base_time': None, 'base_date': None, 'comments': ['Age: 59', 'Sex: Female', 'Dx: 426177001,164934002', 'Rx: Unknown', 'Hx: Unknown', 'Sx: Unknown'], 'sig_name': ['I', 'II', 'III', 'aVR', 'aVL', 'aVF', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6'], 'p_signal': array([[-0.01 , 0.01 , 0.02 , ..., 0.054, 0.049, 0. ],\n", " [-0.024, -0.02 , 0.005, ..., 0.034, 0.034, -0.015],\n", " [-0.02 , -0.02 , 0. , ..., 0.034, 0.034, -0.01 ],\n", " ...,\n", " [ 0.015, 0.01 , -0.005, ..., -0.015, -0.02 , 0.005],\n", " [ 0.01 , 0.01 , 0. , ..., -0.02 , -0.024, 0. ],\n", " [ 0.01 , 0.01 , 0. , ..., -0.024, -0.029, -0.005]]), 'd_signal': None, 'e_p_signal': None, 'e_d_signal': None, 'file_name': ['JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat', 'JS00002.mat'], 'fmt': ['16', '16', '16', '16', '16', '16', '16', '16', '16', '16', '16', '16'], 'samps_per_frame': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'skew': [None, None, None, None, None, None, None, None, None, None, None, None], 'byte_offset': [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24], 'adc_gain': [1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0], 'baseline': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'units': ['mV', 'mV', 'mV', 'mV', 'mV', 'mV', 'mV', 'mV', 'mV', 'mV', 'mV', 'mV'], 'adc_res': [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16], 'adc_zero': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'init_value': [-10, 10, 20, 0, -15, 15, -10, -54, 63, 54, 49, 0], 'checksum': [12346, 26962, 14528, -13537, -6991, 14569, -383, 16468, -29512, -7548, -22267, 31542], 'block_size': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}\n" ] } ], "source": [ "# print keys of first record\n", "print(f\"Keys of first record of SB: {data['SB'][0].__dict__.keys()}\")\n", "\n", "counter_p = 0\n", "counter_e_p = 0\n", "counter_d = 0\n", "counter_e_d = 0\n", "for record in data['SR']:\n", " if record.p_signal is not None:\n", " counter_p += 1\n", " if record.e_p_signal is not None:\n", " counter_e_p += 1\n", " if record.d_signal is not None:\n", " counter_d += 1\n", "\n", "print(f\"Number of records with p_signal: {counter_p}\")\n", "print(f\"Number of records with e_p_signal: {counter_e_p}\")\n", "print(f\"Number of records with d_signal: {counter_d}\")\n", "print(f\"Number of records with e_d_signal: {counter_e_d}\")\n", "\n", "\n", "print(data['SB'][0].__dict__)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 2 }