コード例 #1
0
ファイル: utils_test.py プロジェクト: tieganh/oq-engine
 def test_input_checks_simple_input(self):
     completeness_table = [[1900, 2.0]]
     catalogue = Catalogue.make_from_dict({
         'magnitude': [5.0, 6.0],
         'year': [2000, 2000]
     })
     config = {}
     rec_utils.input_checks(catalogue, config, completeness_table)
コード例 #2
0
 def test_input_checks_sets_magnitude_interval(self):
     fake_completeness_table = 0.0
     catalogue = Catalogue.make_from_dict({'year': [1900]})
     config = {'magnitude_interval': 0.1}
     cmag, ctime, ref_mag, dmag, _ = rec_utils.input_checks(catalogue,
                                                            config, fake_completeness_table)
     self.assertEqual(0.1, dmag)
コード例 #3
0
 def test_input_checks_use_reference_magnitude(self):
     fake_completeness_table = 0.0
     catalogue = Catalogue.make_from_dict({'year': [1900]})
     config = {'reference_magnitude': 3.0}
     cmag, ctime, ref_mag, dmag, _ = rec_utils.input_checks(catalogue,
                                                            config, fake_completeness_table)
     self.assertEqual(3.0, ref_mag)
コード例 #4
0
ファイル: weichert.py プロジェクト: oneconcern/oq-engine
    def calculate(self, catalogue, config, completeness=None):
        '''Calculates recurrence using the Weichert (1980) method'''
        # Input checks
        cmag, ctime, ref_mag, _, config = input_checks(catalogue,
                                                       config,
                                                       completeness)
        if not "dtime" in catalogue.data.keys() or not\
            len(catalogue.data["dtime"]):
            catalogue.data["dtime"] = catalogue.get_decimal_time()
        if not catalogue.end_year:
            catalogue.update_end_year()
        if completeness is None:
            start_year = float(np.min(catalogue.data["year"]))
            completeness = np.column_stack([ctime, cmag])
        # Apply Weichert preparation
        cent_mag, t_per, n_obs = get_completeness_counts(
            catalogue, completeness, config["magnitude_interval"])

        # A few more Weichert checks
        key_list = config.keys()
        if (not 'bvalue' in key_list) or (not config['bvalue']):
            config['bvalue'] = 1.0
        if (not 'itstab' in key_list) or (not config['itstab']):
            config['itstab'] = 1E-5
        if (not 'maxiter' in key_list) or (not config['maxiter']):
            config['maxiter'] = 1000
        bval, sigma_b, rate, sigma_rate, aval, sigma_a = \
            self.weichert_algorithm(t_per, cent_mag, n_obs, ref_mag,
            config['bvalue'], config['itstab'], config['maxiter'])
       
        if not config['reference_magnitude']:
            rate = np.log10(aval)
            sigma_rate = np.log10(aval + sigma_a) - np.log10(aval)

        return bval, sigma_b, rate, sigma_rate
コード例 #5
0
    def calculate(self, catalogue, config=None, completeness=None):
        """
        Calculation of b-value and its uncertainty for a given
        catalogue, using the maximum likelihood method of Aki (1965),
        with a correction for discrete bin width (Bender, 1983).

        :param catalogue:
            See :class:`openquake.hmtk.seismicity.occurrence.base.py`
            for further explanation
        :param config:
            The configuration in this case do not contains specific
            information
        :keyword float completeness:
            Completeness magnitude

        :return float bval:
            b-value of the Gutenberg-Richter relationship
        :return float sigma_b:
            Standard deviation of the GR b-value
        """
        # Input checks
        _cmag, _ctime, _ref_mag, dmag, config = input_checks(
            catalogue, config, completeness)
        rt = recurrence_table(catalogue.data['magnitude'], dmag,
                              catalogue.data['year'])
        bval, sigma_b = self._aki_ml(rt[:, 0], rt[:, 1])
        return bval, sigma_b
コード例 #6
0
ファイル: utils_test.py プロジェクト: gem/oq-hazardlib
 def test_input_checks_sets_magnitude_interval(self):
     fake_completeness_table = 0.0
     catalogue = Catalogue.make_from_dict({'year': [1900]})
     config = {'magnitude_interval' : 0.1}
     cmag, ctime, ref_mag, dmag, _ = rec_utils.input_checks(catalogue,
             config, fake_completeness_table)
     self.assertEqual(0.1, dmag)
コード例 #7
0
ファイル: weichert.py プロジェクト: gem/oq-hazardlib
    def calculate(self, catalogue, config, completeness=None):
        '''Calculates recurrence using the Weichert (1980) method'''
        # Input checks
        cmag, ctime, ref_mag, _, config = input_checks(catalogue,
                                                       config,
                                                       completeness)
        if not "dtime" in catalogue.data.keys() or not\
            len(catalogue.data["dtime"]):
            catalogue.data["dtime"] = catalogue.get_decimal_time()
        if not catalogue.end_year:
            catalogue.update_end_year()
        if completeness is None:
            start_year = float(np.min(catalogue.data["year"]))
            completeness = np.column_stack([ctime, cmag])
        # Apply Weichert preparation
        cent_mag, t_per, n_obs = get_completeness_counts(
            catalogue, completeness, config["magnitude_interval"])

        # A few more Weichert checks
        key_list = config.keys()
        if (not 'bvalue' in key_list) or (not config['bvalue']):
            config['bvalue'] = 1.0
        if (not 'itstab' in key_list) or (not config['itstab']):
            config['itstab'] = 1E-5
        if (not 'maxiter' in key_list) or (not config['maxiter']):
            config['maxiter'] = 1000
        bval, sigma_b, rate, sigma_rate, aval, sigma_a = \
            self.weichert_algorithm(t_per, cent_mag, n_obs, ref_mag,
            config['bvalue'], config['itstab'], config['maxiter'])
       
        if not config['reference_magnitude']:
            rate = np.log10(aval)
            sigma_rate = np.log10(aval + sigma_a) - np.log10(aval)

        return bval, sigma_b, rate, sigma_rate
コード例 #8
0
ファイル: utils_test.py プロジェクト: gem/oq-hazardlib
 def test_input_checks_use_reference_magnitude(self):
     fake_completeness_table = 0.0
     catalogue = Catalogue.make_from_dict({'year': [1900]})
     config = {'reference_magnitude' : 3.0}
     cmag, ctime, ref_mag, dmag, _ = rec_utils.input_checks(catalogue,
             config, fake_completeness_table)
     self.assertEqual(3.0, ref_mag)
コード例 #9
0
    def calculate(self, catalogue, config=None, completeness=None):
        """
        Calculation of b-value and its uncertainty for a given
        catalogue, using the maximum likelihood method of Aki (1965),
        with a correction for discrete bin width (Bender, 1983).

        :param catalogue:
            See :class:`openquake.hmtk.seismicity.occurrence.base.py`
            for further explanation
        :param config:
            The configuration in this case do not contains specific
            information
        :keyword float completeness:
            Completeness magnitude

        :return float bval:
            b-value of the Gutenberg-Richter relationship
        :return float sigma_b:
            Standard deviation of the GR b-value
        """
        # Input checks
        _cmag, _ctime, _ref_mag, dmag, config = input_checks(catalogue, config,
                                                             completeness)
        rt = recurrence_table(
            catalogue.data['magnitude'], dmag, catalogue.data['year'])
        bval, sigma_b = self._aki_ml(rt[:, 0], rt[:, 1])
        return bval, sigma_b
コード例 #10
0
ファイル: kijko_smit.py プロジェクト: vhmar/oq-engine
    def calculate(self, catalogue, config, completeness=None):
        """
        Main function to calculate the a- and b-value
        """
        # Input checks
        cmag, ctime, ref_mag, dmag, config = input_checks(catalogue,
                                                          config,
                                                          completeness)
        ival = 0
        tolerance = 1E-7
        number_intervals = np.shape(ctime)[0]
        b_est = np.zeros(number_intervals, dtype=float)
        neq = np.zeros(number_intervals, dtype=float)
        nyr = np.zeros(number_intervals, dtype=float)

        for ival in range(0, number_intervals):
            id0 = np.abs(ctime - ctime[ival]) < tolerance
            m_c = np.min(cmag[id0])
            if ival == 0:
                id1 = np.logical_and(
                    catalogue.data['year'] >= (ctime[ival] - tolerance),
                    catalogue.data['magnitude'] >= (m_c - tolerance))
                nyr[ival] = float(catalogue.end_year) - ctime[ival] + 1.
            elif ival == number_intervals - 1:
                id1 = np.logical_and(
                    catalogue.data['year'] < (ctime[ival - 1] - tolerance),
                    catalogue.data['magnitude'] >= (m_c - tolerance))
                nyr[ival] = ctime[ival - 1] - ctime[ival]
            else:
                id1 = np.logical_and(
                    catalogue.data['year'] >= (ctime[ival] - tolerance),
                    catalogue.data['year'] < (ctime[ival - 1] - tolerance))
                id1 = np.logical_and(
                    id1, catalogue.data['magnitude'] > (m_c - tolerance))
                nyr[ival] = ctime[ival - 1] - ctime[ival]
            neq[ival] = np.sum(id1)
            # Get a- and b- value for the selected events
            temp_rec_table = recurrence_table(catalogue.data['magnitude'][id1],
                                              dmag,
                                              catalogue.data['year'][id1])

            aki_ml = AkiMaxLikelihood()
            b_est[ival] = aki_ml._aki_ml(temp_rec_table[:, 0],
                                         temp_rec_table[:, 1],
                                         dmag, m_c)[0]
            ival += 1
        total_neq = np.float(np.sum(neq))
        bval = self._harmonic_mean(b_est, neq)
        sigma_b = bval / np.sqrt(total_neq)
        aval = self._calculate_a_value(bval, total_neq, nyr, cmag, ref_mag)
        sigma_a = self._calculate_a_value(bval + sigma_b, total_neq, nyr,
                                          cmag, ref_mag)

        if not config['reference_magnitude']:
            aval = np.log10(aval)
            sigma_a = np.log10(sigma_a) - aval
        else:
            sigma_a = sigma_a - aval
        return bval, sigma_b, aval, sigma_a
コード例 #11
0
    def calculate(self, catalogue, config, completeness=None):
        """ Calculates recurrence parameters a_value and b_value, and their
        respective uncertainties

        :param catalogue: Earthquake Catalogue
            An instance of :class:`openquake.hmtk.seismicity.catalogue`
        :param dict config:
            A configuration dictionary; the only parameter that can be
            defined in this case if the type of average to be applied
            in the calculation
        :param list or numpy.ndarray completeness:
            Completeness table
        """

        # Input checks
        cmag, ctime, ref_mag, dmag, config = input_checks(
            catalogue, config, completeness)

        # Check the configuration
        if not config['Average Type'] in ['Weighted', 'Harmonic']:
            raise ValueError('Average type not recognised in bMaxLiklihood!')
        return self._b_ml(catalogue, config, cmag, ctime, ref_mag, dmag)
コード例 #12
0
    def calculate(self, catalogue, config, completeness=None):
        """ Calculates recurrence parameters a_value and b_value, and their
        respective uncertainties

        :param catalogue: Earthquake Catalogue
            An instance of :class:`openquake.hmtk.seismicity.catalogue`
        :param dict config:
            A configuration dictionary; the only parameter that can be
            defined in this case if the type of average to be applied
            in the calculation
        :param list or numpy.ndarray completeness:
            Completeness table
        """

        # Input checks
        cmag, ctime, ref_mag, dmag, config = input_checks(catalogue,
                                                          config,
                                                          completeness)

        # Check the configuration
        if not config['Average Type'] in ['Weighted','Harmonic']:
            raise ValueError('Average type not recognised in bMaxLiklihood!')
        return self._b_ml(catalogue, config, cmag, ctime, ref_mag, dmag)
コード例 #13
0
 def test_input_checks_use_a_float_for_completeness(self):
     fake_completeness_table = 0.0
     catalogue = Catalogue.make_from_dict({'year': [1900]})
     config = {}
     rec_utils.input_checks(catalogue, config, fake_completeness_table)
コード例 #14
0
ファイル: utils_test.py プロジェクト: gem/oq-hazardlib
 def test_input_checks_use_a_float_for_completeness(self):
     fake_completeness_table = 0.0
     catalogue = Catalogue.make_from_dict({'year': [1900]})
     config = {}
     rec_utils.input_checks(catalogue, config, fake_completeness_table)
コード例 #15
0
ファイル: utils_test.py プロジェクト: gem/oq-hazardlib
 def test_input_checks_simple_input(self):
     completeness_table = [[1900, 2.0]]
     catalogue = Catalogue.make_from_dict(
         {'magnitude': [5.0, 6.0], 'year': [2000, 2000]})
     config = {}
     rec_utils.input_checks(catalogue, config, completeness_table)