Package: cubo
On-Demand Earth System Data Cubes (ESDCs) in PythonGitHub:https://github.com/davemlz/cuboDocumentation:https://cubo.readthedocs.io/PyPI:https://pypi.org/project/cubo/Conda-forge:https://anaconda.org/conda-forge/cuboTutorials:https://cubo.readthedocs.io/en/latest/tutorials.htmlOverviewSpatioTemporal 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 asPlanetary Computeruse this standard.
Additionally,Google Earth Engine (GEE)also provides a gigantic catalogue that users can harness for different tasks in Python.cubois 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 ofcubowith STAC here:importcuboimportxarrayasxrda=cubo.create(lat=4.31,# Central latitude of the cubelon=-76.2,# Central longitude of the cubecollection="sentinel-2-l2a",# Name of the STAC collectionbands=["B02","B03","B04"],# Bands to retrievestart_date="2021-06-01",# Start date of the cubeend_date="2021-06-10",# End date of the cubeedge_size=64,# Edge size of the cube (px)resolution=10,# Pixel size of the cube (m))This chunk of code just created anxr.DataArrayobject 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 ofcubowith GEE here:importcuboimportxarrayasxrda=cubo.create(lat=51.079225,# Central latitude of the cubelon=10.452173,# Central longitude of the cubecollection="COPERNICUS/S2_SR_HARMONIZED",# Id of the GEE collectionbands=["B2","B3","B4"],# Bands to retrievestart_date="2016-06-01",# Start date of the cubeend_date="2017-07-01",# End date of the cubeedge_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 thecollectionis now the ID of the GEE collection to use, and note that thegeeargument must be set toTrue.How does it work?The thing is super easy and simple.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).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.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.).Additional information is used to retrieve the data from the STAC catalogue or from GEE: starts and end dates, name of the collection, endpoint of the catalogue (ignored for GEE), etc.Then, by usingstackstacandpystac_clientthe cube is retrieved as axr. DataArray. In the case of GEE, the cube is retrieved
viaxee.Success! That's whatcubois doing for you, and you just need to provide the coordinates, the edge size, and the additional info to get the cube.InstallationInstall the latest version from PyPI:pip install cuboInstallcubowith the required GEE dependencies from PyPI:pip install cubo[ee]Upgradecuboby running:pip install -U cuboInstall the latest version from conda-forge:conda install -c conda-forge cuboInstall the latest dev version from GitHub by running:pip install git+https://github.com/davemlz/cuboFeaturesMain function:create()cubois pretty straightforward, everything you need is in thecreate()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 foredge_sizeBy default, the units ofedge_sizeare pixels. But you can modify this using theunitsargument: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,)[!TIP]
You can use "px" (pixels), "m" (meters), or any unit available inscipy.constants.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 endpointBy default,cubouses Planetary Computer. But you can use another STAC provider endpoint if you want:da=cubo.create(lat=4.31,lon=-76.2,collection="sentinel-s2-l2a-cogs",bands=["B05","B06","B07"],start_date="2020-01-01",end_date="2020-06-01",edge_size=128,resolution=20,stac="https://earth-search.aws.element84.com/v0")Keywords for searching dataYou can passkwargstopystac_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":10}}# kwarg to pass)LicenseThe project is licensed under the MIT license.Logo AttributionThe logo and images were created usingdice icons created by Freepik - Flaticon.