Compatibility break due to changes in s2dv_cube
Hi @all,
I open this issue for you to know that there will be a compatibility break due to the changes in the s2dv_cube
object. It will affect all the CST_* prefix functions in the CSTools, CSIndicators and CSDownscale packages. The changes are under development in develop-new_s2dv_cube branch. When the branch will be merged on master the changes will be ready to test.
- Approximate date when the changes will be in master: 01/03/2023
- Approximate date of the release of CSTools v5.0.0 in CRAN and installation in BSC usual machines: 10/04/2023
With this calendar, the changes in the scripts can be done during March 2023.
Guidelines:
Here in the following lines I give a summary on how will be the instructions to apply the changes. One recommendation to deal with the changes is to do a copy of your scripts that accept the new s2dv_cube
object before the new version is installed. You can test the new object by sourcing the functions to build the new object:
source("https://earth.bsc.es/gitlab/external/cstools/-/raw/develop-new_s2dv_cube/R/as.s2dv_cube.R")
source("https://earth.bsc.es/gitlab/external/cstools/-/raw/develop-new_s2dv_cube/R/zzz.R")
Also, I attach here the sample data of CSTools with the new structure:
lonlat_prec.rda
lonlat_temp.rda
Finnally, I also attach a file with some examples that use the new as.s2dv_cube() function to read data from Start():
Example-new-as.s2dv_cube.R
Instructions to accept the new s2dv_cube
within your scripts:
- How to create a new s2dv_cube with sample data to test:
dat <- 1 : (1 * 3 * 4 * 5 * 6 * 7)
dim(dat) <- c(dataset = 1, member = 3, sdate = 4, ftime = 5, lat = 6, lon = 7)
lon <- seq(0, 30, 5)
lat <- seq(0, 25, 5)
coords = list(lat = lat, lon = lon)
exp <- list(data = dat, coords = coords)
attr(exp, 'class') <- 's2dv_cube'
- Work with longitudes or latitudes vectors (
$lon
or$lat
elements):
The spatial coordinates in the new s2dv_cube
object are located inside the element $coords
and they can have different names. Whereas the old object had a fixed place to store the longitudes and latitudes:
# Old s2dv_cube:
lat = exp$lat
lon = exp$lon
Then, in the new object, we need to do one extra step to find the longitude ans latitude name. We are going to use the auxiliary functions .KnownLonNames()
and .KnownLatNames()
:
# New object
# 1. Find the longitude and latitude names
lon_name <- names(exp$coords)[[which(names(exp$coords) %in% .KnownLonNames())]]
lat_name <- names(exp$coords)[[which(names(exp$coords) %in% .KnownLatNames())]]
# 2. Access to the spatial coordinates vector:
exp$coords[[lon_name]] <- exp$coords[[lon_name]]
exp$coords[[lat_name]] <- exp$coords[[lon_name]]
- If the function deals with Dates element:
The difference is that the old object has the Dates vector located inexpL$Dates$start
, whereas the new object has them inexpL$attrs$Dates
.
# Old s2dv_cube
time_exp <- exp$Dates$start
# New s2dv_cube
time_exp <- exp$attrs$Dates
- Variable, Datasets, source_files or other elements:
The elements that are not the data array, neither the coordinates, are known as the "attributes"*. The differences in all the attributes are quite similar in all of them. In the new object, the attributes will be located in the category ($attrs).
- Note: We must be careful not to get confused with inner R attributes (intrinsic attributes of R objects) and the element attributes in the new s2dv_cube (a list element).
# Old s2dv_cube
Datasets <- exp$Datasets
# New s2dv_cube
Datasets <- exp$attrs$Datasets
The same with the element $source_files
:
# Old s2dv_cube
source_files <- exp_cor$source_files
Then, in the new object:
source_files <- exp_cor$attrs$source_files
If you have doubts or suggestions you can leave a comment in this issue. Also, if you need some help with the scripts or revisions I am available at any time at the following mail address: eva.rifarovira@bsc.es.
Thank you and sorry for the inconvenience,
Eva