From 6c17304bfa6b7524ac958d61edcb265ea9855d27 Mon Sep 17 00:00:00 2001 From: aho Date: Tue, 19 Nov 2019 18:14:23 +0100 Subject: [PATCH] add example from branch 'develop-example' --- inst/doc/usecase.md | 3 +- inst/doc/usecase/ex1_2_plotmap.R | 110 +++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 inst/doc/usecase/ex1_2_plotmap.R diff --git a/inst/doc/usecase.md b/inst/doc/usecase.md index 2bfb989..af65e8d 100644 --- a/inst/doc/usecase.md +++ b/inst/doc/usecase.md @@ -5,7 +5,8 @@ In this document, you can link to the example scripts for various demands. For t 1. **Retrieve data (use `Start()` only)** 1. [Interpolation in Start()](inst/doc/usecase/ex1_1_tranform.R) Do the interpolation within Start(), and compare with Load() result. When the Start() parameter `transform_extra_cells = 2`, the two results will be the same. - 2. + 2. [Use s2dverification map plotting functions for exp and obs data](inst/doc/usecase/ex1_2_plotmap.R) + Use s2dverification::PlotEquiMap, PlotStereoMap, PlotLayout to visualize load-in data, and use experimental data attributes to load in associated observational data. 2. **Execute computation (use `Compute()`)** 1. [Function working on time dimension](inst/doc/usecase/ex2_1_timedim.R) diff --git a/inst/doc/usecase/ex1_2_plotmap.R b/inst/doc/usecase/ex1_2_plotmap.R new file mode 100644 index 0000000..0287a77 --- /dev/null +++ b/inst/doc/usecase/ex1_2_plotmap.R @@ -0,0 +1,110 @@ +#--------------------------------------------------------------------- +# 1. Check the data with s2dverification map plotting functions +# 2. Read associated data of another data set matching the dates of the first one +#--------------------------------------------------------------------- +library(startR) +library(s2dverification) + +path <- '/esarchive/exp/ecearth/a0lg/monthly_mean/$var$_*/' +repos <- paste0(path, '$var$_*_S$sdate$_$member$_$chunk$.nc') +header <- Start(dat = repos, + var = 'tas', + member = indices(1:5), + sdate = indices(1:21 * 2), + chunk = 'all', + ftime = indices(1:3), + lat = 'all', + lon = 'all', + lat_reorder = Sort(), + lon_reorder = CircularSort(0, 360), + chunk_depends = 'sdate', + ftime_across = 'chunk', + merge_across_dims = TRUE, + split_multiselected_dims = TRUE, + synonims = list(ftime = 'time', + lat = c('lat', 'latitude'), + lon = c('lon', 'longitude')), + return_vars = list(lon = NULL, + lat = NULL, + time = 'sdate') + ) + +lon <- attr(header, 'Variables')$common$lon +lat <- attr(header, 'Variables')$common$lat + +data <- eval(header) #retrieve data + + +# check 5 members +PlotLayout(PlotEquiMap, + c('lon', 'lat'), + Subset(data, c('dat', 'var', 'sdate', 'ftime'), list(1, 1, 1, 1)), + lon, + lat, + fill = FALSE + ) + +# check 3 ftimes +PlotLayout(PlotEquiMap, + c('lon', 'lat'), + Subset(data, c('dat', 'var', 'sdate', 'member'), list(1, 1, 1, 1)), + lon, + lat, + fill = FALSE + ) + +# check 21 sdates +PlotLayout(PlotStereoMap, + c('lon', 'lat'), + Subset(data, c('dat', 'var', 'ftime', 'member'), list(1, 1, 1, 1)), + lon, + lat, + fill = FALSE + ) + + +#----------------------------- +# Associated obs data +#----------------------------- +dates <- attr(header, 'Variables')$common$time #use date attributes in exp data + +path <- '/esarchive/recon/ecmwf/erainterim/monthly_mean/$var$_*/' +repos <- paste0(path, '$var$_$date$.nc') +data_obs <- Start(dat = repos, + var = 'tas', + date = unique(format(dates, '%Y%m')), + ftime = values(dates), + lat = 'all', + lon = 'all', + lat_reorder = Sort(), + lon_reorder = CircularSort(0, 360), + ftime_across = 'date', + merge_across_dims = TRUE, + split_multiselected_dims = TRUE, + synonims = list(ftime = 'time', + lat = c('lat', 'latitude'), + lon = c('lon', 'longitude')), + return_vars = list(lon = NULL, + lat = NULL) + ) + +data_obs <- eval(data_obs) + +# check 3 ftimes +PlotLayout(PlotEquiMap, + c('lon', 'lat'), + Subset(data_obs, c('dat', 'var', 'sdate'), list(1, 1, 1)), + attr(data_obs, 'Variables')$common$lon, + attr(data_obs, 'Variables')$common$lat, + fill = FALSE + ) + +# check 2 sdates +PlotLayout(PlotEquiMap, + c('lon', 'lat'), + Subset(data_obs, c('dat', 'var', 'sdate', 'ftime'), list(1, 1, 1:2, 1)), + attr(data_obs, 'Variables')$common$lon, + attr(data_obs, 'Variables')$common$lat, + fill = FALSE + ) + -- GitLab