--- a +++ b/data_preprocessing.ipynb @@ -0,0 +1,228 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from clinical_ts.timeseries_utils import *\n", + "from clinical_ts.ecg_utils import *" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# prepare data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "target_fs=100\n", + "data_root=Path(\"./ecg_data/\")\n", + "target_root=Path(\"./ecg_data_processed\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Ribeiro 2020" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download the test set from Ribeiro et al 2020 (https://www.nature.com/articles/s41467-020-15432-4) https://doi.org/10.5281/zenodo.3625006 and place it in data_folder_ribeiro_test" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data_folder_ribeiro_test = data_root/\"ribeiro2020_test\"\n", + "target_folder_ribeiro_test = target_root/(\"ribeiro_fs\"+str(target_fs))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "df_ribeiro_test, lbl_itos_ribeiro_test, mean_ribeiro_test, std_ribeiro_test = prepare_data_ribeiro_test(data_folder_ribeiro_test, target_fs=target_fs, channels=12, channel_stoi=channel_stoi_default, target_folder=target_folder_ribeiro_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#reformat everything as memmap for efficiency\n", + "reformat_as_memmap(df_ribeiro_test, target_folder_ribeiro_test/(\"memmap.npy\"),data_folder=target_folder_ribeiro_test,delete_npys=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Zheng 2020" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download the dataset from Zheng et al 2020 (https://www.nature.com/articles/s41597-020-0386-x) https://figshare.com/collections/ChapmanECG/4560497/2 and place it in data_folder_zheng" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data_folder_zheng = data_root/\"zheng2020/\"\n", + "target_folder_zheng = target_root/(\"zheng_fs\"+str(target_fs))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "df_zheng, lbl_itos_zheng, mean_zheng, std_zheng = prepare_data_zheng(data_folder_zheng, denoised=False, target_fs=target_fs, channels=12, channel_stoi=channel_stoi_default, target_folder=target_folder_zheng)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#reformat everything as memmap for efficiency\n", + "reformat_as_memmap(df_zheng, target_folder_zheng/(\"memmap.npy\"),data_folder=target_folder_zheng,delete_npys=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## CinC2020 Challenge" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download the training set of the CinC Challenge 2020 https://physionetchallenges.org/2020/ and place it in data_folder_cinc" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data_folder_cinc = data_root/\"cinc2020/\"\n", + "target_folder_cinc = target_root/(\"cinc_fs\"+str(target_fs))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "df_cinc, lbl_itos_cinc, mean_cinc, std_cinc = prepare_data_cinc(data_folder_cinc, target_fs=target_fs, channels=12, channel_stoi=channel_stoi_default, target_folder=target_folder_cinc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#reformat everything as memmap for efficiency\n", + "reformat_as_memmap(df_cinc, target_folder_cinc/(\"memmap.npy\"),data_folder=target_folder_cinc,delete_npys=True)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## PTB-XL" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download the PTB-XL dataset (https://www.nature.com/articles/s41597-020-0495-6) https://physionet.org/content/ptb-xl/1.0.1/ and place it in data_folder_ptb_xl" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data_folder_ptb_xl = data_root/\"ptb_xl/\"\n", + "target_folder_ptb_xl = target_root/(\"ptb_xl_fs\"+str(target_fs))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df_ptb_xl, lbl_itos_ptb_xl, mean_ptb_xl, std_ptb_xl = prepare_data_ptb_xl(data_folder_ptb_xl, min_cnt=0, target_fs=target_fs, channels=input_channels, channel_stoi=channel_stoi_default, target_folder=target_folder_ptb_xl)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#reformat everything as memmap for efficiency\n", + "reformat_as_memmap(df_ptb_xl, target_folder_ptb_xl/(\"memmap.npy\"),data_folder=target_folder_ptb_xl,delete_npys=True)" + ] + } + ], + "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.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}