wiki:udg/ecoms/RPackage/biascorrection

Version 4 (modified by gutierjm, 7 years ago) (diff)

--

Multi-variable bias correction of seasonal forecast

Taking into account the users' needs, in the following example a calibration of all the variables available, and needed by the users, in the ECOMS-UDG data server.

Since the R language has been adopted for some key tasks in the EUPORIAS and SPECS projects (including the development of comprehensive validation and statistical-downscaling packages), the ecomsUDG.Raccess is envisaged as a user-friendly, R-based interface to the ECOMS User Data Gateway, enabling authentication and remote access to the different datasets (seasonal forecasting, observations, reanalysis) currently available. Moreover, ecomsUDG.Raccess implements data homogenization (a single vocabulary) and time filtering/aggregation functionality.

The ecomsUDG.Raccess package relies on the rJava package as an interface to the powerful capabilities of the Unidata's netCDF Java library.

The following panels show an illustrative use of ECOMS-UDG to obtain the minimum DJF temperature DJF bias for System4 hindcast (one-month lead time) over Europe. WFDEI is used as reference.

R code Output
obs <- loadECOMS(dataset = "WFDEI", 
                  var = "tasmin",
                  season = c(12,1,2))
prd <- loadECOMS(dataset = "System4_seasonal_15", 
                  var = "tasmin", 
                  season = c(12,1,2), 
                  members = 1:2, 
                  leadMonth = 1)
obsr <- interpGridData(gridData = obs, 
                  new.grid = getGrid(prd), 
                  method = "bilinear")
bias <- getBias(obsr,prd)
plotMeanField(bias, multi.member = TRUE) 

First of all, the quantile-quantile mapping and the WFDEI data set are considered to calibrate the seven months corresponding to the initialization of November for the period 2001-2010 in an European domain. For the sake of the simplicity, only one member has been considered in this example.

library(downscaleR)
library(ecomsUDG.Raccess)
library(ncdf4) # Only needed to write NetCDF
loginECOMS_UDG(username = "username", password = "password")
# Seasonal forecast parameters:
dataset <- "System4_seasonal_15"
season <- c(12,1:6)
leadMonth <- 0
members <- 1:2
lonLim <- c(-15,35)
latLim <- c(32, 75)
years <- c(2001:2010)
time <- "DD"

# Bias correction parameters:
interpolationMethod <- "nearest" # Both observation and forecast should be define on the same grid. Options: "nearest" and "bilinear"
method <- "qqmap"
multi.member <- FALSE # Should members be adjusted sepparately (TRUE, default), or jointly (FALSE)?
pr.threshold <- 1 # The minimum value that is considered as a non-zero precipitation.
window <- 30 # Numeric value specifying the time window width used to calibrate. The window is centered on the target day. Default to \code{NULL}, which considers the whole period available.

It is important to note that some variables are derived from others (e.g. wss is estimated from the two wind components). For this reason, in order to reduce the memory requirements of the loading process, we have defined an "advisable order", which is used in this example. It is also advisable to remove non-necesary variables.

# Advisable Order: taking into account the nature (raw/derived) of the target variables we suggest the following order.
variables <- c("ps","wss","huss","tas","tasmax","tasmin","tp","rsds","rlds")
# Surface air pressure
obs <- loadECOMS(dataset = "WFDEI", var = "ps", lonLim = lonLim, latLim = latLim, season = season, years = years)
ps <- loadECOMS(dataset = dataset, var = "ps", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
ps <- interpGridData(ps, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
ps <- biasCorrection(obs, ps, ps, method = method, multi.member = multi.member, window = window)

# Creating a nc-file with the bias-corrected data:
# The function grid2NetCDF builds a nc4-file using a downscaleR object, in this case the surface pressure bias corrected with the qq-map method. The resulting NetCDF is available in the link:
# http://www.meteo.unican.es/work/datasets/psAdjust_System4_1_2_12_6_qqmap_WFDEI_2001_2010.nc4

grid2NetCDF(ps, NetCDFOutFile = "psAdjust_System4_1_2_12_6_qqmap_WFDEI_2001_2010.nc4", missval = 1e20, prec = "float", compression=4, shuffle = TRUE)

# Cleaning the workspace:
obs <- NULL

# Wind speed (at 10m)
obs <- loadECOMS(dataset = "WFDEI", var = "wss", lonLim = lonLim, latLim = latLim, season = season, years = years)
wss <- loadECOMS(dataset = dataset, var = "wss", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
wss <- interpGridData(wss, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
wss <- biasCorrection(obs, wss, wss, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

# Surface (2m) specific humidity
obs <- loadECOMS(dataset = "WFDEI", var = "huss", lonLim = lonLim, latLim = latLim, season = season, years = years)
huss <- loadECOMS(dataset = dataset, var = "huss", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
huss <- interpGridData(huss, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
huss <- biasCorrection(obs, huss, huss, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

# Near-Surface air temperature
obs <- loadECOMS(dataset = "WFDEI", var = "tas", lonLim = lonLim, latLim = latLim, season = season, years = years)
tas <- loadECOMS(dataset = dataset, var = "tas", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
tas <- interpGridData(tas, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
tas <- biasCorrection(obs, tas, tas, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

# Daily Maximum Near-Surface Air Temperature
obs <- loadECOMS(dataset = "WFDEI", var = "tasmax", lonLim = lonLim, latLim = latLim, season = season, years = years)
tasmax <- loadECOMS(dataset = dataset, var = "tasmax", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
tasmax <- interpGridData(tasmax, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
tasmax <- biasCorrection(obs, tasmax, tasmax, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

# Daily Minimum Near-Surface Air Temperature
obs <- loadECOMS(dataset = "WFDEI", var = "tasmin", lonLim = lonLim, latLim = latLim, season = season, years = years)
tasmin <- loadECOMS(dataset = dataset, var = "tasmin", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
tasmin <- interpGridData(tasmin, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
tasmin <- biasCorrection(obs, tasmin, tasmin, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

# Total precipitation amount
obs <- loadECOMS(dataset = "WFDEI", var = "pr", lonLim = lonLim, latLim = latLim, season = season, years = years)
pr <- loadECOMS(dataset = dataset, var = "pr", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
pr <- interpGridData(pr, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
pr <- biasCorrection(obs, pr, pr, method = method, multi.member = multi.member, window = window, pr.threshold = pr.threshold)

# Cleaning the workspace:
obs <- NULL

# Surface Downwelling Shortwave Radiation
obs <- loadECOMS(dataset = "WFDEI", var = "rsds", lonLim = lonLim, latLim = latLim, season = season, years = years)
rsds <- loadECOMS(dataset = dataset, var = "rsds", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
rsds <- interpGridData(rsds, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
rsds <- biasCorrection(obs, rsds, rsds, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

# Net Longwave Surface Radiation
obs <- loadECOMS(dataset = "WFDEI", var = "rlds", lonLim = lonLim, latLim = latLim, season = season, years = years)
rlds <- loadECOMS(dataset = dataset, var = "rlds", members = members, lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth, time = time)

# Interpolating: System4 -> WFDEI grid
rlds <- interpGridData(rlds, new.grid = getGrid(obs), method = interpolationMethod);

# Bias Correction
rlds <- biasCorrection(obs, rlds, rlds, method = method, multi.member = multi.member, window = window)

# Cleaning the workspace:
obs <- NULL

Attachments (1)

Download all attachments as: .zip