Skip to content

Commit cf2d2ee

Browse files
committed
change from by hour to by day
1 parent 0cbd68c commit cf2d2ee

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

scripts/cut_templates_cc.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ def extract_template_numpy(
162162
waveforms_dict = {}
163163
for i, station in stations.iterrows():
164164
station_id = station["station_id"]
165-
for c in station["component"]:
165+
# for c in station["component"]:
166+
for c in ["E", "N", "Z", "1", "2", "3"]:
166167
mseed_name = f"{mseed_path}/{station_id}{c}.mseed"
167168
if os.path.exists(mseed_name):
168169
try:
@@ -194,7 +195,8 @@ def extract_template_numpy(
194195
station_id = station["station_id"]
195196
event = events.loc[idx_eve]
196197

197-
for c in station["component"]:
198+
# for c in station["component"]:
199+
for c in ["E", "N", "Z", "1", "2", "3"]:
198200
ic = config["component_mapping"][c] # 012 for P, 345 for S
199201

200202
if f"{station_id}{c}" in waveforms_dict:
@@ -291,7 +293,7 @@ def cut_templates(root_path, region, config):
291293
# data_path = f"{region}/adloc"
292294
# result_path = f"{region}/cctorch"
293295

294-
data_path = f"{region}/adloc_gamma"
296+
data_path = f"{region}/adloc"
295297
result_path = f"{region}/cctorch"
296298

297299
if not os.path.exists(f"{root_path}/{result_path}"):
@@ -350,13 +352,13 @@ def cut_templates(root_path, region, config):
350352
)
351353

352354
# %%
353-
stations = pd.read_csv(f"{root_path}/{data_path}/ransac_stations.csv")
355+
stations = pd.read_csv(f"{root_path}/{data_path}/adloc_stations.csv")
354356
stations.sort_values(by=["latitude", "longitude"], inplace=True)
355357
print(f"{len(stations) = }")
356358
print(stations.iloc[:5])
357359

358360
# %%
359-
events = pd.read_csv(f"{root_path}/{data_path}/ransac_events.csv", parse_dates=["time"])
361+
events = pd.read_csv(f"{root_path}/{data_path}/adloc_events.csv", parse_dates=["time"])
360362
events.rename(columns={"time": "event_time"}, inplace=True)
361363
events["event_time"] = pd.to_datetime(events["event_time"], utc=True)
362364
reference_t0 = events["event_time"].min()
@@ -416,7 +418,7 @@ def cut_templates(root_path, region, config):
416418
eikonal = init_eikonal2d(eikonal)
417419

418420
# %%
419-
picks = pd.read_csv(f"{root_path}/{data_path}/ransac_picks.csv")
421+
picks = pd.read_csv(f"{root_path}/{data_path}/adloc_picks.csv")
420422
picks = picks[picks["adloc_mask"] == 1]
421423
picks["phase_time"] = pd.to_datetime(picks["phase_time"], utc=True)
422424
min_phase_score = picks["phase_score"].min()
@@ -514,7 +516,11 @@ def cut_templates(root_path, region, config):
514516

515517
picks.to_csv(f"{root_path}/{result_path}/cctorch_picks.csv", index=False)
516518

517-
dirs = sorted(glob(f"{root_path}/{region}/waveforms/????/???/??"), reverse=True)
519+
## By hour
520+
# dirs = sorted(glob(f"{root_path}/{region}/waveforms/????/???/??"), reverse=True)
521+
## By day
522+
dirs = sorted(glob(f"{root_path}/{region}/waveforms/????/???"), reverse=True)
523+
518524
ncpu = min(16, mp.cpu_count())
519525
print(f"Using {ncpu} cores")
520526

@@ -529,8 +535,12 @@ def pbar_update(x):
529535

530536
ctx = mp.get_context("spawn")
531537
picks_group = picks.copy()
532-
picks_group["year_jday_hour"] = picks_group["phase_time"].dt.strftime("%Y-%jT%H")
533-
picks_group = picks_group.groupby("year_jday_hour")
538+
## By hour
539+
# picks_group["year_jday_hour"] = picks_group["phase_time"].dt.strftime("%Y-%jT%H")
540+
# picks_group = picks_group.groupby("year_jday_hour")
541+
## By day
542+
picks_group["year_jday"] = picks_group["phase_time"].dt.strftime("%Y-%j")
543+
picks_group = picks_group.groupby("year_jday")
534544

535545
with ctx.Manager() as manager:
536546
lock = manager.Lock()
@@ -539,12 +549,22 @@ def pbar_update(x):
539549
for d in dirs:
540550

541551
tmp = d.split("/")
542-
year, jday, hour = tmp[-3:]
543-
544-
if f"{year}-{jday}T{hour}" not in picks_group.groups:
552+
## By hour
553+
# year, jday, hour = tmp[-3:]
554+
## By day
555+
year, jday = tmp[-2:]
556+
557+
## By hour
558+
# if f"{year}-{jday}T{hour}" not in picks_group.groups:
559+
## By day
560+
if f"{year}-{jday}" not in picks_group.groups:
545561
pbar_update(d)
546562
continue
547-
picks_ = picks_group.get_group(f"{year}-{jday}T{hour}")
563+
564+
## By hour
565+
# picks_ = picks_group.get_group(f"{year}-{jday}T{hour}")
566+
## By day
567+
picks_ = picks_group.get_group(f"{year}-{jday}")
548568
events_ = events.loc[picks_["idx_eve"].unique()]
549569
picks_ = picks_.set_index(["idx_eve", "idx_sta", "phase_type"])
550570

0 commit comments

Comments
 (0)