Пример #1
0
 def _build_mock_recurrence_branches(self):
     '''
     Given the mock branches return information necessary to define a
     collapse model
     '''
     # Build test data
     mags = COLLAPSE_DATA[0, :-1]
     weights = COLLAPSE_DATA[1:-1, -1]
     rates = COLLAPSE_DATA[1:-1:, :-1]
     expected_rate = COLLAPSE_DATA[-1, :-1]
     test_fault = mtkActiveFault('001', 'A Fault', self.simple_fault,
                                 [(5.0, 1.0)], 0., None)
     test_fault.mfd_models = []
     for (iloc, weight) in enumerate(weights):
         idx = rates[iloc, :] > 0
         model = RecurrenceBranch(None,
                                  None,
                                  None,
                                  None,
                                  None,
                                  weight=weight)
         model.recurrence = IncrementalMFD(np.min(rates[iloc, idx]), 0.1,
                                           rates[iloc, idx])
         model.magnitudes = mags[idx]
         test_fault.mfd_models.append(model)
     return test_fault, expected_rate, np.min(mags), np.max(mags), weights
Пример #2
0
 def test_update_weight(self):
     '''
     Tests the simple function to update the weight
     '''
     self.model = RecurrenceBranch(1200., 12., WC1994, -90., 30.)
     self.model.update_weight(0.5)
     self.assertAlmostEqual(0.5, self.model.weight, 7)
Пример #3
0
    def test_get_recurrence_simple_characteristic(self):
        '''
        Tests the function to get the recurrence calculation for a simple
        characteristic earthquake
        '''
        self.mfd_config = {
            'MFD_spacing': 0.1,
            'Model_Name': 'Characteristic',
            'Model_Weight': 1.0,
            'Maximum_Magnitude': None,
            'Maximum_Uncertainty': None,
            'Lower_Bound': -2.,
            'Upper_Bound': 2.,
            'Sigma': 0.12
        }

        self.model = RecurrenceBranch(8500., 5., WC1994(), 0., 30.)
        self.model.get_recurrence(self.mfd_config)
        # Test the same process using just the openquake.hmtk.faults.mfd.characteristic
        # Implementation
        test_model = Characteristic()
        test_model.setUp(self.mfd_config)
        test_model.get_mmax(self.mfd_config, WC1994(), 0., 8500.)
        _ = test_model.get_mfd(5.0, 8500., 30.)
        self.assertTrue(isinstance(self.model.recurrence, IncrementalMFD))
        self.assertAlmostEqual(self.model.recurrence.min_mag, test_model.mmin)
        self.assertAlmostEqual(self.model.recurrence.bin_width,
                               test_model.bin_width)
        np.testing.assert_array_almost_equal(self.model.recurrence.occur_rates,
                                             test_model.occurrence_rate)
Пример #4
0
def plot_recurrence_models(
        configs, area, slip, msr, rake,
        shear_modulus=30.0, disp_length_ratio=1.25E-5, msr_sigma=0.,
        filename=None, filetype='png', dpi=300):
    """
    Plots a set of recurrence models

    :param list configs:
        List of configuration dictionaries
    """
    plt.figure(figsize=DEFAULT_SIZE)
    for config in configs:
        model = RecurrenceBranch(area, slip, msr, rake, shear_modulus,
                                 disp_length_ratio, msr_sigma, weight=1.0)
        model.get_recurrence(config)
        occurrence = model.recurrence.occur_rates
        cumulative = np.array([np.sum(occurrence[iloc:])
                               for iloc in range(0, len(occurrence))])
        if 'AndersonLuco' in config['Model_Name']:
            flt_label = config['Model_Name'] + ' - ' + config['Model_Type'] +\
                    ' Type'
        else:
            flt_label = config['Model_Name']
        flt_color = np.random.uniform(0.1, 1.0, 3)
        plt.semilogy(model.magnitudes, cumulative, '-', label=flt_label,
                     color=flt_color, linewidth=2.)
        plt.semilogy(model.magnitudes, model.recurrence.occur_rates, '--',
                     color=flt_color, linewidth=2.)
    plt.xlabel('Magnitude', fontsize=14)
    plt.ylabel('Annual Rate', fontsize=14)
    plt.legend(bbox_to_anchor=(1.1, 1.0))
    _save_image(filename, filetype, dpi)
Пример #5
0
 def _build_mock_recurrence_branches(self):
     '''
     Given the mock branches return information necessary to define a
     collapse model
     '''
     # Build test data
     mags = COLLAPSE_DATA[0, :-1]
     weights = COLLAPSE_DATA[1:-1, -1]
     rates = COLLAPSE_DATA[1:-1:, :-1]
     expected_rate = COLLAPSE_DATA[-1, :-1]
     test_fault = mtkActiveFault(
         '001',
         'A Fault',
         self.simple_fault,
         [(5.0, 1.0)],
         0.,
         None)
     test_fault.mfd_models = []
     for (iloc, weight) in enumerate(weights):
         idx = rates[iloc, :] > 0
         model = RecurrenceBranch(None, None, None, None, None,
                                  weight=weight)
         model.recurrence = IncrementalMFD(np.min(rates[iloc, idx]), 0.1,
                                           rates[iloc, idx])
         model.magnitudes = mags[idx]
         test_fault.mfd_models.append(model)
     return test_fault, expected_rate, np.min(mags), np.max(mags), weights
Пример #6
0
def plot_recurrence_models(configs,
                           area,
                           slip,
                           msr,
                           rake,
                           shear_modulus=30.0,
                           disp_length_ratio=1.25E-5,
                           msr_sigma=0.,
                           figure_size=(8, 6),
                           filename=None,
                           filetype='png',
                           dpi=300,
                           ax=None):
    """
    Plots a set of recurrence models

    :param list configs:
        List of configuration dictionaries
    """
    if ax is None:
        fig, ax = plt.subplots(figsize=figure_size)
    else:
        fig = ax.get_figure()

    for config in configs:
        model = RecurrenceBranch(area,
                                 slip,
                                 msr,
                                 rake,
                                 shear_modulus,
                                 disp_length_ratio,
                                 msr_sigma,
                                 weight=1.0)
        model.get_recurrence(config)
        occurrence = model.recurrence.occur_rates
        cumulative = np.array(
            [np.sum(occurrence[iloc:]) for iloc in range(0, len(occurrence))])
        if 'AndersonLuco' in config['Model_Name']:
            flt_label = config['Model_Name'] + ' - ' + config['Model_Type'] +\
                ' Type'
        else:
            flt_label = config['Model_Name']
        flt_color = np.random.uniform(0.1, 1.0, 3)
        ax.semilogy(model.magnitudes,
                    cumulative,
                    '-',
                    label=flt_label,
                    color=flt_color,
                    linewidth=2.)
        ax.semilogy(model.magnitudes,
                    model.recurrence.occur_rates,
                    '--',
                    color=flt_color,
                    linewidth=2.)

    ax.set_xlabel('Magnitude')
    ax.set_ylabel('Annual Rate')
    ax.legend(bbox_to_anchor=(1.1, 1.0))
    _save_image(fig, filename, filetype, dpi)
Пример #7
0
    def test_get_recurrence_simple_characteristic(self):
        '''
        Tests the function to get the recurrence calculation for a simple
        characteristic earthquake
        '''
        self.mfd_config = {'MFD_spacing': 0.1,
                           'Model_Name': 'Characteristic',
                           'Model_Weight': 1.0,
                           'Maximum_Magnitude': None,
                           'Maximum_Uncertainty': None,
                           'Lower_Bound': -2.,
                           'Upper_Bound': 2., 'Sigma': 0.12}

        self.model = RecurrenceBranch(8500., 5., WC1994(), 0., 30.)
        self.model.get_recurrence(self.mfd_config)
        # Test the same process using just the openquake.hmtk.faults.mfd.characteristic
        # Implementation
        test_model = Characteristic()
        test_model.setUp(self.mfd_config)
        test_model.get_mmax(self.mfd_config, WC1994(), 0., 8500.)
        _ = test_model.get_mfd(5.0, 8500., 30.)
        self.assertTrue(isinstance(self.model.recurrence, IncrementalMFD))
        self.assertAlmostEqual(self.model.recurrence.min_mag,
                               test_model.mmin)
        self.assertAlmostEqual(self.model.recurrence.bin_width,
                               test_model.bin_width)
        np.testing.assert_array_almost_equal(self.model.recurrence.occur_rates,
                                             test_model.occurrence_rate)
Пример #8
0
 def test_update_weight(self):
     '''
     Tests the simple function to update the weight
     '''
     self.model = RecurrenceBranch(1200., 12., WC1994,  -90., 30.)
     self.model.update_weight(0.5)
     self.assertAlmostEqual(0.5, self.model.weight, 7)
Пример #9
0
 def test_simple_instantiation(self):
     '''
     Basic instantiation test
     '''
     # Area = 1200 km ^ 2, slip = 12 mm/yr, Rake = -90, Shear Mod =30. GPa
     self.model = RecurrenceBranch(1200., 12., self.msr, -90., 30.)
     expected_dict = {'area': 1200.0,
                      'branch_id': None,
                      'disp_length_ratio': None,
                      'magnitudes': None,
                      'max_mag': None,
                      'msr': WC1994,
                      'msr_sigma': 0.0,
                      'rake': -90.0,
                      'recurrence': None,
                      'shear_modulus': 30.0,
                      'slip': 12.0,
                      'weight': 1.0}
     self.assertDictEqual(self.model.__dict__, expected_dict)
Пример #10
0
class TestRecurrenceBranch(unittest.TestCase):
    '''
    Test the :class: openquake.hmtk.faults.fault_models.RecurrenceBranch - the class
    to control the recurrence calculation for a given model
    '''
    def setUp(self):
        '''
        '''
        self.msr = WC1994
        self.model = None
        self.mfd_config = None

    def test_simple_instantiation(self):
        '''
        Basic instantiation test
        '''
        # Area = 1200 km ^ 2, slip = 12 mm/yr, Rake = -90, Shear Mod =30. GPa
        self.model = RecurrenceBranch(1200., 12., self.msr, -90., 30.)
        expected_dict = {
            'area': 1200.0,
            'branch_id': None,
            'disp_length_ratio': None,
            'magnitudes': None,
            'max_mag': None,
            'msr': WC1994,
            'msr_sigma': 0.0,
            'rake': -90.0,
            'recurrence': None,
            'shear_modulus': 30.0,
            'slip': 12.0,
            'weight': 1.0
        }
        self.assertDictEqual(self.model.__dict__, expected_dict)

    def test_update_weight(self):
        '''
        Tests the simple function to update the weight
        '''
        self.model = RecurrenceBranch(1200., 12., WC1994, -90., 30.)
        self.model.update_weight(0.5)
        self.assertAlmostEqual(0.5, self.model.weight, 7)

    def test_get_recurrence_simple_characteristic(self):
        '''
        Tests the function to get the recurrence calculation for a simple
        characteristic earthquake
        '''
        self.mfd_config = {
            'MFD_spacing': 0.1,
            'Model_Name': 'Characteristic',
            'Model_Weight': 1.0,
            'Maximum_Magnitude': None,
            'Maximum_Uncertainty': None,
            'Lower_Bound': -2.,
            'Upper_Bound': 2.,
            'Sigma': 0.12
        }

        self.model = RecurrenceBranch(8500., 5., WC1994(), 0., 30.)
        self.model.get_recurrence(self.mfd_config)
        # Test the same process using just the openquake.hmtk.faults.mfd.characteristic
        # Implementation
        test_model = Characteristic()
        test_model.setUp(self.mfd_config)
        test_model.get_mmax(self.mfd_config, WC1994(), 0., 8500.)
        _ = test_model.get_mfd(5.0, 8500., 30.)
        self.assertTrue(isinstance(self.model.recurrence, IncrementalMFD))
        self.assertAlmostEqual(self.model.recurrence.min_mag, test_model.mmin)
        self.assertAlmostEqual(self.model.recurrence.bin_width,
                               test_model.bin_width)
        np.testing.assert_array_almost_equal(self.model.recurrence.occur_rates,
                                             test_model.occurrence_rate)
Пример #11
0
class TestRecurrenceBranch(unittest.TestCase):
    '''
    Test the :class: openquake.hmtk.faults.fault_models.RecurrenceBranch - the class
    to control the recurrence calculation for a given model
    '''

    def setUp(self):
        '''
        '''
        self.msr = WC1994
        self.model = None
        self.mfd_config = None

    def test_simple_instantiation(self):
        '''
        Basic instantiation test
        '''
        # Area = 1200 km ^ 2, slip = 12 mm/yr, Rake = -90, Shear Mod =30. GPa
        self.model = RecurrenceBranch(1200., 12., self.msr, -90., 30.)
        expected_dict = {'area': 1200.0,
                         'branch_id': None,
                         'disp_length_ratio': None,
                         'magnitudes': None,
                         'max_mag': None,
                         'msr': WC1994,
                         'msr_sigma': 0.0,
                         'rake': -90.0,
                         'recurrence': None,
                         'shear_modulus': 30.0,
                         'slip': 12.0,
                         'weight': 1.0}
        self.assertDictEqual(self.model.__dict__, expected_dict)

    def test_update_weight(self):
        '''
        Tests the simple function to update the weight
        '''
        self.model = RecurrenceBranch(1200., 12., WC1994,  -90., 30.)
        self.model.update_weight(0.5)
        self.assertAlmostEqual(0.5, self.model.weight, 7)

    def test_get_recurrence_simple_characteristic(self):
        '''
        Tests the function to get the recurrence calculation for a simple
        characteristic earthquake
        '''
        self.mfd_config = {'MFD_spacing': 0.1,
                           'Model_Name': 'Characteristic',
                           'Model_Weight': 1.0,
                           'Maximum_Magnitude': None,
                           'Maximum_Uncertainty': None,
                           'Lower_Bound': -2.,
                           'Upper_Bound': 2., 'Sigma': 0.12}

        self.model = RecurrenceBranch(8500., 5., WC1994(), 0., 30.)
        self.model.get_recurrence(self.mfd_config)
        # Test the same process using just the openquake.hmtk.faults.mfd.characteristic
        # Implementation
        test_model = Characteristic()
        test_model.setUp(self.mfd_config)
        test_model.get_mmax(self.mfd_config, WC1994(), 0., 8500.)
        _ = test_model.get_mfd(5.0, 8500., 30.)
        self.assertTrue(isinstance(self.model.recurrence, IncrementalMFD))
        self.assertAlmostEqual(self.model.recurrence.min_mag,
                               test_model.mmin)
        self.assertAlmostEqual(self.model.recurrence.bin_width,
                               test_model.bin_width)
        np.testing.assert_array_almost_equal(self.model.recurrence.occur_rates,
                                             test_model.occurrence_rate)