diff --git a/inst/doc/usecase.md b/inst/doc/usecase.md index 68bdbf3b8d6279eccbab5e3deaa6dcf47168c84a..9ffbee4cf2bbb3f461e8bb6e69323604568e9693 100644 --- a/inst/doc/usecase.md +++ b/inst/doc/usecase.md @@ -28,24 +28,27 @@ in a comparable structure. It also shows how to use parameters `xxx_tolerance`, get the desired longitude and latitude region. See [FAQ How-to-#11] (/inst/doc/faq.md#11-read-latitude-and-longitude-with-the-usage-of-parameter-xxx_reorder) for more explanation. - 6. [Loading gridpoint data](inst/doc/usecase/ex1_6_gridpoint_data.R) + 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. [Use split and merge parameters together](inst/doc/usecase/ex1_7_split_merge.R) + 7. [Use split and merge parameters together](inst/doc/usecase/ex1_7_split_merge.R) This usecase shows the things to be noticed when the parameters 'split_multiselected_dims' and 'merge_across_dims' are both used. The problem may occur when the dimension number of the splitted selector is more than two. If you are not familiar with the usage of these parameters, please see usecases ex1_2 and ex1_3 first, which are less complicated. You can also go to FAQ How-to-#17 for more explanation. + 8. [Loading tas and tos from Decadal Predictions performed with the EC-Earth model](inst/doc/usecase/ex1_8_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. + 2. **Execute computation (use `Compute()`)** - 1. [Function working on time dimension](inst/doc/usecase/ex2_1_timedim.R) + 1. [Function working on time dimension](inst/doc/usecase/ex2_1_timedim.R) 2. [Function using attributes of the data](inst/doc/usecase/ex2_2_attr.R) Using attributes is only available in startR_v0.1.3 or above. 3. [Use function CDORemap for interpolation](inst/doc/usecase/ex2_3_cdo.R) Using parameter `CDO_module` is only available in startR_v0.1.3 or above. Interpolate data by using `s2dverification::CDORemap` in the workflow. - 4. [Use two functions in workflow](inst/doc/usecase/ex2_4_two_func.R) + 4. [Use two functions in workflow](inst/doc/usecase/ex2_4_two_func.R) 5. - 6. [Use external parameters in atomic function](inst/doc/usecase/ex2_6_ext_param_func.R) - 7. [Calculate the ensemble-adjusted Continuous Ranked Probability Score (CRPS)](inst/doc/usecase/ex2_7_seasonal_forecast_crps.R) + 6. [Use external parameters in atomic function](inst/doc/usecase/ex2_6_ext_param_func.R) + 7. [Calculate the ensemble-adjusted Continuous Ranked Probability Score (CRPS)](inst/doc/usecase/ex2_7_seasonal_forecast_crps.R) Use `SpecsVerification::EnsCrps` to calculate the ensemble-adjusted Continuous Ranked Probability Score (CRPS) for ECWMF experimental data, and do ensemble mean. Use `s2dverification::PlotEquiMap` to plot the CRPS map. - 8. [Use CSTools Calibration function](inst/doc/usecase/ex2_8_calibration.R) + 8. [Use CSTools Calibration function](inst/doc/usecase/ex2_8_calibration.R) Use `CSTools:::.cal`, the interior function of `CSTools::CST_Calibration`, to do the bias adjustment for ECMWF experimental monthly mean data. diff --git a/inst/doc/usecase/ex1_8_tasandtos.R b/inst/doc/usecase/ex1_8_tasandtos.R new file mode 100644 index 0000000000000000000000000000000000000000..38fdf956dfaf61618b04ab46fe9e7c2ccca95e0b --- /dev/null +++ b/inst/doc/usecase/ex1_8_tasandtos.R @@ -0,0 +1,143 @@ +# ----------------------------------------------------- +# Loading tas and tos for EC-Earth decadal predictions: +# 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) +