Changes between Version 8 and Version 9 of udg/ecoms/RPackage/biascorrection


Ignore:
Timestamp:
Mar 31, 2016 6:00:32 PM (6 years ago)
Author:
juaco
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • udg/ecoms/RPackage/biascorrection

    v8 v9  
    11= Bias correction of seasonal forecasting data =
    22
    3 The seasonal forecasting data obtained from the `ecomsUDG.Raccess` package can be easily bias corrected (and downscaled) using the  [https://github.com/SantanderMetGroup/downscaleR downscaleR package] (see a description of the [https://github.com/SantanderMetGroup/downscaleR/wiki/Bias-Correction-and-Model-Output-Statistics-(MOS) bias correction functions]). This package has been developed in the framework of the SPECS and EUPORIAS projects  for bias correction and downscaling of daily climate model outputs (with special focus in seasonal forecasting).
     3The seasonal forecasting data obtained from the `loadeR.ECOMS` package can be easily bias corrected (and downscaled) using the  [https://github.com/SantanderMetGroup/downscaleR/wiki downscaleR] package (see a description of the [https://github.com/SantanderMetGroup/downscaleR/wiki/Bias-Correction-and-Model-Output-Statistics-(MOS) bias correction functions]). This package has been developed in the framework of the SPECS and EUPORIAS projects  for bias correction and downscaling of daily climate model outputs (with special focus in seasonal forecasting).
    44
    55The following panels show an illustrative use of `ECOMS-UDG` and `downscaleR` to obtain the bias corrected series of mean temperature for the period DJFMAM  (one-month lead time; i.e. with the initializations from November) over Europe. WFDEI is used as reference.
    66
    7 Note that, in order to facilitate the use of the resulting bias corrected data in different impact applications, the resulting bias corrected data can be easily exported to netcdf format.
     7Note that, in order to facilitate the use of the resulting bias corrected data in different impact applications, the resulting bias corrected data can be easily exported to NetCDF format using the [https://github.com/SantanderMetGroup/loadeR.2nc loadeR.2nc] extension.
     8
    89||= R code =||= Output =||
    910{{{#!td
    1011  {{{#!text/R
    11 # Packages and loging
    12 library(downscaleR)
    13 library(ecomsUDG.Raccess)
    14 library(ncdf4) # Only needed to write NetCDF
    15 loginECOMS_UDG(username = "username", password = "password")
     12library(loadeR.ECOMS) # Used for remote data access
     13library(downscaleR) # Used for interpolation and bias correction
     14library(loadeR.2nc) # Used to write NetCDF
     15# login to UDG
     16loginUDG(username = "username", password = "password")
    1617  }}}
    1718   {{{#!text/R
     
    3132                  latLim = c(32, 75),
    3233                  years = c(2001:2010))
    33 prd <- interpGridData(prd, new.grid = getGrid(obs),
    34                   method = "nearest");
     34# Parallelization is used to speed-up interpolation:
     35prd <- interpData(prd, new.coordinates = getGrid(obs),
     36                  method = "bilinear",
     37                  parallel = TRUE)
    3538  }}}
    3639  {{{#!text/R
    3740# Bias correction and plotting
    3841prd.bc <- biasCorrection(obs, prd, prd,
    39                   method = "qqmap",
     42                  method = "eqm",
    4043                  multi.member = TRUE,
    4144                  window = 30)
    42 plotMeanField(obs)
    43 plotMeanField(prd, multi.member = FALSE)
    44 plotMeanField(prd.bc, multi.member = FALSE)
     45plotMeanGrid(obs)
     46plotMeanGrid(prd, multi.member = FALSE)
     47plotMeanGrid(prd.bc, multi.member = FALSE)
    4548  }}}
    4649 {{{#!text/R
    4750# Exporting to netcdf4
    4851fileName <- "tas_qqmap_System4_WFDEI_2001_2010.nc4"
    49 grid2NetCDF(prd.bc, NetCDFOutFile = fileName,
    50                   missval = 1e20,
    51                   prec = "float")
     52grid2nc(data = prd.bc,
     53        NetCDFOutFile = fileName,
     54        missval = 1e20,
     55        prec = "float")
    5256  }}}
    5357}}}
     
    7175{{{
    7276#!text/R
    73 # Packages and login
    74 library(downscaleR)
    75 library(ecomsUDG.Raccess)
    76 library(ncdf4) # Only needed to write NetCDF
    77 loginECOMS_UDG(username = "username", password = "password")
    78 
    7977# Seasonal forecast parameters
    8078dataset <- "System4_seasonal_15"
     
    8987# Bias correction parameters
    9088interpolationMethod <- "nearest" # Both observation and forecast should be define on the same grid. Options: "nearest" and "bilinear"
    91 method <- "qqmap"
     89method <- "eqm" \ Empirical quantile mapping
    9290multi.member <- FALSE # Should members be adjusted sepparately (TRUE, default), or jointly (FALSE)?
    9391pr.threshold <- 1 # The minimum value that is considered as a non-zero precipitation.
     
    104102   obs <- NULL
    105103   prd <- NULL
    106    obs <- loadECOMS(dataset = "WFDEI", var = variables[v],
    107         lonLim = lonLim, latLim = latLim, season = season, years = years[1])
     104   obs <- loadECOMS(dataset = "WFDEI",
     105                    var = variables[v],
     106                    lonLim = lonLim,
     107                    latLim = latLim,
     108                    season = season,
     109                    years = years[1])
    108110   
    109    prd <- loadECOMS(dataset = dataset, var = variables[v], time = time, members = members,
    110         lonLim = lonLim, latLim = latLim, season = season, years = years, leadMonth = leadMonth)
     111   prd <- loadECOMS(dataset = dataset,
     112                    var = variables[v],
     113                    time = time,
     114                    members = members,
     115                    lonLim = lonLim,
     116                    latLim = latLim,
     117                    season = season,
     118                    years = years,
     119                    leadMonth = leadMonth)
    111120   
    112    prd <- interpGridData(prd, new.grid = getGrid(obs), method = interpolationMethod);
     121   prd <- interpData(prd, new.coordinates = getGrid(obs),
     122                     method = interpolationMethod)
    113123   
    114    if (any(grepl(obs$Variable$varName,c("tp")))){
    115         prd <- biasCorrection(obs, prd, prd, pr.threshold = pr.threshold,
    116              method = method, multi.member = multi.member, window = window)
    117    }else{
    118         prd <- biasCorrection(obs, prd, prd,
    119              method = method, multi.member = multi.member, window = window)
     124   prd <- if ("tp" %in% obs$Variable$varName) {
     125                biasCorrection(obs, prd, prd, pr.threshold = pr.threshold,
     126                               method = method, multi.member = multi.member,
     127                               window = window)
     128   } else {
     129                biasCorrection(obs, prd, prd, method = method,
     130                               multi.member = multi.member, window = window)
    120131   }
    121132   # Exporting to netcdf4
    122133   fileName <- paste(var[v],"System4_WFDEI.nc4",sep = "_")
    123    grid2NetCDF(prd, NetCDFOutFile = fileName,
    124                   missval = 1e20,
    125                   prec = "float")
     134   grid2nc(prd, NetCDFOutFile = fileName,
     135           missval = 1e20,
     136           prec = "float")
    126137}
    127138}}}