Skip to main content

This driver enables mapchete to write multidimensional arrays into a Zarr archive.

https://badge.fury.io/py/mapchete-xarray.svg https://github.com/ungarj/mapchete_xarray/actions/workflows/python-package.yml/badge.svg https://coveralls.io/repos/github/ungarj/mapchete_xarray/badge.svg?branch=master https://img.shields.io/pypi/pyversions/mapchete_xarray.svg

This driver creates a Zarr according to the structure used by the GDAL Zarr driver. Bands are stored in separate 2D arrays (y, x). If a time dimension is configured, the time axis is applied to the individual bands (time, y, x).

When using a time axis, please note that it has to be initialized with the full time range, i.e. it is not possible to extend the time axis after it was initialized.

If you plan extending your Zarr over multiple process runs you can achieve this by always specifying the full time range in the output configuration and then simply write a couple of slices per process run. Please note that for every process run after initialization you will have to use the –overwrite flag, otherwise the process tile will be skipped.

Usage

A process file can either return a xarray.Dataset, xarray.DataArray or a numpy.ndarray object. Please make sure though that when using a time axis, the timestamps of the slices have to be provided. In case of returning a numpy.ndarray this information is not available so this array has to match exactly to the output Zarr shape on the time and bands axes.

3D output array

For a simple 3D (bands, x, y) output:

# example.mapchete
process: process.py
zoom_levels:
    min: 0
    max: 12
input:
output:
    format: xarray
    path: output.zarr
    dtype: uint16
    bands: 3
pyramid:
    grid: geodetic
    metatiling: 2
# process.py
import numpy as np
import xarray as xr


def execute(
    mp,
    bands=3,
    dtype="uint16",
):
    shape = (bands, *mp.tile.shape)
    dims = ["bands", "Y", "X"]
    coords = {}

    return xr.DataArray(
        data=np.full(shape=shape, fill_value=500, dtype=dtype),
        dims=dims,
        coords=coords,
    )

4D output array

For a simple 4 (time, bands, x, y) output:

# example.mapchete
process: process.py
zoom_levels:
    min: 0
    max: 12
input:
output:
    format: xarray
    path: output.zarr
    dtype: uint16
    bands: 3
    time:
        start: 2022-03-01
        end: 2022-03-31
        pattern: 0 0 * * *
        chunksize: 10
        # alternatively you can use steps:
        # steps:
        #     - 2022-06-01
        #     - 2022-06-04
        #     - 2022-06-06
        #     - 2022-06-09
        #     - 2022-06-11
pyramid:
    grid: geodetic
    metatiling: 2
# process.py
import dateutil
import numpy as np
import xarray as xr


def execute(
    mp,
    bands=3,
    dtype="uint16",
    timestamps=None,
):
    timestamps = [
        "2022-03-01",
        "2022-03-02",
        "2022-03-04",
        "2022-03-07",
        "2022-03-09",
    ]
    shape = (bands, len(timestamps), *mp.tile.shape)
    dims = ["band", "time", "Y", "X"]
    coords = {"time": [dateutil.parser.parse(t) for t in timestamps]}

    return xr.DataArray(
        data=np.full(shape=shape, fill_value=500, dtype=dtype),
        dims=dims,
        coords=coords,
    )

Installation

# install using pip:
$ pip install mapchete_xarray
# verify driver is vailable ('xarray' should be listed as output format):
$ mapchete formats

Current Limitations

  • No reprojection allowed when reading from a Zarr archive.

  • No output pixelbuffer possible.

License

MIT License

Copyright (c) 2019-2022 EOX IT Services

Release files for mapchete-xarray 2023.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mapchete-xarray 2023.6.0
File Size Uploaded
mapchete_xarray-2023.6.0.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mapchete-xarray 2023.6.0
File Interpreter ABI Platform
mapchete_xarray-2023.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.9 kB

Release files / mapchete_xarray-2023.6.0.tar.gz

Download URL mapchete_xarray-2023.6.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fa471cd688c37c249d9fc1bf849c809f26ed7b2e29b9e426cee3440e43ec72e7
BLAKE2b-256 checksum
How to use checksums
50a8b5ca5da89153918158002af4439877e6058dc19b196ce6d826fb9c8dd0ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / mapchete_xarray-2023.6.0-py3-none-any.whl

Download URL mapchete_xarray-2023.6.0-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9a94034bc29eed39185dc0a13449977f0f070930b23bacb351e7b893ed9b4a3
BLAKE2b-256 checksum
How to use checksums
15dc07d92cfcf6240aa3b147ee2f54915612fdf0918ea54c507e8ae59dfb1e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

2023.6.0 This release

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page