-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
79 lines (59 loc) · 2.6 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# pymdim
<!-- badges: start -->
<!-- badges: end -->
The goal of pymdim is to wrap the osgeo.gdal python package for multidim raster.
## Installation
You can install the development version of pymdim like so:
``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(pymdim)
devtools::load_all()
dsn <- sample(eopf_zarr_examples(), 1)
#dsn <- "ZARR:\"/vsizip//vsicurl/https://eopf-public.s3.sbg.perf.cloud.ovh.net/eoproducts/S01SIWSLC_20231201T170634_0027_A117_S27C_VH_IW1_249411.zarr.zip\""
#dsn <- "ZARR:\"/vsizip//vsicurl/https://eopf-public.s3.sbg.perf.cloud.ovh.net/eoproducts/S02MSIL1C_20230629T063559_0000_A064_T3A5.zarr.zip\""
ds <- multidimraster(dsn)
get_all_array_full_names(ds$GetRootGroup())
.alldimensions(ds)
.allaxes(ds)
.allgrids(ds)
```
In Python we can use a similar approach
```python
from osgeo import gdal
dsn = "ZARR:\"/vsizip//vsicurl/https://eopf-public.s3.sbg.perf.cloud.ovh.net/eoproducts/S02MSIL1C_20230629T063559_0000_A064_T3A5.zarr.zip\""
def fun(g):
groups = g.GetGroupNames()
groupname = g.GetFullName()
amd = g.GetMDArrayNames()
md = [f'{groupname}/{amd0}' for amd0 in amd]
md = flatten([md, [fun(g.OpenGroup(g0)) for g0 in groups]])
return md
def flatten(S):
if S == []:
return S
if isinstance(S[0], list):
return flatten(S[0]) + flatten(S[1:])
return S[:1] + flatten(S[1:])
ds = gdal.OpenEx(dsn, gdal.OF_MULTIDIM_RASTER)
g = ds.GetRootGroup()
fun(g)
#['/conditions/geometry/angle', '/conditions/geometry/band', '/conditions/geometry/detector', #'/conditions/geometry/x', '/conditions/geometry/y', '/conditions/geometry/mean_sun_angles', #'/conditions/geometry/mean_viewing_incidence_angles', '/conditions/geometry/sun_angles', #'/conditions/geometry/viewing_incidence_angles', '/conditions/mask/detector_footprint/r10m/x', #'/conditions/mask/detector_footprint/r10m/y', '/conditions/mask/detector_footprint/r10m/b02', #'/conditions/mask/detector_footprint/r10m/b03', '/conditions/mask/detector_footprint/r10m/b04', #'/conditions/mask/detector_footprint/r10m/b08', '/conditions/mask/detector_footprint/r20m/x', #'/conditions/mask/detector_footprint/r20m/y', '/conditions/mask/detector_footprint/r20m/b05', #'/conditions/mask/detector_footprint/r2...
```