Home > TOSSH > TOSSH_code > signature_functions > sig_Q_n_day_min.m

sig_Q_n_day_min

PURPOSE ^

Q_n_day_min calculates n day minimum of flow time series.

SYNOPSIS ^

function [Q_n_day_min, error_flag, error_str] = sig_Q_n_day_min(Q, t, n_day)

DESCRIPTION ^

Q_n_day_min calculates n day minimum of flow time series.
   
   INPUT
   Q: streamflow [mm/timestep]
   t: time [Matlab datetime]
   n_day: window over which minimum should be calculated

   OUTPUT
   Q_n_day_min: n day minimum of flow [mm/n_day]
   error_flag: 0 (no error), 1 (warning), 2 (error in data check), 3
       (error in signature calculation)
   error_str: string contraining error description

   EXAMPLE
   % load example data 
   data = load('example/example_data/33029_daily.mat'); 
   Q = data.Q; 
   t = data.t;
   Q_n_day_min = sig_Q_n_day_min(Q, t, 7);
   Q_n_day_min = sig_Q_n_day_min(Q, t, [1:7]);

   Copyright (C) 2020
   This software is distributed under the GNU Public License Version 3.
   See <https://www.gnu.org/licenses/gpl-3.0.en.html> for details.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Q_n_day_min, error_flag, error_str] = sig_Q_n_day_min(Q, t, n_day)
0002 %Q_n_day_min calculates n day minimum of flow time series.
0003 %
0004 %   INPUT
0005 %   Q: streamflow [mm/timestep]
0006 %   t: time [Matlab datetime]
0007 %   n_day: window over which minimum should be calculated
0008 %
0009 %   OUTPUT
0010 %   Q_n_day_min: n day minimum of flow [mm/n_day]
0011 %   error_flag: 0 (no error), 1 (warning), 2 (error in data check), 3
0012 %       (error in signature calculation)
0013 %   error_str: string contraining error description
0014 %
0015 %   EXAMPLE
0016 %   % load example data
0017 %   data = load('example/example_data/33029_daily.mat');
0018 %   Q = data.Q;
0019 %   t = data.t;
0020 %   Q_n_day_min = sig_Q_n_day_min(Q, t, 7);
0021 %   Q_n_day_min = sig_Q_n_day_min(Q, t, [1:7]);
0022 %
0023 %   Copyright (C) 2020
0024 %   This software is distributed under the GNU Public License Version 3.
0025 %   See <https://www.gnu.org/licenses/gpl-3.0.en.html> for details.
0026 
0027 % check input parameters
0028 if nargin < 3
0029     error('Not enough input arguments.')
0030 end
0031 
0032 ip = inputParser;
0033 ip.CaseSensitive = true;
0034 
0035 % required input arguments
0036 % time series have to be numeric and either a (n,1) or a (1,n) vector
0037 addRequired(ip, 'Q', @(Q) isnumeric(Q) && (size(Q,1)==1 || size(Q,2)==1)) 
0038 % date time series has to be numeric or datetime and either a (n,1) or a (1,n) vector
0039 addRequired(ip, 't', @(t) (isnumeric(t) || isdatetime(t)) && (size(t,1)==1 || size(t,2)==1)) 
0040 % n_day has to be numeric and either a (n,1) or a (1,n) vector
0041 addRequired(ip, 'n_day', @(n_day) isnumeric(n_day) && (size(n_day,1)==1 || size(n_day,2)==1))
0042 
0043 parse(ip, Q, t, n_day)
0044 
0045 % data checks
0046 [error_flag, error_str, timestep, t] = util_DataCheck(Q, t);
0047 if error_flag == 2
0048     Q_n_day_min = NaN;
0049     return
0050 end
0051 
0052 if any(n_day<1 | n_day>length(t)) || any(floor(n_day)~=n_day)
0053     error('Month has to be a vector containing integers between 1 and length(timeseries).')
0054 end
0055 
0056 % calculate signature
0057 Q_n_day_min = NaN(length(n_day),1);
0058 for i=1:length(n_day)
0059     Q_n_day_min(i) = n_day(i)*min(movmean(Q,n_day(i))); % returns value in mm per chosen window n_day
0060 end
0061 
0062 end

Generated on Tue 02-Feb-2021 09:27:04 by m2html © 2005