Hi, this is a bit beyond the small advice, but I modified a bit to do what you need:
import numpy as np
import matplotlib.pyplot as plt
from openquake.hmtk.faults.fault_models import RecurrenceBranch
from openquake.hmtk.plotting.seismicity.catalogue_plots import _save_image
from openquake.hazardlib.scalerel.wc1994 import WC1994
figure_size=(8, 6)
fig, ax = plt.subplots(figsize=figure_size)
YCC = {'Model_Name': 'YoungsCoppersmithCharacteristic',
'MFD_spacing': 0.01,
'Maximum_Magnitude': None,
'Maximum_Magnitude_Uncertainty': None,
'Minimum_Magnitude': 5.5,
'Model_Weight': 1.0,
'b_value': [0.9,0.0],
'delta_m': None,
'area': 150*100, #length*width [km]
'slip': 2.0, #mm/year
'msr': WC1994(),
'rake': 0.0,
'shear_modulus': 30.0,
'disp_length_ratio': 1.25E-5,
'msr_sigma': 0.
}
YCE = {'Model_Name': 'YoungsCoppersmithExponential',
'MFD_spacing': 0.01,
'Maximum_Magnitude': None,
'Maximum_Magnitude_Uncertainty': None,
'Minimum_Magnitude': 6.5,
'Model_Weight': 1.0,
'b_value': [0.8,0.0],
'delta_m': None,
'area': 150*100, #length*width [km]
'slip': 2.0, #mm/year
'msr': WC1994(),
'rake': 0.0,
'shear_modulus': 30.0,
'disp_length_ratio': 1.25E-5,
'msr_sigma': 0.
}
magn = []
c_rates = []
for c in [YCC,YCE]:
model = RecurrenceBranch(c['area'], c['slip'], c['msr'], c['rake'], c['shear_modulus'], c['disp_length_ratio'], c['msr_sigma'], weight=1.0)
model.get_recurrence(c)
occurrence = model.recurrence.occur_rates
cumulative = np.array([np.sum(occurrence[iloc:]) for iloc in range(0, len(occurrence))])
if 'AndersonLuco' in c['Model_Name']:
flt_label = c['Model_Name'] + ' - ' + c['Model_Type'] + ' Type'
else:
flt_label = c['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.)
magn.append(model.magnitudes)
c_rates.append(cumulative)
#plot blended
m = np.linspace(6.5,8.23,50)
avg = (np.interp(m,magn[0],c_rates[0])+np.interp(m,magn[1],c_rates[1]))/2.0
ax.semilogy(m, avg, '--', label='average', color='red', linewidth=2.)
ax.set_xlabel('Magnitude')
ax.set_ylabel('Annual Rate')
ax.legend(bbox_to_anchor=(1.1, 1.0))
_save_image(fig, filename='recurrence2.png', filetype='png', resolution=300)
np.savetxt('YoungsCoppersmithCharacteristic.csv', np.stack((magn[0],c_rates[0]), axis=-1),delimiter=',',header='magnitude,cumulative_rate')
np.savetxt('YoungsCoppersmithExponential.csv', np.stack((magn[1],c_rates[1]), axis=-1),delimiter=',',header='magnitude,cumulative_rate')
np.savetxt('Average.csv', np.stack((m,avg), axis=-1),delimiter=',',header='magnitude,cumulative_rate')