-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aplicar_API.m
106 lines (82 loc) · 3.68 KB
/
Aplicar_API.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
% ********** ******* *** **************
% ********** ******** *** **************
% ** ** **** ***** ***
% ** ** **** ******* ***
% ** ** **** ********* ***
% ** ** **** *** **** ***
% ** ** **** *** **** ***
% ** ** **** **************** ***
% ** ** **** ****************** ***
% ** ** **** *** *** ***
% ********** ******** *** *** ***
% ********** ******* *** **** ***
% Standardized Drought Analysis Toolbox (SDAT)
% This code can be used to generate standardized indicators such as:
% - SPI: Standardized Precipitation Index
% - SSI: Standardized Soil Moisture Index
% - SRI: Standardized Runoff Index
% (also known as Standardized Streamflow Index, SSFI)
% - SRHI: Standardized Relative Humidity Index
% - SGI: Standardised Groundwater level Index
% - Standardized Surface Water Supply Index (SSWSI)
% - Standardized Water Storage Index (SWSI)
% Input data should be a vector of precipitation, soil moisture, etc.
% sc: scale of the index
% Release 02/01/2015
%Refrences:
%Farahmand A., AghaKouchak A., 2015, A Generalized Framework for Deriving Nonparametric Standardized Drought Indicators, Advances in Water Resources, 76, 140-145, doi: 10.1016/j.advwatres.2014.11.012
%download reference: http://amir.eng.uci.edu/publications/15_Drought_Standardized_Index_AWR.pdf
%Hao Z., AghaKouchak A., Nakhjiri N., Farahmand A., 2014, Global Integrated Drought Monitoring and Prediction System, Scientific Data, 1:140001, 1-10, doi: 10.1038/sdata.2014.1.
%download reference: http://www.nature.com/articles/sdata20141
% Please read the disclaimer before using SDAT (Disclaimer.txt). By using SDAT users agree with the disclaimer.
pkg load statistics
files = dir("C:/Users/Usuario/Documents/Sequia/acomodar_estaciones/todas/spi/");
for j=3:length(files)
m= strcat("C:/Users/Usuario/Documents/Sequia/acomodar_estaciones/todas/spi/",files(j).name);
% Sample input data (e.g., a vector of precipitation data);
k = load(m);
td=k;
% sc: scale of the index (>1, e.g., 3-month SPI or SSI)
%sc=3; sc=6;
sc=9;
n=length(td);
SI=zeros(n,1);
% Compute the SPI for each grid from the prcp or smc data
%For some grid, no observation exist.
if length(td(td>=0))/length(td)~=1
SI(n,1)=nan;
else
% Obtain the prcp and smc for the specified time scale and
% compute the standarized drought index (for SPI and SSI)
SI(1:sc-1,1)=nan;
A1=[];
for i=1:sc,
A1=[A1,td(i:length(td)-sc+i)];
end
Y=sum(A1,2);
% Compute the SPI or SSI
nn=length(Y);
SI1=zeros(nn,1);
for k=1:12
d=Y(k:12:nn);
%compute the empirical probability
nnn=length(d);
bp=zeros(nnn,1);
for i=1:nnn
bp(i,1)=sum(d(:,1)<=d(i,1));
end
y=(bp-0.44)./(nnn+0.12);
SI1(k:12:nn,1)=y;
end
SI1(:,1)=norminv(SI1(:,1));
%output
SI(sc:end,1)=SI1;
end
%plot vector
plot(SI, 'linewidth',1.5)
xlabel('time step')
%Modify "time step"
ylabel('Standardized Precipitation Index')
nombre_salida = strcat("C:/Users/Usuario/Documents/Sequia/acomodar_estaciones/todas/spi_salida/","spi_9_meses_",files(j).name)
dlmwrite(nombre_salida,SI);
end