|
import requests |
|
import obspy |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
def read_data(mseed): |
|
data = [] |
|
mseed = mseed.sort() |
|
for c in ["E", "N", "Z"]: |
|
data.append(mseed.select(channel="*"+c)[0].data) |
|
return np.array(data).T |
|
|
|
timestamp = lambda x: x.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] |
|
|
|
|
|
mseed = obspy.read() |
|
data = [] |
|
for i in range(1): |
|
data.append(read_data(mseed)) |
|
data = { |
|
"id": ["test01"], |
|
"timestamp": [timestamp(datetime.now())], |
|
"vec": np.array(data).tolist(), |
|
"dt": 0.01 |
|
} |
|
|
|
|
|
print(data["id"]) |
|
resp = requests.get("http://localhost:8000/predict", json=data) |
|
|
|
print(resp.json()) |
|
|
|
|
|
|
|
plt.figure() |
|
plt.plot(np.array(data["data"])[0,:,1]) |
|
ylim = plt.ylim() |
|
plt.plot([picks[0][0][0], picks[0][0][0]], ylim, label="P-phase") |
|
plt.text(picks[0][0][0], ylim[1]*0.9, f"{picks[0][1][0]:.2f}") |
|
plt.plot([picks[0][2][0], picks[0][2][0]], ylim, label="S-phase") |
|
plt.text(picks[0][2][0], ylim[1]*0.9, f"{picks[0][1][0]:.2f}") |
|
plt.legend() |
|
plt.savefig("test.png") |