update
Browse files- example_fastapi.ipynb +46 -54
example_fastapi.ipynb
CHANGED
@@ -27,11 +27,12 @@
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
-
"execution_count":
|
31 |
"metadata": {},
|
32 |
"outputs": [],
|
33 |
"source": [
|
34 |
-
"
|
|
|
35 |
]
|
36 |
},
|
37 |
{
|
@@ -1262,15 +1263,6 @@
|
|
1262 |
"plt.show()"
|
1263 |
]
|
1264 |
},
|
1265 |
-
{
|
1266 |
-
"cell_type": "code",
|
1267 |
-
"execution_count": 13,
|
1268 |
-
"metadata": {},
|
1269 |
-
"outputs": [],
|
1270 |
-
"source": [
|
1271 |
-
"from app import run_gamma"
|
1272 |
-
]
|
1273 |
-
},
|
1274 |
{
|
1275 |
"cell_type": "code",
|
1276 |
"execution_count": 14,
|
@@ -1281,29 +1273,16 @@
|
|
1281 |
"output_type": "stream",
|
1282 |
"text": [
|
1283 |
"Associating 108 picks with 1 CPUs\n",
|
1284 |
-
"."
|
1285 |
]
|
1286 |
-
}
|
1287 |
-
],
|
1288 |
-
"source": [
|
1289 |
-
"config[\"region\"] = \"Ridgecrest\"\n",
|
1290 |
-
"config[\"event_index\"] = 1\n",
|
1291 |
-
"\n",
|
1292 |
-
"evengts_, picks_ = run_gamma(picks, stations, config)"
|
1293 |
-
]
|
1294 |
-
},
|
1295 |
-
{
|
1296 |
-
"cell_type": "code",
|
1297 |
-
"execution_count": 15,
|
1298 |
-
"metadata": {},
|
1299 |
-
"outputs": [
|
1300 |
{
|
1301 |
"data": {
|
1302 |
"text/plain": [
|
1303 |
-
"<matplotlib.collections.PathCollection at
|
1304 |
]
|
1305 |
},
|
1306 |
-
"execution_count":
|
1307 |
"metadata": {},
|
1308 |
"output_type": "execute_result"
|
1309 |
},
|
@@ -1319,18 +1298,24 @@
|
|
1319 |
}
|
1320 |
],
|
1321 |
"source": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1322 |
"plt.figure()\n",
|
1323 |
"mapping_color = lambda x: f\"C{x}\" if x!= -1 else \"black\"\n",
|
1324 |
-
"plt.scatter(picks_[\"
|
1325 |
]
|
1326 |
},
|
1327 |
{
|
1328 |
"cell_type": "code",
|
1329 |
-
"execution_count":
|
1330 |
"metadata": {},
|
1331 |
"outputs": [],
|
1332 |
"source": [
|
1333 |
-
"# call loalhost:8000/predict\n",
|
1334 |
"picks_ = picks.copy()\n",
|
1335 |
"picks_[\"phase_time\"] = picks_[\"phase_time\"].apply(lambda x: x.isoformat())\n",
|
1336 |
"stations_ = stations.copy()\n",
|
@@ -1338,7 +1323,7 @@
|
|
1338 |
"picks_ = picks_.to_dict(orient=\"records\")\n",
|
1339 |
"stations_ = stations.to_dict(orient=\"records\")\n",
|
1340 |
"\n",
|
1341 |
-
"response = requests.post(f\"{
|
1342 |
"\n",
|
1343 |
"if response.status_code == 200:\n",
|
1344 |
" result = response.json()\n",
|
@@ -1350,16 +1335,16 @@
|
|
1350 |
},
|
1351 |
{
|
1352 |
"cell_type": "code",
|
1353 |
-
"execution_count":
|
1354 |
"metadata": {},
|
1355 |
"outputs": [
|
1356 |
{
|
1357 |
"data": {
|
1358 |
"text/plain": [
|
1359 |
-
"<matplotlib.collections.PathCollection at
|
1360 |
]
|
1361 |
},
|
1362 |
-
"execution_count":
|
1363 |
"metadata": {},
|
1364 |
"output_type": "execute_result"
|
1365 |
},
|
@@ -1386,7 +1371,7 @@
|
|
1386 |
},
|
1387 |
{
|
1388 |
"cell_type": "code",
|
1389 |
-
"execution_count":
|
1390 |
"metadata": {},
|
1391 |
"outputs": [
|
1392 |
{
|
@@ -1429,18 +1414,18 @@
|
|
1429 |
" <tr>\n",
|
1430 |
" <th>0</th>\n",
|
1431 |
" <td>2019-07-04T17:02:55.008</td>\n",
|
1432 |
-
" <td>4.
|
1433 |
" <td>0.326146</td>\n",
|
1434 |
" <td>0.328015</td>\n",
|
1435 |
" <td>0.050179</td>\n",
|
1436 |
-
" <td>97.
|
1437 |
" <td>98</td>\n",
|
1438 |
" <td>49</td>\n",
|
1439 |
" <td>49</td>\n",
|
1440 |
" <td>1</td>\n",
|
1441 |
-
" <td>-117.
|
1442 |
" <td>35.710353</td>\n",
|
1443 |
-
" <td>16.
|
1444 |
" </tr>\n",
|
1445 |
" </tbody>\n",
|
1446 |
"</table>\n",
|
@@ -1448,16 +1433,16 @@
|
|
1448 |
],
|
1449 |
"text/plain": [
|
1450 |
" time magnitude sigma_time sigma_amp cov_time_amp \\\n",
|
1451 |
-
"0 2019-07-04T17:02:55.008
|
1452 |
"\n",
|
1453 |
" gamma_score num_picks num_p_picks num_s_picks event_index longitude \\\n",
|
1454 |
-
"0 97.
|
1455 |
"\n",
|
1456 |
" latitude depth_km \n",
|
1457 |
-
"0 35.710353 16.
|
1458 |
]
|
1459 |
},
|
1460 |
-
"execution_count":
|
1461 |
"metadata": {},
|
1462 |
"output_type": "execute_result"
|
1463 |
}
|
@@ -1468,7 +1453,7 @@
|
|
1468 |
},
|
1469 |
{
|
1470 |
"cell_type": "code",
|
1471 |
-
"execution_count":
|
1472 |
"metadata": {},
|
1473 |
"outputs": [
|
1474 |
{
|
@@ -1529,7 +1514,7 @@
|
|
1529 |
" <td>-117.462</td>\n",
|
1530 |
" <td>694.5</td>\n",
|
1531 |
" <td>1</td>\n",
|
1532 |
-
" <td>0.
|
1533 |
" </tr>\n",
|
1534 |
" <tr>\n",
|
1535 |
" <th>2</th>\n",
|
@@ -1542,7 +1527,7 @@
|
|
1542 |
" <td>-117.598</td>\n",
|
1543 |
" <td>775.0</td>\n",
|
1544 |
" <td>1</td>\n",
|
1545 |
-
" <td>0.
|
1546 |
" </tr>\n",
|
1547 |
" <tr>\n",
|
1548 |
" <th>3</th>\n",
|
@@ -1555,7 +1540,7 @@
|
|
1555 |
" <td>-117.598</td>\n",
|
1556 |
" <td>775.0</td>\n",
|
1557 |
" <td>1</td>\n",
|
1558 |
-
" <td>0.
|
1559 |
" </tr>\n",
|
1560 |
" <tr>\n",
|
1561 |
" <th>4</th>\n",
|
@@ -1568,7 +1553,7 @@
|
|
1568 |
" <td>-117.598</td>\n",
|
1569 |
" <td>775.0</td>\n",
|
1570 |
" <td>1</td>\n",
|
1571 |
-
" <td>0.
|
1572 |
" </tr>\n",
|
1573 |
" <tr>\n",
|
1574 |
" <th>...</th>\n",
|
@@ -1669,10 +1654,10 @@
|
|
1669 |
"\n",
|
1670 |
" phase_type latitude longitude elevation_m event_index gamma_score \n",
|
1671 |
"0 S 36.025 -117.765 1143.0 -1 -1.000000 \n",
|
1672 |
-
"1 P 35.587 -117.462 694.5 1 0.
|
1673 |
-
"2 P 35.816 -117.598 775.0 1 0.
|
1674 |
-
"3 P 35.816 -117.598 775.0 1 0.
|
1675 |
-
"4 P 35.816 -117.598 775.0 1 0.
|
1676 |
".. ... ... ... ... ... ... \n",
|
1677 |
"103 P 36.025 -117.765 1143.0 -1 -1.000000 \n",
|
1678 |
"104 P 35.982 -117.809 1469.0 -1 -1.000000 \n",
|
@@ -1683,7 +1668,7 @@
|
|
1683 |
"[108 rows x 10 columns]"
|
1684 |
]
|
1685 |
},
|
1686 |
-
"execution_count":
|
1687 |
"metadata": {},
|
1688 |
"output_type": "execute_result"
|
1689 |
}
|
@@ -1692,6 +1677,13 @@
|
|
1692 |
"picks_"
|
1693 |
]
|
1694 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1695 |
{
|
1696 |
"cell_type": "code",
|
1697 |
"execution_count": null,
|
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
+
"execution_count": 24,
|
31 |
"metadata": {},
|
32 |
"outputs": [],
|
33 |
"source": [
|
34 |
+
"# GAMMA_API_URL = \"http://127.0.0.1:8000\"\n",
|
35 |
+
"GAMMA_API_URL = \"https://ai4eps-gamma.hf.space\"\n"
|
36 |
]
|
37 |
},
|
38 |
{
|
|
|
1263 |
"plt.show()"
|
1264 |
]
|
1265 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1266 |
{
|
1267 |
"cell_type": "code",
|
1268 |
"execution_count": 14,
|
|
|
1273 |
"output_type": "stream",
|
1274 |
"text": [
|
1275 |
"Associating 108 picks with 1 CPUs\n",
|
1276 |
+
".[{'time': '2019-07-04T17:02:55.008', 'magnitude': 4.339747018742565, 'sigma_time': 0.32614604178710815, 'sigma_amp': 0.3280145301432932, 'cov_time_amp': 0.05017926672657749, 'gamma_score': 97.9995778560105, 'num_picks': 98, 'num_p_picks': 49, 'num_s_picks': 49, 'event_index': 1, 'x(km)': 0.7269972359810098, 'y(km)': 0.5939380031466018, 'z(km)': 16.20145420615579}]\n"
|
1277 |
]
|
1278 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1279 |
{
|
1280 |
"data": {
|
1281 |
"text/plain": [
|
1282 |
+
"<matplotlib.collections.PathCollection at 0x336b22740>"
|
1283 |
]
|
1284 |
},
|
1285 |
+
"execution_count": 14,
|
1286 |
"metadata": {},
|
1287 |
"output_type": "execute_result"
|
1288 |
},
|
|
|
1298 |
}
|
1299 |
],
|
1300 |
"source": [
|
1301 |
+
"from app import run_gamma\n",
|
1302 |
+
"\n",
|
1303 |
+
"config[\"region\"] = \"Ridgecrest\"\n",
|
1304 |
+
"config[\"event_index\"] = 1\n",
|
1305 |
+
"\n",
|
1306 |
+
"evengts_, picks_ = run_gamma(picks, stations, config)\n",
|
1307 |
+
"\n",
|
1308 |
"plt.figure()\n",
|
1309 |
"mapping_color = lambda x: f\"C{x}\" if x!= -1 else \"black\"\n",
|
1310 |
+
"plt.scatter(picks_[\"phase_time\"], picks_[\"latitude\"], c=picks_[\"event_index\"].apply(mapping_color), s=10)"
|
1311 |
]
|
1312 |
},
|
1313 |
{
|
1314 |
"cell_type": "code",
|
1315 |
+
"execution_count": 31,
|
1316 |
"metadata": {},
|
1317 |
"outputs": [],
|
1318 |
"source": [
|
|
|
1319 |
"picks_ = picks.copy()\n",
|
1320 |
"picks_[\"phase_time\"] = picks_[\"phase_time\"].apply(lambda x: x.isoformat())\n",
|
1321 |
"stations_ = stations.copy()\n",
|
|
|
1323 |
"picks_ = picks_.to_dict(orient=\"records\")\n",
|
1324 |
"stations_ = stations.to_dict(orient=\"records\")\n",
|
1325 |
"\n",
|
1326 |
+
"response = requests.post(f\"{GAMMA_API_URL}/predict/\", json={\"picks\": {\"data\":picks_}, \"stations\": {\"data\": stations_}, \"config\": config})\n",
|
1327 |
"\n",
|
1328 |
"if response.status_code == 200:\n",
|
1329 |
" result = response.json()\n",
|
|
|
1335 |
},
|
1336 |
{
|
1337 |
"cell_type": "code",
|
1338 |
+
"execution_count": 32,
|
1339 |
"metadata": {},
|
1340 |
"outputs": [
|
1341 |
{
|
1342 |
"data": {
|
1343 |
"text/plain": [
|
1344 |
+
"<matplotlib.collections.PathCollection at 0x336e17fd0>"
|
1345 |
]
|
1346 |
},
|
1347 |
+
"execution_count": 32,
|
1348 |
"metadata": {},
|
1349 |
"output_type": "execute_result"
|
1350 |
},
|
|
|
1371 |
},
|
1372 |
{
|
1373 |
"cell_type": "code",
|
1374 |
+
"execution_count": 33,
|
1375 |
"metadata": {},
|
1376 |
"outputs": [
|
1377 |
{
|
|
|
1414 |
" <tr>\n",
|
1415 |
" <th>0</th>\n",
|
1416 |
" <td>2019-07-04T17:02:55.008</td>\n",
|
1417 |
+
" <td>4.339747</td>\n",
|
1418 |
" <td>0.326146</td>\n",
|
1419 |
" <td>0.328015</td>\n",
|
1420 |
" <td>0.050179</td>\n",
|
1421 |
+
" <td>97.999578</td>\n",
|
1422 |
" <td>98</td>\n",
|
1423 |
" <td>49</td>\n",
|
1424 |
" <td>49</td>\n",
|
1425 |
" <td>1</td>\n",
|
1426 |
+
" <td>-117.495966</td>\n",
|
1427 |
" <td>35.710353</td>\n",
|
1428 |
+
" <td>16.201454</td>\n",
|
1429 |
" </tr>\n",
|
1430 |
" </tbody>\n",
|
1431 |
"</table>\n",
|
|
|
1433 |
],
|
1434 |
"text/plain": [
|
1435 |
" time magnitude sigma_time sigma_amp cov_time_amp \\\n",
|
1436 |
+
"0 2019-07-04T17:02:55.008 4.339747 0.326146 0.328015 0.050179 \n",
|
1437 |
"\n",
|
1438 |
" gamma_score num_picks num_p_picks num_s_picks event_index longitude \\\n",
|
1439 |
+
"0 97.999578 98 49 49 1 -117.495966 \n",
|
1440 |
"\n",
|
1441 |
" latitude depth_km \n",
|
1442 |
+
"0 35.710353 16.201454 "
|
1443 |
]
|
1444 |
},
|
1445 |
+
"execution_count": 33,
|
1446 |
"metadata": {},
|
1447 |
"output_type": "execute_result"
|
1448 |
}
|
|
|
1453 |
},
|
1454 |
{
|
1455 |
"cell_type": "code",
|
1456 |
+
"execution_count": 34,
|
1457 |
"metadata": {},
|
1458 |
"outputs": [
|
1459 |
{
|
|
|
1514 |
" <td>-117.462</td>\n",
|
1515 |
" <td>694.5</td>\n",
|
1516 |
" <td>1</td>\n",
|
1517 |
+
" <td>0.000016</td>\n",
|
1518 |
" </tr>\n",
|
1519 |
" <tr>\n",
|
1520 |
" <th>2</th>\n",
|
|
|
1527 |
" <td>-117.598</td>\n",
|
1528 |
" <td>775.0</td>\n",
|
1529 |
" <td>1</td>\n",
|
1530 |
+
" <td>0.185935</td>\n",
|
1531 |
" </tr>\n",
|
1532 |
" <tr>\n",
|
1533 |
" <th>3</th>\n",
|
|
|
1540 |
" <td>-117.598</td>\n",
|
1541 |
" <td>775.0</td>\n",
|
1542 |
" <td>1</td>\n",
|
1543 |
+
" <td>0.300784</td>\n",
|
1544 |
" </tr>\n",
|
1545 |
" <tr>\n",
|
1546 |
" <th>4</th>\n",
|
|
|
1553 |
" <td>-117.598</td>\n",
|
1554 |
" <td>775.0</td>\n",
|
1555 |
" <td>1</td>\n",
|
1556 |
+
" <td>0.306604</td>\n",
|
1557 |
" </tr>\n",
|
1558 |
" <tr>\n",
|
1559 |
" <th>...</th>\n",
|
|
|
1654 |
"\n",
|
1655 |
" phase_type latitude longitude elevation_m event_index gamma_score \n",
|
1656 |
"0 S 36.025 -117.765 1143.0 -1 -1.000000 \n",
|
1657 |
+
"1 P 35.587 -117.462 694.5 1 0.000016 \n",
|
1658 |
+
"2 P 35.816 -117.598 775.0 1 0.185935 \n",
|
1659 |
+
"3 P 35.816 -117.598 775.0 1 0.300784 \n",
|
1660 |
+
"4 P 35.816 -117.598 775.0 1 0.306604 \n",
|
1661 |
".. ... ... ... ... ... ... \n",
|
1662 |
"103 P 36.025 -117.765 1143.0 -1 -1.000000 \n",
|
1663 |
"104 P 35.982 -117.809 1469.0 -1 -1.000000 \n",
|
|
|
1668 |
"[108 rows x 10 columns]"
|
1669 |
]
|
1670 |
},
|
1671 |
+
"execution_count": 34,
|
1672 |
"metadata": {},
|
1673 |
"output_type": "execute_result"
|
1674 |
}
|
|
|
1677 |
"picks_"
|
1678 |
]
|
1679 |
},
|
1680 |
+
{
|
1681 |
+
"cell_type": "code",
|
1682 |
+
"execution_count": null,
|
1683 |
+
"metadata": {},
|
1684 |
+
"outputs": [],
|
1685 |
+
"source": []
|
1686 |
+
},
|
1687 |
{
|
1688 |
"cell_type": "code",
|
1689 |
"execution_count": null,
|