File: start.md

package info (click to toggle)
xcube-resampling 0.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,800 kB
  • sloc: python: 7,943; makefile: 9
file content (77 lines) | stat: -rw-r--r-- 1,902 bytes parent folder | download
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
# Getting Started

The `xcube-resampling` package can be installed into an existing Python environment
using

```bash
pip install xcube-resampling
```

or

```bash
conda install -c conda-forge xcube-resampling
```

After installation, you are ready to go and use `resample_in_space` to resample you
datasets: 

### Generate a sample dataset

```python
import numpy as np
import xarray as xr

res = 0.1
source_ds = xr.Dataset(
    data_vars=dict(
        refl=xr.DataArray(
            np.array(
                [
                    [0, 1, 0, 2, 0, 3, 0, 4],
                    [2, 0, 3, 0, 4, 0, 1, 0],
                    [0, 4, 0, 1, 0, 2, 0, 3],
                    [1, 0, 2, 0, 3, 0, 4, 0],
                    [0, 3, 0, 4, 0, 1, 0, 2],
                    [4, 0, 1, 0, 2, 0, 3, 0],
                ],
                dtype=np.float64,
            ),
            dims=("lat", "lon"),
        )
    ),
    coords=dict(
        lon=xr.DataArray(50.0 + res * np.arange(0, 8) + 0.5 * res, dims="lon"),
        lat=xr.DataArray(10.6 - res * np.arange(0, 6) - 0.5 * res, dims="lat"),
    ),
)
```

### Apply resampling

```python
from xcube_resampling.spatial import resample_in_space
from xcube_resampling.gridmapping import GridMapping

target_gm = GridMapping.regular((3, 3), (50.05, 10.05), 0.2, "EPSG:4326")
target_ds = resample_in_space(source_ds, target_gm=target_gm)
```


The resulting dataset `target_ds` has a size of 3×3, as defined by the target 
grid mapping:

```text
<xarray.Dataset> Size: 128B
Dimensions:      (lat: 3, lon: 3)
Coordinates:
    spatial_ref  int64 8B 0
  * lon          (lon) float64 24B 50.15 50.35 50.55
  * lat          (lat) float64 24B 10.55 10.35 10.15
Data variables:
    refl         (lat, lon) float64 72B 0.875 1.375 1.375 1.5 ... 1.25 1.5 1.0

```

For more examples, including visualization, please refer to the
[Example Notebooks](examples/affine.ipynb).