Commit 3158c831 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

minor updates

parent 874cf064
rm(list=ls())
library(downscaleR)
library(WFRTools)
source(file = "./functions/infoGeneral.R")
source(file = "./functions/functionsGeneral.R")
initYears <-c(1981:2010)
currMonths<-c(1:12)
#locName<-"GHA"
locName<-"EU"
resolution<-"0.75"
inPath<-sprintf("../DATA/wfdei_rev3.0/%sdeg/%s", resolution, locName)
outPath<-sprintf("../DATA/wfdei_rev3.1/%sdeg/%s", resolution, locName)
variables<-c("pr")
dir.create(outPath, recursive = TRUE, showWarnings = FALSE)
print("start")
for (variableName in variables) {
for (currMonth in currMonths) {
inFile <- sprintf("%s/%s_wfdei_GPCC_%s_%4d-%4d_%02d.RData",
inPath, variableName, locName,
initYears[1], initYears[length(initYears)],
currMonth)
print(sprintf("Open: %s", inFile))
load(inFile)
RData$Data<-aperm(RData$Data, c(3,2,1))
attr(RData$Data,"dimensions") <- c("time","lat","lon")
outFile <- sprintf("%s/%s_wfdei_GPCC_%s_%4d-%4d_%02d.RData",
outPath, variableName, locName,
initYears[1], initYears[length(initYears)],
currMonth)
print(sprintf("Saving: %s", outFile))
save(file=outFile, RData)
}
}
rm(list=ls())
library(downscaleR)
library(loadeR)
library(ecomsUDG.Raccess)
library(fields) # e.g: using the fields library
library(abind)
library(ncdf4)
source(file = "./functions/infoGeneral.R")
source(file = "./functions/functionsGeneral.R")
source(file = "./functions/functionR2Netcdf.R")
source(file = "./functions/functionNetcdf2R.R")
source(file = "../functions/infoGeneral.R")
source(file = "../functions/functionsGeneral.R")
source(file = "../functions/functionR2Netcdf.R")
source(file = "../functions/functionNetcdf2R.R")
submitscript <- FALSE
targetMonths <- c(1:12)
targetYears <- c(1981:2010)
locName<-"GHA"
locName<-"EU"
resolution<-"0.75"
inPath<-sprintf("../../DATA/wfdei_precip_raw/")
outPath<-sprintf("../../DATA/wfdei_rev4.0/%sdeg/%s", resolution, locName)
if (submitscript) {
targetMonths <- c(1:12)
targetYears <- c(1981:2011)
locName <- 'X'
resolution<-"0.50"
inPath<-sprintf("../WFDEI_nc/%sdeg/%s", resolution, locName)
outPath<-sprintf("../DATA/wfdei_rev4.0/%sdeg/%s", resolution, locName)
} else {
targetMonths <-c(1:12)
targetYears <-c(1981:2010)
# targetYears <-c(1981:1982)
locName<-"GHA"
locName<-"EU"
resolution<-"0.50"
inPath<-sprintf("../WFDEI_nc/")
outPath<-sprintf("../DATA/wfdei_rev4.0/%sdeg/%s", resolution, locName)
}
variables<-names(variableInfo)
variables<-c( "pr", "sfcWind", "rsds", "rlds", "huss", "tas", "tasmin", "tasmax")
variables<-c( "pr")
dir.create(outPath, recursive = TRUE, showWarnings = FALSE)
......@@ -68,7 +57,11 @@ for (targetMonth in targetMonths) {
attr(newGrid,"resX")<-0.75
attr(newGrid,"resY")<-0.75
print("Regridding")
RData <- interpGridData(RData, new.grid = newGrid, method = "bilinear");
# RData <- interpGridData(RData, new.grid = newGrid, method = "bilinear");
RData <- interpData(RData,
new.Coordinates = list(x = c(locationInfo$res0.75[[locName]]$lonmin, locationInfo$res0.75[[locName]]$lonmax, 0.5),
y = c(locationInfo$res0.75[[locName]]$latmin, locationInfo$res0.75[[locName]]$latmax, 0.5)),
method = "bilinear");
}
if (resolution == "0.50") {
......@@ -79,25 +72,25 @@ for (targetMonth in targetMonths) {
iLatMax<-which(RData$xyCoords$y==locationInfo$res0.50[[locName]]$latmax)
RData_new$xyCoords$x<-RData$xyCoords$x[iLonMin:iLonMax]
RData_new$xyCoords$y<-RData$xyCoords$y[iLatMin:iLatMax]
RData_new$Data<-RData$Data[iLonMin:iLonMax,iLatMin:iLatMax,]
attr(RData_new$Data,"dimensions")<-c("lon", "lat", "time")
RData_new$Data<-RData$Data[,iLatMin:iLatMax,iLonMin:iLonMax]
attr(RData_new$Data,"dimensions")<-c("time", "lat", "lon")
attr(RData_new$xyCoords,"projection")<-"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
RData<-RData_new
rm(RData_new)
}
# Check units
RData$Data[]<-RData$Data[]*86400
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
## add some extra attributes
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
attr(RData,"based on") <- "GPCC"
save(file = sprintf("%s.RData",oPrefix), RData)
# R2Netcdf(sprintf("%s.nc4",oPrefix), RData)
# Check units
RData$Data[]<-RData$Data[]*86400
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
## add some extra attributes
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
attr(RData,"based on") <- "GPCC"
save(file = sprintf("%s.RData",oPrefix), RData)
R2Netcdf(sprintf("%s.nc4",oPrefix), RData)
}
# locationInfo <- list(
# GHA = list(lonmin = 27.75, lonmax = 49.25, latmin =-12.25, latmax = 18.25),
# EU = list(lonmin =-24.75, lonmax = 39.75, latmin = 33.25, latmax = 71.75)
# )
#
# ##################### NetCDF outputfiles:
# locationInfoFinal0.75 <- list(
# GHA = list(lonmin = 27.75, lonmax = 49.50, latmin =-12.00, latmax = 18.00),
# EU = list(lonmin =0, lonmax = 0, latmin = 0, latmax = 0)
# )
#
# locationInfoFinal0.50 <- list(
# GHA = list(lonmin = 28.25, lonmax = 49.25, latmin =-11.75, latmax = 17.75),
# EU = list(lonmin =-24.25, lonmax = 39.75, latmin = 33.25, latmax = 71.75)
# )
#
# ############### R-RAW files (sommige 0.75deg latlons niet perfect afgerond)
# locationInfoR0.75 <- list(
# GHA = list(lonmin = 27.75, lonmax = 49.50, latmin =-12.00, latmax = 18.00),
# EU = list(lonmin =-24.75, lonmax = 39.75, latmin = 33.00, latmax = 72.00)
# )
#
# locationInfoR0.50 <- list(
# GHA = list(lonmin = 27.75, lonmax = 49.25, latmin =-12.25, latmax = 18.25),
# EU = list(lonmin =-24.75, lonmax = 39.75, latmin = 33.25, latmax = 71.75)
# )
#
# locationInfoRWFDEI <- list(
# GHA = list(lonmin = 26.75, lonmax = 50.25, latmin =-12.75, latmax = 18.25),
# EU = list(lonmin =-25.25, lonmax = 40.25, latmin = 32.75, latmax = 72.25)
# )
############### NEW!!!!
locationInfo <- list(
res0.75 = list(
GHA = list(lonmin = 27.75, lonmax = 49.50, latmin =-12.00, latmax = 18.00),
EU = list(lonmin =-24.75, lonmax = 39.75, latmin = 33.00, latmax = 72.00)
GHA = list(lonmin = 27.75, lonmax = 49.50, latmin =-12.00, latmax = 18.00, longName = "Greater Horn of Africa"),
EU = list(lonmin =-24.75, lonmax = 39.75, latmin = 33.00, latmax = 72.00, longName = "Europe")
),
res0.50 = list(
GHA = list(lonmin = 28.25, lonmax = 49.25, latmin =-11.75, latmax = 17.75),
EU = list(lonmin =-24.25, lonmax = 39.75, latmin = 33.25, latmax = 71.75)
GHA = list(lonmin = 28.25, lonmax = 49.25, latmin =-11.75, latmax = 17.75, longName = "Greater Horn of Africa"),
EU = list(lonmin =-24.25, lonmax = 39.75, latmin = 33.25, latmax = 71.75, longName = "Europe")
)
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment