{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "794722df-38dd-4e42-853d-2de69e65a50d",
   "metadata": {},
   "source": [
    "# "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e289a332-d665-4441-8d0c-ccd06f2ce5ac",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:34.283003Z",
     "iopub.status.busy": "2024-11-19T12:39:34.282719Z",
     "iopub.status.idle": "2024-11-19T12:39:34.294837Z",
     "shell.execute_reply": "2024-11-19T12:39:34.294126Z",
     "shell.execute_reply.started": "2024-11-19T12:39:34.282976Z"
    }
   },
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "003d55db-fa2b-4073-bb1b-a73d285f1a63",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:34.295809Z",
     "iopub.status.busy": "2024-11-19T12:39:34.295567Z",
     "iopub.status.idle": "2024-11-19T12:39:39.174674Z",
     "shell.execute_reply": "2024-11-19T12:39:39.174112Z",
     "shell.execute_reply.started": "2024-11-19T12:39:34.295789Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/santiago/Software/bat_detectors/batdetect2/.venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from pathlib import Path\n",
    "from typing import List, Optional\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "from batdetect2.models.detectors import DetectorModel\n",
    "from batdetect2.train.augmentations import (\n",
    "    add_echo,\n",
    "    mask_frequency,\n",
    "    mask_time,\n",
    "    mix_examples,\n",
    "    select_random_subclip,\n",
    "    warp_spectrogram,\n",
    ")\n",
    "from batdetect2.train.dataset import LabeledDataset, get_files\n",
    "from batdetect2.train.preprocess import TrainPreprocessingConfig\n",
    "from matplotlib.patches import Rectangle\n",
    "from soundevent import data\n",
    "from soundevent.types import ClassMapper\n",
    "from torch.utils.data import DataLoader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5fe4647c-fb28-4429-bc1e-f1a86c3ee5b3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.175551Z",
     "iopub.status.busy": "2024-11-19T12:39:39.175216Z",
     "iopub.status.idle": "2024-11-19T12:39:39.208347Z",
     "shell.execute_reply": "2024-11-19T12:39:39.207810Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.175533Z"
    }
   },
   "outputs": [],
   "source": [
    "def plot_bboxes(sizes, ax=None):\n",
    "    # Plot the grayscale spectrogram as the base layer\n",
    "    if ax is None:\n",
    "        _, ax = plt.subplots(figsize=(15, 3))\n",
    "    \n",
    "    # Find non-zero size locations\n",
    "    indices = np.argwhere((sizes != 0).any(dim=\"dimension\").values)\n",
    "    \n",
    "    for freq_idx, time_idx in indices:\n",
    "        # Get size at this location\n",
    "        point = sizes.isel(time=time_idx, frequency=freq_idx)\n",
    "    \n",
    "        # Calculate width in seconds\n",
    "        width = point.sel(dimension=\"width\") / config.heatmaps.time_scale\n",
    "    \n",
    "        # Calculate height in Hz\n",
    "        height = point.sel(dimension=\"height\") / config.heatmaps.frequency_scale\n",
    "    \n",
    "        # Draw rectangle\n",
    "        ax.add_artist(\n",
    "            Rectangle((point.time, point.frequency), width, height, ec=\"red\", fc=\"none\")\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "465efd2e-ae6b-46c9-9703-5bad36381706",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.209095Z",
     "iopub.status.busy": "2024-11-19T12:39:39.208903Z",
     "iopub.status.idle": "2024-11-19T12:39:39.237352Z",
     "shell.execute_reply": "2024-11-19T12:39:39.236745Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.209078Z"
    }
   },
   "outputs": [],
   "source": [
    "config = TrainPreprocessingConfig()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3586ae44-2a30-4bbd-9fbd-d39729d288ec",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.238204Z",
     "iopub.status.busy": "2024-11-19T12:39:39.237994Z",
     "iopub.status.idle": "2024-11-19T12:39:39.267466Z",
     "shell.execute_reply": "2024-11-19T12:39:39.266874Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.238185Z"
    }
   },
   "outputs": [],
   "source": [
    "data_dir = Path.cwd().parent / \"example_data\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6b2570e3-7d84-4aff-9f1f-58e9e349698c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.271186Z",
     "iopub.status.busy": "2024-11-19T12:39:39.270856Z",
     "iopub.status.idle": "2024-11-19T12:39:39.303590Z",
     "shell.execute_reply": "2024-11-19T12:39:39.302973Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.271162Z"
    }
   },
   "outputs": [],
   "source": [
    "files = get_files(data_dir / \"preprocessed\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "764364cf-aeff-434a-b23e-9ba9de4f26aa",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.304524Z",
     "iopub.status.busy": "2024-11-19T12:39:39.304262Z",
     "iopub.status.idle": "2024-11-19T12:39:39.401894Z",
     "shell.execute_reply": "2024-11-19T12:39:39.401303Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.304503Z"
    }
   },
   "outputs": [],
   "source": [
    "dataset1 = xr.load_dataset(files[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9195ebf-865b-47db-b91f-4df247a2fe62",
   "metadata": {},
   "source": [
    "# Mix examples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "97ccb005-8be5-410d-862b-774cba96ac88",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.402656Z",
     "iopub.status.busy": "2024-11-19T12:39:39.402459Z",
     "iopub.status.idle": "2024-11-19T12:39:39.449110Z",
     "shell.execute_reply": "2024-11-19T12:39:39.448416Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.402631Z"
    }
   },
   "outputs": [],
   "source": [
    "dataset2 = xr.load_dataset(files[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "75b06a89-9073-477f-b20f-a1b0e1d372d0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.449725Z",
     "iopub.status.busy": "2024-11-19T12:39:39.449545Z",
     "iopub.status.idle": "2024-11-19T12:39:39.739924Z",
     "shell.execute_reply": "2024-11-19T12:39:39.739346Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.449708Z"
    }
   },
   "outputs": [],
   "source": [
    "mixed = mix_examples(dataset1, dataset2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4f4bde5c-9a03-4a2d-9d01-082ba68da308",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:39.740637Z",
     "iopub.status.busy": "2024-11-19T12:39:39.740453Z",
     "iopub.status.idle": "2024-11-19T12:39:40.147319Z",
     "shell.execute_reply": "2024-11-19T12:39:40.146624Z",
     "shell.execute_reply.started": "2024-11-19T12:39:39.740621Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 344020 characters]",
      "text/plain": [
       "<Figure size 1500x900 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, axs = plt.subplots(figsize=(15, 9), nrows=3, ncols=1)\n",
    "dataset1.spectrogram.plot(ax=axs[0], cmap=\"grey\", add_colorbar=False)\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "dataset2.spectrogram.plot(ax=axs[1], cmap=\"grey\", add_colorbar=False)\n",
    "axs[1].set_title(\"Other\")\n",
    "axs[1].axis(\"off\")\n",
    "mixed.spectrogram.plot(ax=axs[2], cmap=\"grey\", add_colorbar=False)\n",
    "axs[2].set_title(\"Mixed\")\n",
    "axs[2].axis(\"off\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a38ad00e-d641-47f8-9f0f-77665408df88",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:40.148386Z",
     "iopub.status.busy": "2024-11-19T12:39:40.148002Z",
     "iopub.status.idle": "2024-11-19T12:39:40.377607Z",
     "shell.execute_reply": "2024-11-19T12:39:40.376962Z",
     "shell.execute_reply.started": "2024-11-19T12:39:40.148365Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 130572 characters]",
      "text/plain": [
       "<Figure size 1500x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_, ax = plt.subplots(figsize=(15, 3))\n",
    "mixed.spectrogram.plot(ax=ax, cmap=\"gray\", add_colorbar=False)\n",
    "mixed.detection.where(mixed.detection > 0.1).plot(\n",
    "    ax=ax, alpha=0.5, cmap=\"magma\", add_colorbar=False\n",
    ")\n",
    "ax.axis(\"off\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c9b5a89d-dd8a-4f14-9025-5efd50244342",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:40.378875Z",
     "iopub.status.busy": "2024-11-19T12:39:40.378559Z",
     "iopub.status.idle": "2024-11-19T12:39:40.617564Z",
     "shell.execute_reply": "2024-11-19T12:39:40.617151Z",
     "shell.execute_reply.started": "2024-11-19T12:39:40.378856Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 129812 characters]",
      "text/plain": [
       "<Figure size 1500x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot the grayscale spectrogram as the base layer\n",
    "_, ax = plt.subplots(figsize=(15, 3))\n",
    "mixed[\"spectrogram\"].plot(ax=ax, cmap=\"grey\", add_colorbar=False)\n",
    "plot_bboxes(mixed[\"size\"], ax=ax)\n",
    "ax.axis(\"off\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c403de62-71d9-4970-a4a1-45f48e3fb760",
   "metadata": {},
   "source": [
    "# Add Echo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "89240bc0-8c9d-4e9d-851e-53a3ed9dc4fb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:40.618167Z",
     "iopub.status.busy": "2024-11-19T12:39:40.618023Z",
     "iopub.status.idle": "2024-11-19T12:39:40.677284Z",
     "shell.execute_reply": "2024-11-19T12:39:40.676790Z",
     "shell.execute_reply.started": "2024-11-19T12:39:40.618154Z"
    }
   },
   "outputs": [],
   "source": [
    "with_echo = add_echo(dataset1, delay=0.01, weight=0.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9aa8e64f-54c2-43a0-8448-139156b7f33e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:40.678010Z",
     "iopub.status.busy": "2024-11-19T12:39:40.677828Z",
     "iopub.status.idle": "2024-11-19T12:39:40.917694Z",
     "shell.execute_reply": "2024-11-19T12:39:40.917275Z",
     "shell.execute_reply.started": "2024-11-19T12:39:40.677993Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 640x480 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 228924 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "fig, axs = plt.subplots(figsize=(15, 6), nrows=2, ncols=1)\n",
    "dataset1.spectrogram.plot(ax=axs[0], add_colorbar=False, cmap=\"grey\")\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "ax2 = plt.subplot(2, 1, 2)\n",
    "with_echo.spectrogram.plot(ax=axs[1], add_colorbar=False, cmap=\"grey\")\n",
    "axs[1].set_title(\"With Echo\")\n",
    "axs[1].axis(\"off\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7337ad7-10db-4475-a5a0-ddae427a3ee0",
   "metadata": {},
   "source": [
    "# Select Random Subclip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ff93c9c9-34cb-4dd0-bd53-8cca9004e9aa",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:40.918295Z",
     "iopub.status.busy": "2024-11-19T12:39:40.918138Z",
     "iopub.status.idle": "2024-11-19T12:39:40.944419Z",
     "shell.execute_reply": "2024-11-19T12:39:40.943914Z",
     "shell.execute_reply.started": "2024-11-19T12:39:40.918281Z"
    }
   },
   "outputs": [],
   "source": [
    "subclip = select_random_subclip(dataset1, duration=0.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9e4a76a6-e7bf-4dfc-b3b5-03e96add4b3e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:40.945172Z",
     "iopub.status.busy": "2024-11-19T12:39:40.944986Z",
     "iopub.status.idle": "2024-11-19T12:39:41.102213Z",
     "shell.execute_reply": "2024-11-19T12:39:41.101768Z",
     "shell.execute_reply.started": "2024-11-19T12:39:40.945154Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 81444 characters]",
      "text/plain": [
       "<Figure size 1500x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_, ax = plt.subplots(figsize=(15, 3))\n",
    "subclip.spectrogram.plot(ax=ax, cmap=\"gray\", add_colorbar=False)\n",
    "subclip.detection.where(subclip.detection > 0.1).plot(\n",
    "    ax=ax, cmap=\"magma\", alpha=0.5, add_colorbar=False\n",
    ")\n",
    "ax.axis(\"off\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "997c7d35-9c12-4ff0-ae79-0e01e15a61b8",
   "metadata": {},
   "source": [
    "# Masked Time Axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "69ec4e86-0811-4a98-b40d-dca33e8a4cc7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:41.102804Z",
     "iopub.status.busy": "2024-11-19T12:39:41.102654Z",
     "iopub.status.idle": "2024-11-19T12:39:41.345462Z",
     "shell.execute_reply": "2024-11-19T12:39:41.344610Z",
     "shell.execute_reply.started": "2024-11-19T12:39:41.102789Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(-0.0005000894307158887),\n",
       " np.float64(0.5115914940834045),\n",
       " np.float64(10031.12109375),\n",
       " np.float64(119604.9921875))"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 225884 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "time_masked = mask_time(dataset1)\n",
    "fig, axs = plt.subplots(figsize=(15, 6), nrows=2, ncols=1)\n",
    "dataset1.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[0])\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "time_masked.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[1])\n",
    "axs[1].set_title(\"Augmented\")\n",
    "axs[1].axis(\"off\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdba0536-07a6-451d-a5ec-de91d1236309",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T11:50:02.969787Z",
     "iopub.status.busy": "2024-11-19T11:50:02.968876Z",
     "iopub.status.idle": "2024-11-19T11:50:03.080225Z",
     "shell.execute_reply": "2024-11-19T11:50:03.079270Z",
     "shell.execute_reply.started": "2024-11-19T11:50:02.969712Z"
    }
   },
   "source": [
    "# Masked Frequency Axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2d0d7222-e4f0-42c2-8e3e-937bb20c87d3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:39:41.346315Z",
     "iopub.status.busy": "2024-11-19T12:39:41.346075Z",
     "iopub.status.idle": "2024-11-19T12:39:41.593501Z",
     "shell.execute_reply": "2024-11-19T12:39:41.592944Z",
     "shell.execute_reply.started": "2024-11-19T12:39:41.346299Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 218732 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "freq_masked = mask_frequency(dataset1)\n",
    "fig, axs = plt.subplots(figsize=(15, 6), nrows=2, ncols=1)\n",
    "dataset1.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[0])\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "freq_masked.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[1])\n",
    "axs[1].set_title(\"Augmented\")\n",
    "axs[1].axis(\"off\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9bf6912-7771-45a1-a820-74cb7a62fcfe",
   "metadata": {},
   "source": [
    "# Warp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "3bf9f9c5-e09f-4e66-9063-1407d3985407",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:46:45.393455Z",
     "iopub.status.busy": "2024-11-19T12:46:45.391855Z",
     "iopub.status.idle": "2024-11-19T12:46:45.459564Z",
     "shell.execute_reply": "2024-11-19T12:46:45.459043Z",
     "shell.execute_reply.started": "2024-11-19T12:46:45.393345Z"
    }
   },
   "outputs": [],
   "source": [
    "warped = warp_spectrogram(dataset1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "50a520d9-1f07-4cab-b280-d6e604a9c7a3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:46:45.811075Z",
     "iopub.status.busy": "2024-11-19T12:46:45.810260Z",
     "iopub.status.idle": "2024-11-19T12:46:46.293931Z",
     "shell.execute_reply": "2024-11-19T12:46:46.293436Z",
     "shell.execute_reply.started": "2024-11-19T12:46:45.811007Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 241128 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, axs = plt.subplots(figsize=(15, 6), nrows=2, ncols=1)\n",
    "dataset1.spectrogram.plot(cmap=\"grey\", add_colorbar=True, ax=axs[0])\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "warped.spectrogram.plot(cmap=\"grey\", add_colorbar=True, ax=axs[1])\n",
    "axs[1].set_title(\"Warped\")\n",
    "axs[1].axis(\"off\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "02d58d69-6122-4a7c-a1fd-e8a5735f7c19",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:46:46.294895Z",
     "iopub.status.busy": "2024-11-19T12:46:46.294709Z",
     "iopub.status.idle": "2024-11-19T12:46:46.690419Z",
     "shell.execute_reply": "2024-11-19T12:46:46.689875Z",
     "shell.execute_reply.started": "2024-11-19T12:46:46.294879Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 248276 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, axs = plt.subplots(figsize=(15, 6), nrows=2, ncols=1)\n",
    "dataset1.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[0])\n",
    "dataset1.detection.where(dataset1.detection > 0.1).plot(cmap=\"magma\", add_colorbar=False, alpha=0.3, ax=axs[0])\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "warped.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[1])\n",
    "warped.detection.where(warped.detection > 0.1).plot(cmap=\"magma\", add_colorbar=False, alpha=0.3, ax=axs[1])\n",
    "axs[1].set_title(\"Warped\")\n",
    "axs[1].axis(\"off\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "bade27a7-f446-4be0-b825-1322c8ae605f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-11-19T12:46:46.691177Z",
     "iopub.status.busy": "2024-11-19T12:46:46.691003Z",
     "iopub.status.idle": "2024-11-19T12:46:47.106432Z",
     "shell.execute_reply": "2024-11-19T12:46:47.105875Z",
     "shell.execute_reply.started": "2024-11-19T12:46:46.691162Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 244708 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, axs = plt.subplots(figsize=(15, 6), nrows=2, ncols=1)\n",
    "dataset1.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[0])\n",
    "plot_bboxes(dataset1[\"size\"], ax=axs[0])\n",
    "axs[0].set_title(\"Original\")\n",
    "axs[0].axis(\"off\")\n",
    "warped.spectrogram.plot(cmap=\"gray\", add_colorbar=False, ax=axs[1])\n",
    "plot_bboxes(warped[\"size\"], ax=axs[1])\n",
    "axs[1].set_title(\"Warped\")\n",
    "axs[1].axis(\"off\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f2e42c9-d1a6-4f32-8305-b74abbb67a8f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "batdetect2-dev",
   "language": "python",
   "name": "batdetect2-dev"
  },
  "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.12.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
