Exemplo n.º 1
0
    def createMTs(self):
        """
        Create a list with all possible mt results,
        one mt for each possible depth
        """
        try:
            self.log.info('Creating Moment Tensor objects ' + \
                          'for all possible centroid depths...\n')

            for depth in self.depth_list:

                _inv1_file = os.path.join(self.dir.inversion, str(depth),
                                          "inv1.dat")
                _inv3_file = os.path.join(self.dir.inversion, str(depth),
                                          "inv3.dat")

                # add moment tensor to list
                mt = origin.MomentTensor()
                mt = isola.load_MT(depth, self.tl, self.origin, _inv1_file,
                                   _inv3_file, mt, self.f1, self.f2, self.f3,
                                   self.f4)
                self.mt_list.append(mt)

            # prints all mts
            self.log.mts(self.mt_list)

        except:
            self.log.info('Error occurred in Moment Tensor collection...\n')
            raise
Exemplo n.º 2
0
    def loadOrigin(self, origin_id, orig, station_list):
        """
        Fetches Origin (and MT) from the scisola database
        and return it in origin object.
        Returns True/False and origin object/error.
        """

        _query = "SELECT `Origin`.`id`, `Origin`.`timestamp`, " + \
        "`Origin`.`datetime`, " + \
        "`Origin`.`magnitude`, `Origin`.`latitude`, " + \
        "`Origin`.`longitude`, `Origin`.`depth`, " + \
        "`Origin`.`automatic`, `Origin`.`results_dir`, " + \
        "`Event`.`id`, " + \
        "`Moment_Tensor`.`cent_shift`, " + \
        "`Moment_Tensor`.`cent_time`, `Moment_Tensor`." + \
        "`cent_latitude`, `Moment_Tensor`.`cent_longitude`, " + \
        "`Moment_Tensor`.`cent_depth`, `Moment_Tensor`." + \
        "`correlation`, `Moment_Tensor`.`var_reduction`, " + \
        "`Moment_Tensor`.`mw`, `Moment_Tensor`.`mrr`, " + \
        "`Moment_Tensor`.`mtt`, `Moment_Tensor`.`mpp`, " + \
        "`Moment_Tensor`.`mrt`, `Moment_Tensor`.`mrp`, " + \
        "`Moment_Tensor`.`mtp`, `Moment_Tensor`.`vol`, " + \
        "`Moment_Tensor`.`dc`, `Moment_Tensor`.`clvd`, " + \
        "`Moment_Tensor`.`mo`, `Moment_Tensor`.`strike`, " + \
        "`Moment_Tensor`.`dip`, `Moment_Tensor`.`rake`, " + \
        "`Moment_Tensor`.`strike_2`, `Moment_Tensor`.`dip_2`, " + \
        "`Moment_Tensor`.`rake_2`, `Moment_Tensor`.`p_azm`, " + \
        "`Moment_Tensor`.`p_plunge`, `Moment_Tensor`.`t_azm`, " + \
        "`Moment_Tensor`.`t_plunge`, `Moment_Tensor`.`b_azm`, " + \
        "`Moment_Tensor`.`b_plunge`, `Moment_Tensor`.`minSV`, " + \
        "`Moment_Tensor`.`maxSV`, `Moment_Tensor`.`CN`, " + \
        "`Moment_Tensor`.`stVar`, `Moment_Tensor`.`fmVar`, " + \
        "`Moment_Tensor`.`frequency_1`, `Moment_Tensor`." + \
        "`frequency_2`, `Moment_Tensor`.`frequency_3`, " + \
        "`Moment_Tensor`.`frequency_4` FROM `Origin` INNER JOIN " + \
        "`Event` ON `Origin`.`id` = `Event`.`Origin_id` INNER JOIN " + \
        "`Moment_Tensor` ON " + \
        "`Origin`.`id` = `Moment_Tensor`.`Origin_id` " + \
        "WHERE `Origin`.`id` = " + str(origin_id) + ";"

        _row = self.read([_query])[0][0]

        # converts string to datetime object
        _orig_tp = date.datetime.strptime(_row[1], "%Y/%m/%d %H:%M:%S.%f")

        orig = origin.Origin()
        orig.id = int(_row[0])
        orig.timestamp = _orig_tp
        orig.datetime = _row[2]
        orig.magnitude = float(_row[3])
        orig.latitude = float(_row[4])
        orig.longitude = float(_row[5])
        orig.depth = float(_row[6])
        orig.automatic = bool(_row[7])
        orig.results_dir = _row[8]
        orig.event_id = _row[9]

        orig.mt = origin.MomentTensor()

        orig.mt.cent_shift = int(_row[10])
        orig.mt.cent_time = float(_row[11])
        orig.mt.cent_latitude = float(_row[12])
        orig.mt.cent_longitude = float(_row[13])
        orig.mt.cent_depth = float(_row[14])
        orig.mt.correlation = float(_row[15])
        orig.mt.var_reduction = float(_row[16])
        orig.mt.mw = float(_row[17])
        orig.mt.mrr = float(_row[18])
        orig.mt.mtt = float(_row[19])
        orig.mt.mpp = float(_row[20])
        orig.mt.mrt = float(_row[21])
        orig.mt.mrp = float(_row[22])
        orig.mt.mtp = float(_row[23])
        orig.mt.vol = float(_row[24])
        orig.mt.dc = float(_row[25])
        orig.mt.clvd = float(_row[26])
        orig.mt.mo = float(_row[27])
        orig.mt.strike = float(_row[28])
        orig.mt.dip = float(_row[29])
        orig.mt.rake = float(_row[30])
        orig.mt.strike2 = float(_row[31])
        orig.mt.dip2 = float(_row[32])
        orig.mt.rake2 = float(_row[33])
        orig.mt.p_azm = float(_row[34])
        orig.mt.p_plunge = float(_row[35])
        orig.mt.t_azm = float(_row[36])
        orig.mt.t_plunge = float(_row[37])
        orig.mt.b_azm = float(_row[38])
        orig.mt.b_plunge = float(_row[39])
        orig.mt.minSV = float(_row[40])
        orig.mt.maxSV = float(_row[41])
        orig.mt.CN = float(_row[42])
        orig.mt.stVar = float(_row[43])
        orig.mt.fmVar = float(_row[44])
        orig.mt.frequency_1 = float(_row[45])
        orig.mt.frequency_2 = float(_row[46])
        orig.mt.frequency_3 = float(_row[47])
        orig.mt.frequency_4 = float(_row[48])

        _query = "SELECT DISTINCT `streamNetworkCode`, " + \
        "`streamStationCode` FROM `Stream_Contribution` " + \
        "WHERE `Origin_id` = " + str(orig.id) + ";"

        _rows = self.read([_query])[0]

        # get stations
        for _row in _rows:
            _station = stream.Station()
            _station.network = _row[0]
            _station.code = _row[1]

            _query = "SELECT `streamCode`, `var_reduction`, " + \
            "`mseed_path` FROM `Stream_Contribution` " + \
            "WHERE `Origin_id` = " + str(orig.id) + \
            " AND streamStationCode = '" + str(_station.code) + \
            "' ORDER BY `streamCode`;"

            _stream_rows = self.read([_query])[0]

            # get station's streams
            for _stream_row in _stream_rows:
                _stream = stream.Stream()
                _stream.code = _stream_row[0]
                _stream.reduction = float(_stream_row[1])
                _stream.mseed_path = _stream_row[2]
                _station.stream_list.append(_stream)

            station_list.append(_station)

        return orig, station_list