Characteristic model plot and HMTK

173 views
Skip to first unread message

Hazem Badreldin

unread,
Jan 17, 2024, 9:04:55 AM1/17/24
to openqua...@googlegroups.com
Dear all,

Kindly if someone could help. Currently I am using the OQ HMTK codes to estimate and plot Youngs and Coppersmith (1985) Characteristic fault model. I have succeeded to plot each fault model alone as indicated below.
I have a couple of questions : first,  how can I delete the dash line which is PDF ? Second, how can I plot many faults in the same plot using oq HMTK notebooks?
Which part of the code should I edit?  
If someone can share an example or the part of the code should I edit?





image.png

Best regards, 
Hazem




Peter Pažák

unread,
Jan 20, 2024, 5:32:32 PM1/20/24
to OpenQuake Users
Hi, the plotting done in geology_mfd_plot.py and you can see there is no switch to turn off the dashed line:

maybe the easiest is to take the whole .py file and modify plot_recurrence_models as you wish (comment out the dashed line plot as I did below).
If you create the axes outside the plotting function and provide them as a parameter, in that way you can combine multiple plots, however if you provide
multiple configs (below) it plots them into one figure:

#taken from geology_mfd_plot.py

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

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)

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}

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}

from openquake.hazardlib.scalerel.wc1994 import WC1994
area = 150*100 #length*width [km]
slip = 2.0 #mm/year
msr = WC1994()
rake = 0.0

plot_recurrence_models([YCC,YCE],area,slip,msr,rake,msr_sigma=0,filename='recurrence.png')

recurrence.png

Dátum: streda 17. januára 2024, čas: 15:04:55 UTC+1, odosielateľ: hazembad...@gmail.com

Hazem Badreldin

unread,
Jan 21, 2024, 10:32:08 AM1/21/24
to openqua...@googlegroups.com
Dear Peter,
Many thanks  for your reply, the code is perfectly fine and working well with me.
Best regards,
Hazem

--
You received this message because you are subscribed to the Google Groups "OpenQuake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openquake-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openquake-users/29fbab26-07f8-43e3-8164-0020aa7ac5f5n%40googlegroups.com.

Zain Khan

unread,
Jan 22, 2024, 1:29:49 AM1/22/24
to openqua...@googlegroups.com
Hey Peter, I hope you are doing great.
I have two questions regarding this one.
First, I want a weighted plot of 50% Characteristic and 50% Exponential. Is there any provision to achieve that? and after
I have made this plot. Now I want to extract the values in terms of .csv file in excel like for x and y axis values other than visual interpretation of the plot. How can I do so?
Thanx!


Peter Pažák

unread,
Jan 22, 2024, 4:49:47 AM1/22/24
to OpenQuake Users
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')

Dátum: pondelok 22. januára 2024, čas: 7:29:49 UTC+1, odosielateľ: zainulab...@gmail.com

Aulia Khalqillah

unread,
Jun 16, 2025, 10:34:31 PM6/16/25
to OpenQuake Users
Dear Peter,

I know this is an old thread, but I found this thread because I have an error related to the YoungsCoppersmithExponential module for calculating the annual rate.

I tried to calculate the annual rate using this approach (your code above) with some modified parameters as attached in the jupyter-notebook file and I got an error of "ValueError: negative dimensions are not allowed" (see screenshoot).

What does the error tell about? and how to solve this error?

Many thanks for your attention.

Screenshot 2025-06-17 093254.png

yc_exponential_model.ipynb
Reply all
Reply to author
Forward
0 new messages