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)
class TestRecurrenceBranch(unittest.TestCase): ''' Test the :class: 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 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)