ropensci / tidync

NetCDF exploration and data extraction
https://docs.ropensci.org/tidync
90 stars 12 forks source link

compound type and group support #43

Open mdsumner opened 7 years ago

mdsumner commented 7 years ago

Two good examples are

KEA: https://gist.github.com/mdsumner/a65ce8d42edfda5e649c7c4f858303b3#file-kea_rhdf5-r-L6

L3BIN format

https::/github.com/mdsumner/roc

mdsumner commented 7 years ago

Groups without compound types here

u <- "https://www.unidata.ucar.edu/software/netcdf/examples/test_hgroups.nc"
tfile <- file.path(tempdir(), basename(u))
download.file(u, tfile, mode = "wb")

library(tidync)
tidync(tfile)
ncdf4::nc_open(tfile)

All the ncdf4 handling is internal, RNetCDF doesn't support them atm.

mdsumner commented 7 years ago

RNetCDF is planning to support these, but also see h5 and rhdf5.

mdsumner commented 6 years ago

Example with starsdata: https://github.com/r-spatial/stars/issues/54#issuecomment-422262589

mdsumner commented 6 years ago

nHere's a recursive approach to get the group names with RNetCDF 2.0.0

s5p = system.file("sentinel5p/S5P_NRTI_L2__NO2____20180717T120113_20180717T120613_03932_01_010002_20180717T125231.nc", package = "starsdata")
library(RNetCDF)
recurse_ptrs <- function(l, tag) {
  lapply(l, modify_ptr, name = tag)
}

modify_ptr <- function(ptr, name) {
  g <- grp.inq.nc(ptr)
  if (length(g$grps) > 0) recurse_ptrs(g$grps, tag = paste(c(name, g$name), collapse = "/")) else paste(c(name, g$name), collapse = "/")
}
x <- recurse_ptrs(grp.inq.nc(open.nc(s5p))$grps, "")
str(unlist(x))
 chr [1:271] "/PRODUCT/SUPPORT_DATA/GEOLOCATIONS" "/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS" "/PRODUCT/SUPPORT_DATA/INPUT_DATA" ...

grp.inq.nc(open.nc(s5p), unlist(x)[6])
etc. etc. 
mdsumner commented 6 years ago

Ugh, this is not going to be fun. ncdf4 already supports groups, but we don't harvest metadata from ncdf4.

If we can use RNetCDF we can pass in the pointer for the appropriate group, and rewind ahead from nc_meta - but if we have to use ncdf4 we have to write another ncmeta extraction for it. That would be helpful anyway so maybe that.

mdsumner commented 6 years ago

actually looks like it can work, most of the effort will be in ncmeta@groups https://github.com/hypertidy/ncmeta/tree/groups

mdsumner commented 5 years ago

Try this HECRAS stuff https://github.com/mkoohafkan/RAStestR/tree/master/inst/sample-data

mdsumner commented 2 years ago

another example in terra issues #686