grimbough / Rarr

A simple native R reader for Zarr Arrays
https://bioconductor.org/packages/Rarr/
MIT License
34 stars 5 forks source link

Reading group of arrays fails for some reason #9

Closed idaflik closed 2 months ago

idaflik commented 2 months ago

Hi, I hope I'm not overseeing some basic mistake from my side, but I feel like this should work but doesn't. What works:

> z1 <- system.file("extdata", "zarr_examples", "row-first",
+                   "int32.zarr",
+                   package = "Rarr"
+ )

> zarr_overview(z1)

Type: Array
Path: /net/home/iflik/R/x86_64-pc-linux-gnu-library/4.4/Rarr/extdata/zarr_examples/row-first/int32.zarr
Shape: 30 x 20 x 10
Chunk Shape: 10 x 10 x 5
No. of Chunks: 12 (3 x 2 x 2)
Data Type: int32
Endianness: little
Compressor: blosc

> read_zarr_array(zarr_array_path = z1, index = list(1:10, 1:5, 1))
, , 1

      [,1] [,2] [,3] [,4] [,5]
 [1,]    1    2    3    4    5
 [2,]    1    0    0    0    0
 [3,]    1    0    0    0    0
 [4,]    1    0    0    0    0
 [5,]    1    0    0    0    0
 [6,]    1    0    0    0    0
 [7,]    1    0    0    0    0
 [8,]    1    0    0    0    0
 [9,]    1    0    0    0    0
[10,]    1    0    0    0    0

But with my own file the exact same works until zarr_overview() but for the exact same file path says "Error in open.connection(con, "rb") : cannot open the connection"

> z1 <- "/net/data/MODIS/MCD43C4/gapfilled-kndvi-8D-0.05deg-1x3600x7200/data/gapfilled_kndvi_2000-2023_8D_0.05deg_1x3600x7200.zarr"

> zarr_overview(z1)

Type: Group of Arrays
Path: /net/data/MODIS/MCD43C4/gapfilled-kndvi-8D-0.05deg-1x3600x7200/data/gapfilled_kndvi_2000-2023_8D_0.05deg_1x3600x7200.zarr
Arrays:
---
  Path: GAPFILL_kNDVI
  Shape: 1098 x 3600 x 7200
  Chunk Shape: 1 x 3600 x 7200
  No. of Chunks: 1098 (1098 x 1 x 1)
  Data Type: float32
  Endianness: little
  Compressor: blosc
---
  Path: lat
  Shape: 3600
  Chunk Shape: 3600
  No. of Chunks: 1 (1)
  Data Type: float64
  Endianness: little
  Compressor: blosc
---
  Path: lon
  Shape: 7200
  Chunk Shape: 7200
  No. of Chunks: 1 (1)
  Data Type: float64
  Endianness: little
  Compressor: blosc
---
  Path: time
  Shape: 1098
  Chunk Shape: 46
  No. of Chunks: 24 (24)
  Data Type: int64
  Endianness: little
  Compressor: blosc

> read_zarr_array(zarr_array_path = "/net/data/MODIS/MCD43C4/gapfilled-kndvi-8D-0.05deg-1x3600x7200/data/gapfilled_kndvi_2000-2023_8D_0.05deg_1x3600x7200.zarr",
+                       index = list(1, NULL, NULL))

Error in open.connection(con, "rb") : cannot open the connection
In addition: Warning message:
In open.connection(con, "rb") :
  cannot open file '/net/data/MODIS/MCD43C4/gapfilled-kndvi-8D-0.05deg-1x3600x7200/data/gapfilled_kndvi_2000-2023_8D_0.05deg_1x3600x7200.zarr/.zarray': No such file or directory

Any idea why?

idaflik commented 2 months ago

never mind - typing it out cleared it for me. needed to append "/GAPFILL_kNDVI" to the file path so that i'm reading in the GAPFILL_kNDVI array instead of a group of arrays. sorry!