def _get_moment_tensor_from_ndk_string(self, ndk_string): ''' Reads the moment tensor from the ndk_string and returns an instance of the GCMTMomentTensor class. By default the ndk format uses the Up, South, East (USE) reference system. ''' moment_tensor = GCMTMomentTensor('USE') tensor_data = _read_moment_tensor_from_ndk_string(ndk_string, 'USE') moment_tensor.tensor = tensor_data[0] moment_tensor.tensor_sigma = tensor_data[1] moment_tensor.exponent = tensor_data[2] return moment_tensor
def write_to_gcmt_class(self): """ Exports the catalogue to an instance of the :class: eqcat.gcmt_catalogue.GCMTCatalogue """ for iloc in range(0, self.get_number_events()): #print iloc gcmt = GCMTEvent() gcmt.identifier = self.data['eventID'][iloc] gcmt.magnitude = self.data['magnitude'][iloc] # Get moment plus scaling if not np.isnan(self.data['moment'][iloc]): scaling = float(self.data['scaling'][iloc]) gcmt.moment = self.data['moment'][iloc] * (10. ** scaling) gcmt.metadata = {'Agency': self.data['Agency'][iloc], 'source': self.data['source'][iloc]} # Get the hypocentre gcmt.hypocentre = GCMTHypocentre() gcmt.hypocentre.source = self.data['source'][iloc] gcmt.hypocentre.date = datetime.date(self.data['year'][iloc], self.data['month'][iloc], self.data['day'][iloc]) second = self.data['second'][iloc] microseconds = int((second - floor(second)) * 1000000) gcmt.hypocentre.time = datetime.time(self.data['hour'][iloc], self.data['minute'][iloc], int(floor(second)), microseconds) gcmt.hypocentre.longitude = self.data['longitude'][iloc] gcmt.hypocentre.latitude = self.data['latitude'][iloc] setattr(gcmt.hypocentre, 'semi_major_90', self.data['SemiMajor90'][iloc]) setattr(gcmt.hypocentre, 'semi_minor_90', self.data['SemiMinor90'][iloc]) setattr(gcmt.hypocentre, 'error_strike', self.data['ErrorStrike'][iloc]) # Get the centroid - basically just copying across the hypocentre gcmt.centroid = GCMTCentroid(gcmt.hypocentre.date, gcmt.hypocentre.time) gcmt.centroid.longitude = gcmt.hypocentre.longitude gcmt.centroid.latitude = gcmt.hypocentre.latitude gcmt.centroid.depth = gcmt.hypocentre.depth gcmt.centroid.depth_error = self.data['depthError'][iloc] if self._check_moment_tensor_components(iloc): # Import tensor components gcmt.moment_tensor = GCMTMomentTensor() # Check moment tensor has all the components! gcmt.moment_tensor.tensor = 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]) gcmt.moment_tensor.tensor_sigma = np.array([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]) #print gcmt.moment_tensor.tensor # Get nodal planes gcmt.nodal_planes = gcmt.moment_tensor.get_nodal_planes() gcmt.principal_axes = gcmt.moment_tensor.get_principal_axes() # Done - append to catalogue self.gcmt_catalogue.gcmts.append(gcmt) return self.gcmt_catalogue
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