From 64f9da6f99bc978e49e85a02dfea8d1ad6d5ea23 Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Tue, 3 Jan 2023 09:20:33 +0100 Subject: [PATCH 1/3] Formatting --- modules/Loading/dates2load.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/Loading/dates2load.R b/modules/Loading/dates2load.R index ca8ecaa3..0e3613f3 100644 --- a/modules/Loading/dates2load.R +++ b/modules/Loading/dates2load.R @@ -19,7 +19,6 @@ dates2load <- function(recipe, logger) { temp_freq <- recipe$Analysis$Variables$freq recipe <- recipe$Analysis$Time - # hcst dates file_dates <- paste0(strtoi(recipe$hcst_start):strtoi(recipe$hcst_end), recipe$sdate) @@ -27,8 +26,7 @@ dates2load <- function(recipe, logger) { if (temp_freq == "monthly_mean") { file_dates <- .add_dims(file_dates) } - - # fcst dates (if fcst_year empty it creates an empty object) + # fcst dates (if fcst_year empty it creates an empty object) if (! is.null(recipe$fcst_year)) { file_dates.fcst <- paste0(recipe$fcst_year, recipe$sdate) if (temp_freq == "monthly_mean") { -- GitLab From 21740a255a3643d2b6eb93b287ed70e8211fabca Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Tue, 3 Jan 2023 09:54:33 +0100 Subject: [PATCH 2/3] Fix handling of leadtimes in systems where the time stamp belongs to the following month --- conf/archive.yml | 8 ++++++++ modules/Loading/Loading.R | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/conf/archive.yml b/conf/archive.yml index 04d69c5a..fb0379a0 100644 --- a/conf/archive.yml +++ b/conf/archive.yml @@ -19,6 +19,7 @@ archive: fcst: 51 hcst: 25 calendar: "proleptic_gregorian" + time_stamp_lag: "0" reference_grid: "/esarchive/exp/ecmwf/system5c3s/monthly_mean/tas_f6h/tas_20180501.nc" system7c3s: name: "Meteo-France System 7" @@ -30,6 +31,7 @@ archive: nmember: fcst: 51 hcst: 25 + time_stamp_lag: "+1" calendar: "proleptic_gregorian" reference_grid: "conf/grid_description/griddes_system7c3s.txt" system21_m1: @@ -43,6 +45,7 @@ archive: fcst: 50 hcst: 30 calendar: "proleptic_gregorian" + time_stamp_lag: "+1" reference_grid: "conf/grid_description/griddes_system21_m1.txt" system35c3s: name: "CMCC-SPS3.5" @@ -55,6 +58,7 @@ archive: fcst: 50 hcst: 40 calendar: "proleptic_gregorian" + time_stamp_lag: "+1" reference_grid: "conf/grid_description/griddes_system35c3s.txt" system2c3s: name: "JMA System 2" @@ -66,6 +70,7 @@ archive: fcst: 10 hcst: 10 calendar: "proleptic_gregorian" + time_stamp_lag: "+1" reference_grid: "conf/grid_description/griddes_system2c3s.txt" eccc1: name: "ECCC CanCM4i" @@ -77,6 +82,7 @@ archive: fcst: 10 hcst: 10 calendar: "proleptic_gregorian" + time_stamp_lag: "+1" reference_grid: "conf/grid_description/griddes_eccc1.txt" glosea6_system600-c3s: name: "UKMO GloSea 6 6.0" @@ -88,6 +94,7 @@ archive: fcst: 62 hcst: 28 calendar: "proleptic_gregorian" + time_stamp_lag: "+1" reference_grid: "conf/grid_description/griddes_ukmo600.txt" ncep-cfsv2: name: "NCEP CFSv2" @@ -99,6 +106,7 @@ archive: fcst: 20 hcst: 20 calendar: "gregorian" + time_stamp_lag: "0" reference_grid: "conf/grid_description/griddes_ncep-cfsv2.txt" Reference: era5: diff --git a/modules/Loading/Loading.R b/modules/Loading/Loading.R index 66a53451..1c8ccad7 100644 --- a/modules/Loading/Loading.R +++ b/modules/Loading/Loading.R @@ -143,7 +143,11 @@ load_datasets <- function(recipe) { ## TODO: Give correct dimensions to $Dates$start ## (sday, sweek, syear instead of file_date) hcst <- as.s2dv_cube(hcst) - + # Adjust dates for models where the time stamp goes into the next month + if (recipe$Analysis$Variables$freq == "monthly_mean") { + hcst$Dates$start[] <- hcst$Dates$start - seconds(exp_descrip$time_stamp_lag) + } + # Load forecast #------------------------------------------------------------------- if (!is.null(recipe$Analysis$Time$fcst_year)) { @@ -151,7 +155,7 @@ load_datasets <- function(recipe) { # with the daily case and the current version of startR not allowing # multiple dims split - fcst <- Start(dat = fcst.path, + fcst <- Start(dat = fcst.path, var = variable, file_date = sdates$fcst, time = idxs$fcst, @@ -193,6 +197,11 @@ load_datasets <- function(recipe) { # Convert fcst to s2dv_cube fcst <- as.s2dv_cube(fcst) + # Adjust dates for models where the time stamp goes into the next month + if (recipe$Analysis$Variables$freq == "monthly_mean") { + fcst$Dates$start[] <- + fcst$Dates$start - seconds(exp_descrip$time_stamp_lag) + } } else { fcst <- NULL -- GitLab From 832702be2ad20814cc221e5c879f0fc424967a8e Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Tue, 3 Jan 2023 10:38:46 +0100 Subject: [PATCH 3/3] Adapt seasonal test to fix pipeline --- tests/testthat/test-seasonal_monthly.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-seasonal_monthly.R b/tests/testthat/test-seasonal_monthly.R index 8caa6c62..b29ccb95 100644 --- a/tests/testthat/test-seasonal_monthly.R +++ b/tests/testthat/test-seasonal_monthly.R @@ -108,19 +108,19 @@ tolerance = 0.0001 ) expect_equal( (data$hcst$Dates$start)[1], -as.POSIXct("1993-12-01", tz = 'UTC') +as.POSIXct("1993-11-30 23:59:59", tz = 'UTC') ) expect_equal( (data$hcst$Dates$start)[2], -as.POSIXct("1994-12-01", tz = 'UTC') +as.POSIXct("1994-11-30 23:59:59", tz = 'UTC') ) expect_equal( (data$hcst$Dates$start)[5], -as.POSIXct("1994-01-01", tz = 'UTC') +as.POSIXct("1993-12-31 23:59:59", tz = 'UTC') ) expect_equal( (data$obs$Dates$start)[10], -as.POSIXct("1995-02-14", tz = 'UTC') +as.POSIXct("1995-01-15 12:00:00", tz = 'UTC') ) }) @@ -153,22 +153,22 @@ c(dat = 1, var = 1, sday = 1, sweek = 1, syear = 1, time = 3, latitude = 3, long ) expect_equal( mean(calibrated_data$fcst$data), -291.1218, +291.6433, tolerance = 0.0001 ) expect_equal( mean(calibrated_data$hcst$data), -289.8596, +290.9006, tolerance = 0.0001 ) expect_equal( as.vector(drop(calibrated_data$hcst$data)[1, , 2, 3, 4]), -c(287.7982, 287.0422, 290.4297), +c(291.8887, 287.0233, 289.8808), tolerance = 0.0001 ) expect_equal( range(calibrated_data$fcst$data), -c(283.5374, 306.2353), +c(283.8926, 299.0644), tolerance = 0.0001 ) @@ -202,7 +202,7 @@ dim(skill_metrics$rpss) ) expect_equal( as.vector(skill_metrics$rpss[, 2, 3]), -c(-1.153829, -1.114743, -1.392457), +c(-0.2918857, -1.4809143, -1.3842286), tolerance = 0.0001 ) expect_equal( -- GitLab