Skip to content

Commit 31fe4e6

Browse files
committed
change from organize by hour to by day
1 parent d8d43cc commit 31fe4e6

File tree

7 files changed

+54
-75
lines changed

7 files changed

+54
-75
lines changed

scripts/download_waveform_v2.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def download_waveform(
210210

211211
client = obspy.clients.fdsn.Client(provider)
212212

213-
DELTATIME = "1H" # 1H or 1D
214-
# DELTATIME = "1D"
213+
# DELTATIME = "1H" # 1H or 1D
214+
DELTATIME = "1D"
215215
if DELTATIME == "1H":
216216
start = datetime.fromisoformat(config["starttime"]).strftime("%Y-%m-%dT%H")
217217
elif DELTATIME == "1D":
@@ -290,31 +290,6 @@ def download_waveform(
290290
if out is not None:
291291
print(out)
292292

293-
tmp_list = sorted(glob(f"{root_path}/{waveform_dir}/????/???/??/*.mseed", recursive=True))
294-
mseed_list = []
295-
for mseed in tmp_list:
296-
tmp = mseed.split("/")
297-
# year, jday = tmp[-3].split("-")
298-
# hour = tmp[-2]
299-
year, jday, hour = tmp[-4], tmp[-3], tmp[-2]
300-
if starttimes[0].strftime("%Y-%jT%H") <= f"{year}-{jday}T{hour}" <= starttimes[-1].strftime("%Y-%jT%H"):
301-
mseed_list.append(mseed)
302-
303-
print(f"rank {rank}: {len(mseed_list) = }, {mseed_list[0]}, {mseed_list[-1]}")
304-
305-
# %% copy to results/network
306-
if not os.path.exists(f"{root_path}/{region}/results/network"):
307-
os.makedirs(f"{root_path}/{region}/results/network")
308-
with open(f"{root_path}/{region}/results/network/mseed_list_{rank:03d}_{num_nodes:03d}.csv", "w") as fp:
309-
fp.write("\n".join(mseed_list))
310-
if protocol != "file":
311-
fs.put(
312-
f"{root_path}/{region}/results/network/mseed_list_{rank:03d}_{num_nodes:03d}.csv",
313-
f"{bucket}/{region}/results/network/mseed_list_{rank:03d}_{num_nodes:03d}.csv",
314-
)
315-
316-
return f"{region}/results/network/mseed_list_{rank:03d}_{num_nodes:03d}.csv"
317-
318293

319294
if __name__ == "__main__":
320295

scripts/merge_adloc_picks.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import os
55
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed
66
from datetime import datetime, timedelta, timezone
7+
from glob import glob
78
from threading import Lock, Thread
89

910
import fsspec
11+
import matplotlib.pyplot as plt
1012
import numpy as np
1113
import pandas as pd
1214
import pyproj
15+
from args import parse_args
1316
from obspy import read_inventory
1417
from obspy.clients.fdsn import Client
1518
from sklearn.cluster import DBSCAN
1619
from tqdm import tqdm
17-
from args import parse_args
18-
from glob import glob
19-
import matplotlib.pyplot as plt
2020
from utils.plotting import plotting_ransac
2121

2222
# %%
@@ -26,6 +26,7 @@
2626
root_path = args.root_path
2727
region = args.region
2828
iter = args.iter
29+
print(f"Merge adloc picks iter={iter}")
2930

3031
data_path = f"{region}/adloc"
3132
result_path = f"{region}/adloc"
@@ -125,8 +126,12 @@
125126
picks.to_csv(f"{root_path}/{result_path}/adloc_picks_sst_{iter}.csv", index=False)
126127
stations.to_csv(f"{root_path}/{result_path}/adloc_stations_sst_{iter}.csv", index=False)
127128

128-
# %%
129+
## save current iteration as the latest
130+
events.to_csv(f"{root_path}/{result_path}/adloc_events.csv", index=False)
131+
picks.to_csv(f"{root_path}/{result_path}/adloc_picks.csv", index=False)
132+
stations.to_csv(f"{root_path}/{result_path}/adloc_stations.csv", index=False)
129133

134+
# %%
130135
events = pd.read_csv(f"{root_path}/{result_path}/adloc_events_sst_{iter}.csv")
131136
picks = pd.read_csv(f"{root_path}/{result_path}/adloc_picks_sst_{iter}.csv")
132137
stations = pd.read_csv(f"{root_path}/{result_path}/adloc_stations_sst_{iter}.csv")

scripts/merge_phasenet_picks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def scan_csv(year, root_path, region, model, fs=None, bucket=None, protocol="fil
3030
if protocol != "file":
3131
csvs = fs.glob(f"{jday}/??/*.csv")
3232
else:
33-
csvs = glob(f"{root_path}/{region}/{model}/picks/{year}/{jday}/??/*.csv")
34-
# csvs = glob(f"{root_path}/{region}/{model}/picks/{year}/{jday}/*.csv")
33+
# csvs = glob(f"{root_path}/{region}/{model}/picks/{year}/{jday}/??/*.csv")
34+
csvs = glob(f"{root_path}/{region}/{model}/picks/{year}/{jday}/*.csv")
3535

3636
csv_list.extend([[year, jday, csv] for csv in csvs])
3737

scripts/run_adloc.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def run_adloc(
3939
picks_file = f"{data_path}/gamma_picks.csv"
4040
events_file = f"{data_path}/gamma_events.csv"
4141

42-
# picks_file = f"{root_path}/{region}/gamma/gamma_picks.csv"
43-
# events_file = f"{root_path}/{region}/gamma/gamma_events.csv"
44-
# result_path = f"{root_path}/{region}/adloc_gamma"
45-
# figure_path = f"{root_path}/{region}/adloc_gamma/figures"
42+
picks_file = f"{root_path}/{region}/gamma/gamma_picks.csv"
43+
events_file = f"{root_path}/{region}/gamma/gamma_events.csv"
44+
result_path = f"{root_path}/{region}/adloc_gamma"
45+
figure_path = f"{root_path}/{region}/adloc_gamma/figures"
4646

4747
# picks_file = f"{root_path}/{region}/gamma_plus/gamma_picks.csv"
4848
# events_file = f"{root_path}/{region}/gamma_plus/gamma_events.csv"
@@ -242,7 +242,7 @@ def run_adloc(
242242
stations["idx_sta"].map(station_term_time[station_term_time["phase_type"] == 1]["residual_time"]).fillna(0)
243243
)
244244

245-
plotting_ransac(stations, figure_path, config, picks, events_init, events, suffix=f"_ransac_sst_{iter}")
245+
plotting_ransac(stations, figure_path, config, picks, events_init, events, suffix=f"_adloc_sst_{iter}")
246246

247247
if "event_index" not in events.columns:
248248
events["event_index"] = events.merge(picks[["idx_eve", "event_index"]], on="idx_eve")["event_index"]
@@ -254,9 +254,9 @@ def run_adloc(
254254
picks["adloc_mask"] = picks["mask"]
255255
picks["adloc_residual_time"] = picks["residual_time"]
256256
picks["adloc_residual_amplitude"] = picks["residual_amplitude"]
257-
picks.to_csv(os.path.join(result_path, f"ransac_picks_sst_{iter}.csv"), index=False)
258-
events.to_csv(os.path.join(result_path, f"ransac_events_sst_{iter}.csv"), index=False)
259-
stations.to_csv(os.path.join(result_path, f"ransac_stations_sst_{iter}.csv"), index=False)
257+
picks.to_csv(os.path.join(result_path, f"adloc_picks_sst_{iter}.csv"), index=False)
258+
events.to_csv(os.path.join(result_path, f"adloc_events_sst_{iter}.csv"), index=False)
259+
stations.to_csv(os.path.join(result_path, f"adloc_stations_sst_{iter}.csv"), index=False)
260260

261261
if iter == 0:
262262
MIN_SST_S = (
@@ -290,9 +290,9 @@ def run_adloc(
290290
stations.drop(["idx_sta", "x_km", "y_km", "z_km"], axis=1, inplace=True, errors="ignore")
291291
# stations.rename({"station_term": "adloc_station_term_s"}, axis=1, inplace=True)
292292

293-
picks.to_csv(os.path.join(result_path, "ransac_picks.csv"), index=False)
294-
events.to_csv(os.path.join(result_path, "ransac_events.csv"), index=False)
295-
stations.to_csv(os.path.join(result_path, "ransac_stations.csv"), index=False)
293+
picks.to_csv(os.path.join(result_path, "adloc_picks.csv"), index=False)
294+
events.to_csv(os.path.join(result_path, "adloc_events.csv"), index=False)
295+
stations.to_csv(os.path.join(result_path, "adloc_stations.csv"), index=False)
296296

297297

298298
# %%

scripts/run_adloc_v2.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import multiprocessing as mp
55
import os
6+
from glob import glob
67
from typing import Dict, List, NamedTuple
78

89
import fsspec
@@ -13,11 +14,10 @@
1314
from adloc.sacloc2d import ADLoc
1415
from adloc.utils import invert_location, invert_location_iter
1516
from args import parse_args
16-
from glob import glob
17+
from pyproj import Proj
1718

1819
# from utils import plotting_ransac
1920
from utils.plotting import plotting, plotting_ransac
20-
from pyproj import Proj
2121

2222

2323
# %%
@@ -375,28 +375,19 @@ def run_adloc(
375375
# %%
376376
print(f"{jdays[node_rank] = }")
377377
if num_nodes == 1:
378-
for i in range(10):
379-
run_adloc(
380-
root_path=root_path,
381-
region=region,
382-
config=config,
383-
jdays=jdays[node_rank],
384-
iter=i,
385-
protocol=protocol,
386-
token=token,
387-
bucket=bucket,
388-
)
389-
os.system(
390-
f"python merge_adloc_picks.py --region {region} --root_path {root_path} --bucket {bucket} --iter {i}"
391-
)
378+
max_iter = 10
392379
else:
380+
max_iter = 1
381+
382+
for i in range(max_iter):
393383
run_adloc(
394384
root_path=root_path,
395385
region=region,
396386
config=config,
397387
jdays=jdays[node_rank],
398-
iter=iter,
388+
iter=i,
399389
protocol=protocol,
400390
token=token,
401391
bucket=bucket,
402392
)
393+
os.system(f"python merge_adloc_picks.py --region {region} --root_path {root_path} --bucket {bucket} --iter {i}")

scripts/run_cctorch.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,25 @@
5050
f"../CCTorch/run.py --pair_list={root_path}/{data_path}/pairs.txt --data_path1={root_path}/{data_path}/template.dat --data_format1=memmap "
5151
f"--data_list1={root_path}/{data_path}/cctorch_picks.csv "
5252
f"--events_csv={root_path}/{data_path}/cctorch_events.csv --picks_csv={root_path}/{data_path}/cctorch_picks.csv --stations_csv={root_path}/{data_path}/cctorch_stations.csv "
53-
f"--config={root_path}/{data_path}/config.json --batch_size={batch} --block_size1={block_size1} --block_size2={block_size2} --result_path={root_path}/{result_path}"
53+
f"--config={root_path}/{data_path}/config.json --batch_size={batch} --block_size1={block_size1} --block_size2={block_size2} "
54+
f"--result_path={root_path}/{result_path}"
5455
)
5556

56-
num_gpu = torch.cuda.device_count()
57-
if num_gpu == 0:
58-
if os.uname().sysname == "Darwin":
59-
cmd = f"python {base_cmd} --device=cpu"
60-
else:
61-
cmd = f"python {base_cmd} --device=cpu"
57+
58+
if torch.cuda.is_available():
59+
device = "cuda"
60+
num_gpu = torch.cuda.device_count()
61+
elif torch.backends.mps.is_available():
62+
device = "mps"
63+
num_gpu = 0
64+
else:
65+
device = "cpu"
66+
num_gpu = 0
67+
68+
if num_gpu > 0:
69+
cmd = f"torchrun --standalone --nproc_per_node {num_gpu} {base_cmd} --device={device}"
6270
else:
63-
cmd = f"torchrun --standalone --nproc_per_node {num_gpu} {base_cmd}"
71+
cmd = f"python {base_cmd} --device={device}"
6472
print(cmd)
6573
os.system(cmd)
6674

scripts/run_phasenet_v2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def run_phasenet(
3434

3535
# %%
3636
waveform_dir = f"{region}/waveforms"
37-
mseed_list = sorted(glob(f"{root_path}/{waveform_dir}/????/???/??/*.mseed"))
38-
subdir = 3
39-
# mseed_list = sorted(glob(f"{root_path}/{waveform_dir}/????/???/*.mseed"))
40-
# subdir = 2
37+
# mseed_list = sorted(glob(f"{root_path}/{waveform_dir}/????/???/??/*.mseed"))
38+
# subdir = 3
39+
mseed_list = sorted(glob(f"{root_path}/{waveform_dir}/????/???/*.mseed"))
40+
subdir = 2
4141

4242
# %%
4343
mseed_3c = defaultdict(list)
@@ -49,8 +49,8 @@ def run_phasenet(
4949

5050
# %%
5151
if not overwrite:
52-
processed = sorted(glob(f"{root_path}/{result_path}/picks/????/???/??/*.csv"))
53-
# processed = sorted(glob(f"{root_path}/{result_path}/picks/????/???/*.csv"))
52+
# processed = sorted(glob(f"{root_path}/{result_path}/picks/????/???/??/*.csv"))
53+
processed = sorted(glob(f"{root_path}/{result_path}/picks/????/???/*.csv"))
5454
processed = ["/".join(f.replace(".csv", "").split("/")[-subdir - 1 :]) for f in processed]
5555
processed = [p[:-1] for p in processed] ## remove the channel suffix
5656
print(f"Number of processed files: {len(processed)}")

0 commit comments

Comments
 (0)