Skip to content

Commit

Permalink
Get dataset working
Browse files Browse the repository at this point in the history
  • Loading branch information
calum-chamberlain committed Nov 19, 2023
1 parent 92e776f commit 07c3cd7
Showing 1 changed file with 98 additions and 10 deletions.
108 changes: 98 additions & 10 deletions eqcorrscan/doc/tutorials/matched-filter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -216,38 +216,126 @@
},
"id": "a4182117cbf6692c"
},
{
"cell_type": "markdown",
"source": [
"Great, now we have some data. EQcorrscan is well set up to use clients for data access,\n",
"using clients allows EQcorrscan to request the data that it needs and take care of \n",
"overlapping chunks of data to ensure that no data are missed: network-based\n",
"matched-filters apply a delay-and-stack step to the correlations from individual\n",
"channels. This increases the signal-to-noise ratio of the correlation sum. However,\n",
"because of the delay part, the stacks made at start and end of chunks of waveform\n",
"data do not use the full network. To get around this *you should overlap your data*.\n",
"\n",
"If you use client-based access to data, EQcorrscan will take care of this for you.\n",
"\n",
"So how do you use clients for local data? Make a local database using obsplus.\n",
"\n",
"If you don't have obsplus installed you should install it now (`conda install obsplus`\n",
"or `pip install obsplus`)."
],
"metadata": {
"collapsed": false
},
"id": "864c0532837b9fc"
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 13,
"outputs": [
{
"name": "stdout",
"name": "stderr",
"output_type": "stream",
"text": [
"clustering.rst matched-filter.ipynb quick_start.ipynb template-creation.rst\r\n",
"mag-calc.rst processing_flow.png subspace.rst waveforms\r\n"
"2023-11-17 09:37:45,637\tnumexpr.utils\tINFO\tNote: NumExpr detected 12 cores but \"NUMEXPR_MAX_THREADS\" not set, so enforcing safe limit of 8.\n",
"2023-11-17 09:37:45,638\tnumexpr.utils\tINFO\tNumExpr defaulting to 8 threads.\n"
]
},
{
"data": {
"text/plain": " network station location channel starttime \\\n0 NZ EDRZ 10 EHE 2023-03-17 00:00:03.528394 \n1 NZ EDRZ 10 EHN 2023-03-17 00:00:05.458394 \n2 NZ EDRZ 10 EHZ 2023-03-17 00:00:03.528394 \n3 NZ KARZ 10 EHE 2023-03-17 00:00:02.963130 \n4 NZ KARZ 10 EHN 2023-03-17 00:00:00.093130 \n5 NZ KARZ 10 EHZ 2023-03-17 00:00:05.823130 \n6 NZ LIRZ 10 EHE 2023-03-17 00:00:01.753132 \n7 NZ LIRZ 10 EHN 2023-03-17 00:00:02.913132 \n8 NZ LIRZ 10 EHZ 2023-03-17 00:00:01.463132 \n9 NZ MARZ 10 EHE 2023-03-17 00:00:01.553130 \n10 NZ MARZ 10 EHN 2023-03-17 00:00:01.683130 \n11 NZ MARZ 10 EHZ 2023-03-17 00:00:00.963130 \n12 NZ MKRZ 10 EHE 2023-03-17 00:00:01.673129 \n13 NZ MKRZ 10 EHN 2023-03-17 00:00:00.143129 \n14 NZ MKRZ 10 EHZ 2023-03-17 00:00:00.053129 \n15 NZ OMRZ 10 EHE 2023-03-17 00:00:02.740000 \n16 NZ OMRZ 10 EHN 2023-03-17 00:00:00.580000 \n17 NZ OMRZ 10 EHZ 2023-03-17 00:00:04.110000 \n18 NZ OPRZ 10 HHE 2023-03-17 00:00:02.993132 \n19 NZ OPRZ 10 HHN 2023-03-17 00:00:03.473132 \n20 NZ OPRZ 10 HHZ 2023-03-17 00:00:01.963132 \n21 NZ TARZ 10 EHE 2023-03-17 00:00:01.850000 \n22 NZ TARZ 10 EHN 2023-03-17 00:00:00.760000 \n23 NZ TARZ 10 EHZ 2023-03-17 00:00:00.630000 \n\n endtime \n0 2023-03-19 00:00:00.098393 \n1 2023-03-19 00:00:04.518393 \n2 2023-03-19 00:00:03.588393 \n3 2023-03-19 00:00:01.273126 \n4 2023-03-19 00:00:00.303126 \n5 2023-03-19 00:00:03.653126 \n6 2023-03-19 00:00:03.523130 \n7 2023-03-19 00:00:04.253130 \n8 2023-03-19 00:00:00.313130 \n9 2023-03-19 00:00:01.593131 \n10 2023-03-19 00:00:04.163131 \n11 2023-03-19 00:00:05.063131 \n12 2023-03-19 00:00:01.763133 \n13 2023-03-19 00:00:02.463133 \n14 2023-03-19 00:00:02.363133 \n15 2023-03-19 00:00:02.470000 \n16 2023-03-19 00:00:00.550000 \n17 2023-03-19 00:00:03.820000 \n18 2023-03-19 00:00:01.243131 \n19 2023-03-19 00:00:04.443131 \n20 2023-03-19 00:00:00.143131 \n21 2023-03-19 00:00:01.580000 \n22 2023-03-19 00:00:00.820000 \n23 2023-03-19 00:00:03.830000 ",
"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>network</th>\n <th>station</th>\n <th>location</th>\n <th>channel</th>\n <th>starttime</th>\n <th>endtime</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>NZ</td>\n <td>EDRZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:03.528394</td>\n <td>2023-03-19 00:00:00.098393</td>\n </tr>\n <tr>\n <th>1</th>\n <td>NZ</td>\n <td>EDRZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:05.458394</td>\n <td>2023-03-19 00:00:04.518393</td>\n </tr>\n <tr>\n <th>2</th>\n <td>NZ</td>\n <td>EDRZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:03.528394</td>\n <td>2023-03-19 00:00:03.588393</td>\n </tr>\n <tr>\n <th>3</th>\n <td>NZ</td>\n <td>KARZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:02.963130</td>\n <td>2023-03-19 00:00:01.273126</td>\n </tr>\n <tr>\n <th>4</th>\n <td>NZ</td>\n <td>KARZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:00.093130</td>\n <td>2023-03-19 00:00:00.303126</td>\n </tr>\n <tr>\n <th>5</th>\n <td>NZ</td>\n <td>KARZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:05.823130</td>\n <td>2023-03-19 00:00:03.653126</td>\n </tr>\n <tr>\n <th>6</th>\n <td>NZ</td>\n <td>LIRZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:01.753132</td>\n <td>2023-03-19 00:00:03.523130</td>\n </tr>\n <tr>\n <th>7</th>\n <td>NZ</td>\n <td>LIRZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:02.913132</td>\n <td>2023-03-19 00:00:04.253130</td>\n </tr>\n <tr>\n <th>8</th>\n <td>NZ</td>\n <td>LIRZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:01.463132</td>\n <td>2023-03-19 00:00:00.313130</td>\n </tr>\n <tr>\n <th>9</th>\n <td>NZ</td>\n <td>MARZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:01.553130</td>\n <td>2023-03-19 00:00:01.593131</td>\n </tr>\n <tr>\n <th>10</th>\n <td>NZ</td>\n <td>MARZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:01.683130</td>\n <td>2023-03-19 00:00:04.163131</td>\n </tr>\n <tr>\n <th>11</th>\n <td>NZ</td>\n <td>MARZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:00.963130</td>\n <td>2023-03-19 00:00:05.063131</td>\n </tr>\n <tr>\n <th>12</th>\n <td>NZ</td>\n <td>MKRZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:01.673129</td>\n <td>2023-03-19 00:00:01.763133</td>\n </tr>\n <tr>\n <th>13</th>\n <td>NZ</td>\n <td>MKRZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:00.143129</td>\n <td>2023-03-19 00:00:02.463133</td>\n </tr>\n <tr>\n <th>14</th>\n <td>NZ</td>\n <td>MKRZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:00.053129</td>\n <td>2023-03-19 00:00:02.363133</td>\n </tr>\n <tr>\n <th>15</th>\n <td>NZ</td>\n <td>OMRZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:02.740000</td>\n <td>2023-03-19 00:00:02.470000</td>\n </tr>\n <tr>\n <th>16</th>\n <td>NZ</td>\n <td>OMRZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:00.580000</td>\n <td>2023-03-19 00:00:00.550000</td>\n </tr>\n <tr>\n <th>17</th>\n <td>NZ</td>\n <td>OMRZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:04.110000</td>\n <td>2023-03-19 00:00:03.820000</td>\n </tr>\n <tr>\n <th>18</th>\n <td>NZ</td>\n <td>OPRZ</td>\n <td>10</td>\n <td>HHE</td>\n <td>2023-03-17 00:00:02.993132</td>\n <td>2023-03-19 00:00:01.243131</td>\n </tr>\n <tr>\n <th>19</th>\n <td>NZ</td>\n <td>OPRZ</td>\n <td>10</td>\n <td>HHN</td>\n <td>2023-03-17 00:00:03.473132</td>\n <td>2023-03-19 00:00:04.443131</td>\n </tr>\n <tr>\n <th>20</th>\n <td>NZ</td>\n <td>OPRZ</td>\n <td>10</td>\n <td>HHZ</td>\n <td>2023-03-17 00:00:01.963132</td>\n <td>2023-03-19 00:00:00.143131</td>\n </tr>\n <tr>\n <th>21</th>\n <td>NZ</td>\n <td>TARZ</td>\n <td>10</td>\n <td>EHE</td>\n <td>2023-03-17 00:00:01.850000</td>\n <td>2023-03-19 00:00:01.580000</td>\n </tr>\n <tr>\n <th>22</th>\n <td>NZ</td>\n <td>TARZ</td>\n <td>10</td>\n <td>EHN</td>\n <td>2023-03-17 00:00:00.760000</td>\n <td>2023-03-19 00:00:00.820000</td>\n </tr>\n <tr>\n <th>23</th>\n <td>NZ</td>\n <td>TARZ</td>\n <td>10</td>\n <td>EHZ</td>\n <td>2023-03-17 00:00:00.630000</td>\n <td>2023-03-19 00:00:03.830000</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [],
"source": [
"from obsplus import WaveBank\n",
"\n",
"bank = WaveBank(outdir)\n",
"\n",
"bank.get_availability_df()"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-11-14T23:54:30.850760283Z",
"start_time": "2023-11-14T23:54:30.706465451Z"
"end_time": "2023-11-16T20:37:47.176447856Z",
"start_time": "2023-11-16T20:37:45.510288831Z"
}
},
"id": "2386f817ee9a4579"
"id": "422d39dd855950a6"
},
{
"cell_type": "markdown",
"source": [
"Obsplus has now scanned the waveforms that we just downloaded and made a table\n",
"of what is there. Great. These `WaveBank` objects have a similar api to obspy\n",
"`Client` objects, so we can use them as a drop-in replacement.\n",
"\n",
"Now we are nearly ready to make some templates.\n",
"\n",
"## Template creation\n",
"\n",
"To make templates you need two things:\n",
"1. Continuous waveform data;\n",
"2. A catalogue of events with picks.\n",
"\n",
"We already have (1). For (2), the catalogue of events, we could use GeoNet picked\n",
"events, however if you have events with picks locally and want to use those\n",
"events as templates you should save those events in a format readable by obspy.\n",
"You can then skip ahead to read those picks back in.\n",
"\n",
"In the worst case scenario you have times that you know that you want your\n",
"template to start at, but they are not in any standard format readble by obspy,\n",
"you can construct events from scratch as below. Note in this example I am just\n",
"populating the picks as this is all we need. You do need to be careful about\n",
"the `waveform_id`: this should match the seed id of the continuous data\n",
"exactly, otherwise the picks will not be used."
],
"metadata": {
"collapsed": false
},
"id": "9f4dd2504fb18202"
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"source": [
"from obspy.core.event import (\n",
" Catalog, Event, Pick, WaveformStreamID)\n",
"from obspy import UTCDateTime\n",
" \n",
"event = Event(\n",
" picks=[\n",
" Pick(time=UTCDateTime(2016, 9, 26, 8, 52, 45, 180000), phase_hint=\"P\",\n",
" waveform_id=WaveformStreamID(\n",
" network_code=\"YG\", station_code=\"RH08\", channel_code=\"BHZ\")),\n",
" Pick(time=UTCDateTime(2016, 9, 26, 8, 52, 45, 809000), phase_hint=\"P\",\n",
" waveform_id=WaveformStreamID(\n",
" network_code=\"YG\", station_code=\"NEB1\", channel_code=\"BHZ\")),\n",
" Pick(time=UTCDateTime(2016, 9, 26, 8, 52, 45, 661000), phase_hint=\"P\",\n",
" waveform_id=WaveformStreamID(\n",
" network_code=\"YG\", station_code=\"NEB3\", channel_code=\"BHZ\"))])\n",
"\n",
"catalog = Catalog([event])"
],
"metadata": {
"collapsed": false
},
"id": "422d39dd855950a6"
"id": "cf480f12b889f227"
}
],
"metadata": {
Expand Down

0 comments on commit 07c3cd7

Please sign in to comment.