Request continuous waveform data from CSV catalog
This example shows how to request waveform data based on a catalog in CSV format.
Below is an example catalog file in CSV format. The catalog is obtained from IRIS web service.
#EventID | Time | Latitude | Longitude | Depth/km | Author | Catalog | Contributor | ContributorID | MagType | Magnitude | MagAuthor | EventLocationName
9993759|2017-01-22T04:30:22|-6.2145|155.1442|135.0|pt,us,at|NEIC PDE|us|us10007uph,pt17022050,at00ok5z6p|mww|7.9|us|SOLOMON ISLANDS
9993037|2017-01-19T23:04:21|-10.3433|161.318|36.0|pt,us,at|NEIC PDE|us|us10007u7n,at00ok1ura,pt17019050|mww|6.5|us|SOLOMON ISLANDS
9953968|2017-01-10T06:13:47|4.4634|122.575|612.71|at,us|NEIC PDE|us|us10007s9c,at00ojjvz0|Mww|7.3|us|CELEBES SEA
9951821|2017-01-03T21:52:30|-19.3542|176.058|12.0|at,us,pt|NEIC PDE|us|us10007pj6,at00oj84rf,pt17003051|Mww|6.9|us|SOUTH OF FIJI ISLANDS
Python script:
import csv
import os
from datetime import datetime, timedelta
from HinetPy import Client, win32
client = Client("username", "password")
with open("events.csv") as csvfile:
reader = csv.DictReader(csvfile, delimiter="|")
reader.fieldnames = [field.strip() for field in reader.fieldnames]
for row in reader: # loop over events
origin = datetime.strptime(row["Time"], "%Y-%m-%dT%H:%M:%S")
starttime = origin + timedelta(hours=9) # deal with TimeZone issue
outdir = origin.strftime("%Y%m%d%H%M")
# skip if outdir already exists to avoid overwrite
if os.path.exists(outdir):
continue
data, ctable = client.get_continuous_waveform(
"0101", starttime, 20, outdir=outdir
)
win32.extract_sac(data, ctable, outdir=outdir, with_sacpz=True)