easyNCDF issueshttps://earth.bsc.es/gitlab/es/easyNCDF/-/issues2022-11-16T11:27:30+01:00https://earth.bsc.es/gitlab/es/easyNCDF/-/issues/7error in output when converting array to ncfile2022-11-16T11:27:30+01:00pdelucaerror in output when converting array to ncfilehello @aho,
I was successfull in converting arrays to ncfiles, but now I have an issue which I can't solve.
Here my sample data: "`/esarchive/scratch/pdeluca/landmarc/data/spei3_thorntwaite_126_MPI-ESM1-2-HR.rds`" (you should be able t...hello @aho,
I was successfull in converting arrays to ncfiles, but now I have an issue which I can't solve.
Here my sample data: "`/esarchive/scratch/pdeluca/landmarc/data/spei3_thorntwaite_126_MPI-ESM1-2-HR.rds`" (you should be able to access it).
And here my script:
```
spei3_126=readRDS(paste("/esarchive/scratch/pdeluca/landmarc/data/spei3_thorntwaite_126_MPI-ESM1-2-HR.rds", sep = ""))
all_spei=list(spei3_126)
## remove +/-Inf and 1949
for (i in 1:length(all_spei)) {
for (j in 1:length(all_spei[[i]])) {
all_spei[[i]][[j]][sapply(all_spei[[i]][[j]], is.infinite)] <- NA
all_spei[[i]][[j]]=all_spei[[i]][[j]][-c(1:12),]
}
}
all_spei_2=all_spei
for (i in 1:length(all_spei_2)) {
all_spei_2[[i]]=bind_rows(all_spei_2[[i]])
}
lon=list()
lat=list()
time=list()
for (i in 1:length(all_spei_2)) {
lon[[i]]=unique(all_spei_2[[i]]$lon)
lat[[i]]=unique(all_spei_2[[i]]$lat)
time[[i]]=c(1:1812)
lon[[i]] = array(data = lon[[i]], dim = c(lon = length(lon[[i]])))
lat[[i]] = array(data = lat[[i]], dim = c(lat = length(lat[[i]])))
time[[i]] = array(data = time[[i]], dim = c(time = length(time[[i]])))
}
data_var=list()
for (i in 1:length(all_spei)) {
data_var[[i]] = lapply(all_spei[[i]], '[[', 1) # get the data only
}
arr1=list()
for (i in 1:length(data_var)) {
arr1[[i]] = array(unlist(data_var[[i]]), dim = c(time = 1812,
lon = length(unique(all_spei_2[[i]]$lon)),
lat = length(unique(all_spei_2[[i]]$lat)))) # turn list to array
arr1[[i]] = s2dv::Reorder(arr1[[i]], c("lon", "lat", "time")) # time needs to be the last one for netCDF
}
for (i in 1:length(data_var)) {
metadata <- list(spei3 = list(standard_name = "spei3"))
attr(arr1[[i]], 'variables') <- metadata
metadata <- list(lon = list(standard_name = "longitude",
units = "degrees_east"))
attr(lon[[i]], 'variables') <- metadata
metadata <- list(lat = list(standard_name = "latitude",
units = "degrees_north"))
attr(lat[[i]], 'variables') <- metadata
metadata <- list(time = list(units = "months"))
attr(time[[i]], 'variables') <- metadata
}
easyNCDF::ArrayToNc(list(arr1[[1]], lon[[1]], lat[[1]], time[[1]]), paste('output.nc', sep = ""))
```
Basically, `output.nc` is not correct and indeed it appears as if there is a duplicated map. I checked the input file and it is fine, so the issue has to be within the conversion from array to ncfile.
Coudl you please try the script and let me know if you find any bug(s)?
Paolo
#### UPDATE
Here below the wrong output from `/esarchive/scratch/pdeluca/landmarc/data/spei3_thorntwaite_126_MPI-ESM1-2-HR.rds`:
![Screenshot_2022-11-09_at_11.28.56](/uploads/2d4194f33dd0c6f00b8bdd6d021c0ba2/Screenshot_2022-11-09_at_11.28.56.png)
the script works fine with this file: `/esarchive/scratch/pdeluca/landmarc/data/spei3_126_CanESM5.rds`.
correct output: ![Screenshot_2022-11-09_at_11.29.50](/uploads/90f341d314e7384c9ff62749853d415c/Screenshot_2022-11-09_at_11.29.50.png)https://earth.bsc.es/gitlab/es/easyNCDF/-/issues/6ArrayToNc: Wrong example in documentation2023-05-30T19:11:40+02:00ahoArrayToNc: Wrong example in documentationThe example at [line22-36](https://earth.bsc.es/gitlab/es/easyNCDF/-/blob/master/R/ArrayToNc.R#L22-36) returns error. The metadata should have the other variable aside from 'tos' since dimension `var = 2`.The example at [line22-36](https://earth.bsc.es/gitlab/es/easyNCDF/-/blob/master/R/ArrayToNc.R#L22-36) returns error. The metadata should have the other variable aside from 'tos' since dimension `var = 2`.https://earth.bsc.es/gitlab/es/easyNCDF/-/issues/4ArrayToNc: example in documentation using metadata attributes doesn't work2023-05-30T19:12:02+02:00Nuria Pérez-ZanónArrayToNc: example in documentation using metadata attributes doesn't workThe example in the function documentation for easyNCDF v0.0.7, doesn't work
```
a <- array(1:400, dim = c(5, 10, 4, 2))
metadata <- list( tos = list(addOffset = 100, scaleFact = 10, dim = list(list(name = 'time', unlim = FALSE))) )
att...The example in the function documentation for easyNCDF v0.0.7, doesn't work
```
a <- array(1:400, dim = c(5, 10, 4, 2))
metadata <- list( tos = list(addOffset = 100, scaleFact = 10, dim = list(list(name = 'time', unlim = FALSE))) )
attr(a, 'variables') <- metadata
names(dim(a)) <- c('lat', 'lon', 'time', 'var')
ArrayToNc(a, './MEDSCOPE/tmp.nc')
Error in vars_info[[j]] : subscript out of bounds
```https://earth.bsc.es/gitlab/es/easyNCDF/-/issues/3ArrayToNc: Not taking into account variable names in attributes list.2019-05-28T10:11:44+02:00Nicolau Manubens GilArrayToNc: Not taking into account variable names in attributes list.As reported by @rcruzgar , the following code doesn't correcly interpret the variable name 'sic_nohole' as provided in the 'variables' attribute in the input array, and the variable in the generated netCDF is assigned the default name va...As reported by @rcruzgar , the following code doesn't correcly interpret the variable name 'sic_nohole' as provided in the 'variables' attribute in the input array, and the variable in the generated netCDF is assigned the default name var1_1. Older versions of this function took the name correctly.
```r
library(easyNCDF)
sic_nohole <- array(rnorm(360*180*460), dim = c(lat = 180, lon = 360, time = 460))
lon <- as.numeric(0:359)
lat <- as.numeric(seq(-90, 90, length.out = 180))
names(dim(sic_nohole)) <- c('lat', 'lon','time')
metadata <- list(sic_nohole = list(units = '1'))
attr(sic_nohole, 'variables') <- metadata
dim(lon) <- length(lon)
names(dim(lon)) <- 'lon'
metadata <- list(lon = list(units = 'degrees_east'))
attr(lon, 'variables') <- metadata
dim(lat) <- length(lat)
names(dim(lat)) <- 'lat'
metadata <- list(lat = list(units = 'degrees_north'))
attr(lat, 'variables') <- metadata
ArrayToNc(list(sic_nohole, lon, lat), 'tmp.nc')
```
```
ncdump -h tmp.nc
netcdf tmp {
dimensions:
lat = 180 ;
lon = 360 ;
time = UNLIMITED ; // (460 currently)
variables:
float var1_1(time, lon, lat) ;
float lon(lon) ;
lon:units = "degrees_east" ;
float lat(lat) ;
lat:units = "degrees_north" ;
}
```Nicolau Manubens GilNicolau Manubens Gilhttps://earth.bsc.es/gitlab/es/easyNCDF/-/issues/2NcToArray: order of returned array dimensions not as requested in parameter ...2018-03-05T23:37:42+01:00Nicolau Manubens GilNcToArray: order of returned array dimensions not as requested in parameter `dim_indices`Causing the bug reported in https://earth.bsc.es/gitlab/es/startR/issues/3Causing the bug reported in https://earth.bsc.es/gitlab/es/startR/issues/3Nicolau Manubens GilNicolau Manubens Gilhttps://earth.bsc.es/gitlab/es/easyNCDF/-/issues/1NcToArray: Bug when `expect_all_indices = TRUE` and extra dimensions of lengt...2018-03-05T23:37:42+01:00Nicolau Manubens GilNcToArray: Bug when `expect_all_indices = TRUE` and extra dimensions of length 1."Error in permutation of wrong length" when `expect_all_indices = TRUE` and there are extra dimensions of length 1 in the file."Error in permutation of wrong length" when `expect_all_indices = TRUE` and there are extra dimensions of length 1 in the file.Release of v0.0.3Nicolau Manubens GilNicolau Manubens Gil