Skip to content

Commit

Permalink
initial push on ste
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov committed Apr 30, 2024
1 parent 077f525 commit e0638a9
Show file tree
Hide file tree
Showing 18 changed files with 557 additions and 1 deletion.
Binary file added examples/data/loads/block_maxima.mat
Binary file not shown.
Binary file added examples/data/loads/example_qoi.mat
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/data/loads/sine_wave.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
t_peaks,peaks
0.015,0.809016994
0.035,0.809016994
0.05,1
0.065,0.809016994
0.085,0.809016994
0.1,1
0.115,0.809016994
0.135,0.809016994
0.15,1
0.165,0.809016994
0.185,0.809016994
0.2,1
0.215,0.809016994
0.235,0.809016994
Binary file added examples/data/loads/ste.mat
Binary file not shown.
Binary file added examples/short_term_extremes_example.mlx
Binary file not shown.
44 changes: 44 additions & 0 deletions mhkit/loads/extreme/block_maxima.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function block_maxima = block_maxima(t, x, t_st)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Find the block maxima of a time-series.
%
% The timeseries (t,x) is divided into blocks of length t_st, and the
% maxima of each block is returned.
%
% Parameters
% ----------
% t : array
% Time array
% x : array
% Global peaks time-series
% t_st : double
% Short-term period
%
% Returns
% -------
% block_maxima : array
% Block maxima (i.e. largest peak in each block)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isa(t,'numeric')
error('ERROR: t must be a double array')
end
if ~isa(x,'numeric')
error('ERROR: x must be a double array')
end
if ~isa(t_st,'double')
error('ERROR: t_st must be a double')
end

py.importlib.import_module('mhkit');

t = py.numpy.array(t);
x = py.numpy.array(x);

result = py.mhkit.loads.extreme.block_maxima(t, x, t_st);

block_maxima = double(result);

end
45 changes: 45 additions & 0 deletions mhkit/loads/extreme/global_peaks.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function [t_peaks,peaks] = global_peaks(t,data)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Find the global peaks of a zero-cenered response time-series.
%
% The global peaks are the maxima between consecutive zero
% up-crossings.
%
% Parameters
% ----------
% t : array
% Time array
% data: array
% Response time-series
%
% Returns
% -------
% t_peaks : array
% Time array for peaks
% peaks : array
% Peak values of the response time-series
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isa(t,'numeric')
error('ERROR: t must be a double array')
end
if ~isa(data,'numeric')
error('ERROR: data must be a double array')
end

py.importlib.import_module('mhkit');

t = py.numpy.array(t);
data = py.numpy.array(data);

result = py.mhkit.loads.extreme.global_peaks(t, data);

t_peaks = double(result{1});
peaks = double(result{2});

end



22 changes: 22 additions & 0 deletions mhkit/loads/extreme/number_of_short_term_peaks.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function n_st = number_of_short_term_peaks(n, t, t_st)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Estimate the number of peaks in a specified period.
%
% Parameters
% ----------
% n : int
% Number of peaks in analyzed timeseries.
% t : double
% Length of time of analyzed timeseries.
% t_st : double
% Short-term period for which to estimate the number of peaks.
%
% Returns
% -------
% n_st : double
% Number of peaks in short term period.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n_st = n * t_st / t;
57 changes: 57 additions & 0 deletions mhkit/loads/extreme/peaks_distribution_peaks_over_threshold.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function [pks, result] = peaks_distribution_peaks_over_threshold(peaks, x, method, options)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Estimate the peaks distribution by fitting a Weibull
% distribution to the peaks of the response.
%
% To learn more about the methods that can be used in this function,
% refer to the scipy.stats.rv_continuous methods documentation!
%
% Parameters
% ----------
% peaks : array
% Global peaks
% x : array or double
% Input for the statistical function/method
% method : str
% Statistical method to apply to resulting data. Options to
% choose from are: "pdf", "cdf", "ppf", or "sf"
% threshold : double or int (optional)
% Threshold value. Only peaks above this value will be used.
% Default value calculated as: `mean(x) + 1.4 * std(x)`
% Returns
% -------
% p : array or double
% Probability distribution of the peaks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

arguments
peaks
x
method
options.threshold double
end

if ~isa(peaks,'numeric')
error('ERROR: peaks must be a double array')
end
if ~isa(method,'string')
error('ERROR: method must be a string')
end

py.importlib.import_module('mhkit');

p = py.numpy.array(peaks);
x = py.numpy.array(x);

if exist("threshold", 'var')==1
result = py.mhkit.loads.extreme.peaks_distribution_peaks_over_threshold(p, options.threshold);
else
result = py.mhkit.loads.extreme.peaks_distribution_peaks_over_threshold(p);
end
stat = py.mhkit_python_utils.scipy_stats.convert_to_array(result, x, method);

pks = double(stat);

end
46 changes: 46 additions & 0 deletions mhkit/loads/extreme/peaks_distribution_weibull.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function [pks, result] = peaks_distribution_weibull(peaks, x, method)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Estimate the peaks distribution by fitting a Weibull
% distribution to the peaks of the response.
%
% To learn more about the methods that can be used in this function,
% refer to the scipy.stats.rv_continuous methods documentation!
%
% Parameters
% ----------
% peaks : array
% Global peaks
% x : array or double
% Input for the statistical function/method
% method : str
% Statistical method to apply to resulting data. Options to
% choose from are: "pdf", "cdf", "ppf", or "sf"
%
% Returns
% -------
% p : array or double
% Probability distribution of the peaks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isa(peaks,'numeric')
error('ERROR: peaks must be a double array')
end

if ~isa(method,'string')
error('ERROR: method must be a string')
end

py.importlib.import_module('mhkit');

p = py.numpy.array(peaks);
x = py.numpy.array(x);

result = py.mhkit.loads.extreme.peaks_distribution_weibull(p);

stat = py.mhkit_python_utils.scipy_stats.convert_to_array(result, x, method);

pks = double(stat);

end
45 changes: 45 additions & 0 deletions mhkit/loads/extreme/peaks_distribution_weibull_tail_fit.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function [pks, result] = peaks_distribution_weibull_tail_fit(peaks, x, method)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Estimate the peaks distribution by using the Weibull tail fit method.
%
% To learn more about the methods that can be used in this function,
% refer to the scipy.stats.rv_continuous methods documentation!
%
% Parameters
% ----------
% peaks : array
% Global peaks
% x : array or double
% Input for the statistical function/method
% method : str
% Statistical method to apply to resulting data. Options to
% choose from are: "pdf", "cdf", "ppf", or "sf"
%
% Returns
% -------
% p : array or double
% Probability distribution of the peaks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isa(peaks,'numeric')
error('ERROR: peaks must be a double array')
end

if ~isa(method,'string')
error('ERROR: method must be a string')
end

py.importlib.import_module('mhkit');

p = py.numpy.array(peaks);
x = py.numpy.array(x);

result = py.mhkit.loads.extreme.peaks_distribution_weibull_tail_fit(p);

stat = py.mhkit_python_utils.scipy_stats.convert_to_array(result, x, method);

pks = double(stat);

end
60 changes: 60 additions & 0 deletions mhkit/loads/extreme/short_term_extreme.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function ste = short_term_extreme(t, data, t_st, type, x, method)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Estimate the peaks distribution by fitting a Weibull
% distribution to the peaks of the response.
%
% To learn more about the methods that can be used in this function,
% refer to the scipy.stats.rv_continuous methods documentation!
%
% Parameters
% ----------
% t : array
% Time array
% data : array
% Response timeseries
% t_st : double or int
% Short time period
% type : string
% Method for estimating the short-term extreme distribution
% x : array or double
% Input for the statistical function/method
% method : str
% Statistical method to apply to resulting data. Options to
% choose from are: "pdf", "cdf", "ppf", or "sf"
%
% Returns
% -------
% ste : array or double
% Probability distribution of the peaks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isa(t,'numeric')
error('ERROR: t must be a double array')
end
if ~isa(data,'numeric')
error('ERROR: data must be a double array')
end
if ~isa(t_st,'numeric')
error('ERROR: t_st must be a double')
end
if ~isa(type,'string')
error('ERROR: type must be a string')
end
if ~isa(method,'string')
error('ERROR: method must be a string')
end

py.importlib.import_module('mhkit');

t = py.numpy.array(t);
data = py.numpy.array(data);

result = py.mhkit.loads.extreme.short_term_extreme(t, data, t_st, type);

stat = py.mhkit_python_utils.scipy_stats.convert_to_array(result, x, method);

ste = double(stat);

end
46 changes: 46 additions & 0 deletions mhkit/loads/extreme/ste_block_maxima_gev.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function ste = ste_block_maxima_gev(block_maxima, x, method)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Approximate the short-term extreme distribution using the block
% maxima method and the Generalized Extreme Value distribution.
%
% To learn more about the methods that can be used in this function,
% refer to the scipy.stats.rv_continuous methods documentation!
%
% Parameters
% ----------
% block_maxima : array
% Block maxima (i.e. largest peak in each block).
% x : array
% Input for the statistical function/method
% method : str
% Statistical method to apply to resulting data. Options to
% choose from are: "pdf", "cdf", "ppf", or "sf"
%
% Returns
% -------
% block_maxima : array
% Block maxima (i.e. largest peak in each block)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isa(block_maxima,'numeric')
error('ERROR: block_maxima must be a double array')
end

if ~isa(method,'string')
error('ERROR: method must be a string')
end

py.importlib.import_module('mhkit');

block_maxima = py.numpy.array(block_maxima);
x = py.numpy.array(x);

result = py.mhkit.loads.extreme.ste_block_maxima_gev(block_maxima);

stat = py.mhkit_python_utils.scipy_stats.convert_to_array(result, x, method);

ste = double(stat);

end
Loading

0 comments on commit e0638a9

Please sign in to comment.