Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with mdim test: Error: cannot open driver #692

Closed
barracuda156 opened this issue Jun 26, 2024 · 8 comments
Closed

Error with mdim test: Error: cannot open driver #692

barracuda156 opened this issue Jun 26, 2024 · 8 comments

Comments

@barracuda156
Copy link

Any idea why this may be failing?

R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: powerpc-apple-darwin10.0.0d2 (32-bit)

> Sys.setenv(TZ="")
> suppressPackageStartupMessages(library(stars))
> matrix(1:4,2)
     [,1] [,2]
[1,]    1    3
[2,]    2    4
> m = matrix(1:4,2)
> s = st_as_stars(m)
> 
> s = st_set_dimensions(s, st_dimensions(s), xy = NULL) 
> sfc = st_sfc(st_point(0:1), st_point(3:2))
> s = st_set_dimensions(s, 1, sfc) |> st_set_crs(4326)
> tm = as.POSIXct("2023-03-04 12:35") + c(0, 3600)
> s = st_set_dimensions(s, 2, tm)
> f = tempfile(fileext = ".nc")
> write_mdim(s, f, as_float = FALSE)
Error: cannot open driver
Execution halted
@barracuda156 barracuda156 changed the title Errow with mdim test: Error: cannot open driver Error with mdim test: Error: cannot open driver Jun 26, 2024
@barracuda156
Copy link
Author

The same failure occurs with examples:

The error most likely occurred in:

> ### Name: mdim
> ### Title: Read or write data using GDAL's multidimensional array API
> ### Aliases: mdim read_mdim write_mdim
> 
> ### ** Examples
> 
> set.seed(135)
> m = matrix(runif(10), 2, 5)
> names(dim(m)) = c("stations", "time")
> times = as.Date("2022-05-01") + 1:5
> pts = st_as_sfc(c("POINT(0 1)", "POINT(3 5)"))
> s = st_as_stars(list(Precipitation = m)) |>
+  st_set_dimensions(1, values = pts) |>
+  st_set_dimensions(2, values = times)
> nc = tempfile(fileext=".nc")
> if (compareVersion(sf_extSoftVersion()["GDAL"], "3.4.0") > -1) {
+   write_mdim(s, nc)
+   # try ncdump on the generated file
+   print(read_mdim(nc))
+ }
Error: cannot open driver

@edzer
Copy link
Member

edzer commented Jun 26, 2024

I'm seeing

Sys.setenv(TZ="")
library(stars)
# Loading required package: abind
# Loading required package: sf
# Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
m = matrix(1:4,2)
s = st_as_stars(m)
s = st_set_dimensions(s, st_dimensions(s), xy = NULL)
sfc = st_sfc(st_point(0:1), st_point(3:2))
s = st_set_dimensions(s, 1, sfc) |> st_set_crs(4326)
tm = as.POSIXct("2023-03-04 12:35") + c(0, 3600)
s = st_set_dimensions(s, 2, tm)
f = tempfile(fileext = ".nc")
write_mdim(s, f, as_float = FALSE)
# Warning messages:
# 1: In CPL_write_mdim(file, driver, dimx, cdl, wkt, xy, root_group_options,  :
#   GDAL Error 6: SetIndexingVariable() not implemented
# 2: In CPL_write_mdim(file, driver, dimx, cdl, wkt, xy, root_group_options,  :
#   GDAL Error 6: SetIndexingVariable() not implemented
read_mdim(f)
# stars object with 2 dimensions and 1 attribute
# attribute(s):
#     Min. 1st Qu. Median Mean 3rd Qu. Max.
# A1     1    1.75    2.5  2.5    3.25    4
# dimension(s):
#    from to                  offset   delta  refsys point
# X1    1  2                      NA      NA  WGS 84  TRUE
# X2    1  2 2023-03-04 12:35:00 UTC 1 hours POSIXct    NA
#                      values
# X1 POINT (0 1), POINT (3 2)
# X2                     NULL

Is this a GDAL version issue?

@barracuda156
Copy link
Author

@edzer Perhaps 3.9.0 is not too old? https://ports.macports.org/port/gdal

@edzer
Copy link
Member

edzer commented Jun 26, 2024

It's not about the age, but about how GDAL was built: linked against libnetcdf, or not. If not, the netcdf driver is missing and you get errors of this type.

@barracuda156
Copy link
Author

barracuda156 commented Jun 26, 2024

@edzer I am building GDAL now with netcdf support enabled. Once confirmed tests pass then, I will close both issues as resolved.

P. S. Perhaps it is worth adding a note about this requirement though. Currently nothing is said about GDAL being linked to netcdf: https://cran.r-project.org/web/packages/stars/index.html
sf is also silent: https://cran.r-project.org/web/packages/sf/index.html
So how one is supposed to know it is necessary?

@edzer
Copy link
Member

edzer commented Jun 26, 2024

I could add a message at startup time of stars when the netcdf driver is missing.

@barracuda156
Copy link
Author

I could add a message at startup time of stars when the netcdf driver is missing.

That will be helpful, I think.

@barracuda156
Copy link
Author

barracuda156 commented Jun 26, 2024

@edzer Files are now found, but specifically mdim example and test still fail for me, though differently:

* checking examples ...sh: line 1: 70105 Segmentation fault      LANGUAGE=en _R_CHECK_INTERNALS2_=1 '/opt/local/Library/Frameworks/R.framework/Resources/bin/R' --vanilla --encoding=UTF-8 > 'stars-Ex.Rout' 2>&1 < 'stars-Ex.R'
 ERROR
Running examples in ‘stars-Ex.R’ failed
The error most likely occurred in:

> ### Name: mdim
> ### Title: Read or write data using GDAL's multidimensional array API
> ### Aliases: mdim read_mdim write_mdim
> 
> ### ** Examples
> 
> set.seed(135)
> m = matrix(runif(10), 2, 5)
> names(dim(m)) = c("stations", "time")
> times = as.Date("2022-05-01") + 1:5
> pts = st_as_sfc(c("POINT(0 1)", "POINT(3 5)"))
> s = st_as_stars(list(Precipitation = m)) |>
+  st_set_dimensions(1, values = pts) |>
+  st_set_dimensions(2, values = times)
> nc = tempfile(fileext=".nc")
> if (compareVersion(sf_extSoftVersion()["GDAL"], "3.4.0") > -1) {
+   write_mdim(s, nc)
+   # try ncdump on the generated file
+   print(read_mdim(nc))
+ }
Warning in CPL_write_mdim(file, driver, dimx, cdl, wkt, xy, root_group_options,  :
  GDAL Error 6: SetIndexingVariable() not implemented
Warning in CPL_write_mdim(file, driver, dimx, cdl, wkt, xy, root_group_options,  :
  GDAL Error 6: SetIndexingVariable() not implemented

 *** caught segfault ***
address 0xc0000000, cause 'memory not mapped'

Traceback:
 1: CPL_write_mdim(file, driver, dimx, cdl, wkt, xy, root_group_options,     options, as_float)
 2: gdal_write_mdim(filename, driver, c(dim(x), attr(cdl, "dims")),     cdl, wkt, xy, root_group_options = root_group_options, options = options,     as_float = as_float)
 3: write_mdim(s, nc)
An irrecoverable exception occurred. R is aborting now ...
  Running ‘mdim.R’/opt/local/Library/Frameworks/R.framework/Resources/bin/BATCH: line 60: 70383 Segmentation fault      ${R_HOME}/bin/R -f ${in} ${opts} ${R_BATCH_OPTIONS} > ${out} 2>&1

 ERROR
Running the tests in ‘tests/mdim.R’ failed.
Last 13 lines of output:
  > sfc = st_sfc(st_point(0:1), st_point(3:2))
  > s = st_set_dimensions(s, 1, sfc) |> st_set_crs(4326)
  > tm = as.POSIXct("2023-03-04 12:35") + c(0, 3600)
  > s = st_set_dimensions(s, 2, tm)
  > f = tempfile(fileext = ".nc")
  > write_mdim(s, f, as_float = FALSE)
  
   *** caught segfault ***
  address 0xc0000000, cause 'memory not mapped'
  
  Traceback:
   1: CPL_write_mdim(file, driver, dimx, cdl, wkt, xy, root_group_options,     options, as_float)
   2: gdal_write_mdim(filename, driver, c(dim(x), attr(cdl, "dims")),     cdl, wkt, xy, root_group_options = root_group_options, options = options,     as_float = as_float)
   3: write_mdim(s, f, as_float = FALSE)
  An irrecoverable exception occurred. R is aborting now ...
* DONE

Status: 2 ERRORs, 1 WARNING, 2 NOTEs
See
  ‘/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_R_R-stars/R-stars/work/stars/stars.Rcheck/00check.log’
for details.

But it looks like it is using R BATCH, which is known to be broken for w/e reason: https://trac.macports.org/ticket/67059

All other tests now pass (with GDAL +netcdf).

edzer added a commit that referenced this issue Jun 26, 2024
@edzer edzer closed this as completed Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants