[edit] fixing bugs (in progress)
This commit is contained in:
parent
618dd10c23
commit
36b0aea86c
13
QtPyLoT.py
13
QtPyLoT.py
@ -203,7 +203,7 @@ class MainWindow(QMainWindow):
|
|||||||
"Load location information on "
|
"Load location information on "
|
||||||
"the actual event.")
|
"the actual event.")
|
||||||
loadpilotevent = self.createAction(self, "Load PILOT &event ...",
|
loadpilotevent = self.createAction(self, "Load PILOT &event ...",
|
||||||
self.load_pilot, "Ctrl+E",
|
self.load_pilotevent, "Ctrl+E",
|
||||||
loadpiloticon,
|
loadpiloticon,
|
||||||
"Load PILOT event from information "
|
"Load PILOT event from information "
|
||||||
"Matlab binary collections.")
|
"Matlab binary collections.")
|
||||||
@ -397,17 +397,22 @@ class MainWindow(QMainWindow):
|
|||||||
filt = "PILOT location files (*.mat)"
|
filt = "PILOT location files (*.mat)"
|
||||||
caption = "Select PILOT loaction file"
|
caption = "Select PILOT loaction file"
|
||||||
fn_loc = QFileDialog().getOpenFileName(self, caption=caption,
|
fn_loc = QFileDialog().getOpenFileName(self, caption=caption,
|
||||||
filter=filt)
|
filter=filt, dir=self.getRoot())
|
||||||
|
fn_loc = fn_loc[0]
|
||||||
|
loc_dir = os.path.split(fn_loc)[0]
|
||||||
filt = "PILOT phases files (*.mat)"
|
filt = "PILOT phases files (*.mat)"
|
||||||
caption = "Select PILOT phases file"
|
caption = "Select PILOT phases file"
|
||||||
fn_phases = QFileDialog().getOpenFileName(self, caption=caption,
|
fn_phases = QFileDialog().getOpenFileName(self, caption=caption,
|
||||||
filter=filt)
|
filter=filt, dir=loc_dir)
|
||||||
|
fn_phases = fn_phases[0]
|
||||||
type = QInputDialog().getItem(self, self.tr("Select phases type"),
|
type = QInputDialog().getItem(self, self.tr("Select phases type"),
|
||||||
self.tr("Type:"), [self.tr("manual"),
|
self.tr("Type:"), [self.tr("manual"),
|
||||||
self.tr("automatic")])
|
self.tr("automatic")])
|
||||||
|
|
||||||
if type.startswith('auto'):
|
if type[0].startswith('auto'):
|
||||||
type = 'auto'
|
type = 'auto'
|
||||||
|
else:
|
||||||
|
type = type[0]
|
||||||
|
|
||||||
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
|
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
|
||||||
self.load_data(fname_dict, type=type)
|
self.load_data(fname_dict, type=type)
|
||||||
|
@ -68,8 +68,8 @@ def create_creation_info(agency_id=None, creation_time=None, author=None):
|
|||||||
creation_time=creation_time)
|
creation_time=creation_time)
|
||||||
|
|
||||||
|
|
||||||
def create_event(origintime, cinfo, originloc=None, etype=None, resID=None,
|
def create_event(origintime, cinfo, originloc=None, etype='earthquake',
|
||||||
authority_id=None):
|
resID=None, authority_id=None):
|
||||||
'''
|
'''
|
||||||
create_event - funtion to create an ObsPy Event
|
create_event - funtion to create an ObsPy Event
|
||||||
|
|
||||||
@ -90,14 +90,12 @@ def create_event(origintime, cinfo, originloc=None, etype=None, resID=None,
|
|||||||
:type authority_id: str
|
:type authority_id: str
|
||||||
:return: An ObsPy :class: `~obspy.core.event.Event` object
|
:return: An ObsPy :class: `~obspy.core.event.Event` object
|
||||||
'''
|
'''
|
||||||
etype = ope.EventType(etype)
|
|
||||||
if originloc is not None:
|
if originloc is not None:
|
||||||
o = create_origin(origintime, cinfo,
|
o = create_origin(origintime, cinfo,
|
||||||
originloc[0], originloc[1], originloc[2])
|
originloc[0], originloc[1], originloc[2])
|
||||||
else:
|
else:
|
||||||
o = None
|
o = None
|
||||||
if etype is None:
|
|
||||||
etype = ope.EventType('earthquake') # defaults to 'earthquake'
|
|
||||||
if not resID:
|
if not resID:
|
||||||
resID = create_resourceID(origintime, etype, authority_id)
|
resID = create_resourceID(origintime, etype, authority_id)
|
||||||
elif isinstance(resID, str):
|
elif isinstance(resID, str):
|
||||||
@ -216,7 +214,7 @@ def create_resourceID(timetohash, restype, authority_id=None, hrstr=None):
|
|||||||
if hrstr is None:
|
if hrstr is None:
|
||||||
resID = ope.ResourceIdentifier(restype + '/' + hid[0:6])
|
resID = ope.ResourceIdentifier(restype + '/' + hid[0:6])
|
||||||
else:
|
else:
|
||||||
resID = ope.ResourceIdentifier(restype + '/' + hrstr + '_' + hid[0:6])
|
resID = ope.ResourceIdentifier(restype + '/' + hrstr)
|
||||||
if authority_id is not None:
|
if authority_id is not None:
|
||||||
resID.convertIDToQuakeMLURI(authority_id=authority_id)
|
resID.convertIDToQuakeMLURI(authority_id=authority_id)
|
||||||
return resID
|
return resID
|
@ -54,86 +54,86 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id='RUB', **kwargs):
|
|||||||
author=locauthor,
|
author=locauthor,
|
||||||
creation_time=locctime)
|
creation_time=locctime)
|
||||||
np = 0
|
np = 0
|
||||||
try:
|
#try:
|
||||||
eventNum = loc['ID'][0]
|
eventNum = str(loc['ID'][0])
|
||||||
|
|
||||||
# retrieve eventID for the actual database
|
# retrieve eventID for the actual database
|
||||||
idsplit = eventNum.split('.')
|
idsplit = eventNum.split('.')
|
||||||
|
|
||||||
# retrieve date information
|
# retrieve date information
|
||||||
julday = int(idsplit[1])
|
julday = int(idsplit[1])
|
||||||
year = int(idsplit[2])
|
year = int(idsplit[2])
|
||||||
hour = int(loc['hh'])
|
hour = int(loc['hh'])
|
||||||
minute = int(loc['mm'])
|
minute = int(loc['mm'])
|
||||||
second = int(loc['ss'])
|
second = int(loc['ss'])
|
||||||
|
|
||||||
year = four_digits(year)
|
year = four_digits(year)
|
||||||
|
|
||||||
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
|
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
|
||||||
minute=minute, second=second)
|
minute=minute, second=second)
|
||||||
|
|
||||||
stations = [stat for stat in phases['stat'][0:-1:3]]
|
stations = [stat for stat in phases['stat'][0:-1:3]]
|
||||||
|
|
||||||
event = create_event(eventDate, loccinfo, etype='earthquake',
|
lat = float(loc['LAT'])
|
||||||
resID=eventNum, authority_id=authority_id)
|
lon = float(loc['LON'])
|
||||||
|
dep = float(loc['DEP'])
|
||||||
|
|
||||||
lat = float(loc['LAT'])
|
event = create_event(eventDate, loccinfo, originloc=(lat, lon, dep),
|
||||||
lon = float(loc['LON'])
|
etype='earthquake', resID=eventNum,
|
||||||
dep = float(loc['DEP'])
|
authority_id=authority_id)
|
||||||
|
|
||||||
origin = create_origin(eventDate, loccinfo, lat, lon, dep)
|
for n, pick in enumerate(phases['Ptime']):
|
||||||
for n, pick in enumerate(phases['Ptime']):
|
if pick[0] > 0:
|
||||||
if pick[0] > 0:
|
kwargs = {'year': int(pick[0]),
|
||||||
kwargs = {'year': int(pick[0]),
|
'month': int(pick[1]),
|
||||||
'month': int(pick[1]),
|
'day': int(pick[2]),
|
||||||
'day': int(pick[2]),
|
'hour': int(pick[3]),
|
||||||
'hour': int(pick[3]),
|
'minute': int(pick[4]),
|
||||||
'minute': int(pick[4]),
|
'second': int(str(pick[5]).split('.')[0]),
|
||||||
'second': int(str(pick[5]).split('.')[0]),
|
'microsecond': int(str(pick[5]).split('.')[1][0:6])}
|
||||||
'microsecond': int(str(pick[5]).split('.')[1][0:6])}
|
spick = phases['Stime'][n]
|
||||||
spick = phases['Stime'][n]
|
if spick[0] > 0:
|
||||||
if spick[0] > 0:
|
skwargs = {'year': int(spick[0]),
|
||||||
skwargs = {'year': int(spick[0]),
|
'month': int(spick[1]),
|
||||||
'month': int(spick[1]),
|
'day': int(spick[2]),
|
||||||
'day': int(spick[2]),
|
'hour': int(spick[3]),
|
||||||
'hour': int(spick[3]),
|
'minute': int(spick[4]),
|
||||||
'minute': int(spick[4]),
|
'second': int(str(spick[5]).split('.')[0]),
|
||||||
'second': int(str(spick[5]).split('.')[0]),
|
'microsecond': int(str(spick[5]).split('.')[1][0:6])}
|
||||||
'microsecond': int(str(spick[5]).split('.')[1][0:6])}
|
spicktime = UTCDateTime(**skwargs)
|
||||||
spicktime = UTCDateTime(**skwargs)
|
else:
|
||||||
else:
|
spicktime = None
|
||||||
spicktime = None
|
ppicktime = UTCDateTime(**kwargs)
|
||||||
ppicktime = UTCDateTime(**kwargs)
|
|
||||||
|
|
||||||
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
|
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
|
||||||
if picktime is not None:
|
if picktime is not None:
|
||||||
if phase == 'P':
|
if phase == 'P':
|
||||||
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
||||||
stations[n].strip(), 'z'))
|
stations[n].strip(), 'z'))
|
||||||
else:
|
else:
|
||||||
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
||||||
stations[n].strip(), '[ne]'))
|
stations[n].strip(), '[ne]'))
|
||||||
print(wffn)
|
print(wffn)
|
||||||
pick = create_pick(eventDate, np, picktime, eventNum, pickcinfo,
|
pick = create_pick(eventDate, np, picktime, eventNum, pickcinfo,
|
||||||
phase, stations[n], wffn, authority_id)
|
phase, stations[n], wffn, authority_id)
|
||||||
event.picks.append(pick)
|
event.picks.append(pick)
|
||||||
pickID = pick.get('id')
|
pickID = pick.get('id')
|
||||||
arrival = create_arrival(pickID, pickcinfo, phase)
|
arrival = create_arrival(pickID, pickcinfo, phase)
|
||||||
origin.arrivals.append(arrival)
|
if event.origins:
|
||||||
event.picks.append(pick)
|
event.origins[0].arrivals.append(arrival)
|
||||||
np += 1
|
event.picks.append(pick)
|
||||||
|
|
||||||
|
if event.origins:
|
||||||
|
origin = event.origins[0]
|
||||||
magnitude = create_magnitude(origin.get('id'), loccinfo)
|
magnitude = create_magnitude(origin.get('id'), loccinfo)
|
||||||
magnitude.mag = float(loc['Mnet'])
|
magnitude.mag = float(loc['Mnet'])
|
||||||
magnitude.magnitude_type = 'Ml'
|
magnitude.magnitude_type = 'Ml'
|
||||||
|
|
||||||
event.origins.append(origin)
|
|
||||||
event.magnitudes.append(magnitude)
|
event.magnitudes.append(magnitude)
|
||||||
return event
|
return event
|
||||||
|
|
||||||
except AttributeError as e:
|
#except AttributeError as e:
|
||||||
raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
|
# raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
|
||||||
insufficient data!'.format(e, phasfn, locfn))
|
# insufficient data!'.format(e, phasfn, locfn))
|
||||||
|
|
||||||
|
|
||||||
def picks_from_pilot(fn):
|
def picks_from_pilot(fn):
|
||||||
|
Loading…
Reference in New Issue
Block a user