def read_ndk_event(self, raw_data, id0): ''' Reads a 5-line batch of data into a set of GCMTs ''' gcmt = GCMTEvent() # Get hypocentre ndkstring = raw_data[id0].rstrip('\n') gcmt.hypocentre = self._read_hypocentre_from_ndk_string(ndkstring) # GCMT metadata ndkstring = raw_data[id0 + 1].rstrip('\n') gcmt = self._get_metadata_from_ndk_string(gcmt, ndkstring) # Get Centroid ndkstring = raw_data[id0 + 2].rstrip('\n') gcmt.centroid = self._read_centroid_from_ndk_string(ndkstring, gcmt.hypocentre) # Get Moment Tensor ndkstring = raw_data[id0 + 3].rstrip('\n') gcmt.moment_tensor = self._get_moment_tensor_from_ndk_string(ndkstring) # Get principal axes ndkstring = raw_data[id0 + 4].rstrip('\n') gcmt.principal_axes = self._get_principal_axes_from_ndk_string( ndkstring[3:48], exponent=gcmt.moment_tensor.exponent) # Get Nodal Planes gcmt.nodal_planes = self._get_nodal_planes_from_ndk_string( ndkstring[57:]) # Get Moment and Magnitude gcmt.moment, gcmt.version, gcmt.magnitude = \ self._get_moment_from_ndk_string(ndkstring, gcmt.moment_tensor.exponent) return gcmt
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