asSeason: Function to sort a given date to meteorological seasons (DJF,...

Description Usage Arguments Value Author(s) Examples

View source: R/fdbk_asdataframe.R

Description

Function to sort a given date to meteorological seasons (DJF, MAM, JJA, SON). Useful to stratify scores by season in order to plot scores for different seasons and compare them

Usage

1

Arguments

a

date in format yyyymmdd (at least). hours and/or minutes and/or seconds can be specified in format yyyymmddHHMMSS. Can be given as a string or numeric.

Value

a string corresponding to the four seasons (DJF, MAM, JJA, SON)

Author(s)

Felix <felix.fundel@dwd.de>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#EXAMPLE 1 simple examples with one date
asSeason("20150201") returns "DJF"
asSeason(20150201) also returns "DJF"
asSeason("201502011234") also returns "DJF"
asSeason("151201") returns an error (format yymmdd not accepted)
#EXAMPLE 2 Example of how to use this function to stratify scores by season
and show a plot of comparison fot different seasons

require(ggplot2)
fnames       = "/Users/josuegehring/Desktop/verTEMP.2014120112"
cond        = list(obs="!is.na(obs)",varno="varno%in%c(2,3,4,29)",ident="ident%in%c(6610)",varno="varno%in%c(2)")
columnnames = c("obs","veri_data","varno","state","level","veri_initial_date","ident")
DT          = fdbk_dt_multi_large(fnames,cond,columnnames,1)
levels = c(100000,92500,85000,70000,60000,50000,40000,30000)
DT = fdbk_dt_binning_level(DT,"level",levels,includeAll=TRUE)
DT$varno    = varno_to_name(DT$varno)
DT$season = as.character(lapply(DT$veri_initial_date, asSeason))
DT = na.omit(DT)
strat       = c("season","level")
scores      = fdbk_dt_verif_continuous(DT,strat)
scores      = scores[!is.na(scores),]
ii = scores$scorename=="ME"
scores = scores[ii]
data = data.frame(scores$level,scores$scores,scores$season)
colnames(data) = c("level","scores","season")
data = data[order(data$level),]
p =  ggplot(data,aes(x=scores,y=level,group=season,colour=season))+
  geom_point()+geom_path() + 
  theme_bw()+theme(axis.text.x  = element_text(angle=70,hjust = 1))+scale_y_reverse()
print(p)

rfxf/Rfdbk documentation built on May 27, 2019, 7:22 a.m.