-
Notifications
You must be signed in to change notification settings - Fork 6
/
.Rhistory
512 lines (512 loc) · 23.6 KB
/
.Rhistory
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
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
193
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# For every column, it's biascorrected respectively.
frc_data <- lapply(2:n, function(x) biasCorrect_core(frc[, x], hindcast[, x], obs[, 2], method = method,
scaleType = scaleType, preci = preci))
frc_data <- do.call('cbind', frc_data)
} else stop('Wrong TS input, check your TS dimension.')
} else if (input == 'hyfo') {
print('Under development...')
}
names <- colnames(frc)
frc <- data.frame(frc[, 1], frc_data)
colnames(frc) <- names
return(frc)
}
# this is only used to calculate the value column,
biasCorrect_core <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', preci = FALSE){
# default is the simplest method in biascorrection, just do simple addition and subtraction.
if (method == 'delta') {
# comes from downscaleR biascorrection method
frcMean <- mean(obs[, 2], na.rm = TRUE)
hindcastMean <- mean(hindcast[, 2], na.rm = TRUE)
frc <- obs - hindcastMean + frcMean
} else if (method == 'scaling') {
obsMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
if (scaleType == 'multi') {
frc <- frc / hindcastMean * obsMean
} else if (scaleType == 'add') {
frc <- frc - hindcastMean + obsMean
}
} else if (method == 'eqm') {
# To be added, right now too complicated and not so much use.
}
return(frc)
}
aaa <- biasCorrect(frc, hindcast, obs)
debug(biasCorrect)
aaa <- biasCorrect(frc, hindcast, obs)
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
hindcast[, 1] != obs[, 1]
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
aaa <- biasCorrect(frc, hindcast, obs)
hindcast[, 1] != obs[, 1]
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
obs
obs[, 2]
#' Biascorrect the input timeseries or hyfo dataset
#'
#' Biascorrect the input time series or dataset, the input time series or dataset should consist of observation, hindcast, and forecast.
#' observation and hindcast should belong to the same period, in order to calibrate. Then the modified forecast
#' will be returned. If the input is a time series, first column should be date column and rest columns should be
#' the value column. If the input is a hyfo dataset, the dataset should be the result of \code{loadNcdf}, or a list
#' file with the same format.
#'
#' @param frc a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the forecast to be calibrated.
#' @param hindcast a hyfo grid data output or a dataframe(time series) consists of Date column and one or more value columns,
#' representing the hindcast data. This data will be used in the calibration of the forecast, so it's better to have the same date period as
#' observation data. Check details for more information.
#' @param obs a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the observation data.
#' @param method bias correct method, including 'delta', 'scaling'...
#' @param scaleType only when the method "scaling" is chosen, scaleType will be available. Two different types
#' of scaling method, 'add' and 'mult', which means additive and multiplicative scaling method. More info check
#' details.
#' @param input If input is a time series, \code{input = 'TS'} needs to be assigned, or hyfo will take it as
#' an hyfo output grid file. Default is time series input, where in most of the cases we prefer. If your input
#' is a hyfo output file, \code{input = 'hyfo'}.
#' @param preci If the precipitation is biascorrected, then you have to assign \code{preci = TRUE}. Since for
#' precipitation, some biascorrect methods may not apply to, or some methods are specially for precipitation.
#' Default is FALSE.
#' @details
#'
#' \strong {Hindcast}
#'
#' Since climate forecast is based on global condition, when downscaling to different regions, it may include
#' some bias, biascorrection is used then to fix the bias. In order to bias correct, we need to pick up some
#' data from the forecast to train with the observation, which is called hindcast in this function. Hindcast
#' should have \strong{EVERY} attributes that forecast has.
#'
#' Hindcast is also called re-forecast, is the forecast of the past. E.g. you have a forecast from year 2000-2010, assuming now you are in 2005. So from 2000-2005, this period
#' is the hindcast period, and 2005-2010, this period is the forecast period.
#'
#'
#' \strong {How it works}
#'
#' Forecast product has to be calibrated, usually the system is doing forecast in real time. So, e.g., if the
#' forecast starts from year 2000, assuming you are in year 2003, then you will have 3 years' hindcast
#' data (year 2000 - 2003), which can be used to calibrate. And your forecast period is (2003-2004)
#'
#' E.g. you have observation from 2001 - 2002, this is your input obs. Then you can take the same
#' period (2001-2002) from the forecast, which is the hindcast period. For forecast, you can take any period.
#' The program will evaluate the obs and hindcast, to get the modification of the forecast, and then add the
#' modification to the forecast data.
#'
#' \strong {method}
#'
#' Different methods used in the bias correction.
#'
#' \strong {delta}
#' This method consists on adding to the observations the mean change signal (delta method).
#' This method is applicable to any kind of variable but it is preferable to avoid it for bounded variables
#' (e.g. precipitation, wind speed, etc.) because values out of the variable range could be obtained
#' (e.g. negative wind speeds...)
#'
#'
#'
#' @references
#' Bias correction methods come from \code{biasCorrection} from \code{dowscaleR}
#' Santander Meteorology Group (2015). downscaleR: Climate data manipulation and statistical downscaling. R
#' package version 0.6-0. https://github.com/SantanderMetGroup/downscaleR/wiki
#' @export
biasCorrect <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', input = 'TS', preci = FALSE){
if (input == 'TS') {
# First check if the first column is Date
if (!grepl('-|/', obs[1, 1]) | !grepl('-|/', hindcast[1, 1]) | !grepl('-|/', frc[1, 1])) {
stop('First column is not date or Wrong Date formate, check the format in ?as.Date{base}
and use as.Date to convert.If your input is a hyfo dataset, put input = "hyfo" as an
argument, check help for more info.')
}
# change to date type is easier, but in case in future the flood part is added, Date type doesn't have
# hour, min and sec, so, it's better to convert it into POSIxlt.
if (as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])) {
warning('time of obs and time of hindcast are not the same, which may cause inaccuracy in
the calibration.')
}
if (ncol(frc) == 2) {
frc_data <- biasCorrect_core(frc[, 2], hindcast[, 2], obs[, 2], method = method,
scaleType = scaleType, preci = preci)
} else if (ncol(frc) > 2) {
# In this case more than one value columns exist in the dataset, both frc and hindcast.
n <- ncol(frc)
# For every column, it's biascorrected respectively.
frc_data <- lapply(2:n, function(x) biasCorrect_core(frc[, x], hindcast[, x], obs[, 2], method = method,
scaleType = scaleType, preci = preci))
frc_data <- do.call('cbind', frc_data)
} else stop('Wrong TS input, check your TS dimension.')
} else if (input == 'hyfo') {
print('Under development...')
}
names <- colnames(frc)
frc <- data.frame(frc[, 1], frc_data)
colnames(frc) <- names
return(frc)
}
# this is only used to calculate the value column,
biasCorrect_core <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', preci = FALSE){
# default is the simplest method in biascorrection, just do simple addition and subtraction.
if (method == 'delta') {
# comes from downscaleR biascorrection method
frcMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
frc <- obs - hindcastMean + frcMean
} else if (method == 'scaling') {
obsMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
if (scaleType == 'multi') {
frc <- frc / hindcastMean * obsMean
} else if (scaleType == 'add') {
frc <- frc - hindcastMean + obsMean
}
} else if (method == 'eqm') {
# To be added, right now too complicated and not so much use.
}
return(frc)
}
aaa <- biasCorrect(frc, hindcast, obs)
aaa
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
aaa1
aaa1 == aaa
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
debug(biasCorrect)
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
as.POSIXlt(hindcast[, 1]) - as.POSIXlt(obs[, 1])
typeof(as.POSIXlt(hindcast[, 1]))
typeof(as.POSIXlt(hindcast[1, 1]))
str(as.POSIXlt(hindcast[1, 1]))
str(as.Date(hindcast[1, 1]))
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
str(as.Date(hindcast[1, 1]))
str(as.Date(hindcast[1, 1]))
as.POSIXlt(hindcast[, 1]) == as.POSIXlt(obs[, 1])
!(as.POSIXlt(hindcast[, 1]) == as.POSIXlt(obs[, 1]))
#' Biascorrect the input timeseries or hyfo dataset
#'
#' Biascorrect the input time series or dataset, the input time series or dataset should consist of observation, hindcast, and forecast.
#' observation and hindcast should belong to the same period, in order to calibrate. Then the modified forecast
#' will be returned. If the input is a time series, first column should be date column and rest columns should be
#' the value column. If the input is a hyfo dataset, the dataset should be the result of \code{loadNcdf}, or a list
#' file with the same format.
#'
#' @param frc a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the forecast to be calibrated.
#' @param hindcast a hyfo grid data output or a dataframe(time series) consists of Date column and one or more value columns,
#' representing the hindcast data. This data will be used in the calibration of the forecast, so it's better to have the same date period as
#' observation data. Check details for more information.
#' @param obs a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the observation data.
#' @param method bias correct method, including 'delta', 'scaling'...
#' @param scaleType only when the method "scaling" is chosen, scaleType will be available. Two different types
#' of scaling method, 'add' and 'mult', which means additive and multiplicative scaling method. More info check
#' details.
#' @param input If input is a time series, \code{input = 'TS'} needs to be assigned, or hyfo will take it as
#' an hyfo output grid file. Default is time series input, where in most of the cases we prefer. If your input
#' is a hyfo output file, \code{input = 'hyfo'}.
#' @param preci If the precipitation is biascorrected, then you have to assign \code{preci = TRUE}. Since for
#' precipitation, some biascorrect methods may not apply to, or some methods are specially for precipitation.
#' Default is FALSE.
#' @details
#'
#' \strong {Hindcast}
#'
#' Since climate forecast is based on global condition, when downscaling to different regions, it may include
#' some bias, biascorrection is used then to fix the bias. In order to bias correct, we need to pick up some
#' data from the forecast to train with the observation, which is called hindcast in this function. Hindcast
#' should have \strong{EVERY} attributes that forecast has.
#'
#' Hindcast is also called re-forecast, is the forecast of the past. E.g. you have a forecast from year 2000-2010, assuming now you are in 2005. So from 2000-2005, this period
#' is the hindcast period, and 2005-2010, this period is the forecast period.
#'
#'
#' \strong {How it works}
#'
#' Forecast product has to be calibrated, usually the system is doing forecast in real time. So, e.g., if the
#' forecast starts from year 2000, assuming you are in year 2003, then you will have 3 years' hindcast
#' data (year 2000 - 2003), which can be used to calibrate. And your forecast period is (2003-2004)
#'
#' E.g. you have observation from 2001 - 2002, this is your input obs. Then you can take the same
#' period (2001-2002) from the forecast, which is the hindcast period. For forecast, you can take any period.
#' The program will evaluate the obs and hindcast, to get the modification of the forecast, and then add the
#' modification to the forecast data.
#'
#' \strong {method}
#'
#' Different methods used in the bias correction.
#'
#' \strong {delta}
#' This method consists on adding to the observations the mean change signal (delta method).
#' This method is applicable to any kind of variable but it is preferable to avoid it for bounded variables
#' (e.g. precipitation, wind speed, etc.) because values out of the variable range could be obtained
#' (e.g. negative wind speeds...)
#'
#'
#'
#' @references
#' Bias correction methods come from \code{biasCorrection} from \code{dowscaleR}
#' Santander Meteorology Group (2015). downscaleR: Climate data manipulation and statistical downscaling. R
#' package version 0.6-0. https://github.com/SantanderMetGroup/downscaleR/wiki
#' @export
biasCorrect <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', input = 'TS', preci = FALSE){
if (input == 'TS') {
# First check if the first column is Date
if (!grepl('-|/', obs[1, 1]) | !grepl('-|/', hindcast[1, 1]) | !grepl('-|/', frc[1, 1])) {
stop('First column is not date or Wrong Date formate, check the format in ?as.Date{base}
and use as.Date to convert.If your input is a hyfo dataset, put input = "hyfo" as an
argument, check help for more info.')
}
# change to date type is easier, but in case in future the flood part is added, Date type doesn't have
# hour, min and sec, so, it's better to convert it into POSIxlt.
if (! (as.POSIXlt(hindcast[, 1]) == as.POSIXlt(obs[, 1]))) {
warning('time of obs and time of hindcast are not the same, which may cause inaccuracy in
the calibration.')
}
if (ncol(frc) == 2) {
frc_data <- biasCorrect_core(frc[, 2], hindcast[, 2], obs[, 2], method = method,
scaleType = scaleType, preci = preci)
} else if (ncol(frc) > 2) {
# In this case more than one value columns exist in the dataset, both frc and hindcast.
n <- ncol(frc)
# For every column, it's biascorrected respectively.
frc_data <- lapply(2:n, function(x) biasCorrect_core(frc[, x], hindcast[, x], obs[, 2], method = method,
scaleType = scaleType, preci = preci))
frc_data <- do.call('cbind', frc_data)
} else stop('Wrong TS input, check your TS dimension.')
} else if (input == 'hyfo') {
print('Under development...')
}
names <- colnames(frc)
frc <- data.frame(frc[, 1], frc_data)
colnames(frc) <- names
return(frc)
}
# this is only used to calculate the value column,
biasCorrect_core <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', preci = FALSE){
# default is the simplest method in biascorrection, just do simple addition and subtraction.
if (method == 'delta') {
# comes from downscaleR biascorrection method
frcMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
frc <- obs - hindcastMean + frcMean
} else if (method == 'scaling') {
obsMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
if (scaleType == 'multi') {
frc <- frc / hindcastMean * obsMean
} else if (scaleType == 'add') {
frc <- frc - hindcastMean + obsMean
}
} else if (method == 'eqm') {
# To be added, right now too complicated and not so much use.
}
return(frc)
}
debug(biasCorrect)
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
obsMean
#' Biascorrect the input timeseries or hyfo dataset
#'
#' Biascorrect the input time series or dataset, the input time series or dataset should consist of observation, hindcast, and forecast.
#' observation and hindcast should belong to the same period, in order to calibrate. Then the modified forecast
#' will be returned. If the input is a time series, first column should be date column and rest columns should be
#' the value column. If the input is a hyfo dataset, the dataset should be the result of \code{loadNcdf}, or a list
#' file with the same format.
#'
#' @param frc a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the forecast to be calibrated.
#' @param hindcast a hyfo grid data output or a dataframe(time series) consists of Date column and one or more value columns,
#' representing the hindcast data. This data will be used in the calibration of the forecast, so it's better to have the same date period as
#' observation data. Check details for more information.
#' @param obs a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the observation data.
#' @param method bias correct method, including 'delta', 'scaling'...
#' @param scaleType only when the method "scaling" is chosen, scaleType will be available. Two different types
#' of scaling method, 'add' and 'mult', which means additive and multiplicative scaling method. More info check
#' details.
#' @param input If input is a time series, \code{input = 'TS'} needs to be assigned, or hyfo will take it as
#' an hyfo output grid file. Default is time series input, where in most of the cases we prefer. If your input
#' is a hyfo output file, \code{input = 'hyfo'}.
#' @param preci If the precipitation is biascorrected, then you have to assign \code{preci = TRUE}. Since for
#' precipitation, some biascorrect methods may not apply to, or some methods are specially for precipitation.
#' Default is FALSE.
#' @details
#'
#' \strong {Hindcast}
#'
#' Since climate forecast is based on global condition, when downscaling to different regions, it may include
#' some bias, biascorrection is used then to fix the bias. In order to bias correct, we need to pick up some
#' data from the forecast to train with the observation, which is called hindcast in this function. Hindcast
#' should have \strong{EVERY} attributes that forecast has.
#'
#' Hindcast is also called re-forecast, is the forecast of the past. E.g. you have a forecast from year 2000-2010, assuming now you are in 2005. So from 2000-2005, this period
#' is the hindcast period, and 2005-2010, this period is the forecast period.
#'
#'
#' \strong {How it works}
#'
#' Forecast product has to be calibrated, usually the system is doing forecast in real time. So, e.g., if the
#' forecast starts from year 2000, assuming you are in year 2003, then you will have 3 years' hindcast
#' data (year 2000 - 2003), which can be used to calibrate. And your forecast period is (2003-2004)
#'
#' E.g. you have observation from 2001 - 2002, this is your input obs. Then you can take the same
#' period (2001-2002) from the forecast, which is the hindcast period. For forecast, you can take any period.
#' The program will evaluate the obs and hindcast, to get the modification of the forecast, and then add the
#' modification to the forecast data.
#'
#' \strong {method}
#'
#' Different methods used in the bias correction.
#'
#' \strong {delta}
#' This method consists on adding to the observations the mean change signal (delta method).
#' This method is applicable to any kind of variable but it is preferable to avoid it for bounded variables
#' (e.g. precipitation, wind speed, etc.) because values out of the variable range could be obtained
#' (e.g. negative wind speeds...)
#'
#'
#'
#' @references
#' Bias correction methods come from \code{biasCorrection} from \code{dowscaleR}
#' Santander Meteorology Group (2015). downscaleR: Climate data manipulation and statistical downscaling. R
#' package version 0.6-0. https://github.com/SantanderMetGroup/downscaleR/wiki
#' @export
biasCorrect <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', input = 'TS', preci = FALSE){
if (input == 'TS') {
# First check if the first column is Date
if (!grepl('-|/', obs[1, 1]) | !grepl('-|/', hindcast[1, 1]) | !grepl('-|/', frc[1, 1])) {
stop('First column is not date or Wrong Date formate, check the format in ?as.Date{base}
and use as.Date to convert.If your input is a hyfo dataset, put input = "hyfo" as an
argument, check help for more info.')
}
# change to date type is easier, but in case in future the flood part is added, Date type doesn't have
# hour, min and sec, so, it's better to convert it into POSIxlt.
# if condition only accepts one condition, for list comparison, there are a lot of conditions, better
# further process it, like using any.
if (any(as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1]))) {
warning('time of obs and time of hindcast are not the same, which may cause inaccuracy in
the calibration.')
}
if (ncol(frc) == 2) {
frc_data <- biasCorrect_core(frc[, 2], hindcast[, 2], obs[, 2], method = method,
scaleType = scaleType, preci = preci)
} else if (ncol(frc) > 2) {
# In this case more than one value columns exist in the dataset, both frc and hindcast.
n <- ncol(frc)
# For every column, it's biascorrected respectively.
frc_data <- lapply(2:n, function(x) biasCorrect_core(frc[, x], hindcast[, x], obs[, 2], method = method,
scaleType = scaleType, preci = preci))
frc_data <- do.call('cbind', frc_data)
} else stop('Wrong TS input, check your TS dimension.')
} else if (input == 'hyfo') {
print('Under development...')
}
names <- colnames(frc)
frc <- data.frame(frc[, 1], frc_data)
colnames(frc) <- names
return(frc)
}
# this is only used to calculate the value column,
biasCorrect_core <- function(frc, hindcast, obs, method = 'delta', scaleType = 'multi', preci = FALSE){
# default is the simplest method in biascorrection, just do simple addition and subtraction.
if (method == 'delta') {
# comes from downscaleR biascorrection method
frcMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
frc <- obs - hindcastMean + frcMean
} else if (method == 'scaling') {
obsMean <- mean(obs, na.rm = TRUE)
hindcastMean <- mean(hindcast, na.rm = TRUE)
if (scaleType == 'multi') {
frc <- frc / hindcastMean * obsMean
} else if (scaleType == 'add') {
frc <- frc - hindcastMean + obsMean
}
} else if (method == 'eqm') {
# To be added, right now too complicated and not so much use.
}
return(frc)
}
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
debug(biasCorrect)
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
aaa1 <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
obsMean
hindcastMean
frc
frc1 <- frc / hindcastMean * obsMean
frc1
frc1 - frc
frc1/obsMean
frc1/obsMean * hindcastMean
frc
frc1/obsMean * hindcastMean == frc
frc
frc * 3
frc * 100
frc * 100 /5
frc
frc1
obsMean
hindcastMean
obs / hindcastMean
frc1
frc
0.09 * 0.108
0.093 * 0.108
frc1
frc[35]
frc[35] /hindcastMean * obsMean
frc1[35]
frc1
q
devtools::document()
?extractPeriod
data(testdl)
datalist <- extractPeriod(testdl, startDate = '1994-1-1', endDate = '1995-10-1')
frc <- datalist[[1]]
hindcast <- datalist[[2]]
obs <- datalist[[3]]
# default method is delta
frc_new <- biasCorrect(frc, hindcast, obs)
undebug(biasCorrect)
frc_new
frc_new <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
frc_new
devtools::build()
?biasCorrection
??biasCorrection
devtools::document()
devtools::check()
devtools::document()
devtools::check()
devtools::document()
devtools::check()
devtools::build()
devtools::build()
install.packages("~/hyfo_1.1.7.tar.gz", repos = NULL, type = "source")
?biasCorrection
library(hyfo)
?biasCorrection
?biasCorrect
devtools::document()
devtools::build()
install.packages("~/hyfo_1.1.7.tar.gz", repos = NULL, type = "source")
library(hyfo)
?biasCorrect
datalist <- extractPeriod(testdl, startDate = '1994-1-1', endDate = '1995-10-1')
frc <- datalist[[1]]
hindcast <- datalist[[2]]
obs <- datalist[[3]]
frc_new <- biasCorrect(frc, hindcast, obs)
frc_new
frc_new <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
frc_new
?getFrcEnsem
filePath <- system.file("extdata", "tnc.nc", package = "hyfo")
varname <- getNcdfVar(filePath)
nc <- loadNcdf(filePath, varname)
a <- getFrcEnsem(nc)
a1 <- getFrcEnsem(tgridData)
a <- getFrcEnsem(nc, cell = c(6,2))
b <- getFrcEnsem(nc, coord = c(-1.4, 43.2))