def getEvent(self, eventid): """Get a ScalarEvent object from the ASDF file. Args: eventid (str): ID of event to search for in ASDF file. Returns: ScalarEvent: Flattened version of Obspy Event object. """ eventobj = None for event in self.dataset.events: if event.resource_id.id.find(eventid) > -1: eventobj = event break if eventobj is None: fmt = 'Event with a resource id containing %s could not be found.' raise KeyError(fmt % eventid) eventobj2 = ScalarEvent.fromEvent(eventobj) return eventobj2
def test_scalar(): eid = 'usp000hat0' time = UTCDateTime('2010-04-06 22:15:01.580') lat = 2.383 lon = 97.048 depth = 31.0 mag = 7.8 event = ScalarEvent() origin = Origin(resource_id=eid, time=time, latitude=lat, longitude=lon, depth=depth * 1000) magnitude = Magnitude(mag=mag) event.origins = [origin] event.magnitudes = [magnitude] assert event.id == eid assert event.time == time assert event.latitude == lat assert event.longitude == lon assert event.depth_km == depth assert event.magnitude == mag subdir = os.path.join('data', 'testdata', 'usp000hat0_quakeml.xml') quakeml = pkg_resources.resource_filename('gmprocess', subdir) catalog = read_events(quakeml) tevent = catalog.events[0] event = ScalarEvent.fromEvent(tevent) assert event.id == 'quakeml:us.anss.org/origin/pde20100406221501580_31' assert event.time == time assert event.latitude == lat assert event.longitude == lon assert event.depth_km == depth assert event.magnitude == mag event = ScalarEvent() event.fromParams(eid, time, lat, lon, depth, mag) assert isinstance(event, Event) assert event.origins[0].resource_id == eid assert event.origins[0].time == time assert event.origins[0].latitude == lat assert event.origins[0].longitude == lon assert event.origins[0].depth == depth * 1000 assert event.magnitudes[0].mag == mag tevent = Event() origin = Origin(resource_id=eid, time=time, longitude=lon, latitude=lat, depth=depth * 1000) magnitude = Magnitude(resource_id=eid, mag=mag) tevent.origins = [origin] tevent.magnitudes = [magnitude] event2 = ScalarEvent.fromEvent(tevent) assert isinstance(event2, Event) assert event2.origins[0].resource_id == eid assert event2.origins[0].time == time assert event2.origins[0].latitude == lat assert event2.origins[0].longitude == lon assert event2.origins[0].depth == depth * 1000 assert event2.magnitudes[0].mag == mag