Skip to content
Snippets Groups Projects
gmmExample.m 2.95 KiB
Newer Older
  • Learn to ignore specific revisions
  • %% nshmp-haz Ground Motion Model (GMM) calculator example script
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    
    % =========================================================================
    
    % This script provides instruction on how to access ground motion models
    
    % (GMMs) implemented in the nshmp-haz library.
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    %
    
    % See the README for instructions on how to set up Matlab to use nshmp-haz.
    % =========================================================================
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    
    
    % Specify path to nshmp-haz library:
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    nshmpHaz = '/path/to/repository/nshmp-haz/dist/nshmp-haz.jar';
    
    
    % Make Matlab aware of nshmp-haz by adding it to the 'dynamic' classpath:
    javaaddpath(nshmpHaz);
    
    % Alternatively, one can add nshmp-haz to the faster 'static' classpath by
    % saving a file with the name `javaclasspath.txt` to the Matlab preferences
    % directory, as specified by the `prefdir` command, and with single line:
    %
    %     /path/to/repository/nshmp-haz/dist/nshmp-haz.jar
    %
    % Although the static classpath is generally a little faster, you must
    % restart Matlab any time nshmp-haz.jar is rebuilt with updated code.
    
    import gov.usgs.earthquake.nshmp.etc.*
    
    % =========================================================================
    % Single model ground motion calculation:
    
    % Initialize calculator:
    hazMat = HazMat.init(nshmpHaz);
    
    % Note that hazMat is stateless and reusable and should therefore be
    % initialized external to this script if doing many calculations.
    
    % Set up a GMM input parameter object. These data are a source and site
    % parameterization that will satisfy all currently implemented Gmms. Note
    % that not all models will necessarily use all parameters.
    input = GmmParams();
    input.Mw    =   6.5; % moment magnitude
    input.rJB   =   5.0; % Joyner-Boore distance
    input.rRup  =   5.1; % distance to closest point on rupture surface
    input.rX    =   5.1; % distance from source trace; hanging (+); foot (-) wall
    input.dip   =  90.0; % in degrees
    input.width =  10.0; % in km
    input.zTop  =   1.0; % in km
    input.zHyp  =   6.0; % in km
    input.rake  =   0.0; % in degrees
    input.vs30  = 760.0; % in m/s
    input.z2p5  =   NaN; % in km; NaN triggers default basin depth model
    input.z1p0  =   NaN; % in km; NaN triggers default basin depth model
    
    % Specify a ground motion model. GMM identifiers:
    
    % https://earthquake.usgs.gov/nshmp/docs/nshmp-lib/gov/usgs/earthquake/nshmp/gmm/Gmm.html
    
    % Specify an intensity measure type (IMT). IMT identifiers:
    
    % https://earthquake.usgs.gov/nshmp/docs/nshmp-lib/gov/usgs/earthquake/nshmp/gmm/Imt.html
    
    % Do a calculation. The MatUtil.calc(gmm, imt, gmmInput) method returns an
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    % array of [ln(median ground motion), sigma]
    
    result = hazMat.gmmMean(gmm, imt, input)
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    
    % =========================================================================
    % Determinisitic response spectrum calculation:
    
    
    % The object returned by the MatUtil.spectrum(gmm, gmmInput) method may
    % be dumped into a struct.
    
    spectrumResult = struct(hazMat.gmmSpectrum(gmm, input))
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    % =========================================================================