Commit 880e1284 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

rev5.0 + South America added

parent 9dc90807
......@@ -13,15 +13,13 @@ submitscript <- FALSE
if (submitscript) {
members <- c(1:15)
# members <- c(1:1)
# members <- c(1:2)
targetMonths <- c(1:12)
# targetMonths <- c(1)
# targetMonths <- c(3)
targetYears <- c(1981:2011)
# targetYears <- c(1981:1982)
leadMonths <- c(X:X)
locName <- 'X'
# outPath<-"../DATA/System4_seasonal_15/0.75deg/EU_noBC"
outPath<-sprintf("../DATA/System4_seasonal_15_rev3.0/0.75deg/%s_noBC", locName)
outPath<-sprintf("../DATA/System4_seasonal_15_rev5.0/0.75deg/%s_noBC_RAW", locName)
} else {
members <-c(1,2)
targetMonths <-c(1:2)
......@@ -31,18 +29,23 @@ if (submitscript) {
# locName<-"GHA"
# locName<-"EU"
locName<-"SA"
outPath <- "./testData/noBC/"
outPath<-"./testData/newDownload"
outPath<-"./testData/rawDownload/"
}
variables<-names(variableInfo)
#variables<-c("pr", "rsds", "rlds")
#variables<-c( "sfcWind", "psl" , "huss", "tas", "tasmin", "tasmax")
#variables<-c("tas", "rsds", "rlds", "pr")
dir.create(outPath, recursive = TRUE, showWarnings = FALSE)
#variables<-c( "tas", "tasmin", "tasmax", "rsds", "rlds", "huss", "sfcWind", "pr")
#variables<-c( "pr")
#variables<-c( "tas")
#variables<-c( "tasmin")
#variables<-c( "tasmax")
#variables<-c( "rsds")
#variables<-c( "rlds")
#variables<-c( "huss")
#variables<-c( "sfcWind")
for (variableName in variables) {
outPathVar <- sprintf("%s/%s", outPath, variableName)
dir.create(outPathVar, recursive = TRUE, showWarnings = FALSE)
for (targetMonth in targetMonths) {
for (leadMonth in leadMonths) {
## get the available target years for the current targetMonth and leadMonth
......@@ -55,27 +58,32 @@ for (variableName in variables) {
variableNameECOMS<-variableName
}
print(sprintf("targetMonth: %s, leadMonth: %s, years: %d-%d",month.name[targetMonth], leadMonth, availableTargetYears[1], availableTargetYears[nYears]))
oPrefix <- sprintf("%s/%s_forcing_seas15_%s_noBC_E%02d-%02d_%4d-%4d_%02d_LM%d",
outPath, variableName, locName,
oPrefix <- sprintf("%s/%s_forcing_seas15_%s_noBC_E%02d-%02d_TAR%4d-%4d_%02d_LM%d",
outPathVar, variableName, locName,
members[1], members[length(members)],
availableTargetYears[1], availableTargetYears[nYears],
targetMonth, leadMonth)
print(oPrefix)
RData<-loadECOMS(dataset = "System4_seasonal_15",
var = variableNameECOMS,
members = members,
lonLim = c(locationInfo$res0.75[[locName]]$lonmin, locationInfo$res0.75[[locName]]$lonmax),
latLim = c(locationInfo$res0.75[[locName]]$latmin, locationInfo$res0.75[[locName]]$latmax),
season = targetMonth,
years = availableTargetYears,
leadMonth = leadMonth,
time = "DD")
# print(RData$InitializationDates)
# print(RData$Dates$start)
nummm<-1
while (!exists("RData")) {
try({
RData<-loadECOMS(dataset = "System4_seasonal_15",
var = variableNameECOMS,
members = members,
lonLim = c(locationInfo$res0.75[[locName]]$lonmin, locationInfo$res0.75[[locName]]$lonmax),
latLim = c(locationInfo$res0.75[[locName]]$latmin, locationInfo$res0.75[[locName]]$latmax),
season = targetMonth,
years = availableTargetYears,
leadMonth = leadMonth,
time = "DD",
aggr.d = variableInfo[[variableName]]$aggr)
}, silent=T)
if (nummm > 1){Sys.sleep(120)}
nummm<-nummm+1
}
RData$xyCoords$x[]<-round(RData$xyCoords$x[],2)
RData$xyCoords$y[]<-round(RData$xyCoords$y[],2)
......@@ -90,7 +98,8 @@ for (variableName in variables) {
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
save(file = sprintf("%s.RData",oPrefix), RData)
# R2Netcdf(sprintf("%s.nc4",oPrefix), RData)
R2Netcdf(sprintf("%s.nc4",oPrefix), RData)
rm(RData)
}
}
}
......@@ -16,7 +16,7 @@ if (submitscript) {
targetYears <- c(1981:2011)
locName <- 'X'
resolution<-"0.50"
outPath<-sprintf("../DATA/wfdei_rev3.0/%sdeg/%s", resolution, locName)
outPath<-sprintf("../DATA/wfdei_rev5.0/%sdeg/%s", resolution, locName)
} else {
targetMonths <-c(1:12)
......@@ -26,12 +26,12 @@ if (submitscript) {
locName<-"EU"
locName<-"SA"
resolution<-"0.50"
outPath<-sprintf("../DATA/wfdei_rev3.0/%sdeg/%s", resolution, locName)
outPath<-sprintf("../DATA/wfdei_rev5.0/%sdeg/%s", resolution, locName)
}
variables<-names(variableInfo)
variables<-c( "pr", "sfcWind", "rsds", "rlds", "huss", "tas", "tasmin", "tasmax")
variables<-c( "pr")
variables<-c("tas", "tasmin", "tasmax", "pr", "sfcWind", "rsds", "rlds", "huss")
#variables<-c( "pr")
dir.create(outPath, recursive = TRUE, showWarnings = FALSE)
......@@ -107,6 +107,6 @@ for (variableName in variables) {
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
save(file = sprintf("%s.RData",oPrefix), RData)
# R2Netcdf(sprintf("%s.nc4",oPrefix), RData)
R2Netcdf(sprintf("%s.nc4",oPrefix), RData)
}
}
rm(list=ls())
library(fields) # e.g: using the fields library
library(abind)
library(ncdf4)
library(loadeR.ECOMS)
source(file = "./functions/infoGeneral.R")
source(file = "./functions/functionsGeneral.R")
source(file = "./functions/functionR2Netcdf.R")
library(downscaleR) # Used for interpolation and bias correction
loginUDG(username = "wietsefranssen", password = "ECOMS")
submitscript <- FALSE
locName<-"GHA"
locName<-"EU"
locName<-"SA"
resolution<-"0.50"
outPath<-sprintf("../DATA/maskkk")
variableName<-c( "tas")
dir.create(outPath, recursive = TRUE, showWarnings = FALSE)
if ('ecomsName' %in% names(variableInfo[[variableName]])) {
variableNameECOMS<-variableInfo[[variableName]]$ecomsName
} else {
variableNameECOMS<-variableName
}
oFile <- sprintf("%s/mask_wfdei_%s_%s.nc4",
outPath, locName,resolution)
print(oFile)
if (resolution == "0.50") {
lonLim = c(locationInfo$res0.50[[locName]]$lonmin, locationInfo$res0.50[[locName]]$lonmax)
latLim = c(locationInfo$res0.50[[locName]]$latmin, locationInfo$res0.50[[locName]]$latmax)
} else {
# lonLim = c(locationInfo$res0.75[[locName]]$lonmin-1.5, locationInfo$res0.75[[locName]]$lonmax+1.5)
# latLim = c(locationInfo$res0.75[[locName]]$latmin-1.5, locationInfo$res0.75[[locName]]$latmax+1.5)
lonLim = c(locationInfo$res0.75[[locName]]$lonmin, locationInfo$res0.75[[locName]]$lonmax)
latLim = c(locationInfo$res0.75[[locName]]$latmin, locationInfo$res0.75[[locName]]$latmax)
}
RData<-loadECOMS(dataset = "WFDEI",
var = variableNameECOMS,
lonLim = lonLim,
latLim = latLim,
season = 1,
years = 1981,
time = "DD")
RData$xyCoords$x[]<-round(RData$xyCoords$x[],2)
RData$xyCoords$y[]<-round(RData$xyCoords$y[],2)
if (resolution == "0.75") {
newGrid<-getGrid(RData)
newGrid$x <- c(locationInfo$res0.75[[locName]]$lonmin, locationInfo$res0.75[[locName]]$lonmax)
newGrid$y <- c(locationInfo$res0.75[[locName]]$latmin, locationInfo$res0.75[[locName]]$latmax)
attr(newGrid,"resX")<-0.75
attr(newGrid,"resY")<-0.75
print("Regridding")
RData <- interpGrid(RData, new.grid = newGrid, method = "bilinear");
}
# Check units
RData$Variable$varName<-variableName
attr(RData$Variable,"standard_name")<-variableInfo[[variableName]]$standardName
attr(RData$Variable,"long_name")<-variableInfo[[variableName]]$longName
attr(RData$Variable,"units")<-variableInfo[[variableName]]$unitsEcoms
## FIX
RData$Dates$start<-RData$Dates$start[1]
RData$Dates$end<-RData$Dates$end[1]
RData$Data<-RData$Data[1,,]
RData$Data[!is.na(RData$Data)]<-1
attributes(RData$Variable)<-NULL
attr(RData$Variable, "long_name") <- "land-sea mask"
attr(RData$Variable, "standard_name") <- "mask"
attr(RData$Variable, "units") <- "-"
attr(RData$Variable, "title") <- "land-sea mask"
RData$Variable$varName<-"mask"
## add some extra attributes
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
R2Netcdf(oFile, RData)
#!/bin/bash
#SBATCH --account=5120867-01
#SBATCH --time=50000
#SBATCH --mem=16024
#SBATCH --mem=64024
#SBATCH --ntasks=1
#SBATCH --output=./log/log_download_<location>_leadMonth<leadMonth>_%j.txt
#SBATCH --job-name=DL
......
#!/bin/bash
tmpScripts="./tmpScripts"
#location="GHA"
location="EU"
#location="EU"
#location="SA"
location="GLOBAL"
mkdir -p $tmpScripts
for iLeadMonth in $(seq -f "%02g" 0 6); do
for iLeadMonth in $(seq -f "%02g" 0 0); do
#for iLeadMonth in $(seq -f "%02g" 0 6); do
echo "leadMonth: $iLeadMonth"
sed -e "s|<leadMonth>|$iLeadMonth|g" \
-e "s|<location>|$location|g" \
jobScriptDownloadSeas15 > $tmpScripts"/jobScriptDownloadSeas15_"$location"_leadMonth"$iLeadMonth
1a_jobScriptDownloadSeas15 > $tmpScripts"/jobScriptDownloadSeas15_"$location"_leadMonth"$iLeadMonth
sed -e "s|submitscript <- FALSE|submitscript <- TRUE|g" \
-e "s|leadMonths <- c(X:X)|leadMonths <- c($iLeadMonth:$iLeadMonth)|g" \
-e "s|locName <- 'X'|locName <- '$location'|g" \
doDownloadSeas15.R > $tmpScripts"/doDownloadSeas15_"$location"_leadMonth"$iLeadMonth".R"
1a_doDownloadSeas15.R > $tmpScripts"/doDownloadSeas15_"$location"_leadMonth"$iLeadMonth".R"
sbatch "$tmpScripts/jobScriptDownloadSeas15_"$location"_leadMonth"$iLeadMonth
done
rm(list=ls())
source(file = "./functions/functionsGeneral.R")
source(file = "./functions/functionR2Netcdf.R")
source(file = "./functions/functionNetcdf2R.R")
source(file = "./functions/functionConvert.R")
source(file = "./functions/infoGeneral.R")
submitscript <- FALSE
if (submitscript) {
members <- c(1:15)
initYears <- c(1981:2010)
initMonths <- c(X:X)
locName <- 'X'
resolution <- 'X'
inPath <- sprintf("../DATA/System4_seasonal_15_rev1.0/%s_%s", locName, resolution)
outPath <- sprintf("../DATA/System4_seasonal_15_rev4.0/%sdeg/%s_noBC", resolution, locName)
} else {
members <- c(1:2)
initYears <- c(1981:1982)
initMonths <- 1
locName <- "GHA"
#locName <- "EU"
resolution <- "0.75"
inPath <- sprintf("../DATA/System4_seasonal_15_rev1.0/%s_%s", locName, resolution)
outPath <- sprintf("../DATA/System4_seasonal_15_rev4.0/%sdeg/%s_noBC", resolution, locName)
}
mask<-Netcdf2R(inFile = sprintf("../DATA/mask/mask_wfdei_%s_%s.nc4", locName, resolution), "mask")
variables<-names(variableInfo)
print("start")
for (variableName in variables) {
dir.create(sprintf("%s/%s", outPath, variableName), recursive = TRUE, showWarnings = FALSE)
for (initMonth in initMonths) {
for (iMember in members) {
for (initYear in initYears) {
if ('ecomsName' %in% names(variableInfo[[variableName]])) {
variableNameECOMS<-variableInfo[[variableName]]$ecomsName
} else {
variableNameECOMS<-variableName
}
## Load file...
inFile <- sprintf("%s/%s/%s_forcing_seas15_%s_noBC_E%02d_%04d_%02d.RData", inPath, variableNameECOMS, variableNameECOMS, locName, iMember, initYear, initMonth)
print(sprintf("Reading: %s",inFile))
load(file = inFile)
RData<-sys4
rm(sys4)
# Check units
RData$Variable$varName<-variableName
attr(RData$Variable,"standard_name")<-variableInfo[[variableName]]$standardName
attr(RData$Variable,"long_name")<-variableInfo[[variableName]]$longName
attr(RData$Variable,"units")<-variableInfo[[variableName]]$unitsEcoms
RData$xyCoords$x[]<-round(RData$xyCoords$x[],2)
RData$xyCoords$y[]<-round(RData$xyCoords$y[],2)
## set all negative precipitation values 0
if (variableName == "pr") {
RData$Data[RData$Data < 0] <- 0
}
## Convert Units
if (variableName == "rsds" || variableName == "rlds") {
RData<-convert(RData, fromUnit = "1 W m-2", toUnit = variableInfo[[variableName]]$units)
} else {
RData<-convert(RData, toUnit = variableInfo[[variableName]]$units)
# RData<-convert(RData, fromUnit = variableInfo[[variableName]]$unitsEcoms, toUnit = variableInfo[[variableName]]$units)
}
## check if grids are the same as mask
## if not: make the same as mask
if (RData$xyCoords$x[1] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$lonmin ||
RData$xyCoords$x[length(RData$xyCoords$x)] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$lonmax ||
RData$xyCoords$y[1] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$latmin ||
RData$xyCoords$y[length(RData$xyCoords$y)] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$latmax) {
indexesLat<-c(which(RData$xyCoords$y==mask$xyCoords$y[1]):which(RData$xyCoords$y==mask$xyCoords$y[length(mask$xyCoords$y)]))
indexesLon<-c(which(RData$xyCoords$x==mask$xyCoords$x[1]):which(RData$xyCoords$x==mask$xyCoords$x[length(mask$xyCoords$x)]))
RData$xyCoords$x<-RData$xyCoords$x[indexesLon]
RData$xyCoords$y<-RData$xyCoords$y[indexesLat]
attr(RData$Data,"projection") <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
RData$Data<-RData$Data[,indexesLat,indexesLon]
attr(RData$Data,"dimensions") <- c("time","lat","lon")
}
## Apply mask
for (iTime in 1:length(RData$Dates$start)) {
RData$Data[iTime,,]<-RData$Data[iTime,,]*mask$Data[1,,]
}
## add some extra attributes
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
## Save file...
outPrefix <- sprintf("%s/%s/%s_forcing_seas15_%s_noBC_E%02d_INIT%04d_%02d", outPath, variableName, variableName, locName, iMember, initYear, initMonth)
# print(outPrefix)
R2Netcdf(paste0(outPrefix, ".nc4"), RData)
}
}
}
}
rm(list=ls())
source(file = "./functions/functionsGeneral.R")
source(file = "./functions/functionR2Netcdf.R")
source(file = "./functions/functionNetcdf2R.R")
source(file = "./functions/functionConvert.R")
source(file = "./functions/infoGeneral.R")
submitscript <- FALSE
if (submitscript) {
members <- c(1:15)
#members <- c(1:2)
targetMonths <- c(1:12)
# targetMonths <- c(3)
targetYears <- c(1981:2011)
#leadMonths <- c(3)
leadMonths <- c(X:X)
locName <- 'X'
resolution <- "0.50"
inPath <- sprintf("../DATA/System4_seasonal_15_rev5.0/0.75deg/%s_noBC_RAW", locName)
outPath <- sprintf("../DATA/System4_seasonal_15_rev5.0/%sdeg/%s_noBC_biasformat", resolution, locName)
} else {
members <-c(1,2)
targetMonths <-c(3)
targetYears <-c(2009:2011)
targetYears <-c(1981:2011)
leadMonths <-c(3)
locName<-"GHA"
# locName<-"EU"
# locName<-"SA"
resolution <- "0.50"
inPath <- sprintf("../DATA/System4_seasonal_15_rev5.0/0.75deg/%s_noBC_RAW", locName)
outPath <- sprintf("../DATA/System4_seasonal_15_rev5.0/%sdeg/%s_noBC_biasformat", resolution, locName)
}
mask<-Netcdf2R(inFile = sprintf("../DATA/mask/mask_wfdei_%s_%s.nc4", locName, resolution), "mask")
variables<-names(variableInfo)
#variables<-"pr"
print("start")
for (variableName in variables) {
dir.create(sprintf("%s/%s", outPath, variableName), recursive = TRUE, showWarnings = FALSE)
for (targetMonth in targetMonths) {
for (leadMonth in leadMonths) {
## get the available target years for the current targetMonth and leadMonth
availableTargetYears <- getAvailableTargetYears(targetYears = targetYears, targetMonth = targetMonth, leadMonth = leadMonth)
nYears <- length(availableTargetYears)
if ('ecomsName' %in% names(variableInfo[[variableName]])) {
variableNameECOMS<-variableInfo[[variableName]]$ecomsName
} else {
variableNameECOMS<-variableName
}
inFile <- sprintf("%s/%s/%s_forcing_seas15_%s_noBC_E%02d-%02d_TAR%4d-%4d_%02d_LM%d.nc4",
inPath, variableName, variableName, locName,
members[1], members[length(members)],
availableTargetYears[1], availableTargetYears[nYears],
targetMonth, leadMonth)
outFile <- sprintf("%s/%s/%s_forcing_seas15_%s_noBC_E%02d-%02d_TAR%4d-%4d_%02d_LM%d.nc4",
outPath, variableName, variableName, locName,
members[1], members[length(members)],
availableTargetYears[1], availableTargetYears[nYears],
targetMonth, leadMonth)
## Load file...
RData <- Netcdf2R(inFile, variableName)
# Check units
RData$Variable$varName<-variableName
attr(RData$Variable,"standard_name")<-variableInfo[[variableName]]$standardName
attr(RData$Variable,"long_name")<-variableInfo[[variableName]]$longName
attr(RData$Variable,"units")<-variableInfo[[variableName]]$unitsEcoms
RData$xyCoords$x[]<-round(RData$xyCoords$x[],2)
RData$xyCoords$y[]<-round(RData$xyCoords$y[],2)
RData$xyCoords$x<-as.numeric(RData$xyCoords$x)
RData$xyCoords$y<-as.numeric(RData$xyCoords$y)
## set all negative precipitation values 0
if (variableName == "pr") {
RData$Data[RData$Data < 0] <- 0
################# Add first days if needed
if (leadMonth == 0) {
require(Hmisc)
sYear<-format(as.Date(RData$Dates$start[1]), "%Y")
month<-format(as.Date(RData$Dates$start[1]), "%m")
nTimeOld<-length(RData$Dates$start)
eYear<-format(as.Date(RData$Dates$start[nTimeOld]), "%Y")
targetDates<-NULL
for (iYear in c(sYear:eYear)) {
sDate <- as.Date(paste0(iYear,"/", month,"/01"))
edayMonth <- monthDays(as.Date(paste0(iYear,"/", month,"/01")))
eDate <- as.Date(paste0(iYear,"/", month,"/", edayMonth))
## List of dates that should be in dataset
if(is.null(targetDates)) {
targetDates<-seq(sDate, eDate, "days")
} else {
targetDates<-c(targetDates, seq(sDate, eDate, "days"))
}
}
#print(targetDates)
## Get the ndexnumbers of the missing dates
# missingIndexes <- which(is.na(match(targetDates,as.Date(RData$Dates$start))))
indexes <- match(targetDates,as.Date(RData$Dates$start))
nTimeNew <- length(targetDates)
RDataNew<-RData
RDataNew$Dates$start <- format(targetDates, "%Y-%m-%d %X GMT")
RDataNew$Dates$end <- format(targetDates+1, "%Y-%m-%d %X GMT")
RDataNew$Data <-array(NA, dim = c(dim(RData$Data)[1],nTimeNew,dim(RData$Data)[3],dim(RData$Data)[4]))
iTimeOld <- 1
for (iTime in c(1:nTimeNew)) {
# print(paste(iTime, iTimeOld))
if (is.na(indexes[iTime])){
RDataNew$Data[,iTime,,] <- 0
} else {
RDataNew$Data[,iTime,,] <- RData$Data[,iTimeOld,,]
iTimeOld <- iTimeOld + 1
}
}
attr(RDataNew$Data,"dimensions") <- attributes(RData$Data)[2]$dimensions
RData <- RDataNew
}
#######################
}
## Convert Units
if (variableName == "rsds" || variableName == "rlds") {
RData<-convert(RData, fromUnit = "1 W m-2", toUnit = variableInfo[[variableName]]$units)
} else {
RData<-convert(RData, toUnit = variableInfo[[variableName]]$units)
# RData<-convert(RData, fromUnit = variableInfo[[variableName]]$unitsEcoms, toUnit = variableInfo[[variableName]]$units)
}
# ## check if grids are the same as mask
# ## if not: make the same as mask
# if (RData$xyCoords$x[1] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$lonmin ||
# RData$xyCoords$x[length(RData$xyCoords$x)] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$lonmax ||
# RData$xyCoords$y[1] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$latmin ||
# RData$xyCoords$y[length(RData$xyCoords$y)] != locationInfo[[sprintf("res%s",resolution)]][[locName]]$latmax) {
#
# indexesLat<-c(which(RData$xyCoords$y==mask$xyCoords$y[1]):which(RData$xyCoords$y==mask$xyCoords$y[length(mask$xyCoords$y)]))
# indexesLon<-c(which(RData$xyCoords$x==mask$xyCoords$x[1]):which(RData$xyCoords$x==mask$xyCoords$x[length(mask$xyCoords$x)]))
# RData$xyCoords$x<-RData$xyCoords$x[indexesLon]
# RData$xyCoords$y<-RData$xyCoords$y[indexesLat]
# attr(RData$Data,"projection") <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
# RData$Data<-RData$Data[,indexesLat,indexesLon]
# attr(RData$Data,"dimensions") <- c("time","lat","lon")
# }
attr(RData$Data,"projection") <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
if (resolution == "0.50") {
# newGrid<-getGrid(mask)
# print("Regridding")
# RData <- interpGrid(RData, new.coordinates = newGrid, method = "bilinear")
## Save file...
outFileTmp<-paste0(outFile,".tmp")
R2Netcdf(outFileTmp, RData)
rm(RData)
outFileGrid<-paste0(outFile,"grid.txt")
gridString<-paste0("gridtype = lonlat\n",
"xsize = ", length(mask$xyCoords$x), "\n",
"ysize = ", length(mask$xyCoords$y), "\n",
"xfirst = ", mask$xyCoords$x[1], "\n",
"xinc = 0.5\n",
"yfirst = ", mask$xyCoords$y[1], "\n",
"yinc = 0.5")
# print(outFileGrid)
write(gridString, file = outFileGrid)
system(paste0("cdo remapbil,", outFileGrid, " ", outFileTmp, " ", outFile),wait = TRUE)
RData <- Netcdf2R(outFile, variableName)
file.remove(outFileGrid)
file.remove(outFileTmp)
}
## Apply mask
for (iTime in 1:length(RData$Dates$start)) {
for (iMember in 1:length(RData$Members)) {
RData$Data[iMember,iTime,,]<-RData$Data[iMember,iTime,,]*mask$Data[1,,]
}
}
# ## Make NA values really NA values
# RData$Data[is.na(RData$Data)] <- NaN
## add some extra attributes
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
## Save file...
R2Netcdf(outFile, RData)
rm(RData)
}
}
}