Commit 45662c3a authored by Mijian Xu's avatar Mijian Xu 😷
Browse files

Using IRIS fetch

parent a67a0a2f
......@@ -20,3 +20,6 @@ doc/.texpadtmp/bqmail.synctex.gz
doc/.texpadtmp/bqmail.toc
bin/bqmail_conti
*/__pycache__/
.idea/
......@@ -2,10 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fff014b2-7657-4967-99c2-c292348d91dd" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/EventCMT.dat" beforeDir="false" afterPath="$PROJECT_DIR$/EventCMT.dat" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bqmail.py" beforeDir="false" afterPath="$PROJECT_DIR$/bqmail.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/head.cfg" beforeDir="false" afterPath="$PROJECT_DIR$/head.cfg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/searchDMC.py" beforeDir="false" afterPath="$PROJECT_DIR$/searchDMC.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util.py" beforeDir="false" afterPath="$PROJECT_DIR$/util.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
......@@ -18,21 +17,24 @@
<session id="-1477451627">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.13" value="1" />
<entry key="project.opened" value="1" />
<entry key="project.open.time.3" value="1" />
<entry key="project.opened" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="cfg" value="1" />
<entry key="dat" value="2" />
<entry key="gitignore" value="1" />
<entry key="py" value="4" />
<entry key="txt" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="PLAIN_TEXT" value="4" />
<entry key="PLAIN_TEXT" value="5" />
<entry key="Python" value="4" />
</counts>
</usages-collector>
......@@ -40,24 +42,37 @@
<counts>
<entry key="Python Console" value="155" />
<entry key="cfg" value="65" />
<entry key="py" value="529" />
<entry key="gitignore" value="3" />
<entry key="py" value="721" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="PLAIN_TEXT" value="65" />
<entry key="Python" value="684" />
<entry key="PLAIN_TEXT" value="68" />
<entry key="Python" value="876" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/bqmail.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="631">
<caret line="223" column="39" selection-start-line="223" selection-start-column="39" selection-end-line="223" selection-end-column="39" />
<state relative-caret-position="608">
<caret line="179" column="76" selection-start-line="179" selection-start-column="76" selection-end-line="179" selection-end-column="76" />
<folding>
<element signature="e#195#210#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="360">
<caret line="24" column="6" selection-start-line="24" selection-start-column="6" selection-end-line="24" selection-end-column="6" />
</state>
</provider>
</entry>
......@@ -67,10 +82,10 @@
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/searchDMC.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1053">
<state relative-caret-position="708">
<caret line="142" column="37" selection-start-line="142" selection-start-column="37" selection-end-line="142" selection-end-column="37" />
<folding>
<marker date="1540004203686" expanded="true" signature="743:780" ph="..." />
......@@ -82,7 +97,7 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/EventCMT.dat">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="89">
<state relative-caret-position="630555">
<caret line="42037" column="34" selection-start-line="42037" selection-start-column="34" selection-end-line="42037" selection-end-column="34" />
</state>
</provider>
......@@ -91,10 +106,9 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/util.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="21" column="19" lean-forward="true" selection-start-line="21" selection-start-column="19" selection-end-line="21" selection-end-column="19" />
<state>
<folding>
<element signature="e#23#40#0" expanded="true" />
<element signature="e#23#37#0" expanded="true" />
</folding>
</state>
</provider>
......@@ -111,6 +125,11 @@
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>timerange</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
......@@ -118,14 +137,15 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/head.cfg" />
<option value="$PROJECT_DIR$/searchDMC.py" />
<option value="$PROJECT_DIR$/util.py" />
<option value="$PROJECT_DIR$/bqmail.py" />
<option value="$PROJECT_DIR$/searchDMC.py" />
<option value="$PROJECT_DIR$/.gitignore" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="57" />
<component name="ProjectFrameBounds">
<option name="x" value="68" />
<option name="y" value="23" />
<option name="width" value="2492" />
<option name="height" value="1417" />
......@@ -188,14 +208,11 @@
</component>
<component name="ToolWindowManager">
<frame x="68" y="23" width="2492" height="1417" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24969648" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24969648" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
<window_info anchor="bottom" id="Python Console" weight="0.32981133" />
<window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.32981133" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
......@@ -203,6 +220,10 @@
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" order="8" visible="true" weight="0.32981133" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="bottom" id="Python Console" order="10" weight="0.32981133" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
......@@ -212,56 +233,59 @@
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/rq.txt" />
<entry file="file://$PROJECT_DIR$/EventCMT.dat">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="89">
<state relative-caret-position="630555">
<caret line="42037" column="34" selection-start-line="42037" selection-start-column="34" selection-end-line="42037" selection-end-column="34" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/rq.txt">
<entry file="file://$PROJECT_DIR$/searchDMC.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-6786">
<caret selection-end-line="5949" />
<state relative-caret-position="708">
<caret line="142" column="37" selection-start-line="142" selection-start-column="37" selection-end-line="142" selection-end-column="37" />
<folding>
<marker date="1540004203686" expanded="true" signature="743:780" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/head.cfg">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
<caret line="10" column="8" selection-start-line="10" selection-end-line="10" selection-end-column="8" />
</state>
</provider>
<entry file="file://$PROJECT_DIR$/updateCatalog.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/util.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="21" column="19" lean-forward="true" selection-start-line="21" selection-start-column="19" selection-end-line="21" selection-end-column="19" />
<state>
<folding>
<element signature="e#23#40#0" expanded="true" />
<element signature="e#23#37#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bqmail.py">
<entry file="file://$PROJECT_DIR$/head.cfg">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="631">
<caret line="223" column="39" selection-start-line="223" selection-start-column="39" selection-end-line="223" selection-end-column="39" />
<state relative-caret-position="150">
<caret line="10" column="8" selection-start-line="10" selection-end-line="10" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/updateCatalog.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/searchDMC.py">
<entry file="file://$PROJECT_DIR$/bqmail.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1053">
<caret line="142" column="37" selection-start-line="142" selection-start-column="37" selection-end-line="142" selection-end-column="37" />
<state relative-caret-position="608">
<caret line="179" column="76" selection-start-line="179" selection-start-column="76" selection-end-line="179" selection-end-column="76" />
<folding>
<marker date="1540004203686" expanded="true" signature="743:780" ph="..." />
<element signature="e#195#210#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="360">
<caret line="24" column="6" selection-start-line="24" selection-start-column="6" selection-end-line="24" selection-end-column="6" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
......@@ -13,6 +13,18 @@
# 2017/09/11
#
import datetime
import os, re
import sys, getopt
import time
from obspy import taup, UTCDateTime
import distaz
from util import sendmail, generatemsg, wsfetch
import configparser
config = configparser.ConfigParser()
def Usage():
print('Usage:')
print('python bqmail.py -Nnetwork -Sstation -b -Bsec_begin/sec_end [-Cchannel] [-Plat/lon/phase] [-Llocation] [-cdatetimefile] [-Fformat] [-Mmagmin/magmax] head.cfg')
......@@ -35,20 +47,6 @@ def Usage():
print(' bqmail -NIC -SBJT -b2015-2-3T00:12:23 -e2015-4-3 -B-100/600 -L10 -Fminiseed head.cfg')
import datetime
import os, re
import sys, getopt
import time
from obspy import taup
import distaz
from util import sendmail,generatemsg
try:
import configparser
config = configparser.ConfigParser()
except:
import ConfigParser
config = ConfigParser.ConfigParser()
head = ''
argv = sys.argv[1:]
for o in argv:
......@@ -125,24 +123,8 @@ else:
sys.exit(1)
if isyrange:
if "T" in starttime:
strfmt = "%Y-%m-%dT%H:%M:%S"
else:
strfmt = "%Y-%m-%d"
try:
datemin = datetime.datetime.strptime(starttime,strfmt)
except:
print("Wrong format in -b option")
sys.exit(1)
if "T" in endtime:
strfm = "%Y-%m-%dT%H:%M:%S"
else:
strfmt = "%Y-%m-%d"
try:
datemax = datetime.datetime.strptime(endtime,strfmt)
except:
print("Wrong format in -e option")
sys.exit(1)
datemin = UTCDateTime(starttime)
datemax = UTCDateTime(endtime)
event=[]
config.read(head)
......@@ -170,6 +152,7 @@ if isyrange:
else:
LABEL = 'IRIS_'+network+"_"+station
if not isyrange:
EVENT = open(datetimefile, 'r')
for evenum in EVENT.readlines():
......@@ -182,37 +165,20 @@ else:
trange_sp = timerange.split('/')
btime = float(trange_sp[0])
etime = float(trange_sp[1])
EVENT = open(eventlst,'r')
for evenum in EVENT:
evenum = evenum.strip()
(year, mon, day, jjj, hour, min, sec, lat, lon, dep, mw) = evenum.split()
year = int(year)
mon = int(mon)
day = int(day)
jjj = int(jjj)
hour = int(hour)
min = int(min)
sec = int(sec)
lat = float(lat)
lon = float(lon)
dep = float(dep)
mw = float(mw)
if mw < magmin or mw > magmax:
continue
evt_time = datetime.datetime(year,mon,day,hour,min,sec)
if datemin <= evt_time <= datemax:
if isph == 1:
dis = distaz.distaz(stla, stlo, lat, lon).delta
arr = mod.get_travel_times(source_depth_in_km=dep, distance_in_degree=dis, phase_list=[phase])
if len(arr) != 0:
arr_time = evt_time + datetime.timedelta(seconds=arr[0].time)
date = arr_time + datetime.timedelta(seconds=btime)
dateend = arr_time + datetime.timedelta(seconds=etime)
else:
date = evt_time + datetime.timedelta(seconds=btime)
dateend = evt_time + datetime.timedelta(seconds=etime)
cat = wsfetch('IRIS', starttime=datemin, endtime=datemax, minmagnitude=magmin, maxmagnitude=magmax)
for evt in cat:
if isph:
dis = distaz.distaz(stla, stlo, evt[1], evt[2]).delta
arr = mod.get_travel_times(source_depth_in_km=evt[3], distance_in_degree=dis, phase_list=[phase])
if len(arr) != 0:
arr_time = evt[0] + arr[0].time
date = arr_time + btime
dateend = arr_time + etime
else:
date = evt[0] + btime
dateend = evt[0] + etime
event.append([date.strftime('%Y %m %d %H %M %S'), dateend.strftime('%Y %m %d %H %M %S')])
if event == []:
if not event:
print('No events found in the range')
msg = generatemsg(NAME, INST, EMAIL, MEDIA, ALTERNATEMEDIA, LABEL)
......
#!/usr/bin/env python
import subprocess
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from obspy.clients.fdsn import Client
def wsfetch(server, starttime=None, endtime=None, minlatitude=None,
maxlatitude=None, minlongitude=None, maxlongitude=None,
latitude=None, longitude=None, minradius=None,
maxradius=None, mindepth=None, maxdepth=None,
minmagnitude=None, maxmagnitude=None, magnitudetype=None,
includeallorigins=None, includeallmagnitudes=None,
includearrivals=None, eventid=None, limit=None, offset=None,
orderby='time-asc', catalog=None, contributor=None):
if not isinstance(server, str):
raise TypeError('server name should be \'str\' type')
locs = locals()
locs.pop('server')
client = Client(server)
cat = client.get_events(**locs)
data = [[evt.origins[0].time, evt.origins[0].latitude, evt.origins[0].longitude, evt.origins[0].depth * 0.001,
evt.magnitudes[0].mag, evt.magnitudes[0].magnitude_type] for evt in cat]
return data
def generatemsg(NAME, INST, EMAIL, MEDIA, ALTERNATEMEDIA, LABEL):
......@@ -41,3 +56,6 @@ def sendmail(sender, recipient, contents, server='localhost', port=465, passwd='
smtpObj.sendmail(sender, recipient, msg.as_string())
except smtplib.SMTPException:
print("Error in linking {}".format(server))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment