From bd064d807431c70307f2ee1ec36d75a379de783c Mon Sep 17 00:00:00 2001 From: nperez Date: Thu, 7 May 2020 14:56:49 +0200 Subject: [PATCH 1/5] Usecase 1.7 to load tas and tos --- inst/doc/usecase.md | 3 + inst/doc/usecase/ex1_7_tasandtos.R | 143 +++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 inst/doc/usecase/ex1_7_tasandtos.R diff --git a/inst/doc/usecase.md b/inst/doc/usecase.md index 35130e0..4a27232 100644 --- a/inst/doc/usecase.md +++ b/inst/doc/usecase.md @@ -30,6 +30,9 @@ for more explanation. 6. [Loading gridpoint data](inst/doc/usecase/ex1_6_gridpoint_data.R) **Start** can be used to load single point data by providing a vector of longitudes and latitudes. This use case also ilustrates how to reformat it to get a 'gridpoint' dimension. + 7. [Loading tas and tos from Decadal EC-Earth Simulations](inst/doc/usecase/ex1_7_tasandtos.R) + Some climate indices needs to be computed loading 'tas' (air temperature at 2m) over land and 'tos' (ocean surface temperature) over sea. Using **startR**, you can load these data in a unique **Start** call or with multiple separately for each variable. + 2. **Execute computation (use `Compute()`)** diff --git a/inst/doc/usecase/ex1_7_tasandtos.R b/inst/doc/usecase/ex1_7_tasandtos.R new file mode 100644 index 0000000..958520e --- /dev/null +++ b/inst/doc/usecase/ex1_7_tasandtos.R @@ -0,0 +1,143 @@ +# ----------------------------------------------------- +# Loading tas and tos for EC-Earth decadal simulations: +# Authors: Carlos Delgado and Núria Pérez-Zanón +# ------------------------------------------------------ + +# Three ways to load the same data are provided: +# 1) single Start call providing two paths and two variable names +# 2) single Start call providing one path and two variabe names +# 3) two Start call one for each path and variable + + +# Case 1) returns dimensions 'dataset' and 'var' with length 2 , but only the positions of the diagonal are filled: +# tas is stored in {dataset = 1, var = 1} +# tos is stored in {dataset = 2, var = 2} +# NOTE!!! check {datastet = 1, var = 2} because an issue in ESMValTool:https://earth.bsc.es/gitlab/es/auto-ecearth3/issues/1258 + +library(startR) + +paths = list(list(path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Amon/$var$/gr/v20190713/$var$_Amon_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc'), + list(path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Omon/$var$/gr/v20190713/$var$_Omon_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc')) +data1 <- Start(dataset = paths, + var = c('tas','tos'), + sdate = paste0(1960:1962), + fmonth = 1, + lat = values(list(0, 10)), + lon = values(list(0, 10)), + fyear = 'all', + member = indices(1), + fyear_depends = 'sdate', + fmonth_across = 'fyear', + merge_across_dims = TRUE, + synonims = list(fmonth = c('fmonth','time'), + lon = c('lon', 'longitude'), + lat = c('lat', 'latitude')), + return_vars = list(lat = 'dataset', lon = 'dataset'), + num_procs = 1, retrieve = TRUE) + +dim(data1) +#dataset var sdate fmonth lat lon member +# 2 2 3 12 14 15 1 +# Check empty and filled dimensions: +sum(is.na(data1[1,1,,,,,])) == (3*12*14*15) +#[1] FALSE +sum(is.na(data1[1,2,,,,,])) == (3*12*14*15) +#[1] TRUE +sum(is.na(data1[2,2,,,,,])) == (3*12*14*15) +#[1] FALSE +sum(is.na(data1[2,1,,,,,])) == (3*12*14*15) +#[1] TRUE + +lat1 <- as.vector(attributes(data1)$Variables$dat1$lat) +lon1 <- as.vector(attributes(data1)$Variables$dat1$lon) + +# --------------------------------------------------------------- + +# Case 2) using a single path, {dataset = 1, var = 2, type = 1} +# 'type' dimension is necessary to distinguish between 'Amon' and 'Omon'. + +library(startR) + +path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/$type$/$var$/gr/v20190713/$var$_$type$_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc' +data2 <- Start(dataset = path, + var = c('tas', 'tos'), + type = 'all', + type_depends = 'var', + sdate = paste0(1960:1962), + fmonth = 1, + lat = values(list(0, 10)), + lon = values(list(0, 10)), + fyear = indices(1), + member = indices(1), + fyear_depends = 'sdate', + fmonth_across = 'fyear', + merge_across_dims = TRUE, + synonims = list(fmonth = c('fmonth','time'), + lon = c('lon', 'longitude'), + lat = c('lat', 'latitude')), + return_vars = list(lat = 'dataset', lon = 'dataset'), + num_procs = 1, retrieve = TRUE) + +dim(data2) +# dataset var type sdate fmonth lat lon member +# 1 2 1 3 1 14 15 1 + + +# --------------------------------------------------------------- + +# Case 3) Two different Start calls can save data_tas and data_tos both with {dataset = 1 and var = 1} dimensions and avoiding extra dimensions like 'type'. + +path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Amon/$var$/gr/v20190713/$var$_Amon_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc' +data_tas <- Start(dataset = path, + var = 'tas', + sdate = paste0(1960:1962), + fmonth = 1, + lat = values(list(0, 10)), + lon = values(list(0, 10)), + fyear = indices(1), + member = indices(1), + fyear_depends = 'sdate', + fmonth_across = 'fyear', + merge_across_dims = TRUE, + synonims = list(fmonth = c('fmonth','time'), + lon = c('lon', 'longitude'), + lat = c('lat', 'latitude')), + return_vars = list(lat = 'dataset', lon = 'dataset'), + num_procs = 1, retrieve = TRUE) + +dim(data_tas) +#dataset var sdate fmonth lat lon member +# 1 1 3 1 14 15 1 + +path = '/esarchive/exp/ecearth/a1ua/cmorfiles/DCPP/EC-Earth-Consortium/EC-Earth3/dcppA-hindcast/$member$/Omon/$var$/gr/v20190713/$var$_Omon_EC-Earth3_dcppA-hindcast_s$sdate$-$member$_gr_$fyear$.nc' +data_tos <- Start(dataset = path, + var = 'tos', + sdate = paste0(1960:1962), + fmonth = 1, + lat = values(list(0, 10)), + lon = values(list(0, 10)), + fyear = indices(1), + member = indices(1), + fyear_depends = 'sdate', + fmonth_across = 'fyear', + merge_across_dims = TRUE, + synonims = list(fmonth = c('fmonth','time'), + lon = c('lon', 'longitude'), + lat = c('lat', 'latitude')), + return_vars = list(lat = 'dataset', lon = 'dataset'), + num_procs = 1, retrieve = TRUE) + +dim(data_tos) +#dataset var sdate fmonth lat lon member +# 1 1 3 1 14 15 1 + +# --------------------------------------------------------------------- + +# Comparison cases 1) to 3): +#---------------------------------------------------------------------- + +all(data1[1, 1, , , , , ] == data_tas[1, 1, , , , , ]) +all((data1[2, 2, , , , , ]) == data_tos[1, 1, , , , , ], na.rm = TRUE) +all(data2[1, 1, 1, , , , , ] == data_tas[1, 1, , , , ,]) +all((data2[1, 2, 1, , , , , ]) == data_tos[1, 1, , , , , ], na.rm = TRUE) + -- GitLab From c9aee6c387d8c4328b1bf5910faf2f25e880efbe Mon Sep 17 00:00:00 2001 From: cdelgado Date: Thu, 7 May 2020 16:58:52 +0200 Subject: [PATCH 2/5] Update usecase.md --- inst/doc/usecase.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/doc/usecase.md b/inst/doc/usecase.md index 4a27232..02daa5f 100644 --- a/inst/doc/usecase.md +++ b/inst/doc/usecase.md @@ -30,8 +30,8 @@ for more explanation. 6. [Loading gridpoint data](inst/doc/usecase/ex1_6_gridpoint_data.R) **Start** can be used to load single point data by providing a vector of longitudes and latitudes. This use case also ilustrates how to reformat it to get a 'gridpoint' dimension. - 7. [Loading tas and tos from Decadal EC-Earth Simulations](inst/doc/usecase/ex1_7_tasandtos.R) - Some climate indices needs to be computed loading 'tas' (air temperature at 2m) over land and 'tos' (ocean surface temperature) over sea. Using **startR**, you can load these data in a unique **Start** call or with multiple separately for each variable. + 7. [Loading tas and tos from Decadal Predictions performed with the EC-Earth model](inst/doc/usecase/ex1_7_tasandtos.R) + Some climate indices needs to be computed loading 'tas' (air temperature at 2m) over land and 'tos' (ocean surface temperature) over sea. Using **startR**, you can load these data in a unique **Start** call or with multiple calls separately for each variable. -- GitLab From 722e60004c542491533993488bf08753f933b95d Mon Sep 17 00:00:00 2001 From: cdelgado Date: Thu, 7 May 2020 17:05:02 +0200 Subject: [PATCH 3/5] Update ex1_7_tasandtos.R --- inst/doc/usecase/ex1_7_tasandtos.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/doc/usecase/ex1_7_tasandtos.R b/inst/doc/usecase/ex1_7_tasandtos.R index 958520e..a97958f 100644 --- a/inst/doc/usecase/ex1_7_tasandtos.R +++ b/inst/doc/usecase/ex1_7_tasandtos.R @@ -1,12 +1,12 @@ # ----------------------------------------------------- -# Loading tas and tos for EC-Earth decadal simulations: +# Loading tas and tos for EC-Earth historical simulations: # Authors: Carlos Delgado and Núria Pérez-Zanón # ------------------------------------------------------ # Three ways to load the same data are provided: # 1) single Start call providing two paths and two variable names # 2) single Start call providing one path and two variabe names -# 3) two Start call one for each path and variable +# 3) two Start call (one for each path and variable) # Case 1) returns dimensions 'dataset' and 'var' with length 2 , but only the positions of the diagonal are filled: -- GitLab From 1ea32fb7c69ea9333c6997172bd119dab3b6b4bc Mon Sep 17 00:00:00 2001 From: cdelgado Date: Thu, 7 May 2020 17:09:25 +0200 Subject: [PATCH 4/5] Update ex1_7_tasandtos.R --- inst/doc/usecase/ex1_7_tasandtos.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/doc/usecase/ex1_7_tasandtos.R b/inst/doc/usecase/ex1_7_tasandtos.R index a97958f..38fdf95 100644 --- a/inst/doc/usecase/ex1_7_tasandtos.R +++ b/inst/doc/usecase/ex1_7_tasandtos.R @@ -1,5 +1,5 @@ # ----------------------------------------------------- -# Loading tas and tos for EC-Earth historical simulations: +# Loading tas and tos for EC-Earth decadal predictions: # Authors: Carlos Delgado and Núria Pérez-Zanón # ------------------------------------------------------ -- GitLab From 2b8d8c7bf666bec4c5ba987efd44a6ad16cd7115 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 8 May 2020 09:50:55 +0200 Subject: [PATCH 5/5] Modify number due to conflict with master --- inst/doc/usecase/{ex1_7_tasandtos.R => ex1_8_tasandtos.R} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename inst/doc/usecase/{ex1_7_tasandtos.R => ex1_8_tasandtos.R} (100%) diff --git a/inst/doc/usecase/ex1_7_tasandtos.R b/inst/doc/usecase/ex1_8_tasandtos.R similarity index 100% rename from inst/doc/usecase/ex1_7_tasandtos.R rename to inst/doc/usecase/ex1_8_tasandtos.R -- GitLab