diff --git a/etc/README.md b/etc/README.md index b9f59f31f577fd027c8fa86ebf375e87c664b0b3..651a7d888630e3e5e99c3d0a769fa304ffe007e4 100644 --- a/etc/README.md +++ b/etc/README.md @@ -3,13 +3,10 @@ See the [examples](examples) directory as a starting point for command-line use of `nshmp-haz`. -[Matlab](matlab) provides scripts for how to complete calculations for ground motion models -used in this repository. +The [Matlab](matlab) directory provides scripts for how to perform hazard calculations +in this repository. -For hazard calculations based on code in this repository, please see the Matlab scripts in -[Matlab](matlab). - -To use the `nshmp-haz` ground motion model implementations directly, please see the Matlab +To perform ground motion model (GMM) implementations directly, please see the Matlab scripts in [`nshmp-ws`](../../nshmp-ws/etc/matlab). [Nshm](nshm) contains site lists and map polygons commonly used by the USGS NSHMP. diff --git a/etc/matlab/gmm-inputs.csv b/etc/matlab/gmm-inputs.csv deleted file mode 100644 index dc4f5e207506b53a41b5e7fe9a0fc78178b47392..0000000000000000000000000000000000000000 --- a/etc/matlab/gmm-inputs.csv +++ /dev/null @@ -1,38 +0,0 @@ - dip, -0, -2.5, -5, -7.5, -10, -12.5, -15, -17.5, -20, -22.5, -25, -27.5, -30, -32.5, -35, -37.5, -40, -42.5, -45, -47.5, -50, -52.5, -55, -57.5, -60, -62.5, -65, -67.5, -70, -72.5, -75, -77.5, -80, -82.5, -85, -87.5, -90, \ No newline at end of file diff --git a/etc/matlab/gmmBatchExample.m b/etc/matlab/gmmBatchExample.m deleted file mode 100644 index eadd4d9a276d9a689f20b8662c35243507ebb19f..0000000000000000000000000000000000000000 --- a/etc/matlab/gmmBatchExample.m +++ /dev/null @@ -1,96 +0,0 @@ -%% nshmp-haz Ground Motion Model (GMM) batch processing example script - -clear; - -%% Read CSV file of GMM inputs -% -% Each column of the CSV file is a GMM input parameter with the -% first row dictating that GMM input field. -% -% Example CSV to change only dip: -% dip, -% 0.0, -% 45.0, -% 90.0, -% -% For a full list of GMM input paramters see: -% https://earthquake.usgs.gov/nshmp/docs/nshmp-lib/gov/usgs/earthquake/nshmp/gmm/GmmInput.html -% -% If 'null' is supplied as a value or a GMM input field and values are -% not given, the default values are used: -% https://earthquake.usgs.gov/nshmp/docs/nshmp-lib/gov/usgs/earthquake/nshmp/gmm/GmmInput.Builder.html#withDefaults() -inputs = fileread('gmm-inputs.csv'); - - -%% URL to POST the CSV file of GMM inputs -% -% Must update the URL host if not on localhost. -% -% The GMMs must be specified in the URL query string. -% -% All GMM services are available to call for batch processing. -host = 'http://localhost:8080'; - -service = '/nshmp-haz/gmm/spectra'; - -query = 'gmm=AB_06_PRIME&gmm=CAMPBELL_03&gmm=FRANKEL_96'; - -url = strcat(host, service, '?', query); - - -%% Set the response to JSON. -% -% The HTTP POST response is in JSON format. -options = weboptions('ContentType', 'json'); - - -%% Conduct HTTP POST Request -% -% Conduct a HTTP POST request, sending the CSV file of GMM inputs. -% -% The POST response is loaded into a structure -% following the returned JSON structure. -svcResponse = webwrite(url, inputs, options); - - -%% Check Response -% -% Check to see if the response returned an error and check -% to see if the field 'response' exists in the structure. -% -% If the URL does not contain a query string of GMMs the response -% returned will be the service usage. -if strcmp('error', svcResponse.status) || ~isfield(svcResponse, 'response') - return; -end - - -%% Retreive the data -% -% Loop through each response spectrum response and obtain the means -% and sigmas. -for response = svcResponse.response' - - % Request structure contains the GMMs and GMM input parameters used - request = response.request; - - % The GMMs used for the calculation - gmms = request.gmms; - - % The GMM input parameters used for the calculation - gmmInput = request.input; - - % Get the means - for means = response.means.data - data = means.data; - xMeans = data.xs; - yMeans = data.ys; - end - - % Get the sigmas - for sigmas = response.sigmas.data - data = sigmas.data; - xSigmas = data.xs; - ySigmas = data.ys; - end -end diff --git a/etc/matlab/gmmExample.m b/etc/matlab/gmmExample.m deleted file mode 100644 index ef643803018d3a8fd90b178486a7ff0a4de362a7..0000000000000000000000000000000000000000 --- a/etc/matlab/gmmExample.m +++ /dev/null @@ -1,73 +0,0 @@ -%% nshmp-haz Ground Motion Model (GMM) calculator example script - -% ========================================================================= -% This script provides instruction on how to access ground motion models -% (GMMs) implemented in the nshmp-haz library. -% -% See the README for instructions on how to set up Matlab to use nshmp-haz. -% ========================================================================= - -clear - -% Specify path to nshmp-haz library: -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 -gmm = 'ASK_14'; - -% Specify an intensity measure type (IMT). IMT identifiers: -% https://earthquake.usgs.gov/nshmp/docs/nshmp-lib/gov/usgs/earthquake/nshmp/gmm/Imt.html -imt = 'PGA'; - -% Do a calculation. The MatUtil.calc(gmm, imt, gmmInput) method returns an -% array of [ln(median ground motion), sigma] -result = hazMat.gmmMean(gmm, imt, input) - -% ========================================================================= -% 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)) -% ========================================================================= diff --git a/etc/matlab/hazard_curves.m b/etc/matlab/hazard_curves.m index 946592d0c2001e69086447eacf5fe45e2897b48c..202c6b4e02f71827de910cff42b1edbba1b14d4c 100644 --- a/etc/matlab/hazard_curves.m +++ b/etc/matlab/hazard_curves.m @@ -5,7 +5,7 @@ % Author: Demi Girot (dgirot@usgs.gov) % Peter Powers (pmpowers@usgs.gov) % -% Updated: 05/16/2023 +% Updated: 05/23/2023 % % This script demonstrates how to call web services for the hazard % calculations implemented in USGS National Sesmic Hazard Models and plot @@ -29,8 +29,10 @@ urlbase = "https://earthquake.usgs.gov/ws/nshmp/conus-2018/dynamic/hazard/"; % If you are running nshmp-haz locally, use this URL: % urlbase = "http://localhost:8080/hazard/"; -% Struct of input parameters: +% Location input for plot title at.location = 'Denver, Colorado'; + +% Struct of input parameters: in.longitude = -104.992; in.latitude = 39.74; in.vs30 = 760; @@ -51,7 +53,10 @@ function plotHazard(hazard, in, at) plot_handles = []; legend_labels = {}; + % Struct for hazard data data = hazard.data; + + % imt display in plot title imt = hazard.imt.display; for j = 1 : length(data) @@ -76,14 +81,12 @@ function plotHazard(hazard, in, at) xlabel('Ground Motion (g)') ylabel('Annual Frequency of Exceedance') title(string(at.location),'FontSize',20) - subtitle(['(' num2str(in.latitude) ',' num2str(in.longitude) '), ' num2str(imt)],'FontSize',16) + subtitle(['(' num2str(in.latitude) ',' num2str(in.longitude) '), '... + num2str(imt)],'FontSize',16) set(gca,'FontSize',20) - legend( ... - plot_handles,legend_labels, ... - 'Location','best', ... - 'Interpreter', 'none'); + legend(plot_handles,legend_labels,'Location','best'); end @@ -101,6 +104,7 @@ url = url + ... "&maxdir=" + string(in.maxdir) + ... "&imt=" + string(in.imt); +% Timeout increased to compute hazard calculations options = weboptions('Timeout',30); response = webread(url,options); diff --git a/etc/matlab/response_spectra.m b/etc/matlab/response_spectra.m deleted file mode 100644 index bb9bc73c7228d8706d13fcd231d4ed37e3d64a38..0000000000000000000000000000000000000000 --- a/etc/matlab/response_spectra.m +++ /dev/null @@ -1,139 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% Response spectra web service example -% -% Author: Demi Girot (dgirot@usgs.gov) -% Peter Powers (pmpowers@usgs.gov) -% -% Created: 09/16/2021 -% Updated: 01/12/2022 -% -% This script assembles a response spectra web service URL request, makes -% the request, places the result in a struct, and generates a simple plot. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Create web service URL -clearvars -% The root url for the response spectra web service -urlbase = "https://staging-earthquake.usgs.gov/ws/nshmp/data/gmm/spectra?"; - -% The ground motion models (GMMs) of interest -% -% For allowed identifiers, see: -% https://earthquake.usgs.gov/nshmp/docs/nshmp-lib/gov/usgs/earthquake/nshmp/gmm/Gmm.html -gmms = ["BJF_97" "CB_03" "CY_14"]; - -% Ground motion model parameters -Mw = 6.5; -dip = 90; -rake = 0; -width = 14; -rJB = 10; -rRup = 10.012; -rX = 10; -vs30 = 760; -zHyp = 7.5; -zTop = 0.5; - -url = createUrl( ... - urlbase, gmms, ... - Mw, dip, rake, width, rJB, rRup, rX, vs30, zHyp, zTop); -%% Call web service - -% Open a browser window with the web service URL to show the JSON response -web(url); - -% Call the web service and place response in a struct -data = webread(url); - -%% Summary of each GMM dataset - -means = data.response.means.data; -sigmas = data.response.sigmas.data; - -c = newline; - -for i=1:length(means) - gmm = ... - "GMM: " + means(i).label + c + ... - "Periods: " + mat2str(means(i).data.xs') + c + ... - "Means: " + mat2str(means(i).data.ys') + c + ... - "Sigmas: " + mat2str(sigmas(i).data.ys') -end - -%% Make a simple plot of means data with epistemic uncertainty from web -% service response - -figure(1) -cla - -plot_handles = []; -legend_labels = {}; - -% loop means response array -for i = 1:length(means) - disp(means(i)) - - gmm_id = means(i).id; - gmm_label = means(i).label; - gmm_xs = means(i).data.xs; - gmm_ys = means(i).data.ys; - epi_tree = means(i).tree; - - % Plot the total spectrum - PH = semilogx(gmm_xs, gmm_ys, 'LineWidth', 2); - hold on; grid on - plot_handles = [plot_handles PH]; - legend_labels{end+1} = gmm_id; - - % Plot epistemic spectra, if present - if ~isempty(epi_tree) - for j = 1 : length(epi_tree) - epi_branch = epi_tree(j); - epi_label = epi_branch.id; - epi_ys = epi_branch.values; - PHE = semilogx(gmm_xs, epi_ys,'LineWidth',1,'LineStyle','--','Color',PH.Color); - plot_handles = [plot_handles PHE]; - legend_labels{end+1} = [gmm_id ' ' epi_label]; - end - - end -end - -xlabel('Periods (sec)','FontSize',12) -ylabel('Median Ground Motion (g)','FontSize',12) -title('Ground Motion vs Response Spectra (Means)', 'FontSize', 14) -axis([0.001 10 0.005 0.8]); -set(gca, 'FontSize', 12); -set(gca, 'XTick', [0.01 0.1 1 10]); -set(gca, 'XTickLabel', {'0.01','0.1','1','10'}); - -l = legend(plot_handles, legend_labels, 'Location', 'northwest'); -set(l, 'Interpreter', 'none') - - -%% Build URL function - -function url = createUrl( ... - urlbase, gmms, ... - Mw, dip, rake, width, rJB, rRup, rX, vs30, zHyp, zTop) - - url = urlbase; - for i = 1:size(gmms, 2) - if i == 1 - url = url + "gmm=" + gmms(i); - else - url = url + "&gmm=" + gmms(i); - end - end - url = url + ... - "&Mw=" + num2str(Mw) + ... - "&dip=" + num2str(dip) + ... - "&rake=" + num2str(rake) + ... - "&width=" + num2str(width) + ... - "&rJB=" + num2str(rJB) + ... - "&rRup=" + num2str(rRup) + ... - "&rX=" + num2str(rX) + ... - "&vs30=" + num2str(vs30) + ... - "&zHyp=" + num2str(zHyp) + ... - "&zTop=" + num2str(zTop); -end