Esempio n. 1
0
def plot_observed_recurrence(catalogue,
                             completeness,
                             dmag,
                             end_year=None,
                             figure_size=DEFAULT_SIZE,
                             filename=None,
                             filetype='png',
                             dpi=300):
    """
    Plots the observed recurrence taking into account the completeness
    """
    # Get completeness adjusted recurrence table
    if isinstance(completeness, float):
        # Unique completeness
        completeness = np.array(
            [[np.min(catalogue.data['year']), completeness]])
    if not end_year:
        end_year = catalogue.update_end_year()
    catalogue.data["dtime"] = catalogue.get_decimal_time()
    cent_mag, t_per, n_obs = get_completeness_counts(catalogue, completeness,
                                                     dmag)
    obs_rates = n_obs / t_per
    cum_obs_rates = np.array(
        [np.sum(obs_rates[i:]) for i in range(len(obs_rates))])

    plt.figure(figsize=figure_size)
    plt.semilogy(cent_mag, obs_rates, 'bo', label="Incremental")
    plt.semilogy(cent_mag, cum_obs_rates, 'rs', label="Cumulative")
    plt.xlim([cent_mag[0] - 0.1, cent_mag[-1] + 0.1])
    plt.xlabel('Magnitude', fontsize=16)
    plt.ylabel('Annual Rate', fontsize=16)
    plt.legend(fontsize=14)
    plt.tick_params(labelsize=12)
    _save_image(filename, filetype, dpi)
    plt.show()
Esempio n. 2
0
def plot_recurrence_model(input_model, catalogue, completeness, dmag,
        figure_size=(10, 8), filename=None, filetype='png', dpi=300):
    """
    Plot a calculated recurrence model over an observed catalogue, adjusted for
    time-varying completeness
    """
    if figure_size is None:
        figure_size=(10, 8)
    if dmag is None:
        dmag = 0.1
    annual_rates, cumulative_rates = _get_recurrence_model(input_model)
    # Get observed annual recurrence
    if not catalogue.end_year:
        catalogue.update_end_year()
    cent_mag, t_per, n_obs = get_completeness_counts(catalogue,
                                                     completeness,
                                                     dmag)
    obs_rates = n_obs / t_per
    cum_obs_rates = np.array([np.sum(obs_rates[i:])
                              for i in range(len(obs_rates))])
    # Create plot
    plt.figure(figsize=figure_size)
    plt.semilogy(cent_mag, obs_rates, 'bo')
    plt.semilogy(annual_rates[:, 0], annual_rates[:, 1], 'b-')
    plt.semilogy(cent_mag, cum_obs_rates, 'rs')
    plt.semilogy(annual_rates[:, 0], cumulative_rates, 'r-')
    plt.grid(which='both')
    plt.xlabel('Magnitude', fontsize='16')
    plt.ylabel('Annual Rate', fontsize='16')
    plt.legend(['Observed Incremental Rate',
                'Model Incremental Rate',
                'Observed Cumulative Rate',
                'Model Cumulative Rate'], fontsize=14)
    plt.tick_params(labelsize=12)
    _save_image(filename, filetype, dpi)
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
def plot_observed_recurrence(catalogue, completeness, dmag, end_year=None,
        figure_size=DEFAULT_SIZE, filename=None, filetype='png', dpi=300):
    """
    Plots the observed recurrence taking into account the completeness
    """
    # Get completeness adjusted recurrence table
    if isinstance(completeness, float):
        # Unique completeness
        completeness = np.array([[np.min(catalogue.data['year']),
                                  completeness]])
    if not end_year:
        end_year = catalogue.update_end_year()
    catalogue.data["dtime"] = catalogue.get_decimal_time() 
    cent_mag, t_per, n_obs = get_completeness_counts(catalogue,
                                                     completeness,
                                                     dmag)
    obs_rates = n_obs / t_per
    cum_obs_rates = np.array([np.sum(obs_rates[i:])
                              for i in range(len(obs_rates))])
 
    plt.figure(figsize=figure_size)
    plt.semilogy(cent_mag, obs_rates, 'bo', label="Incremental")
    plt.semilogy(cent_mag, cum_obs_rates, 'rs', label="Cumulative")
    plt.xlim([cent_mag[0] - 0.1, cent_mag[-1] + 0.1])
    plt.xlabel('Magnitude', fontsize=16)
    plt.ylabel('Annual Rate', fontsize=16)
    plt.legend(fontsize=14)
    plt.tick_params(labelsize=12)
    _save_image(filename, filetype, dpi)
    plt.show()
Esempio n. 6
0
 def test_completeness_counts(self):
     """
     Assert that the correct counts are returned
     """
     expected_data = np.array([[3.25, 20.0, 1281.0], [3.75, 20.0, 468.0],
                               [4.25, 35.0, 275.0], [4.75, 35.0, 116.0],
                               [5.25, 50.0, 55.0], [5.75, 50.0, 17.0],
                               [6.25, 80.0, 11.0], [6.75, 80.0, 2.0],
                               [7.25, 100.0, 1.0]])
     cent_mag, t_per, n_obs = rec_utils.get_completeness_counts(
         self.catalogue, self.completeness, 0.5)
     np.testing.assert_array_almost_equal(cent_mag, expected_data[:, 0])
     np.testing.assert_array_almost_equal(t_per, expected_data[:, 1])
     np.testing.assert_array_almost_equal(n_obs, expected_data[:, 2])
     self.assertEqual(self.catalogue.get_number_events(),
                      int(np.sum(n_obs)))
Esempio n. 7
0
 def test_completeness_counts(self):
     """
     Assert that the correct counts are returned
     """
     expected_data = np.array([[3.25, 20.0, 1281.0],
                               [3.75, 20.0,  468.0],
                               [4.25, 35.0,  275.0],
                               [4.75, 35.0,  116.0],
                               [5.25, 50.0,   55.0],
                               [5.75, 50.0,   17.0],
                               [6.25, 80.0,   11.0],
                               [6.75, 80.0,    2.0],
                               [7.25,100.0,    1.0]])
     cent_mag, t_per, n_obs = rec_utils.get_completeness_counts(
         self.catalogue, self.completeness, 0.5)
     np.testing.assert_array_almost_equal(cent_mag, expected_data[:, 0])
     np.testing.assert_array_almost_equal(t_per, expected_data[:, 1])
     np.testing.assert_array_almost_equal(n_obs, expected_data[:, 2])
     self.assertEqual(self.catalogue.get_number_events(),
                      int(np.sum(n_obs)))