Skip to content

Commit

Permalink
add obspy data download
Browse files Browse the repository at this point in the history
  • Loading branch information
YijianZhou committed Aug 27, 2023
1 parent e332e50 commit 591c41e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import multiprocessing as mp

# i/o files
time_range = '20190704-20190707'
num_workers = 10
num_workers = 4
fsta = 'input/example_pal_format1.sta'
time_range = '20190704-20190707'
out_root = '/data/Example_data'
if not os.path.exists(out_root): os.makedirs(out_root)
start_time, end_time = [UTCDateTime(date) for date in time_range.split('-')]
Expand Down
47 changes: 47 additions & 0 deletions example_mess_workdir/0.2_down_data-obspy_eg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
""" Download FDSN data with obspy MassDownloader
"""
import os
from obspy import UTCDateTime
from obspy.clients.fdsn.mass_downloader import RectangularDomain, Restrictions, MassDownloader

# i/o paths
data_root = '/data/Example_data'
sta_dir = 'output/eg_stations'
# down params
providers = ["SCEDC"]
chn_codes = ['HH*','EH*']
loc_codes = ["*"]
num_workers = 10
start_date, end_date = UTCDateTime('20190704'), UTCDateTime('20190707')
lat_rng = [35.25,36.25]
lon_rng = [-118,-117,1]
num_day = int((end_date - start_date) / 86400) + 1
print('data range:')
print('latitude range: %s'%(lat_rng))
print('longitude range: %s'%(lon_rng))
print('time range: %s'%[start_date, end_date])

domain = RectangularDomain(minlatitude=lat_rng[0], maxlatitude=lat_rng[1],
minlongitude=lon_rng[0], maxlongitude=lon_rng[1])
for day_idx in range(num_day):
t0 = start_date + 86400*day_idx
t1 = start_date + 86400*(day_idx+1)
print('downloading %s'%t0)
# 1. set domain & restrict
restrict = Restrictions(
starttime=t0, endtime=t1,
network="*", station="*",
reject_channels_with_gaps=False,
minimum_length=0.0,
minimum_interstation_distance_in_m=10,
channel_priorities=chn_codes,
location_priorities=loc_codes)
# 2. set storage
out_dir = os.path.join(data_root, ''.join(str(t0.date).split('-')))
if not os.path.exists(out_dir): os.makedirs(out_dir)
# 3. start download
mdl = MassDownloader(providers=providers)
mdl.download(domain, restrict,
threads_per_client=num_workers, mseed_storage=out_dir,
stationxml_storage=sta_dir)

0 comments on commit 591c41e

Please sign in to comment.