-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# %% | ||
import fsspec | ||
import h5py | ||
import obspy | ||
import pandas as pd | ||
|
||
|
||
def map_cloud_path(root_path, provider, starttime, network, station, location, channels): | ||
paths = [] | ||
for channel in channels.split(","): | ||
if isinstance(starttime, str): | ||
starttime = pd.Timestamp(starttime) | ||
if provider.lower() == "scedc": | ||
year = starttime.strftime("%Y") | ||
dayofyear = starttime.strftime("%j") | ||
if location == "": | ||
location = "__" | ||
path = f"{root_path}/{provider.lower()}-pds/continuous_waveforms/{year}/{year}_{dayofyear}/{network}{station:_<5}{channel}{location:_<2}_{year}{dayofyear}.ms" | ||
elif provider.lower() == "ncedc": | ||
year = starttime.strftime("%Y") | ||
dayofyear = starttime.strftime("%j") | ||
path = f"{root_path}/{provider.lower()}-pds/continuous_waveforms/{network}/{year}/{year}.{dayofyear}/{station}.{network}.{channel}.{location}.D.{year}.{dayofyear}" | ||
else: | ||
raise ValueError(f"Unknown provider: {provider}") | ||
paths.append(path) | ||
|
||
return paths | ||
|
||
|
||
# %% | ||
if __name__ == "__main__": | ||
# %% | ||
mseed_list = [ | ||
{ | ||
"provider": "ncedc", | ||
"network": "NC", | ||
"station": "KCT", | ||
"location": "", | ||
"channels": "HHE,HHN,HHZ", | ||
"year": "2012", | ||
"month": "01", | ||
"day": "01", | ||
}, | ||
{ | ||
"provider": "ncedc", | ||
"network": "NC", | ||
"station": "KRP", | ||
"location": "", | ||
"channels": "HHE,HHN,HHZ", | ||
"year": "2012", | ||
"month": "01", | ||
"day": "01", | ||
}, | ||
{ | ||
"provider": "ncedc", | ||
"network": "NC", | ||
"station": "KHMB", | ||
"location": "", | ||
"channels": "HHE,HHN,HHZ", | ||
"year": "2012", | ||
"month": "01", | ||
"day": "01", | ||
}, | ||
] | ||
# %% | ||
file_list = [] | ||
root_path = "s3:/" | ||
for mseed_info in mseed_list: | ||
starttime = pd.Timestamp(f"{mseed_info['year']}-{mseed_info['month']}-{mseed_info['day']}T00:00:00") | ||
file_path = map_cloud_path( | ||
root_path, | ||
mseed_info["provider"], | ||
starttime, | ||
mseed_info["network"], | ||
mseed_info["station"], | ||
mseed_info["location"], | ||
mseed_info["channels"], | ||
) | ||
file_list.append("|".join(file_path)) | ||
# with fsspec.open(file_path, "rb", anon=True) as f: | ||
# stream = obspy.read(f) | ||
# stream.plot() # %% | ||
|
||
with open("data_list.txt", "w") as f: | ||
f.write("file_name\n") | ||
f.write("\n".join(file_list)) | ||
|
||
num_files = len(file_list) | ||
with open("pair_list.txt", "w") as f: | ||
for i in range(num_files): | ||
for j in range(i + 1, num_files): | ||
f.write(f"{i},{j}\n") | ||
|
||
|
||
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# %% | ||
from pathlib import Path | ||
|
||
import h5py | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import pandas as pd | ||
from tqdm.auto import tqdm | ||
|
||
|
||
def get_args_parser(add_help=True): | ||
|
||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Read CCTorch Results", add_help=add_help) | ||
parser.add_argument("--result_path", type=str, default="results", help="path to results") | ||
parser.add_argument("--figure_path", type=str, default="figures", help="path to figures") | ||
return parser | ||
|
||
|
||
# %% | ||
if __name__ == "__main__": | ||
|
||
args = get_args_parser().parse_args() | ||
|
||
result_path = Path(args.result_path) | ||
figure_path = Path(args.figure_path) | ||
if not figure_path.exists(): | ||
figure_path.mkdir(parents=True) | ||
|
||
h5_files = sorted(result_path.glob("*.h5")) | ||
print(f"{len(h5_files)} hdf5 files found") | ||
|
||
data = [] | ||
index = [] | ||
for h5_file in h5_files: | ||
with h5py.File(h5_file, "r") as fp: | ||
print(fp.keys()) | ||
ch1_list = fp.keys() | ||
for ch1 in ch1_list: | ||
ch2_list = fp[ch1].keys() | ||
for ch2 in ch2_list: | ||
plt.figure() | ||
plt.plot(fp[f"{ch1}/{ch2}"]["xcorr"][0, :]) | ||
plt.plot(fp[f"{ch1}/{ch2}"]["xcorr"][1, :] + 1) | ||
plt.plot(fp[f"{ch1}/{ch2}"]["xcorr"][2, :] + 2) | ||
plt.savefig(figure_path / f"ambient_noise_{ch1}_{ch2}.png", dpi=300, bbox_inches="tight") | ||
# raise | ||
# for ch2 in ch2_list: | ||
# data.append(fp[ch1][ch2]["xcorr"][:]) | ||
# index.append(ch2) | ||
|
||
raise |