changed usage signature of some function from module utils and the corresponding calls

This commit is contained in:
Sebastian Wehling-Benatelli 2015-06-11 10:12:50 +02:00
parent 546e919dc9
commit c5da8fd994
3 changed files with 29 additions and 16 deletions

View File

@ -509,8 +509,8 @@ class MainWindow(QMainWindow):
if new.exec_() != QDialog.Rejected: if new.exec_() != QDialog.Rejected:
evtpar = new.getValues() evtpar = new.getValues()
cinfo = createCreationInfo(agency_id=self.agency) cinfo = createCreationInfo(agency_id=self.agency)
event = createEvent(evtpar['origintime']) event = createEvent(evtpar['origintime'], cinfo)
self.data = Data(self, evtdata=createEvent(**evtpar)) self.data = Data(self, evtdata=event)
self.dirty = True self.dirty = True
def closeEvent(self, event): def closeEvent(self, event):

View File

@ -74,14 +74,14 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
stations = [stat for stat in phases['stat'][0:-1:3]] stations = [stat for stat in phases['stat'][0:-1:3]]
event = createEvent(eventDate, loccinfo, 'earthquake', eventNum, event = createEvent(eventDate, loccinfo, None, 'earthquake', eventNum,
authority_id) authority_id)
lat = float(loc['LAT']) lat = float(loc['LAT'])
lon = float(loc['LON']) lon = float(loc['LON'])
dep = float(loc['DEP']) dep = float(loc['DEP'])
origin = createOrigin(eventDate, loccinfo, lat, lon, dep, eventNum) origin = createOrigin(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]),

View File

@ -107,8 +107,7 @@ def createResourceID(timetohash, restype, authority_id=None, hrstr=None):
return resID return resID
def createOrigin(origintime, cinfo, latitude, longitude, depth, resID=None, def createOrigin(origintime, cinfo, latitude, longitude, depth):
authority_id=None):
''' '''
createOrigin - function to create an ObsPy Origin createOrigin - function to create an ObsPy Origin
:param origintime: the origins time of occurence :param origintime: the origins time of occurence
@ -121,15 +120,14 @@ def createOrigin(origintime, cinfo, latitude, longitude, depth, resID=None,
:type depth: float :type depth: float
:return: An ObsPy :class: `~obspy.core.event.Origin` object :return: An ObsPy :class: `~obspy.core.event.Origin` object
''' '''
if resID is None:
resID = createResourceID(origintime, 'orig', authority_id=authority_id) assert isinstance(origintime, UTCDateTime), "origintime has to be " \
elif isinstance(resID, str): "a UTCDateTime object, but " \
resID = createResourceID(origintime, 'orig', authority_id=authority_id, "actually is of type " \
hrstr=resID) "'%s'" % type(origintime)
origin = ope.Origin() origin = ope.Origin()
origin.resource_id = resID origin.time = origintime
origin.time = UTCDateTime(origintime)
origin.creation_info = cinfo origin.creation_info = cinfo
origin.latitude = latitude origin.latitude = latitude
origin.longitude = longitude origin.longitude = longitude
@ -137,33 +135,48 @@ def createOrigin(origintime, cinfo, latitude, longitude, depth, resID=None,
return origin return origin
def createEvent(origintime, cinfo, etype, resID=None, authority_id=None): def createEvent(origintime, cinfo, originloc=None, etype=None, resID=None,
authority_id=None):
''' '''
createEvent - funtion to create an ObsPy Event createEvent - funtion to create an ObsPy Event
:param origintime: the events origintime :param origintime: the events origintime
:type origintime: :class: `~obspy.core.utcdatetime.UTCDateTime` object :type origintime: :class: `~obspy.core.utcdatetime.UTCDateTime` object
:param cinfo: An ObsPy :class: `~obspy.core.event.CreationInfo` object :param cinfo: An ObsPy :class: `~obspy.core.event.CreationInfo` object
holding information on the creation of the returned object holding information on the creation of the returned object
:type cinfo: :class: `~obspy.core.event.CreationInfo` object :type cinfo: :class: `~obspy.core.event.CreationInfo` object
:param originloc: tuple containing the location of the origin
(LAT, LON, DEP) affiliated with the event which is created
:type originloc: tuple, list
:param etype: Event type str object. converted via ObsPy to a valid event :param etype: Event type str object. converted via ObsPy to a valid event
type string. type string.
:type etype: str :type etype: str
:param resID: Resource identifier of the created event :param resID: Resource identifier of the created event
:type resID: :class: `~obspy.core.event.ResourceIdentifier` object :type resID: :class: `~obspy.core.event.ResourceIdentifier` object, str
:param authority_id: name of the institution carrying out the processing :param authority_id: name of the institution carrying out the processing
: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) etype = ope.EventType(etype)
if originloc is not None:
o = createOrigin(origintime, cinfo,
originloc[0], originloc[1], originloc[2])
else:
o = None
if etype is None: if etype is None:
etype = ope.EventType('earthquake') # defaults to 'earthquake' etype = ope.EventType('earthquake') # defaults to 'earthquake'
if resID is None: if not resID:
resID = createResourceID(origintime, etype, authority_id) resID = createResourceID(origintime, etype, authority_id)
elif isinstance(resID, str): elif isinstance(resID, str):
resID = createResourceID(origintime, etype, authority_id, resID) resID = createResourceID(origintime, etype, authority_id, resID)
elif not isinstance(resID, ope.ResourceIdentifier):
raise TypeError("unsupported type(resID) for resource identifier "
"generation: %s" % type(resID))
event = ope.Event(resource_id=resID) event = ope.Event(resource_id=resID)
event.creation_info = cinfo event.creation_info = cinfo
event.event_type = etype event.event_type = etype
if o:
event.origins = [o]
return event return event