{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c6ec59ca-b58c-443c-9a98-25b824705bb5",
   "metadata": {},
   "source": [
    "*This notebook provides an example on how to create a SeisBench dataset from an xls event catalog and a folder with mseed files*\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a00a8204-932b-4488-85a0-6eea6f306523",
   "metadata": {},
   "outputs": [],
   "source": [
    "import seisbench\n",
    "import seisbench.data as sbd\n",
    "import seisbench.util as sbu\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "import obspy\n",
    "import os\n",
    "from pathlib import Path\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e44f9bb-4ae8-412c-a14d-3cc0885504c6",
   "metadata": {},
   "source": [
    "# Creating a dataset\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70c64dc6-e4dd-4c01-939d-a28914866f5d",
   "metadata": {},
   "source": [
    "##### The catalog has a custom format with the following properties: \n",
    "###### 'Datetime', 'X', 'Y', 'Depth', 'Mw', 'Phases', 'mseed_name'\n",
    "###### Phases is a string with detected phases seperated by comma: <Phase> <Station> <Datetime> e.g. \"Pg BRDW 2020-01-01 10:09:44.400, Sg BRDW 2020-01-01 10:09:45.696\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "143d04f7-e00a-4724-895e-f3dad72896e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Datetime</th>\n",
       "      <th>X</th>\n",
       "      <th>Y</th>\n",
       "      <th>Depth</th>\n",
       "      <th>Mw</th>\n",
       "      <th>Phases</th>\n",
       "      <th>mseed_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-01-01 10:09:42.200</td>\n",
       "      <td>5.582503e+06</td>\n",
       "      <td>5.702646e+06</td>\n",
       "      <td>0.7</td>\n",
       "      <td>2.469231</td>\n",
       "      <td>Pg BRDW 2020-01-01 10:09:44.400, Sg BRDW 2020-...</td>\n",
       "      <td>20200101100941.mseed</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Datetime             X             Y  Depth        Mw  \\\n",
       "0 2020-01-01 10:09:42.200  5.582503e+06  5.702646e+06    0.7  2.469231   \n",
       "\n",
       "                                              Phases            mseed_name  \n",
       "0  Pg BRDW 2020-01-01 10:09:44.400, Sg BRDW 2020-...  20200101100941.mseed  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_path = str(Path.cwd().parent) + \"/datasets/igf/\"\n",
    "catalog =  pd.read_excel(input_path + \"Catalog_20_21.xlsx\", index_col=0)\n",
    "catalog.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "03257d45-299d-4ed1-bc64-03303d2a9873",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Pg BRDW 2020-01-01 10:09:44.400, Sg BRDW 2020-01-01 10:09:45.696, Pg GROD 2020-01-01 10:09:45.206, Sg GROD 2020-01-01 10:09:46.655, Pg GUZI 2020-01-01 10:09:45.116, Sg GUZI 2020-01-01 10:09:46.561, Pg JEDR 2020-01-01 10:09:44.920, Sg JEDR 2020-01-01 10:09:46.285, Pg MOSK2 2020-01-01 10:09:45.417, Sg MOSK2 2020-01-01 10:09:46.921, Pg NWLU 2020-01-01 10:09:45.686, Sg NWLU 2020-01-01 10:09:47.175, Pg PCHB 2020-01-01 10:09:45.213, Sg PCHB 2020-01-01 10:09:46.565, Pg PPOL 2020-01-01 10:09:44.755, Sg PPOL 2020-01-01 10:09:46.069, Pg RUDN 2020-01-01 10:09:44.502, Sg RUDN 2020-01-01 10:09:45.756, Pg RYNR 2020-01-01 10:09:43.442, Sg RYNR 2020-01-01 10:09:44.394, Pg RZEC 2020-01-01 10:09:46.075, Sg RZEC 2020-01-01 10:09:47.587, Pg SGOR 2020-01-01 10:09:45.817, Sg SGOR 2020-01-01 10:09:47.284, Pg TRBC2 2020-01-01 10:09:44.833, Sg TRBC2 2020-01-01 10:09:46.095, Pg TRN2 2020-01-01 10:09:44.488, Sg TRN2 2020-01-01 10:09:45.698, Pg TRZS 2020-01-01 10:09:46.232, Sg TRZS 2020-01-01 10:09:47.727, Pg ZMST 2020-01-01 10:09:43.592, Sg ZMST 2020-01-01 10:09:44.553, Pg LUBW 2020-01-01 10:09:43.119, Sg LUBW 2020-01-01 10:09:43.929'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "catalog.Phases[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe0627b1-6fa0-4b5a-8a60-d80626b5c9be",
   "metadata": {},
   "source": [
    "#### SeisBench dataset format \n",
    "\n",
    "A dataset consists of 2 components: \n",
    "* a metadata file, called `metadata.csv`, with properties of assosiated waveforms\n",
    "* a waveforms file, called `waveforms.hdf5`, containing the raw waveforms\n",
    "\n",
    "\n",
    "A dataset is created with `WaveformDataWriter` provided by SeisBench\n",
    "\n",
    "### Define train/val/test split\n",
    "\n",
    "Strategy: \n",
    "Assign chronologically 70% picks to train, 15% to val, 15% to test sets. \n",
    "(Note: Counting picks based on `Phases` column in the `Catalog_20_21.xlsx` produces sets with slightly different proportion as not all traces are available.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "07ab344c-f03f-49aa-8fa2-537fbb154716",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: xlabel='Datetime'>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 25760 characters]",
      "text/plain": [
       "<Figure size 700x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "catalog['pick_count'] = catalog.Phases.apply(lambda x: x.count(\"Pg\"))\n",
    "catalog.index = catalog.Datetime\n",
    "catalog = catalog.sort_index()\n",
    "catalog['pick_count_cumsum'] = catalog.pick_count.cumsum()\n",
    "catalog.pick_count_cumsum.plot(figsize=(7,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4fabb4c3-4056-4bad-94e6-f907977762a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_th = 0.7 * catalog.pick_count_cumsum[-1]\n",
    "dev_th = 0.85 * catalog.pick_count_cumsum[-1]\n",
    "\n",
    "catalog['split'] = 'test'\n",
    "for i, event in catalog.iterrows(): \n",
    "    if event['pick_count_cumsum'] < train_th: \n",
    "        catalog.loc[i, 'split'] = 'train' \n",
    "    elif event['pick_count_cumsum'] < dev_th: \n",
    "        catalog.loc[i, 'split'] = 'dev' \n",
    "    else:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "35254721-fe1e-447c-9195-84695868f1d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6996718237224566"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "catalog[catalog.split == 'train'].pick_count.sum() / catalog.pick_count.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "95d297ed-0da7-4985-954e-645a8a89b6a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.149929676511955"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "catalog[catalog.split == 'dev'].pick_count.sum() / catalog.pick_count.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "28451050-6b1c-4fe6-a905-799383515d5b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.15039849976558836"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "catalog[catalog.split == 'test'].pick_count.sum() / catalog.pick_count.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "be679508-478a-4195-b5e7-a9fea9bbf724",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_event_params(event): \n",
    "    event_params = {\n",
    "        'source_origin_time': event.Datetime, \n",
    "        'source_latitude_deg': event.Y, \n",
    "        'source_longitude_deg': event.X, \n",
    "        'source_depth_km': event.Depth, \n",
    "        'source_magnitude': event.Mw, \n",
    "        'split': event.split\n",
    "    }\n",
    "    return event_params\n",
    "\n",
    "def get_event_picks(event): \n",
    "    \n",
    "    picks = [ann.split(' ') for ann in event.Phases.split(', ')]\n",
    "    picks = pd.DataFrame(picks, columns = ['pick', 'station', 'date', 'hour'])\n",
    "    picks.index = pd.DatetimeIndex(picks.date + ' ' + picks.hour, tz= \"UTC\")\n",
    "\n",
    "    return picks\n",
    "\n",
    "def get_mseed(fname):\n",
    "    return obspy.read(fname)\n",
    "\n",
    "\n",
    "def get_trace_params(trace): \n",
    "    trace_params = {\n",
    "        \"station_network_code\": trace.stats.network,\n",
    "        \"station_code\": trace.stats.station,\n",
    "        \"trace_channel\": trace.stats.channel\n",
    "    }\n",
    "    return trace_params\n",
    "    \n",
    "def get_waves_timestamps(station, phases_string): \n",
    "    \n",
    "    p_ts = None\n",
    "    s_ts = None\n",
    "\n",
    "    return p_ts, s_ts\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "77373c87-019d-4c7d-90b3-54e36874750a",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_path = input_path + \"seisbench_format/\"\n",
    "metadata_path = output_path + \"metadata.csv\"\n",
    "waveforms_path = output_path + \"waveforms.hdf5\"\n",
    "train = 0.7\n",
    "dev = 0.15\n",
    "test = 0.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6f098f39-85aa-43e0-90e8-b66c90a11d31",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Traces converted: 35784it [01:01, 578.58it/s]\n"
     ]
    }
   ],
   "source": [
    "with sbd.WaveformDataWriter(metadata_path, waveforms_path) as writer:\n",
    "\n",
    "    # Define data format\n",
    "    writer.data_format = {\n",
    "        \"dimension_order\": \"CW\",\n",
    "        \"component_order\": \"ZNE\",\n",
    "    }\n",
    "    \n",
    "    for event in catalog.itertuples():\n",
    "        # if \"2020-03-03 05:04:43\" not in str(event.Datetime): \n",
    "        #     continue\n",
    "        event_params = get_event_params(event)\n",
    "        event_picks = get_event_picks(event)\n",
    "        if pd.isna(event.mseed_name): \n",
    "            continue\n",
    "        if os.path.exists(input_path + \"mseeds/mseeds_2020/\" + event.mseed_name):\n",
    "            mseed_path = input_path + \"mseeds/mseeds_2020/\" + event.mseed_name \n",
    "        elif os.path.exists(input_path + \"mseeds/mseeds_2021/\" + event.mseed_name):\n",
    "            mseed_path = input_path + \"mseeds/mseeds_2021/\" + event.mseed_name \n",
    "        else: \n",
    "            continue\n",
    "        \n",
    "        \n",
    "        stream = get_mseed(mseed_path)\n",
    "        \n",
    "        for pick_time, pick in event_picks.iterrows():\n",
    "            waveforms = stream.select(station=pick.station)\n",
    "            if len(waveforms) == 0:\n",
    "                # No waveform data available\n",
    "                continue\n",
    "        \n",
    "            trace_params = get_trace_params(waveforms[0])\n",
    "        \n",
    "            sampling_rate = waveforms[0].stats.sampling_rate\n",
    "            # Check that the traces have the same sampling rate\n",
    "            assert all(trace.stats.sampling_rate == sampling_rate for trace in waveforms)\n",
    "            \n",
    "            actual_t_start, data, _ = sbu.stream_to_array(\n",
    "                waveforms,\n",
    "                component_order=writer.data_format[\"component_order\"],\n",
    "            )\n",
    "            \n",
    "            trace_params[\"trace_sampling_rate_hz\"] = sampling_rate\n",
    "            trace_params[\"trace_start_time\"] = str(actual_t_start)\n",
    "\n",
    "            pick_time = obspy.core.utcdatetime.UTCDateTime(pick_time)\n",
    "            pick_idx = (pick_time - actual_t_start) * sampling_rate\n",
    "\n",
    "            trace_params[f\"trace_{pick.pick}_arrival_sample\"] = int(pick_idx)\n",
    "            # sample = (pick.time - actual_t_start) * sampling_rate\n",
    "            # trace_params[f\"trace_{pick.phase_hint}_arrival_sample\"] = int(sample)\n",
    "            # trace_params[f\"trace_{pick.phase_hint}_status\"] = pick.evaluation_mode\n",
    "            \n",
    "            writer.add_trace({**event_params, **trace_params}, data)\n",
    "\n",
    "        # break\n",
    "            \n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7a66d99-4dfa-4c3a-937b-6df437eb8833",
   "metadata": {},
   "source": [
    "### Load converted dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "cdb07cfb-96c5-4444-81c8-1362fa3ceea8",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = sbd.WaveformDataset(output_path, sampling_rate=100)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "33c77509-7aab-4833-a372-16030941395d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unnamed dataset - 35784 traces\n"
     ]
    }
   ],
   "source": [
    "print(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d3440c7-318b-41f3-8035-48ce3cd9a764",
   "metadata": {},
   "source": [
    "#### Plot sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1753f65e-fe5d-4cfa-ab42-ae161ac4a253",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.lines.Line2D at 0x14d6c12d0>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 188988 characters]",
      "text/plain": [
       "<Figure size 1500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(15, 5))\n",
    "ax = fig.add_subplot(111)\n",
    "ax.plot(data.get_waveforms(0).T)\n",
    "ax.axvline(data.metadata[\"trace_Pg_arrival_sample\"].iloc[0], color=\"green\", lw=3)\n",
    "# ax.axvline(data.metadata[\"trace_Sg_arrival_sample\"].iloc[0], color=\"black\", lw=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1110dd5f-a6ff-4cb0-bd94-4904116e3233",
   "metadata": {},
   "source": [
    "#### Check train/dev/test proportions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bf7dae75-c90b-44f8-a51d-44e8abaaa3c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training examples: 24738 69.1%\n",
      "Development examples: 5508 15.4%\n",
      "Test examples: 5538 15.5 %\n"
     ]
    }
   ],
   "source": [
    "all_samples = len(data.train()) + len(data.dev()) + len(data.test())\n",
    "print(f\"Training examples: {len(data.train())} {len(data.train())/all_samples * 100:.1f}%\" )\n",
    "print(f\"Development examples: {len(data.dev())} {len(data.dev())/all_samples * 100:.1f}%\")\n",
    "print(f\"Test examples: {len(data.test())} {len(data.test())/all_samples * 100:.1f} %\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "de82db24-d983-4592-a0eb-f96beecb2f69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>source_origin_time</th>\n",
       "      <th>source_latitude_deg</th>\n",
       "      <th>source_longitude_deg</th>\n",
       "      <th>source_depth_km</th>\n",
       "      <th>source_magnitude</th>\n",
       "      <th>split</th>\n",
       "      <th>station_network_code</th>\n",
       "      <th>station_code</th>\n",
       "      <th>trace_channel</th>\n",
       "      <th>trace_sampling_rate_hz</th>\n",
       "      <th>trace_start_time</th>\n",
       "      <th>trace_Pg_arrival_sample</th>\n",
       "      <th>trace_name</th>\n",
       "      <th>trace_Sg_arrival_sample</th>\n",
       "      <th>trace_chunk</th>\n",
       "      <th>trace_component_order</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2020-01-01 10:09:42.200</td>\n",
       "      <td>5.702646e+06</td>\n",
       "      <td>5.582503e+06</td>\n",
       "      <td>0.7</td>\n",
       "      <td>2.469231</td>\n",
       "      <td>train</td>\n",
       "      <td>PL</td>\n",
       "      <td>BRDW</td>\n",
       "      <td>EHE</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-01T10:09:36.480000Z</td>\n",
       "      <td>792.0</td>\n",
       "      <td>bucket0$0,:3,:2001</td>\n",
       "      <td>NaN</td>\n",
       "      <td></td>\n",
       "      <td>ZNE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2020-01-01 10:09:42.200</td>\n",
       "      <td>5.702646e+06</td>\n",
       "      <td>5.582503e+06</td>\n",
       "      <td>0.7</td>\n",
       "      <td>2.469231</td>\n",
       "      <td>train</td>\n",
       "      <td>PL</td>\n",
       "      <td>BRDW</td>\n",
       "      <td>EHE</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-01T10:09:36.480000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>bucket0$1,:3,:2001</td>\n",
       "      <td>921.0</td>\n",
       "      <td></td>\n",
       "      <td>ZNE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2020-01-01 10:09:42.200</td>\n",
       "      <td>5.702646e+06</td>\n",
       "      <td>5.582503e+06</td>\n",
       "      <td>0.7</td>\n",
       "      <td>2.469231</td>\n",
       "      <td>train</td>\n",
       "      <td>PL</td>\n",
       "      <td>GROD</td>\n",
       "      <td>EHE</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-01T10:09:36.480000Z</td>\n",
       "      <td>872.0</td>\n",
       "      <td>bucket0$2,:3,:2001</td>\n",
       "      <td>NaN</td>\n",
       "      <td></td>\n",
       "      <td>ZNE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>2020-01-01 10:09:42.200</td>\n",
       "      <td>5.702646e+06</td>\n",
       "      <td>5.582503e+06</td>\n",
       "      <td>0.7</td>\n",
       "      <td>2.469231</td>\n",
       "      <td>train</td>\n",
       "      <td>PL</td>\n",
       "      <td>GROD</td>\n",
       "      <td>EHE</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-01T10:09:36.480000Z</td>\n",
       "      <td>NaN</td>\n",
       "      <td>bucket0$3,:3,:2001</td>\n",
       "      <td>1017.0</td>\n",
       "      <td></td>\n",
       "      <td>ZNE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2020-01-01 10:09:42.200</td>\n",
       "      <td>5.702646e+06</td>\n",
       "      <td>5.582503e+06</td>\n",
       "      <td>0.7</td>\n",
       "      <td>2.469231</td>\n",
       "      <td>train</td>\n",
       "      <td>PL</td>\n",
       "      <td>GUZI</td>\n",
       "      <td>CNE</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-01T10:09:36.476000Z</td>\n",
       "      <td>864.0</td>\n",
       "      <td>bucket0$4,:3,:2001</td>\n",
       "      <td>NaN</td>\n",
       "      <td></td>\n",
       "      <td>ZNE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   index       source_origin_time  source_latitude_deg  source_longitude_deg  \\\n",
       "0      0  2020-01-01 10:09:42.200         5.702646e+06          5.582503e+06   \n",
       "1      1  2020-01-01 10:09:42.200         5.702646e+06          5.582503e+06   \n",
       "2      2  2020-01-01 10:09:42.200         5.702646e+06          5.582503e+06   \n",
       "3      3  2020-01-01 10:09:42.200         5.702646e+06          5.582503e+06   \n",
       "4      4  2020-01-01 10:09:42.200         5.702646e+06          5.582503e+06   \n",
       "\n",
       "   source_depth_km  source_magnitude  split station_network_code station_code  \\\n",
       "0              0.7          2.469231  train                   PL         BRDW   \n",
       "1              0.7          2.469231  train                   PL         BRDW   \n",
       "2              0.7          2.469231  train                   PL         GROD   \n",
       "3              0.7          2.469231  train                   PL         GROD   \n",
       "4              0.7          2.469231  train                   PL         GUZI   \n",
       "\n",
       "  trace_channel  trace_sampling_rate_hz             trace_start_time  \\\n",
       "0           EHE                   100.0  2020-01-01T10:09:36.480000Z   \n",
       "1           EHE                   100.0  2020-01-01T10:09:36.480000Z   \n",
       "2           EHE                   100.0  2020-01-01T10:09:36.480000Z   \n",
       "3           EHE                   100.0  2020-01-01T10:09:36.480000Z   \n",
       "4           CNE                   100.0  2020-01-01T10:09:36.476000Z   \n",
       "\n",
       "   trace_Pg_arrival_sample          trace_name  trace_Sg_arrival_sample  \\\n",
       "0                    792.0  bucket0$0,:3,:2001                      NaN   \n",
       "1                      NaN  bucket0$1,:3,:2001                    921.0   \n",
       "2                    872.0  bucket0$2,:3,:2001                      NaN   \n",
       "3                      NaN  bucket0$3,:3,:2001                   1017.0   \n",
       "4                    864.0  bucket0$4,:3,:2001                      NaN   \n",
       "\n",
       "  trace_chunk trace_component_order  \n",
       "0                               ZNE  \n",
       "1                               ZNE  \n",
       "2                               ZNE  \n",
       "3                               ZNE  \n",
       "4                               ZNE  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.metadata.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37fe0dd1-ba9b-46ff-9abd-eb40f73649e3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ccd6908-cff7-42b2-a6a3-51ac0557a7dc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
