plot_maps.R 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/usr/bin/env Rscript
  2. library(s2dverification)
  3. args <- commandArgs(TRUE)
  4. comptrend <- T # Trend as a function of the start date for each leadtime
  5. compcor <- T # Correlation Coefficient
  6. comprms <- T # Root Mean Square Error
  7. comprmsss <- T # Root Mean Square Skill Score
  8. compratrms <- T # Ratio RMSE expid1 / expid2
  9. var <- args[1] # tos/tas/prlr
  10. season <- args[2] # Year/DJF/MAM/JJA/SON
  11. ly <- args[3] # ly1/ly2-5/ly6-9 for Forecast year 1 / years 2 to 5 / years
  12. # 6 to 9
  13. nltimemax <- 124 # number of leadtimes max in the experiments (in months)
  14. lstexpid <- c('i00k','b02p') # list of ids
  15. mon0 <- 11 # initial month
  16. year0 <- 1960 # first start date
  17. yearf <- 2005 # last start date
  18. intsdate <- 5 # interval between start dates
  19. obs <- switch(var, 'tas' = 'GHCNERSSTGISS', 'tos' = 'ERSST', 'prlr' = 'GPCC')
  20. syears <- seq(year0, yearf, intsdate)
  21. imon2 <- paste("0", as.character(mon0), sep = "")
  22. sdates <- paste(as.character(syears), substr(imon2, nchar(imon2) - 1,
  23. nchar(imon2)), '01', sep = "")
  24. savename <- paste(var, '_', season, '_', ly, sep = '')
  25. for (expid in lstexpid ) {
  26. savename <- paste(savename, '_', expid, sep = '')
  27. }
  28. savename <- paste(savename, '.sav', sep = '')
  29. if (file.exists(savename)) {
  30. load(savename)
  31. } else {
  32. if (is.na(match('b02p', lstexpid)) == TRUE) {
  33. lstload <- lstexpid
  34. } else {
  35. lstload <- lstexpid[-match('b02p', lstexpid)]
  36. }
  37. toto <- Load(var, lstload, obs,sdates, nleadtime = nltimemax,
  38. leadtimemin = switch(ly, 'ly1' = 1, 'ly2-5' = 13, 'ly6-9' = 61),
  39. leadtimemax = switch(ly, 'ly1' = switch(season, 'SON' = 13, 12),
  40. 'ly2-5' = switch(season, 'SON' = 61, 60),
  41. 'ly6-9' = switch(season, 'SON' = 109, 108)), output = 'lonlat')
  42. if (is.na(match('b02p', lstexpid)) == FALSE) {
  43. toto1bis <- Load(var, 'b02p', obs = NULL, '19501101', output = 'lonlat')
  44. toto1ter <- Histo2Hindcast(toto1bis$mod, '19501101', paste(as.character(
  45. syears + switch(ly, 'ly1' = 0, 'ly2-5' = 1, 'ly6-9' = 5)),
  46. substr(imon2, nchar(imon2) - 1, nchar(imon2)), '01', sep = ""),
  47. nleadtimesout = switch(ly, 'ly1' = switch(season, 'SON' = 13,
  48. 12), switch(season, 'SON' = 49, 48)))
  49. toto1beta <- array(dim = c(dim(toto$mod)[1] + dim(toto1ter)[1],
  50. max(dim(toto$mod)[2], dim(toto1ter)[2]), dim(toto$mod)[3:6]))
  51. toto1beta[1:dim(toto$mod)[1], 1:dim(toto$mod)[2], , , , ] <- toto$mod
  52. toto1beta[(dim(toto$mod)[1] + 1):(dim(toto$mod)[1] + dim(toto1ter)[1]),
  53. 1:dim(toto1ter)[2], , , , ] <- toto1ter
  54. toto$mod <- toto1beta
  55. lstexpid <- c(lstload, 'b02p')
  56. }
  57. toto_exp <- InsertDim(Mean1Dim(Season(toto$mod, 4, mon0, switch(season,
  58. 'Year' = mon0, 'DJF' = 12, 'MAM' = 3, 'JJA' = 6,
  59. 'SON' = 9), switch(season,
  60. 'Year' = (mon0 + 12 - 2) %% 12 + 1, 'DJF' = 2,
  61. 'MAM' = 5, 'JJA' = 8, 'SON' = 11)), 4), 4, 1)
  62. toto_obs <- InsertDim(Mean1Dim(Season(toto$obs, 4, mon0, switch(season,
  63. 'Year' = mon0, 'DJF' = 12, 'MAM' = 3, 'JJA' = 6,
  64. 'SON' = 9), switch(season,
  65. 'Year' = (mon0 + 12 - 2) %% 12 + 1, 'DJF' = 2,
  66. 'MAM' = 5, 'JJA' = 8, 'SON' = 11)), 4), 4, 1)
  67. if (var == 'prlr') {
  68. toto$mod <- toto$mod * 1000 * 3600 * 24
  69. toto$obs <- toto$obs * 1000 * 3600 * 24
  70. }
  71. toto=list(mod=toto_exp,obs=toto_obs,lat=toto$lat,lon=toto$lon)
  72. save(toto,file=savename)
  73. }
  74. clims <- Clim(toto$mod, toto$obs)
  75. ano_exp <- Ano(toto$mod, clims$clim_exp)
  76. ano_obs <- Ano(toto$obs, clims$clim_obs)
  77. if (compcor) {
  78. cor <- Corr(Mean1Dim(ano_exp, 2), Mean1Dim(ano_obs, 2), 1, 2)
  79. cols <- c("dodgerblue4", "dodgerblue1", "forestgreen", "yellowgreen",
  80. "white", "white", "yellow", "orange", "red", "saddlebrown")
  81. lims <- seq(-1, 1, 0.2)
  82. for (jexp in 1:length(lstexpid)) {
  83. flag <- array(F, dim = dim(cor[jexp, 1, 2, 1, , ]))
  84. flag[which(cor[jexp, 1, 2, 1, , ] > cor[jexp, 1, 4, 1, , ])] <- T
  85. postscript(paste('CorCoef2d_', var, '_', lstexpid[jexp], '_', season, '_',
  86. ly, '.eps', sep = ''))
  87. PlotEquiMap(cor[jexp, 1, 2, 1, , ], toto$lon, toto$lat,
  88. toptitle = paste('Correlation Coefficient', lstexpid[jexp],
  89. switch(season, 'Year' = 'annual', season), switch(var,
  90. 'tas' = 'near surface temperature',
  91. 'tos' = 'sea surface temperature', 'prlr' = 'precipitation'),
  92. switch(var, 'tas' = 'GHCNv2+ERSSTv3b+GISTEMP',
  93. 'tas' = 'ERSSTv3b', 'prlr' = 'GPCC'), switch(ly,
  94. 'ly1' = 'Year1', 'ly2-5' = 'Year2-5', 'ly6-9' = 'Year6-9')),
  95. sizetit = 0.8, brks = lims, cols = cols, colNA = switch(var,
  96. 'prlr' = 'white', grey(0.4)), filled.continents = switch(var,
  97. 'tas' = F, 'tos' = T, 'prlr' = F), dots = t(flag), intylat = 45)
  98. dev.off()
  99. }
  100. }
  101. if (comprms) {
  102. rmse <- RMS(Mean1Dim(ano_exp, 2), Mean1Dim(ano_obs, 2), 1, 2)
  103. cols <- rev(c("dodgerblue4", "dodgerblue1", "forestgreen", "yellowgreen",
  104. "white", "white", "yellow", "orange", "red", "saddlebrown"))
  105. lims <- c(0, 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.7, 1, 1.5, 2)
  106. lims <- switch(var, 'tas' = lims * 2, 'tos' = lims * 2, lims)
  107. rmse[which(rmse > max(lims))] <- max(lims)
  108. for (jexp in 1:length(lstexpid)) {
  109. postscript(paste('RMSE2d_', var, '_', lstexpid[jexp], '_', season, '_', ly,
  110. '.eps', sep = ''))
  111. PlotEquiMap(rmse[jexp, 1, 2, 1, , ], toto$lon, toto$lat,
  112. toptitle = paste('RMSE', lstexpid[jexp], switch(season,
  113. 'Year' = 'annual', season), switch(var,
  114. 'tas' = 'near surface temperature',
  115. 'tos' = 'sea surface temperature', 'prlr' = 'precipitation'),
  116. switch(var, 'tas' = 'GHCNv2+ERSSTv3b+GISTEMP',
  117. 'tas' = 'ERSSTv3b', 'prlr' = 'GPCC'), switch(ly,
  118. 'ly1' = 'Year1', 'ly2-5' = 'Year2-5', 'ly6-9' = 'Year6-9')),
  119. sizetit = 0.8, brks = lims, cols = cols, colNA = switch(var,
  120. 'prlr' = 'white', grey(0.4)), filled.continents = switch(var,
  121. 'tas' = F, 'tos' = T, 'prlr' = F), intylat = 45)
  122. dev.off()
  123. }
  124. }
  125. if (comprmsss) {
  126. rmsss <- RMSSS(Mean1Dim(ano_exp, 2), Mean1Dim(ano_obs, 2), 1, 2)
  127. cols <- c("dodgerblue4", "dodgerblue1", "forestgreen", "yellowgreen",
  128. "white", "white", "yellow", "orange", "red", "saddlebrown")
  129. lims <- seq(-1, 1, 0.2)
  130. for (jexp in 1:length(lstexpid)) {
  131. flag <- array(F, dim = dim(rmsss[jexp, 1, 2, 1, , ]))
  132. flag[which(rmsss[jexp, 1, 2, 1, , ] < 0.05)] <- T
  133. rmsss[which(-1 > rmsss)] = -1
  134. postscript(paste('RMSSS2d_', var, '_', lstexpid[jexp], '_', season, '_', ly,
  135. '.eps', sep = ''))
  136. PlotEquiMap(rmsss[jexp, 1, 1, 1, , ], toto$lon, toto$lat,
  137. toptitle = paste('RMSSS', lstexpid[jexp], switch(season,
  138. 'Year' = 'annual', season), switch(var,
  139. 'tas' = 'near surface temperature',
  140. 'tos' = 'sea surface temperature', 'prlr' = 'precipitation'),
  141. switch(var, 'tas' = 'GHCNv2+ERSSTv3b+GISTEMP',
  142. 'tas' = 'ERSSTv3b', 'prlr' = 'GPCC'), switch(ly,
  143. 'ly1' = 'Year1', 'ly2-5' = 'Year2-5', 'ly6-9' = 'Year6-9')),
  144. sizetit = 0.8, brks = lims, cols = cols, colNA = switch(var,
  145. 'prlr' = 'white', grey(0.4)), filled.continents = switch(var,
  146. 'tas' = F, 'tos' = T, 'prlr' = F), dots = t(flag), intylat = 45)
  147. dev.off()
  148. }
  149. }
  150. if (compratrms) {
  151. ratrms <- RatioRMS(Mean1Dim(ano_exp, 2)[1, , 1, , ],
  152. Mean1Dim(ano_exp, 2)[2, , 1, , ],
  153. Mean1Dim(ano_obs, 2)[1, , 1, , ], 1)
  154. cols <- rev(c("dodgerblue4", "dodgerblue1", "forestgreen", "yellowgreen",
  155. "white", "white", "yellow", "orange", "red", "saddlebrown"))
  156. lims <- c(0, 0.5, 0.8, 0.9, 0.95, 1, 1.05, 1.1, 1.2, 2, 6)
  157. flag <- array(F, dim = dim(ratrms[1, , ]))
  158. flag[which(ratrms[2, , ] < 0.05)] <- T
  159. postscript(paste('Rati_RMSE2d_', var, '_', lstexpid[1], '_', lstexpid[2],
  160. '_', season, '_', ly, '.eps', sep = ''))
  161. PlotEquiMap(ratrms[1, , ], toto$lon, toto$lat, toptitle = paste('RMSE',
  162. lstexpid[1], '/ RMSE', lstexpid[2], switch(season,
  163. 'Year' = 'annual', season), switch(var,
  164. 'tas' = 'near surface temperature',
  165. 'tos' = 'sea surface temperature', 'prlr' = 'precipitation'),
  166. switch(var, 'tas' = 'GHCNv2+ERSSTv3b+GISTEMP', 'tas' = 'ERSSTv3b',
  167. 'prlr' = 'GPCC'), switch(ly, 'ly1' = 'Year1', 'ly2-5' = 'Year2-5',
  168. 'ly6-9' = 'Year6-9')), sizetit = 0.8, brks = lims, cols = cols,
  169. colNA = switch(var, 'prlr' = 'white', grey(0.4)),
  170. filled.continents = switch(var, 'tas' = F, 'tos' = T, 'prlr' = F),
  171. dots = t(flag), intylat = 45)
  172. dev.off()
  173. }