{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":97984,"databundleVersionId":14096757,"sourceType":"competition"}],"dockerImageVersionId":31234,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Cell 1: Setup and Imports\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom pathlib import Path\nimport cv2\nfrom PIL import Image\n\n# Competition data paths\nINPUT_PATH = Path('/kaggle/input/physionet-ecg-image-digitization')\nprint(\"Available files:\")\n!ls {INPUT_PATH}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T04:09:55.900985Z","iopub.execute_input":"2025-12-17T04:09:55.901277Z","iopub.status.idle":"2025-12-17T04:09:57.867754Z","shell.execute_reply.started":"2025-12-17T04:09:55.901238Z","shell.execute_reply":"2025-12-17T04:09:57.866450Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Cell 2: Load metadata\ntrain_df = pd.read_csv(INPUT_PATH / 'train.csv')\nprint(f\"Training samples: {len(train_df)}\")\nprint(f\"\\nColumns: {train_df.columns.tolist()}\")\ntrain_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T04:10:18.294937Z","iopub.execute_input":"2025-12-17T04:10:18.295288Z","iopub.status.idle":"2025-12-17T04:10:18.353132Z","shell.execute_reply.started":"2025-12-17T04:10:18.295251Z","shell.execute_reply":"2025-12-17T04:10:18.352140Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Cell 3: Explore a sample ECG image\nsample_folder = list((INPUT_PATH / 'train').iterdir())[0]\nsample_images = list(sample_folder.glob('*.png'))\nsample_csv = list(sample_folder.glob('*.csv'))[0]\n\nprint(f\"Sample ID: {sample_folder.name}\")\nprint(f\"Images: {len(sample_images)}\")\nprint(f\"Ground truth CSV: {sample_csv.name}\")\n\n# Display first ECG image\nimg = Image.open(sample_images[0])\nplt.figure(figsize=(15, 8))\nplt.imshow(img)\nplt.title(f\"ECG Image: {sample_images[0].name}\")\nplt.axis('off')\nplt.show()\n\nprint(f\"Image size: {img.size}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T04:10:35.239482Z","iopub.execute_input":"2025-12-17T04:10:35.240267Z","iopub.status.idle":"2025-12-17T04:10:37.521724Z","shell.execute_reply.started":"2025-12-17T04:10:35.240230Z","shell.execute_reply":"2025-12-17T04:10:37.520763Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Cell 4: Load and plot ground truth signal\ngt_df = pd.read_csv(sample_csv)\nprint(f\"Signal shape: {gt_df.shape}\")\nprint(f\"Leads: {gt_df.columns.tolist()}\")\n\n# Plot all 12 leads\nfig, axes = plt.subplots(6, 2, figsize=(15, 12))\nfor idx, col in enumerate(gt_df.columns):\n    ax = axes[idx // 2, idx % 2]\n    ax.plot(gt_df[col].values, linewidth=0.5)\n    ax.set_title(col)\n    ax.set_ylabel('mV')\nplt.tight_layout()\nplt.suptitle('Ground Truth ECG Signals (12 Leads)', y=1.02)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T04:10:58.218254Z","iopub.execute_input":"2025-12-17T04:10:58.218897Z","iopub.status.idle":"2025-12-17T04:10:59.830362Z","shell.execute_reply.started":"2025-12-17T04:10:58.218864Z","shell.execute_reply":"2025-12-17T04:10:59.829291Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}