reticulate::use_python("/workenv/bin/python3")
reticulate::py_require("numcodecs")
numcodecs <- reticulate::import("numcodecs")
## just found by eye
zlib <- numcodecs$zlib$Zlib(4L)
file <- "NSIDC0051_SEAICE_PS_S25km_19781026_v2.0.nc"
virtualizarr <- reticulate::import("virtualizarr")
varname <- "N07_ICECON"
## I can get the encoding if I *load* it, which means the reference-encoding is somewhere else in the xarray
ds <- virtualizarr$open_virtual_dataset(file, loadable_variables = varname)
enc <- ds[[varname]]$encoding
ds <- virtualizarr$open_virtual_dataset(file)
## the manifest of references, we just grab one (there is only one in this file)
mani <- ds[[varname]]$variable$data$manifest$dict()[[1]]
## raw binary connection
con <- file(mani$path, "rb")
## seek to start of compressed chunk
seek(con, mani$offset)
endian <- "little"
bytes <- readBin(con, "raw", size = 1, n = mani$length, endian = "big", signed = TRUE)
close(con)
## these are uint8
ints <- readBin(as.raw(zlib$decode(bytes)), "int", size = 1, signed = FALSE, n = prod(unlist(enc$chunksizes)))
ximage::ximage(matrix(ints, rev(unlist(enc$chunksizes))[2]))
Last active
March 26, 2025 07:31
-
-
Save mdsumner/638848fb77d3b6d36a36ce0ea3e37350 to your computer and use it in GitHub Desktop.
Author
mdsumner
commented
Mar 26, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment