Exemplo n.º 1
0
 def _get_origin_classes(self, orig_group, mag_list):
     """
     Gets the Origin class representation for a particular event
     :param orig_group:
         Pandas Group object
     :param list:
         List of :class: Magnitude objects
     """
     origin_list = []
     norig = orig_group.shape[0]
     for iloc in range(0, norig):
         # Get location
         location = Location(orig_group.originID.values[iloc],
                             orig_group.longitude.values[iloc],
                             orig_group.latitude.values[iloc],
                             orig_group.depth.values[iloc],
                             orig_group.semimajor90.values[iloc],
                             orig_group.semiminor90.values[iloc],
                             orig_group.error_strike.values[iloc],
                             orig_group.depth_error.values[iloc])
         # origin
         orig_date = date(orig_group.year.values[iloc],
                          orig_group.month.values[iloc],
                          orig_group.day.values[iloc])
         micro_seconds = (orig_group.second.values[iloc] -
                          np.floor(orig_group.second.values[iloc])) * 1.0E6
         seconds = int(orig_group.second.values[iloc])
         if seconds > 59:
             seconds = 0
             minute_inc = 1
         else:
             minute_inc = 0
         orig_time = time(orig_group.hour.values[iloc],
                          orig_group.minute.values[iloc] + minute_inc,
                          seconds, int(micro_seconds))
         origin = Origin(orig_group.originID.values[iloc],
                         orig_date,
                         orig_time,
                         location,
                         orig_group.Agency.values[iloc],
                         is_prime=bool(orig_group.prime.values[iloc]),
                         time_error=orig_group.time_error.values[iloc])
         for mag in mag_list:
             if mag.origin_id == origin.id:
                 origin.magnitudes.append(mag)
         origin_list.append(origin)
     return origin_list
Exemplo n.º 2
0
def get_event_origin_row(row, selected_agencies=[]):
    '''
    Parses the Origin row from ISF format to an instance of an
    isf_catalogue.Origin class. If the author is not one of the selected
    agencies then None is returns
    '''
    origin_id = _to_str(row[128:])
    author = _to_str(row[118:127])
    if len(selected_agencies) and not author in selected_agencies:
        # Origin not an instance of (or authored by) a selected agency
        return None
    # Get date yyyy/mm/dd
    ymd = map(int, row[:10].split('/'))
    #print "YMD",ymd
    date = datetime.date(ymd[0], ymd[1], ymd[2])
    # Get time
    time, time_error, time_rms = get_time_from_str(row)
    # Get longitude and latitude
    latitude = float(row[36:44])
    longitude = float(row[45:54])
    # Get error ellipse
    semimajor90 = _to_float(row[55:60])
    semiminor90 = _to_float(row[61:66])
    error_strike = _to_float(row[67:70])
    # Get depths
    #depth = _to_float(row[71:75])
    depth = _to_float(row[71:75])
    depthSolution = _to_str(row[76:78])
    #if depthSolution == "f":
    #    print "depth= ", depth, "DepthSolution =", depthSolution
    depth_error = _to_float(row[78:82])
    # Create location class
    location = Location(origin_id, longitude, latitude, depth, depthSolution,
                        semimajor90, semiminor90, error_strike, depth_error)
    # Get the metadata
    metadata = get_origin_metadata(row)
    return Origin(origin_id,
                  date,
                  time,
                  location,
                  author,
                  time_error=time_error,
                  time_rms=time_rms,
                  metadata=metadata)
 def parse(self):
     '''
     Returns the catalogue as an instance of an ISFCatalogue
     An ISF catalogue will have two origins: The hypocentre solution and
     the centroid
     '''
     isf_cat = ISFCatalogue('GCMT', 'GCMT')
     n_cmts = self.catalogue.number_events()
     base_id = 'GCMT_'
     counter = 1
     for gcmt in self.catalogue.gcmts:
         # Get IDs
         event_id = base_id + ("%06d" % counter)
         counter += 1
         origin_id = gcmt.identifier.strip(' ')
         # Two origins - 1 hypocentre (mb, Ms, Mw), 2 - centroid (Mw)
         origin_mags = []
         if gcmt.hypocentre.m_b:
             origin_mags.append(Magnitude(event_id,
                                          origin_id, 
                                          gcmt.hypocentre.m_b,
                                          gcmt.hypocentre.source, 
                                          scale='mb'))
         if gcmt.hypocentre.m_s:
             origin_mags.append(Magnitude(event_id,
                                          origin_id, 
                                          gcmt.hypocentre.m_s,
                                          gcmt.hypocentre.source, 
                                          scale='Ms'))
         m_w = Magnitude(event_id,
                         gcmt.centroid.centroid_id, gcmt.magnitude, 'GCMT', 
                         scale='Mw')
         origin_mags.append(m_w)
         # Get locations
         hypo_loc = Location(origin_id, 
                             gcmt.hypocentre.longitude,
                             gcmt.hypocentre.latitude, 
                             gcmt.hypocentre.depth)
         centroid_loc = Location(origin_id + "-C",
                                 gcmt.centroid.longitude,
                                 gcmt.centroid.latitude,
                                 gcmt.centroid.depth,
                                 depth_error=gcmt.centroid.depth_error)
         # Get origins
         hypo = Origin(origin_id, 
                       gcmt.hypocentre.date, 
                       gcmt.hypocentre.time, 
                       hypo_loc, 
                       gcmt.hypocentre.source,
                       is_prime=True)
         hypo.magnitudes = origin_mags
         # Get centroids
         centroid = Origin(origin_id + "-C",
                           gcmt.centroid.date,
                           gcmt.centroid.time,
                           centroid_loc,
                           'GCMT',
                           is_centroid=True,
                           time_error=gcmt.centroid.time_error)
         centroid.magnitudes = [m_w]
         event = Event(event_id, [hypo, centroid], origin_mags,
                       gcmt.hypocentre.location)
         setattr(event, 'tensor', gcmt.moment_tensor)
         isf_cat.events.append(event)
     return isf_cat
Exemplo n.º 4
0
 def parse(self):
     '''
     Returns the catalogue as an instance of an ISFCatalogue
     An ISF catalogue will have two origins: The hypocentre solution and
     the centroid
     '''
     isf_cat = ISFCatalogue('GCMT', 'GCMT')
     n_cmts = self.catalogue.number_events()
     base_id = 'GCMT_'
     counter = 1
     for gcmt in self.catalogue.gcmts:
         # Get IDs
         event_id = base_id + ("%06d" % counter)
         counter += 1
         origin_id = gcmt.identifier.strip(' ')
         # Two origins - 1 hypocentre (mb, Ms, Mw), 2 - centroid (Mw)
         origin_mags = []
         if gcmt.hypocentre.m_b:
             origin_mags.append(Magnitude(event_id,
                                          origin_id, 
                                          gcmt.hypocentre.m_b,
                                          gcmt.hypocentre.source, 
                                          scale='mb'))
         if gcmt.hypocentre.m_s:
             origin_mags.append(Magnitude(event_id,
                                          origin_id, 
                                          gcmt.hypocentre.m_s,
                                          gcmt.hypocentre.source, 
                                          scale='Ms'))
         m_w = Magnitude(event_id,
                         gcmt.centroid.centroid_id, gcmt.magnitude, 'GCMT', 
                         scale='Mw')
         origin_mags.append(m_w)
         # Get locations
         hypo_loc = Location(origin_id, 
                             gcmt.hypocentre.longitude,
                             gcmt.hypocentre.latitude, 
                             gcmt.hypocentre.depth)
         centroid_loc = Location(gcmt.centroid.centroid_id,
                                 gcmt.centroid.longitude,
                                 gcmt.centroid.latitude,
                                 gcmt.centroid.depth,
                                 depth_error=gcmt.centroid.depth_error)
         # Get origins
         hypo = Origin(origin_id, 
                       gcmt.hypocentre.date, 
                       gcmt.hypocentre.time, 
                       hypo_loc, 
                       gcmt.hypocentre.source,
                       is_prime=True)
         hypo.magnitudes = origin_mags
         # Get centroids
         centroid = Origin(gcmt.centroid.centroid_id,
                           gcmt.centroid.date,
                           gcmt.centroid.time,
                           centroid_loc,
                           'GCMT',
                           is_centroid=True,
                           time_error=gcmt.centroid.time_error)
         centroid.magnitudes = [m_w]
         event = Event(event_id, [hypo, centroid], origin_mags,
                       gcmt.hypocentre.location)
         setattr(event, 'tensor', gcmt.moment_tensor)
         isf_cat.events.append(event)
     return isf_cat
    def write_to_isf_catalogue(self, catalogue_id, name):
        """
        Exports the catalogue to an instance of the :class:
        eqcat.isf_catalogue.ISFCatalogue
        """
        isf_cat = ISFCatalogue(catalogue_id, name)
        for iloc in range(0, self.get_number_events()):
            # Origin ID
            event_id = str(self.data['eventID'][iloc])
            origin_id = event_id
            # Create Magnitude
            mag = self.data["magnitude"][iloc]
            if not mag or np.isnan(mag):
                # No magnitude - not useful
                continue

            mag = [Magnitude(event_id,
                             origin_id, 
                             mag, 
                             catalogue_id, 
                             scale=self.data["magnitudeType"][iloc], 
                             sigma=self.data['sigmaMagnitude'][iloc])]

            # Create Location
            semimajor90 = self.data['SemiMajor90'][iloc]
            semiminor90 = self.data['SemiMinor90'][iloc]
            error_strike = self.data['ErrorStrike'][iloc]
            if np.isnan(semimajor90):
                semimajor90 = None
            if np.isnan(semiminor90):
                semiminor90 = None
            if np.isnan(error_strike):
                error_strike = None
            depth_error = self.data['depthError'][iloc]
            if np.isnan(depth_error):
                depth_error = None
            locn = Location(origin_id,
                            self.data['longitude'][iloc],
                            self.data['latitude'][iloc],
                            self.data['depth'][iloc],
                            semimajor90,
                            semiminor90,
                            error_strike,
                            depth_error)

            # Create Origin
            # Date
            eq_date = datetime.date(self.data['year'][iloc],
                                    self.data['month'][iloc],
                                    self.data['day'][iloc])
            # Time
            secs = self.data['second'][iloc]
            
            microsecs = int((secs - floor(secs)) * 1E6)
            eq_time = datetime.time(self.data['hour'][iloc],
                                    self.data['minute'][iloc],
                                    int(secs),
                                    microsecs)
            origin = Origin(origin_id, eq_date, eq_time, locn, catalogue_id, 
                            is_prime=True)
            origin.magnitudes = mag
            event = Event(event_id, [origin], origin.magnitudes)
            isf_cat.events.append(event)
        return isf_cat
    def write_to_isf_catalogue(self, catalogue_id, name):
        """
        Exports the catalogue to an instance of the :class:
        eqcat.isf_catalogue.ISFCatalogue
        """
        isf_cat = ISFCatalogue(catalogue_id, name)
        for iloc in range(0, self.get_number_events()):
            # Origin ID
            event_id = str(self.data['eventID'][iloc])
            origin_id = event_id
            # Create Magnitude
            mag = [Magnitude(event_id,
                             origin_id, 
                             self.data['magnitude'][iloc], 
                             catalogue_id, 
                             scale='Mw', 
                             sigma=self.data['sigmaMagnitude'][iloc])]
            # Create Moment
            if not np.isnan(self.data['moment'][iloc]):
                moment = self.data['moment'][iloc] *\
                    (10. ** self.data['scaling'][iloc]) 
                mag.append(Magnitude(event_id,
                                     origin_id,
                                     moment,
                                     catalogue_id,
                                     scale='Mo'))

            # Create Location
            semimajor90 = self.data['SemiMajor90'][iloc]
            semiminor90 = self.data['SemiMinor90'][iloc]
            error_strike = self.data['ErrorStrike'][iloc]
            if np.isnan(semimajor90):
                semimajor90 = None
            if np.isnan(semiminor90):
                semiminor90 = None
            if np.isnan(error_strike):
                error_strike = None
            depth_error = self.data['depthError'][iloc]
            if np.isnan(depth_error):
                depth_error = None
            locn = Location(origin_id,
                            self.data['longitude'][iloc],
                            self.data['latitude'][iloc],
                            self.data['depth'][iloc],
                            semimajor90,
                            semiminor90,
                            error_strike,
                            depth_error)
            

            # Create Origin
            # Date
            eq_date = datetime.date(self.data['year'][iloc],
                                    self.data['month'][iloc],
                                    self.data['day'][iloc])
            # Time
            secs = self.data['second'][iloc]
            
            microsecs = int((secs - floor(secs)) * 1E6)
            eq_time = datetime.time(self.data['hour'][iloc],
                                    self.data['minute'][iloc],
                                    int(secs),
                                    microsecs)
            origin = Origin(origin_id, eq_date, eq_time, locn, catalogue_id, 
                            is_prime=True)
            origin.magnitudes = mag
            event = Event(event_id, [origin], origin.magnitudes)
            if self._check_moment_tensor_components(iloc):
                # If a moment tensor is found then add it to the event
                moment_tensor = GCMTMomentTensor()
                scaling = 10. ** self.data['scaling'][iloc]
                moment_tensor.tensor = scaling * utils.COORD_SYSTEM['USE'](
                    self.data['mrr'][iloc],
                    self.data['mtt'][iloc],
                    self.data['mpp'][iloc],
                    self.data['mrt'][iloc],
                    self.data['mpr'][iloc],
                    self.data['mtp'][iloc])
                moment_tensor.exponent = self.data['scaling'][iloc]
                setattr(event, 'tensor', moment_tensor)
            isf_cat.events.append(event)
        return isf_cat
    def write_to_isf_catalogue(self, catalogue_id, name):
        """
        Exports the catalogue to an instance of the :class:
        eqcat.isf_catalogue.ISFCatalogue
        """
        isf_cat = ISFCatalogue(catalogue_id, name)
        for iloc in range(0, self.get_number_events()):
            # Origin ID
            event_id = str(self.data['eventID'][iloc])
            origin_id = event_id
            # Create Magnitude
            mag = [Magnitude(event_id,
                             origin_id, 
                             self.data['magnitude'][iloc], 
                             name, 
                             scale='Mw', 
                             sigma=self.data['sigmaMagnitude'][iloc])]
            # Create Moment
            if not np.isnan(self.data['moment'][iloc]):
                moment = self.data['moment'][iloc] *\
                    (10. ** self.data['scaling'][iloc]) 
                mag.append(Magnitude(event_id,
                                     origin_id,
                                     moment,
                                     name,
                                     scale='Mo'))

            # Create Location
            semimajor90 = self.data['SemiMajor90'][iloc]
            semiminor90 = self.data['SemiMinor90'][iloc]
            error_strike = self.data['ErrorStrike'][iloc]
            if np.isnan(semimajor90):
                semimajor90 = None
            if np.isnan(semiminor90):
                semiminor90 = None
            if np.isnan(error_strike):
                error_strike = None
            depth_error = self.data['depthError'][iloc]
            if np.isnan(depth_error):
                depth_error = None
            locn = Location(origin_id,
                            self.data['longitude'][iloc],
                            self.data['latitude'][iloc],
                            self.data['depth'][iloc],
                            semimajor90,
                            semiminor90,
                            error_strike,
                            depth_error)
            

            # Create Origin
            # Date
            eq_date = datetime.date(self.data['year'][iloc],
                                    self.data['month'][iloc],
                                    self.data['day'][iloc])
            # Time
            secs = self.data['second'][iloc]
            
            microsecs = int((secs - floor(secs)) * 1E6)
            eq_time = datetime.time(self.data['hour'][iloc],
                                    self.data['minute'][iloc],
                                    int(secs),
                                    microsecs)
            origin = Origin(origin_id, eq_date, eq_time, locn, name, 
                            is_prime=True)
            origin.magnitudes = mag
            event = Event(event_id, [origin], origin.magnitudes)
            if self._check_moment_tensor_components(iloc):
                # If a moment tensor is found then add it to the event
                moment_tensor = GCMTMomentTensor()
                scaling = 10. ** self.data['scaling'][iloc]
                moment_tensor.tensor = scaling * utils.COORD_SYSTEM['USE'](
                    self.data['mrr'][iloc],
                    self.data['mtt'][iloc],
                    self.data['mpp'][iloc],
                    self.data['mrt'][iloc],
                    self.data['mpr'][iloc],
                    self.data['mtp'][iloc])
                moment_tensor.exponent = self.data['scaling'][iloc]
                setattr(event, 'tensor', moment_tensor)
            isf_cat.events.append(event)
        return isf_cat