Newer
Older
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/CST_Analogs.R
\name{Analogs}
\alias{Analogs}
\title{Search for analogs based on large scale fields.}
\usage{
Analogs(expL, obsL, time_obsL, expVar = NULL, obsVar = NULL,
region = NULL, nAnalogs = 1, return_list = FALSE)
}
\arguments{
\item{expL}{an array of N named dimensions containing the experimental field
on the large scale for which the analog is aimed. This field is used to in
all the criterias. If parameter 'expVar' is not provided, the function will
return the expL analog. The element 'data' in the 's2dv_cube' object must
have, at least, latitudinal and longitudinal dimensions. The object is
expect to be already subset for the desired large scale region.}
\item{obsL}{an array of N named dimensions containing the observational field
on the large scale. The element 'data' in the 's2dv_cube' object must have
the same latitudinal and longitudinal dimensions as parameter 'expL' and a
temporal dimension with the maximum number of available observations.}
\item{expVar}{an array of N named dimensions containing the experimental
field on the local scale, usually a different variable to the parameter
'expL'. If it is not NULL (by default, NULL), the returned field by this
function will be the analog of parameter 'expVar'.}
\item{obsVar}{an array of N named dimensions containing the field of the same variable as the passed in parameter 'expVar' for the same region.}
\item{criteria}{a character string indicating the criteria to be used for the selection of analogs:
\itemize{
\item{Large_dist} minimal distance in the large scale pattern;
\item{Local_dist} minimal distance in the large scale pattern and minimal
distance in the local scale pattern; and
\item{Local_cor} minimal distance in the large scale pattern, minimal
distance in the local scale pattern and maxima correlation in the
local variable to downscale.}}
\item{lonVar}{a vector containing the longitude of parameter 'expVar'.}
\item{latVar}{a vector containing the latitude of parameter 'expVar'.}
\item{region}{a vector of length four indicating the minimum longitude,
the maximum longitude, the minimum latitude and the maximum latitude.}
\item{nAnalogs}{number of Analogs to be selected to apply the criterias (this
is not the necessary the number of analogs that the user can get, but the number
of events with minimal distance in which perform the search of the best Analog.
The default value for the Large_dist criteria is 1, the default value for
the Local_dist criteria is 10 and same for Local_cor. If return_list is
False you will get just the first one for downscaling purposes. If return_list
is True you will get the list of the best analogs that were searched in nAnalogs
under the selected criterias.}
\item{return_list}{TRUE if you want to get a list with the best analogs FALSE
#'if not.}
dowscaled values of the best analogs for the criteria selected.
This function perform a downscaling using Analogs. To compute
the analogs, the function search for days with similar large scale conditions
to downscaled fields in the local scale.
The large scale and the local scale regions are defined by the user.
The large scale is usually given by atmospheric circulation as sea level
pressure or geopotential height (Yiou et al, 2013) but the function gives the
possibility to use another field. The local scale will be usually given by
precipitation or temperature fields, but might be another variable.
The analogs function will find the best analogs based in three criterias:
(1) Minimal distance in the large scale pattern (i.e. SLP)
(2) Minimal distance in the large scale pattern (i.e. SLP) and minimal
distance in the local scale pattern (i.e. SLP).
(3) Minimal distance in the large scale pattern (i.e. SLP), minimal
distance in the local scale pattern (i.e. SLP) and maxima correlation in the
local variable to downscale (i.e Precipitation).
The search of analogs must be done in the longest dataset posible. This is
important since it is necessary to have a good representation of the
possible states of the field in the past, and therefore, to get better
analogs. Once the search of the analogs is complete, and in order to used the
three criterias the user can select a number of analogsi, using parameter
'nAnalogs' to restrict
the selection of the best analogs in a short number of posibilities, the best
ones.
This function has not constrains of specific regions, variables to downscale,
or data to be used (seasonal forecast data, climate projections data,
reanalyses data).
The regrid into a finner scale is done interpolating with CST_Load.
Then, this interpolation is corrected selecting the analogs in the large
and local scale in based of the observations.
The function is an adapted version of the method of Yiou et al 2013.
}
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
require(zeallot)
# Example 1:Large_dist
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*2)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
downscale_field <- Analogs(expL, obsL, time_obsL)
layout(matrix(1:3,1,3,byrow=T))
image(expL,main="expL")
image(downscale_field$AnalogsFields,
main=paste0("Best_Analog ",downscale_field$DatesAnalogs))
# Example 2:Large_dist imposing nAnalogs and return_list
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:1980),expL*1.5)
dim(obsL) <- c(lat = 4, lon = 5, time = 100)
time_obsL <- paste(rep("01", 100), rep("01", 100), 1920 : 2019, sep = "-")
nAnalogs=30
downscale_field <- Analogs(expL, obsL, time_obsL,nAnalogs=nAnalogs,return_list = TRUE)
str(downscale_field)
plot.new()
layout(matrix(1:3,1,3,byrow=T))
image(expL,main="expL")
image(downscale_field$AnalogsFields[,,1],
main=paste0("Best_Analog ",downscale_field$DatesAnalogs[1]))
image(downscale_field$AnalogsFields[,,2],
main=paste0("2nd Best_Analog ",downscale_field$DatesAnalogs[2]))
# Example 3:Local_dist with obsVar and expVar return_list = FALSE
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*2)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar <- expL[1:3,1:3]
dim(expVar) <- c(lat = 3, lon = 3)
obsVar <- obsL[1:3,1:3,1:10]
dim(obsVar) <- c(lat = 3, lon = 3, time = 10)
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_scale <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,obsVar=obsVar,expVar=expVar,
criteria="Local_dist",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 5, return_list = FALSE)
plot.new()
layout(matrix(1:3,1,3,byrow=T))
image(expL,main="expL")
image(expVar,main="expVar")
image(Local_scale$AnalogsFields,
main=paste0("Best_Analog ",Local_scale$DatesAnalogs))
# Example 4:Large_dist and Local_dist analogs. Local_dist with obsVar and expVar. return_list = FALSE in both
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*5)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar <- expL[1:3,1:3]
dim(expVar) <- c(lat = 3, lon = 3)
obsVar <- obsL[1:3,1:3,1:10]
dim(obsVar) <- c(lat = 3, lon = 3, time = 10)
# analogs of large scale using criteria 1
Large_scale <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,
criteria="Large_dist",
nAnalogs = 10, return_list = FALSE)
# analogs of local scale using criteria 2
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_scale <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,obsVar=obsVar,expVar=expVar,
criteria="Local_dist",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 10, return_list = FALSE)
plot.new()
layout(matrix(1:4,2,2,byrow=T))
image(expL,main="expL")
image(Large_scale$AnalogsFields,
main=paste0("Best_Analog ",Large_scale$DatesAnalogs))
image(expVar,main="expVar")
image(Local_scale$AnalogsFields,
main=paste0("Best_Analog ",Local_scale$DatesAnalogs))
# Example 5: Local_dist without obsVar and expVar
expL <- rnorm(1:20)
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
obsL <- c(rnorm(1:180),expL*2)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_scale2 <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,
criteria="Local_dist",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 10, return_list = FALSE)
plot.new()
layout(matrix(1:4,2,2,byrow=T))
image(expL,main="expL")
image(Local_scale2$AnalogsFields,
main=paste0("Best_Analog ",Local_scale2$DatesAnalogs))
image(expVar,main="expVar")
image(Local_scale$AnalogsFields,
main=paste0("Best_Analog ",Local_scale$DatesAnalogs))
# Example 6:Local_dist with obsVar and expVar return_list = TRUE
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*2)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar <- expL[1:3,1:3]
dim(expVar) <- c(lat = 3, lon = 3)
obsVar <- obsL[1:3,1:3,1:10]
dim(obsVar) <- c(lat = 3, lon = 3, time = 10)
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_scale <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,obsVar=obsVar,expVar=expVar,
criteria="Local_dist",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 5, return_list = TRUE)
str(Local_scale)
# Example 7: Local_cor with obsVar and expVar return_list = FALSE
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*5)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar <- expL[1:3,1:3]
dim(expVar) <- c(lat = 3, lon = 3)
obsVar <- obsL[1:3,1:3,1:10]
dim(obsVar) <- c(lat = 3, lon = 3, time = 10)
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_corr <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,obsVar=obsVar,expVar=expVar,
criteria="Local_cor",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 5, return_list = FALSE)
plot.new()
layout(matrix(1:3,1,3,byrow=T))
image(expL,main="expL")
image(expVar,main="expVar")
image(Local_corr$AnalogsFields[,,1],
main=paste0("Best_Analog ",Local_corr$DatesAnalogs[1]))
# Example 8: Local_cor return list TRUE
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*5)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar <- expL[1:3,1:3]
dim(expVar) <- c(lat = 3, lon = 3)
obsVar <- obsL[1:3,1:3,1:10]
dim(obsVar) <- c(lat = 3, lon = 3, time = 10)
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_corr <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,obsVar=obsVar,expVar=expVar,
criteria="Local_cor",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 5, return_list = TRUE)
plot.new()
layout(matrix(1:4,2,2,byrow=T))
image(expL,main="expL")
image(expVar,main="expVar")
image(Local_corr$AnalogsFields[,,1],
main=paste0("Best_Analog ",Local_corr$DatesAnalogs[1]))
image(Local_corr$AnalogsFields[,,2],
main=paste0("2nd Best_Analog ",Local_corr$DatesAnalogs[2]))
# Example 9: Large_dist, Local_dist, and Local_cor return list FALSE same variable
expL <- rnorm(1:20)
dim(expL) <- c(lat = 4, lon = 5)
obsL <- c(rnorm(1:180),expL*7)
dim(obsL) <- c(lat = 4, lon = 5, time = 10)
time_obsL <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
# analogs of large scale using criteria 1
Large_scale <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,
criteria="Large_dist",
nAnalogs = 10, return_list = TRUE)
# analogs of local scale using criteria 2
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_scale <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,
criteria="Local_dist",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 10, return_list = TRUE)
# analogs of local scale using criteria 2
Local_corr <- Analogs(expL=expL,
obsL=obsL, time_obsL=time_obsL,
criteria="Local_cor",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 10, return_list = TRUE)
plot.new()
layout(matrix(1:9,3,3,byrow=T))
image(expL,main="expL")
image(Large_scale$AnalogsFields[,,1],
main=paste0("Best_Analog C1 ",Large_scale$DatesAnalogs[1]))
image(Large_scale$AnalogsFields[,,2],
main=paste0("Best_Analog C1 ",Large_scale$DatesAnalogs[2]))
image(expVar,main="expVar")
image(Local_scale$AnalogsFields[,,1],
main=paste0("Best_Analog C2 ",Local_scale$DatesAnalogs[1]))
image(Local_scale$AnalogsFields[,,2],
main=paste0("Best_Analog C2 ",Local_scale$DatesAnalogs[2]))
image(expVar,main="expVar")
image(Local_corr$AnalogsFields[,,1],
main=paste0("Best_Analog C3 ",Local_corr$DatesAnalogs[1]))
image(Local_corr$AnalogsFields[,,2],
main=paste0("2nd Best_Analog C3 ",Local_corr$DatesAnalogs[2]))
# Example 10: Large_dist, Local_dist, and Local_cor return list FALSE different variable
expL1 <- rnorm(1:20)
dim(expL1) <- c(lat = 4, lon = 5)
obsL1 <- c(rnorm(1:180),expL1*5)
dim(obsL1) <- c(lat = 4, lon = 5, time = 10)
time_obsL1 <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar1 <- expL1[1:3,1:3]
dim(expVar1) <- c(lat = 3, lon = 3)
obsVar1 <- obsL1[1:3,1:3,1:10]
dim(obsVar1) <- c(lat = 3, lon = 3, time = 10)
# analogs of large scale using criteria 1
Large_scale <- Analogs(expL=expL1,
obsL=obsL1, time_obsL=time_obsL1,expVar=expVar1,obsVar=obsVar1,
criteria="Large_dist",
nAnalogs = 10, return_list = TRUE)
# analogs of local scale using criteria 2
lonmin=-1
lonmax=2
latmin=30
latmax=33
region=c(lonmin,lonmax,latmin,latmax)
Local_scale <- Analogs(expL=expL1,
obsL=obsL1, time_obsL=time_obsL1,obsVar=obsVar1,expVar=expVar1,
criteria="Local_dist",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 10, return_list = TRUE)
# analogs of local scale using criteria 3 and another variable so different obsL, expL, obsVar and expVar
expL2 <- rnorm(1:20)
dim(expL2) <- c(lat = 4, lon = 5)
obsL2 <- c(rnorm(1:180),expL2*5)
dim(obsL2) <- c(lat = 4, lon = 5, time = 10)
time_obsL2 <- paste(rep("01", 10), rep("01", 10), 1994 : 2003, sep = "-")
expVar2 <- expL2[1:3,1:3]
dim(expVar2) <- c(lat = 3, lon = 3)
obsVar2 <- obsL2[1:3,1:3,1:10]
dim(obsVar2) <- c(lat = 3, lon = 3, time = 10)
Local_corr <- Analogs(expL=expL2,
obsL=obsL2, time_obsL=time_obsL2,obsVar=obsVar2,expVar=expVar2,
criteria="Local_cor",lonVar=seq(-1,5,1.5),
latVar=seq(30,35,1.5),region=region,
nAnalogs = 10, return_list = TRUE)
plot.new()
layout(matrix(1:9,3,3,byrow=T))
image(expL1,main="expL Var1")
image(Large_scale$AnalogsFields[,,1],
main=paste0("BestAn. Var1 C1 ",Large_scale$DatesAnalogs[1]))
image(Large_scale$AnalogsFields[,,2],
main=paste0("BestAn. Var1 C1 ",Large_scale$DatesAnalogs[2]))
image(expVar1,main="expVar1")
image(Local_scale$AnalogsFields[,,1],
main=paste0("BestAn. Var1 C2 ",Local_scale$DatesAnalogs[1]))
image(Local_scale$AnalogsFields[,,2],
main=paste0("BestAn. Var1 C2 ",Local_scale$DatesAnalogs[2]))
image(expVar2,main="expVar2")
image(Local_corr$AnalogsFields[,,1],
main=paste0("BestAn. Var2 C3 ",Local_corr$DatesAnalogs[1]))
image(Local_corr$AnalogsFields[,,2],
main=paste0("2nd BestAn. Var2 C3 ",Local_corr$DatesAnalogs[2]))
\references{
Yiou, P., T. Salameh, P. Drobinski, L. Menut, R. Vautard,
and M. Vrac, 2013 : Ensemble reconstruction of the atmospheric column
from surface pressure using analogues. Clim. Dyn., 41, 1419-1437.
\email{pascal.yiou@lsce.ipsl.fr}
}
\author{
Carmen Alvarez-Castro, \email{carmen.alvarez-castro@cmcc.it}
Nuria Perez-Zanon \email{nuria.perez@bsc.es}
}