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_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