File size: 1,218 Bytes
0eb79a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import obspy
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime

### Start running the model first:
### FLASK_ENV=development FLASK_APP=app.py flask run

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]

## prepare some test data
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
    }

## run prediction
print(data["id"])
resp = requests.get("http://localhost:8000/predict", json=data)
# picks = resp.json()["picks"]
print(resp.json())


## plot figure
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")