Skip to main content

cubo

On-Demand Earth System Data Cubes (ESDCs) in Python

PyPI conda-forge Documentation Status Documentation Status Documentation Status Tests License GitHub Sponsors Buy me a coffee Ko-fi Twitter Black isort


GitHub: https://github.com/davemlz/cubo

Documentation: https://cubo.readthedocs.io/

PyPI: https://pypi.org/project/cubo/

Conda-forge: https://anaconda.org/conda-forge/cubo

Tutorials: https://cubo.readthedocs.io/en/latest/tutorials.html

Paper: https://doi.org/10.1109/IGARSS53475.2024.10640742


News

Overview

SpatioTemporal Asset Catalogs (STAC) provide a standardized format that describes geospatial information. Multiple platforms are using this standard to provide clients several datasets. Nice platforms such as Planetary Computer use this standard. Additionally, Google Earth Engine (GEE) also provides a gigantic catalogue that users can harness for different tasks in Python.

cubo is a Python package that provides users of STAC and GEE an easy way to create On-Demand Earth System Data Cubes (ESDCs). This is perfectly suitable for Deep Learning (DL) tasks. You can easily create a lot of ESDCs by just knowing a pair of coordinates and the edge size of the cube in pixels!

Check the simple usage of cubo with STAC here:

import cubo
import xarray as xr

da = cubo.create(
    lat=4.31, # Central latitude of the cube
    lon=-76.2, # Central longitude of the cube
    collection="sentinel-2-l2a", # Name of the STAC collection
    bands=["B02","B03","B04"], # Bands to retrieve
    start_date="2021-06-01", # Start date of the cube
    end_date="2021-06-10", # End date of the cube (included)
    edge_size=64, # Edge size of the cube (px)
    resolution=10, # Pixel size of the cube (m)
)

Cubo Description

This chunk of code just created an xr.DataArray object given a pair of coordinates, the edge size of the cube (in pixels), and additional information to get the data from STAC (Planetary Computer by default, but you can use another provider!). Note that you can also use the resolution you want (in meters) and the bands that you require.

Now check the simple usage of cubo with GEE here:

import cubo
import xarray as xr

da = cubo.create(
    lat=51.079225, # Central latitude of the cube
    lon=10.452173, # Central longitude of the cube
    collection="COPERNICUS/S2_SR_HARMONIZED", # Id of the GEE collection
    bands=["B2","B3","B4"], # Bands to retrieve
    start_date="2016-06-01", # Start date of the cube
    end_date="2017-07-01", # End date of the cube (included)
    edge_size=128, # Edge size of the cube (px)
    resolution=10, # Pixel size of the cube (m)
    gee=True # Use GEE instead of STAC
)

This chunk of code is very similar to the STAC-based cubo code. Note that the collection is now the ID of the GEE collection to use, and note that the gee argument must be set to True (or stac="ee").

And you can even combine multiple collections from STAC and GEE in one cube:

import cubo

dt = cubo.create(
    lat=51.3397, # Central latitude of the cube
    lon=12.3731, # Central longitude of the cube
    collection=["sentinel-2-l2a", "COPERNICUS/S2_CLOUD_PROBABILITY"], # Collections to use
    bands={"sentinel-2-l2a": ["B02", "B03", "B04"], "COPERNICUS/S2_CLOUD_PROBABILITY": "probability"}, # Bands of each collection
    stac={
        "https://planetarycomputer.microsoft.com/api/stac/v1": "sentinel-2-l2a", # STAC collections
        "ee": "COPERNICUS/S2_CLOUD_PROBABILITY", # GEE collections
    },
    start_date="2022-06-14", # Start date of the cube
    end_date="2022-06-17", # End date of the cube (included)
    edge_size=128, # Edge size of the cube (px)
    resolution=10, # Pixel size of the cube (m)
    datatree=True, # One node per collection
)

All collections share the same pixel grid, so they are co-registered by design!

How does it work?

The thing is super easy and simple.

  1. You have the coordinates of a point of interest. The cube will be created around these coordinates (i.e., these coordinates will be approximately the spatial center of the cube).
  2. Internally, the coordinates are transformed to the projected UTM coordinates [x,y] in meters (i.e., local UTM CRS). They are rounded to the closest pair of coordinates that are divisible by the resolution you requested.
  3. The edge size you provide is used to create a Bounding Box (BBox) for the cube in the local UTM CRS given the exact amount of pixels (Note that the edge size should be a multiple of 2, otherwise it will be rounded, usual edge sizes for ML are 64, 128, 256, 512, etc.).
  4. Additional information is used to retrieve the data from the STAC catalogue or from GEE: starts and end dates, name of the collection(s), endpoint of the catalogue(s), etc.
  5. Then, by using stackstac and pystac_client the cube is retrieved as a xr.DataArray. In the case of GEE, the cube is retrieved via xee using exactly the same pixel grid. When using multiple collections, the cubes are merged, or returned as a xr.DataTree.
  6. Success! That's what cubo is doing for you, and you just need to provide the coordinates, the edge size, and the additional info to get the cube.

Installation

Install the latest version from PyPI:

pip install cubo

Install cubo with the required GEE dependencies from PyPI:

pip install cubo[ee]

Upgrade cubo by running:

pip install -U cubo

Install the latest version from conda-forge:

conda install -c conda-forge cubo

Install the latest dev version from GitHub by running:

pip install git+https://github.com/davemlz/cubo

Features

Main function: create()

cubo is pretty straightforward, everything you need is in the create() function:

da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-06-01",
    end_date="2021-06-10",
    edge_size=64,
    resolution=10,
)

Using different units for edge_size

By default, the units of edge_size are pixels. But you can modify this using the units argument:

da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-06-01",
    end_date="2021-06-10",
    edge_size=1500,
    units="m",
    resolution=10,
)
da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-06-01",
    end_date="2021-06-10",
    edge_size=1.5,
    units="kilo",
    resolution=10,
)

Using another endpoint

By default, cubo uses Planetary Computer. But you can use another STAC provider endpoint if you want:

da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["rededge1","rededge2","rededge3"],
    start_date="2020-01-01",
    end_date="2020-06-01",
    edge_size=128,
    resolution=20,
    stac="https://earth-search.aws.element84.com/v1"
)

Keywords for searching data

You can pass kwargs to pystac_client.Client.search() if required:

da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-01-01",
    end_date="2021-06-10",
    edge_size=64,
    resolution=10,
    query={"eo:cloud_cover": {"lt": 40}} # kwarg to pass
)

Multiple collections

You can use multiple collections by passing a list to collection and a dictionary with the bands of each collection to bands. By default, the cubes are merged along the band dimension (the time dimension is the union of the timestamps of all collections):

da = cubo.create(
    lat=51.3397,
    lon=12.3731,
    collection=["sentinel-2-l2a", "sentinel-1-rtc"],
    bands={"sentinel-2-l2a": ["B04", "B08"], "sentinel-1-rtc": ["vv", "vh"]},
    start_date="2022-06-01",
    end_date="2022-06-15",
    edge_size=64,
    resolution=10,
)

DataTrees and Datasets

Collections rarely share timestamps. Use datatree=True to get a xr.DataTree with one node per collection (each one with its own time and band dimensions, but sharing the spatial coordinates), and dataset=True to get one variable per band:

dt = cubo.create(
    lat=51.3397,
    lon=12.3731,
    collection=["sentinel-2-l2a", "sentinel-1-rtc"],
    bands={"sentinel-2-l2a": ["B04", "B08"], "sentinel-1-rtc": ["vv", "vh"]},
    start_date="2022-06-01",
    end_date="2022-06-15",
    edge_size=64,
    resolution=10,
    datatree=True,
    dataset=True,
)

dt["sentinel-1-rtc"]["vv"]

Pixel coordinates

By default, the x and y coordinates are the top-left corners of the pixels (for both STAC and GEE). Use xy_coords="center" to get the center of the pixels instead:

da = cubo.create(
    lat=4.31,
    lon=-76.2,
    collection="sentinel-2-l2a",
    bands=["B02","B03","B04"],
    start_date="2021-06-01",
    end_date="2021-06-10",
    edge_size=64,
    resolution=10,
    xy_coords="center",
)

License

The project is licensed under the MIT license.

Citation

If you use this work, please consider citing the following paper:

@inproceedings{montero2024cubo,
  title = {On-Demand Earth System Data Cubes},
  url = {http://dx.doi.org/10.1109/IGARSS53475.2024.10640742},
  DOI = {10.1109/igarss53475.2024.10640742},
  booktitle = {IGARSS 2024 - 2024 IEEE International Geoscience and Remote Sensing Symposium},
  publisher = {IEEE},
  author = {Montero,  David and Aybar,  César and Ji,  Chaonan and Kraemer,  Guido and S\"{o}chting,  Maximilian and Teber,  Khalil and Mahecha,  Miguel D.},
  year = {2024},
  month = jul,
  pages = {7529–7532}
}

Logo Attribution

The logo and images were created using dice icons created by Freepik - Flaticon.

RSC4Earth

Metadata

Release files for cubo 2026.10.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 cubo 2026.10.0
File Size Uploaded Provenance Actions
cubo-2026.10.0.tar.gz 23.0 kB With provenance Details for cubo-2026.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cubo 2026.10.0
File Interpreter ABI Platform Actions
cubo-2026.10.0-py3-none-any.whl Python 3 none any Details for cubo-2026.10.0-py3-none-any.whl

Total release size: 40.0 kB

Release files / cubo-2026.10.0.tar.gz

Download URL cubo-2026.10.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ac7dcb0151c331227cb92c88912652cdd4a49740651d9134c199dda0f9474ef4
BLAKE2b-256 checksum
How to use checksums
3d43c2384158f400b547168ab635d19404a06b96795b6f73f81a7ec131bd22e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / cubo-2026.10.0-py3-none-any.whl

Download URL cubo-2026.10.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f229b67ae6393e0adf03707d811153781b064a0226e776ac6a96e0467563742d
BLAKE2b-256 checksum
How to use checksums
1589ff5411ccd0cf27d60cf95cb9b4e357a6071bf4b21c77d775824d50043545
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for cubo 2026.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cubo-2026.10.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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