Commit fe847531 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

changed reformat into reorder

parent ddf9dc2d
rm(list=ls())
library(fields) # e.g: using the fields library
library(abind)
library(ncdf4)
library(ecomsUDG.Raccess)
source(file = "./functions/functionsGeneral.R")
source(file = "./functions/functionReformat.R")
source(file = "./functions/functionR2Netcdf.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<-"0.75"
inPath<-sprintf("../DATA/System4_seasonal_15_rev1.0/%s_%s", locName, resolution)
outPath<-sprintf("../DATA/System4_seasonal_15_rev1.1REF2/%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_rev1.x/%sdeg/%s_noBC", resolution, locName)
}
variables<-names(variableInfo)
#variables<-c( "pr" , "psl" , "rsds" , "rlds" , "tasmin","tasmax", "huss" , "sfcWind")
dir.create(outPath, recursive = TRUE, showWarnings = FALSE)
leadMonths<-c(0:6)
print("start")
for (initMonth in initMonths) {
for (variableName in variables) {
if ('ecomsName' %in% names(variableInfo[[variableName]])) {
variableNameECOMS<-variableInfo[[variableName]]$ecomsName
} else {
variableNameECOMS<-variableName
}
inFile <- sprintf("%s/%s/%s_forcing_seas15_%s_noBC_E<MEMBERS>_<YEARS>_%02d.RData", inPath, variableNameECOMS, variableNameECOMS, locName, initMonth)
print(inFile)
RDataAllLeadMonths <- reformat2Bias(members, initYears, initMonth, variableNameECOMS, locName, iFile = inFile)
for (leadMonth in leadMonths) {
targetMonth <- getInitTargetInfo( initYear = 0000, initMonth = initMonth, leadMonth = leadMonth )$targetMonth
targetSYear <- getInitTargetInfo( initYear = initYears[1], initMonth = initMonth, leadMonth = leadMonth )$targetYear
targetEYear <- getInitTargetInfo( initYear = initYears[length(initYears)], initMonth = initMonth, leadMonth = leadMonth )$targetYear
print(sprintf("targetmonth: %s, leadMonth: %s",targetMonth, leadMonth))
oPrefix <- sprintf("%s/%s_forcing_seas15_%s_noBC_E%02d-%02d_TAR%4d-%4d_%02d_LM%d",
outPath, variableName, locName,
members[1], members[length(members)],
targetSYear, targetEYear,
targetMonth, leadMonth)
print(oPrefix)
RData<-RDataAllLeadMonths[[paste0("LeadMonth_",leadMonth)]]
# print(RData$InitializationDates)
# print(RData$Dates$start)
## set all negative precipitation values 0
if (variableName == "pr") {
RData$Data[RData$Data < 0] <- 0
}
RData$xyCoords$x[]<-round(RData$xyCoords$x[],2)
RData$xyCoords$y[]<-round(RData$xyCoords$y[],2)
# 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
## add some extra attributes
attr(RData,"contact") <- "Wietse Franssen (wietse.franssen@wur.nl)"
save(RData, file = paste0(oPrefix, ".RData"))
#R2Netcdf(paste0(oPrefix, ".nc4"), RData)
}
}
}
......@@ -3,7 +3,7 @@
#SBATCH --time=5000
#SBATCH --mem=32024
#SBATCH --ntasks=1
#SBATCH --output=./log/log_reformat_<location>_initMonth<initMonth>_%j.txt
#SBATCH --output=./log/log_doReorder_combYears_combMembers_sepLeadmonths_<location>_initMonth<initMonth>_%j.txt
#SBATCH --job-name=Reformat
#SBATCH --partition=ESG_Std
#SBATCH --mail-type=FAIL
......@@ -17,6 +17,6 @@ module load R/3.2.0
#
# run current job
echo '******** start Rscript...'
Rscript ./tmpScripts/doReformat_<location>_initMonth<initMonth>.R
Rscript ./tmpScripts/doReorder_combYears_combMembers_sepLeadmonths_<location>_initMonth<initMonth>.R
date
......@@ -8,10 +8,10 @@ for iInitMonth in $(seq -f "%02g" 1 12); do
echo "leadMonth: $iInitMonth"
sed -e "s|<initMonth>|$iInitMonth|g" \
-e "s|<location>|$location|g" \
jobScriptReformat > $tmpScripts"/jobScriptReformat_"$location"_initMonth"$iInitMonth
jobScriptReorder_combYears_combMembers_sepLeadmonths > $tmpScripts"/jobScriptReorder_combYears_combMembers_sepLeadmonths_"$location"_initMonth"$iInitMonth
sed -e "s|submitscript <- FALSE|submitscript <- TRUE|g" \
-e "s|initMonths <- c(X:X)|initMonths <- c($iInitMonth:$iInitMonth)|g" \
-e "s|locName <- 'X'|locName <- '$location'|g" \
doReformat.R > $tmpScripts"/doReformat_"$location"_initMonth"$iInitMonth".R"
sbatch "$tmpScripts/jobScriptReformat_"$location"_initMonth"$iInitMonth
doReorder_combYears_combMembers_sepLeadmonths.R > $tmpScripts"/doReorder_combYears_combMembers_sepLeadmonths_"$location"_initMonth"$iInitMonth".R"
sbatch "$tmpScripts/jobScriptReorder_combYears_combMembers_sepLeadmonths_"$location"_initMonth"$iInitMonth
done
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