根据CSV地震目录申请连续波形数据

这个例子展示了如何根据CSV格式的地震目录申请波形数据。

下面的CSV格式的示例地震目录来自于 IRIS web service

  1. #EventID | Time | Latitude | Longitude | Depth/km | Author | Catalog | Contributor | ContributorID | MagType | Magnitude | MagAuthor | EventLocationName
  2. 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
  3. 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
  4. 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
  5. 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脚本

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import os
  5. import csv
  6. from datetime import datetime, timedelta
  7.  
  8. from HinetPy import Client, win32
  9.  
  10. client = Client("username", "password")
  11. with open("events.csv") as csvfile:
  12. reader = csv.DictReader(csvfile, delimiter="|")
  13. reader.fieldnames = [field.strip() for field in reader.fieldnames]
  14. for row in reader: # loop over events
  15. origin = datetime.strptime(row['Time'], "%Y-%m-%dT%H:%M:%S")
  16. starttime = origin + timedelta(hours=9) # deal with TimeZone issue
  17. outdir = origin.strftime("%Y%m%d%H%M")
  18.  
  19. # skip if outdir already exists to avoid overwrite
  20. if os.path.exists(outdir):
  21. continue
  22.  
  23. data, ctable = client.get_continuous_waveform('0101', starttime, 20, outdir=outdir)
  24. win32.extract_sac(data, ctable, outdir=outdir, with_pz=True)