[edit] fixing bugs (in progress)

This commit is contained in:
Sebastian Wehling-Benatelli 2016-05-27 12:53:34 +02:00
parent 618dd10c23
commit 36b0aea86c
3 changed files with 78 additions and 75 deletions

View File

@ -203,7 +203,7 @@ class MainWindow(QMainWindow):
"Load location information on "
"the actual event.")
loadpilotevent = self.createAction(self, "Load PILOT &event ...",
self.load_pilot, "Ctrl+E",
self.load_pilotevent, "Ctrl+E",
loadpiloticon,
"Load PILOT event from information "
"Matlab binary collections.")
@ -397,17 +397,22 @@ class MainWindow(QMainWindow):
filt = "PILOT location files (*.mat)"
caption = "Select PILOT loaction file"
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)"
caption = "Select PILOT phases file"
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"),
self.tr("Type:"), [self.tr("manual"),
self.tr("automatic")])
if type.startswith('auto'):
if type[0].startswith('auto'):
type = 'auto'
else:
type = type[0]
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
self.load_data(fname_dict, type=type)

View File

@ -68,8 +68,8 @@ def create_creation_info(agency_id=None, creation_time=None, author=None):
creation_time=creation_time)
def create_event(origintime, cinfo, originloc=None, etype=None, resID=None,
authority_id=None):
def create_event(origintime, cinfo, originloc=None, etype='earthquake',
resID=None, authority_id=None):
'''
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
:return: An ObsPy :class: `~obspy.core.event.Event` object
'''
etype = ope.EventType(etype)
if originloc is not None:
o = create_origin(origintime, cinfo,
originloc[0], originloc[1], originloc[2])
else:
o = None
if etype is None:
etype = ope.EventType('earthquake') # defaults to 'earthquake'
if not resID:
resID = create_resourceID(origintime, etype, authority_id)
elif isinstance(resID, str):
@ -216,7 +214,7 @@ def create_resourceID(timetohash, restype, authority_id=None, hrstr=None):
if hrstr is None:
resID = ope.ResourceIdentifier(restype + '/' + hid[0:6])
else:
resID = ope.ResourceIdentifier(restype + '/' + hrstr + '_' + hid[0:6])
resID = ope.ResourceIdentifier(restype + '/' + hrstr)
if authority_id is not None:
resID.convertIDToQuakeMLURI(authority_id=authority_id)
return resID

View File

@ -54,86 +54,86 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id='RUB', **kwargs):
author=locauthor,
creation_time=locctime)
np = 0
try:
eventNum = loc['ID'][0]
#try:
eventNum = str(loc['ID'][0])
# retrieve eventID for the actual database
idsplit = eventNum.split('.')
# retrieve eventID for the actual database
idsplit = eventNum.split('.')
# retrieve date information
julday = int(idsplit[1])
year = int(idsplit[2])
hour = int(loc['hh'])
minute = int(loc['mm'])
second = int(loc['ss'])
# retrieve date information
julday = int(idsplit[1])
year = int(idsplit[2])
hour = int(loc['hh'])
minute = int(loc['mm'])
second = int(loc['ss'])
year = four_digits(year)
year = four_digits(year)
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
minute=minute, second=second)
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
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',
resID=eventNum, authority_id=authority_id)
lat = float(loc['LAT'])
lon = float(loc['LON'])
dep = float(loc['DEP'])
lat = float(loc['LAT'])
lon = float(loc['LON'])
dep = float(loc['DEP'])
event = create_event(eventDate, loccinfo, originloc=(lat, lon, dep),
etype='earthquake', resID=eventNum,
authority_id=authority_id)
origin = create_origin(eventDate, loccinfo, lat, lon, dep)
for n, pick in enumerate(phases['Ptime']):
if pick[0] > 0:
kwargs = {'year': int(pick[0]),
'month': int(pick[1]),
'day': int(pick[2]),
'hour': int(pick[3]),
'minute': int(pick[4]),
'second': int(str(pick[5]).split('.')[0]),
'microsecond': int(str(pick[5]).split('.')[1][0:6])}
spick = phases['Stime'][n]
if spick[0] > 0:
skwargs = {'year': int(spick[0]),
'month': int(spick[1]),
'day': int(spick[2]),
'hour': int(spick[3]),
'minute': int(spick[4]),
'second': int(str(spick[5]).split('.')[0]),
'microsecond': int(str(spick[5]).split('.')[1][0:6])}
spicktime = UTCDateTime(**skwargs)
else:
spicktime = None
ppicktime = UTCDateTime(**kwargs)
for n, pick in enumerate(phases['Ptime']):
if pick[0] > 0:
kwargs = {'year': int(pick[0]),
'month': int(pick[1]),
'day': int(pick[2]),
'hour': int(pick[3]),
'minute': int(pick[4]),
'second': int(str(pick[5]).split('.')[0]),
'microsecond': int(str(pick[5]).split('.')[1][0:6])}
spick = phases['Stime'][n]
if spick[0] > 0:
skwargs = {'year': int(spick[0]),
'month': int(spick[1]),
'day': int(spick[2]),
'hour': int(spick[3]),
'minute': int(spick[4]),
'second': int(str(spick[5]).split('.')[0]),
'microsecond': int(str(spick[5]).split('.')[1][0:6])}
spicktime = UTCDateTime(**skwargs)
else:
spicktime = None
ppicktime = UTCDateTime(**kwargs)
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
if picktime is not None:
if phase == 'P':
wffn = os.path.join(sdir, '{0}*{1}*'.format(
stations[n].strip(), 'z'))
else:
wffn = os.path.join(sdir, '{0}*{1}*'.format(
stations[n].strip(), '[ne]'))
print(wffn)
pick = create_pick(eventDate, np, picktime, eventNum, pickcinfo,
phase, stations[n], wffn, authority_id)
event.picks.append(pick)
pickID = pick.get('id')
arrival = create_arrival(pickID, pickcinfo, phase)
origin.arrivals.append(arrival)
event.picks.append(pick)
np += 1
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
if picktime is not None:
if phase == 'P':
wffn = os.path.join(sdir, '{0}*{1}*'.format(
stations[n].strip(), 'z'))
else:
wffn = os.path.join(sdir, '{0}*{1}*'.format(
stations[n].strip(), '[ne]'))
print(wffn)
pick = create_pick(eventDate, np, picktime, eventNum, pickcinfo,
phase, stations[n], wffn, authority_id)
event.picks.append(pick)
pickID = pick.get('id')
arrival = create_arrival(pickID, pickcinfo, phase)
if event.origins:
event.origins[0].arrivals.append(arrival)
event.picks.append(pick)
if event.origins:
origin = event.origins[0]
magnitude = create_magnitude(origin.get('id'), loccinfo)
magnitude.mag = float(loc['Mnet'])
magnitude.magnitude_type = 'Ml'
event.origins.append(origin)
event.magnitudes.append(magnitude)
return event
return event
except AttributeError as e:
raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
insufficient data!'.format(e, phasfn, locfn))
#except AttributeError as e:
# raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
# insufficient data!'.format(e, phasfn, locfn))
def picks_from_pilot(fn):