Zarr Cloud native format in Earth Observation Application Packages¶
Part 1 - Application Package execution¶
Use cwltool
to run the Application Package
Modules used¶
In [1]:
Copied!
import yaml
from shutil import which
import nest_asyncio
from cwltool.main import main
from io import StringIO
import argparse
import json
nest_asyncio.apply()
import yaml
from shutil import which
import nest_asyncio
from cwltool.main import main
from io import StringIO
import argparse
import json
nest_asyncio.apply()
Container runtime¶
Check if podman
or docker
are available:
In [2]:
Copied!
if which("podman"):
podman = True
elif which("docker"):
podman = False
else:
raise ValueError("No container engine")
if which("podman"):
podman = True
elif which("docker"):
podman = False
else:
raise ValueError("No container engine")
Prepare the Application Package execution¶
Use cwltool
and Python to execute the Application Package.
In [3]:
Copied!
params = {
"stac_items": [
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210623_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_10TFK_20210708_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210713_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_10TFK_20210718_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210723_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_10TFK_20210728_0_L2A",
],
"bands": ["green", "nir"],
"aoi": "-121.399,39.834,-120.74,40.472",
"epsg": "EPSG:4326",
}
with open("params.yaml", "w") as file:
print(yaml.dump(params), file=file)
params = {
"stac_items": [
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210623_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_10TFK_20210708_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210713_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_10TFK_20210718_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210723_0_L2A",
"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_10TFK_20210728_0_L2A",
],
"bands": ["green", "nir"],
"aoi": "-121.399,39.834,-120.74,40.472",
"epsg": "EPSG:4326",
}
with open("params.yaml", "w") as file:
print(yaml.dump(params), file=file)
Application Package execution¶
We use the released application package available here: https://github.com/eoap/zarr-cloud-native-format/releases
In [4]:
Copied!
parsed_args = argparse.Namespace(
podman=podman,
parallel=True,
validate=False,
debug=False,
outdir="./runs",
quiet=True,
workflow="https://github.com/eoap/zarr-cloud-native-format/releases/download/0.1.0/app-water-bodies.0.1.0.cwl#water-bodies",
job_order=["params.yaml"],
)
stream_out = StringIO()
stream_err = StringIO()
res = main(
args=parsed_args,
stdout=stream_out,
stderr=stream_err,
)
assert res == 0
parsed_args = argparse.Namespace(
podman=podman,
parallel=True,
validate=False,
debug=False,
outdir="./runs",
quiet=True,
workflow="https://github.com/eoap/zarr-cloud-native-format/releases/download/0.1.0/app-water-bodies.0.1.0.cwl#water-bodies",
job_order=["params.yaml"],
)
stream_out = StringIO()
stream_err = StringIO()
res = main(
args=parsed_args,
stdout=stream_out,
stderr=stream_err,
)
assert res == 0
Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca" Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca" Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca" Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca" Trying to pull ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca... Trying to pull ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca... Trying to pull ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca... Trying to pull ghcr.io/eoap/mastering-app-package/crop@sha256:324a0735cc4998f3f790c0e9b7a7df28e8ce8987d5f0798bd2d63c0e72d17dca...
Getting image source signatures Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Getting image source signatures Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Getting image source signatures Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b
Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Getting image source signatures Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695 Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9
Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b
Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9
Copying blob sha256:f28f7600e2164bcfcf455f3534d1a31e010658c037af7cd19fdab3e26ab05695
Copying blob sha256:b500675c4294481dd5feb6af7ff52e8110354daf5a747159638bb2ee118ff6ec
Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a
Copying config sha256:3bf0c307a6e57ca5e5866c94399f61de51f66eccbc09e9cb711ac8d9fadac4b8 Writing manifest to image destination Storing signatures Copying config sha256:3bf0c307a6e57ca5e5866c94399f61de51f66eccbc09e9cb711ac8d9fadac4b8 Writing manifest to image destination Storing signatures Copying config sha256:3bf0c307a6e57ca5e5866c94399f61de51f66eccbc09e9cb711ac8d9fadac4b8 Writing manifest to image destination Storing signatures Copying config sha256:3bf0c307a6e57ca5e5866c94399f61de51f66eccbc09e9cb711ac8d9fadac4b8 Writing manifest to image destination Storing signatures
Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/norm_diff@sha256:632991ef2c15e98c46cfa1ac7dd35a638bbe4e5c434d7503a76cf3570b17383f" Trying to pull ghcr.io/eoap/mastering-app-package/norm_diff@sha256:632991ef2c15e98c46cfa1ac7dd35a638bbe4e5c434d7503a76cf3570b17383f...
Getting image source signatures Copying blob sha256:8b2158d8ad6f3c70a45e897e1863cf4df3184fc232cf8e8ccfa2582acd5ac926 Copying blob sha256:ef00e4beaf93abe050db25df3c1dae2ecf91abff7f7517b8d54ecce413c2c5d3 Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:8b2158d8ad6f3c70a45e897e1863cf4df3184fc232cf8e8ccfa2582acd5ac926 Copying blob sha256:ef00e4beaf93abe050db25df3c1dae2ecf91abff7f7517b8d54ecce413c2c5d3
Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/norm_diff@sha256:632991ef2c15e98c46cfa1ac7dd35a638bbe4e5c434d7503a76cf3570b17383f" Trying to pull ghcr.io/eoap/mastering-app-package/norm_diff@sha256:632991ef2c15e98c46cfa1ac7dd35a638bbe4e5c434d7503a76cf3570b17383f...
Getting image source signatures Copying blob sha256:8b2158d8ad6f3c70a45e897e1863cf4df3184fc232cf8e8ccfa2582acd5ac926 Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:ef00e4beaf93abe050db25df3c1dae2ecf91abff7f7517b8d54ecce413c2c5d3 Copying blob sha256:8b2158d8ad6f3c70a45e897e1863cf4df3184fc232cf8e8ccfa2582acd5ac926 Copying blob sha256:ef00e4beaf93abe050db25df3c1dae2ecf91abff7f7517b8d54ecce413c2c5d3
Copying config sha256:6c3ad36d7cb603bf7ee4d226cd7a053dfcded3fd06c56c8c7e4b32d4ffc43778 Writing manifest to image destination Storing signatures Copying config sha256:6c3ad36d7cb603bf7ee4d226cd7a053dfcded3fd06c56c8c7e4b32d4ffc43778 Writing manifest to image destination Storing signatures
Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/otsu@sha256:0541948f46a7a1a9f30f17973b7833482660f085700ccc98bb743a35a37dabae" Trying to pull ghcr.io/eoap/mastering-app-package/otsu@sha256:0541948f46a7a1a9f30f17973b7833482660f085700ccc98bb743a35a37dabae...
Getting image source signatures Copying blob sha256:92a367ab67a83360a0fb18859133d578e13d921619016c303a239c19e8e37136 Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:7a7f7e015d87a940408f146e8182f84be8cfe64d1241b7c6c0ce79307d3fb1f8 Copying blob sha256:7a7f7e015d87a940408f146e8182f84be8cfe64d1241b7c6c0ce79307d3fb1f8 Copying blob sha256:92a367ab67a83360a0fb18859133d578e13d921619016c303a239c19e8e37136 Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/otsu@sha256:0541948f46a7a1a9f30f17973b7833482660f085700ccc98bb743a35a37dabae"
Trying to pull ghcr.io/eoap/mastering-app-package/otsu@sha256:0541948f46a7a1a9f30f17973b7833482660f085700ccc98bb743a35a37dabae...
Getting image source signatures Copying blob sha256:92a367ab67a83360a0fb18859133d578e13d921619016c303a239c19e8e37136 Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:7a7f7e015d87a940408f146e8182f84be8cfe64d1241b7c6c0ce79307d3fb1f8 Copying blob sha256:92a367ab67a83360a0fb18859133d578e13d921619016c303a239c19e8e37136 Copying blob sha256:7a7f7e015d87a940408f146e8182f84be8cfe64d1241b7c6c0ce79307d3fb1f8
Copying config sha256:c49c69c30b8fa1f9bafdb6ef6a02d10c5ffb9d544105bead2a45ab11a6ded061 Writing manifest to image destination Storing signatures Copying config sha256:c49c69c30b8fa1f9bafdb6ef6a02d10c5ffb9d544105bead2a45ab11a6ded061 Writing manifest to image destination Storing signatures
Error: error inspecting object: no such object: "ghcr.io/eoap/mastering-app-package/stac@sha256:e2ee1914cd06a0abc369034a8c8ef9ecf9b8e872b2efbc864d41c741e9faa392" Trying to pull ghcr.io/eoap/mastering-app-package/stac@sha256:e2ee1914cd06a0abc369034a8c8ef9ecf9b8e872b2efbc864d41c741e9faa392...
Getting image source signatures Copying blob sha256:63e222fc85464c39bd153865e5278488712623e988bc76729b5c7d58ac1d3c50 Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:8b3ea93d0ced40723f300e776223de95083eecb5c159035a6ed1927a5788181d Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:8b3ea93d0ced40723f300e776223de95083eecb5c159035a6ed1927a5788181d Copying blob sha256:63e222fc85464c39bd153865e5278488712623e988bc76729b5c7d58ac1d3c50
Copying config sha256:95b7e9f38e089be288a7271beebd8620f3013fd4db16c5f8321dfaca1a2fcf0b Writing manifest to image destination Storing signatures
Error: error inspecting object: no such object: "ghcr.io/eoap/zarr-cloud-native-format/stac-zarr@sha256:f46d62ef625411db4c746024889742df0d56cafd46bd5aa66c0241951156c2e7" Trying to pull ghcr.io/eoap/zarr-cloud-native-format/stac-zarr@sha256:f46d62ef625411db4c746024889742df0d56cafd46bd5aa66c0241951156c2e7...
Getting image source signatures Copying blob sha256:bb39d21d8e010576cbe50dd3eb30a590ef7362a1968e1e038e834e821e8b2d1b Copying blob sha256:ddee35dfe011992ed9d752dc61e7dc4377fda83f63e03c0e193a4a4e6714cc2b Copying blob sha256:a2318d6c47ec9cac5acc500c47c79602bcf953cec711a18bc898911a0984365b Copying blob sha256:cd4054fd866013877f7664cf997a9b812814d226ee5f3d830d2a275387e67f8a Copying blob sha256:8a7a13810b7d60799d98f4a85010c5343a11ce82bf99a2a9231356ee56cd32f9 Copying blob sha256:7c40428b68e8826a064660476d5a906954ff3f95111f7ef4592147aa8d989927 Copying blob sha256:bb39d21d8e010576cbe50dd3eb30a590ef7362a1968e1e038e834e821e8b2d1b Copying blob sha256:7c40428b68e8826a064660476d5a906954ff3f95111f7ef4592147aa8d989927
Copying config sha256:409346d794fe71fba513494253def4e9049818f1f5fb2a770eebd75b98f9ef87 Writing manifest to image destination Storing signatures
The stream_out
object contains the cwltool stdout.
We can list the results keys with:
In [5]:
Copied!
results = json.loads(stream_out.getvalue())
list(results.keys())
results = json.loads(stream_out.getvalue())
list(results.keys())
Out[5]:
['stac_catalog']
And find the location of the directory containing the STAC Catalog:
In [6]:
Copied!
results["stac_catalog"]["location"]
results["stac_catalog"]["location"]
Out[6]:
'file:///home/runner/work/zarr-cloud-native-format/zarr-cloud-native-format/docs/runs/1enbusn_'
Part 2 - Inspect Application Package results¶
Read the STAC Catalog containing the zarr result
Modules¶
In [7]:
Copied!
import pystac
import os
from pystac.extensions.datacube import DatacubeExtension
import pystac
import os
from pystac.extensions.datacube import DatacubeExtension
Inpect the STAC Item metadata¶
In [8]:
Copied!
cat = pystac.Catalog.from_file(
os.path.join(
results["stac_catalog"]["location"].replace("file://", ""), "catalog.json"
)
)
cat = pystac.Catalog.from_file(
os.path.join(
results["stac_catalog"]["location"].replace("file://", ""), "catalog.json"
)
)
In [9]:
Copied!
cat.describe()
cat.describe()
* <Catalog id=water-bodies> * <Item id=water-bodies>
In [10]:
Copied!
item = next(cat.get_all_items())
item
item = next(cat.get_all_items())
item
Out[10]:
- type "Feature"
- stac_version "1.0.0"
stac_extensions[] 1 items
- 0 "https://stac-extensions.github.io/datacube/v2.2.0/schema.json"
- id "water-bodies"
geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -121.39905410179915
- 1 39.833916743259095
1[] 2 items
- 0 -120.76135965075635
- 1 39.82336095080461
2[] 2 items
- 0 -120.73995321724426
- 1 40.471999341669175
3[] 2 items
- 0 -121.38373773482932
- 1 40.482798837728375
4[] 2 items
- 0 -121.39905410179915
- 1 39.833916743259095
bbox[] 4 items
- 0 -121.39905410179915
- 1 39.82336095080461
- 2 -120.73995321724426
- 3 40.482798837728375
properties
- proj:epsg "epsg:32610"
cube:dimensions
x
- type "spatial"
- axis "x"
extent[] 2 items
- 0 636995.0
- 1 691585.0
- reference_system "epsg:32610"
y
- type "spatial"
- axis "y"
extent[] 2 items
- 0 4410555.0
- 1 4482595.0
- reference_system "epsg:32610"
time
- type "temporal"
extent[] 2 items
- 0 "2021-06-23T19:03:23.000000000"
- 1 "2021-07-28T19:03:25.000000000"
cube:variables
data
- type "bands"
- description "water bodies"
dimensions[] 3 items
- 0 "y"
- 1 "x"
- 2 "time"
- datetime "2025-01-02T12:02:15.357747Z"
links[] 3 items
0
- rel "root"
- href "/home/runner/work/zarr-cloud-native-format/zarr-cloud-native-format/docs/runs/1enbusn_/catalog.json"
- type "application/json"
- title "Water bodies catalog"
1
- rel "self"
- href "/home/runner/work/zarr-cloud-native-format/zarr-cloud-native-format/docs/runs/1enbusn_/water-bodies/water-bodies.json"
- type "application/json"
2
- rel "parent"
- href "/home/runner/work/zarr-cloud-native-format/zarr-cloud-native-format/docs/runs/1enbusn_/catalog.json"
- type "application/json"
- title "Water bodies catalog"
assets
data
- href "./result.zarr"
- type "application/vnd+zarr"
roles[] 1 items
- 0 "data"
In [11]:
Copied!
zarr_asset = item.get_assets()["data"]
zarr_asset
zarr_asset = item.get_assets()["data"]
zarr_asset
Out[11]:
- href "./result.zarr"
- type "application/vnd+zarr"
roles[] 1 items
- 0 "data"
Inspect the datacube extension metadata:
In [12]:
Copied!
dc_item = DatacubeExtension.ext(item)
dc_item = DatacubeExtension.ext(item)
- List and describe the dimensions
In [13]:
Copied!
dc_item.dimensions
dc_item.dimensions
Out[13]:
{'x': <pystac.extensions.datacube.HorizontalSpatialDimension at 0x7f2bb87440e0>, 'y': <pystac.extensions.datacube.HorizontalSpatialDimension at 0x7f2b98c0e630>, 'time': <pystac.extensions.datacube.TemporalDimension at 0x7f2b98c0e600>}
In [14]:
Copied!
for key, value in dc_item.dimensions.items():
print(key, dc_item.dimensions[key].to_dict())
for key, value in dc_item.dimensions.items():
print(key, dc_item.dimensions[key].to_dict())
x {'type': 'spatial', 'axis': 'x', 'extent': [636995.0, 691585.0], 'reference_system': 'epsg:32610'} y {'type': 'spatial', 'axis': 'y', 'extent': [4410555.0, 4482595.0], 'reference_system': 'epsg:32610'} time {'type': 'temporal', 'extent': ['2021-06-23T19:03:23.000000000', '2021-07-28T19:03:25.000000000']}
- List and describe the variables
In [15]:
Copied!
dc_item.variables
dc_item.variables
Out[15]:
{'data': <pystac.extensions.datacube.Variable at 0x7f2b98c0e660>}
In [16]:
Copied!
for key, value in dc_item.variables.items():
print(key, dc_item.variables[key].to_dict())
for key, value in dc_item.variables.items():
print(key, dc_item.variables[key].to_dict())
data {'type': 'bands', 'description': 'water bodies', 'dimensions': ['y', 'x', 'time']}
In [17]:
Copied!
dc_item.variables["data"].to_dict()
dc_item.variables["data"].to_dict()
Out[17]:
{'type': 'bands', 'description': 'water bodies', 'dimensions': ['y', 'x', 'time']}
Part 3 - Inspect the zarr result¶
Open the Zarr result
Modules¶
In [18]:
Copied!
import xarray as xr
import xarray as xr
Open the Zarr result with xarray¶
In [19]:
Copied!
water_bodies = xr.open_zarr(zarr_asset.get_absolute_href(), consolidated=True)
water_bodies = xr.open_zarr(zarr_asset.get_absolute_href(), consolidated=True)
In [20]:
Copied!
xr.set_options(display_style="text")
water_bodies
xr.set_options(display_style="text")
water_bodies
Out[20]:
<xarray.Dataset> Size: 236MB Dimensions: (time: 6, y: 7205, x: 5460) Coordinates: * time (time) datetime64[ns] 48B 2021-06-23T19:03:23 ... 2021-07-28... * x (x) float64 44kB 6.37e+05 6.37e+05 ... 6.916e+05 6.916e+05 * y (y) float64 58kB 4.483e+06 4.483e+06 ... 4.411e+06 4.411e+06 Data variables: data (time, y, x) uint8 236MB dask.array<chunksize=(1, 7205, 5460), meta=np.ndarray> spatial_ref int32 4B ...
- Check the geospatial metadata
In [21]:
Copied!
water_bodies.data_vars["spatial_ref"]
water_bodies.data_vars["spatial_ref"]
Out[21]:
<xarray.DataArray 'spatial_ref' ()> Size: 4B [1 values with dtype=int32] Attributes: (12/18) GeoTransform: 636990 10 0 4482600 0 -10 crs_wkt: PROJCRS["WGS 84 / UTM zone 10N",BASEGE... false_easting: 500000.0 false_northing: 0.0 geographic_crs_name: WGS 84 grid_mapping_name: transverse_mercator ... ... projected_crs_name: WGS 84 / UTM zone 10N reference_ellipsoid_name: WGS 84 scale_factor_at_central_meridian: 0.9996 semi_major_axis: 6378137.0 semi_minor_axis: 6356752.314245179 spatial_ref: PROJCRS["WGS 84 / UTM zone 10N",BASEGE...
In [22]:
Copied!
str(water_bodies.data_vars["spatial_ref"].values)
str(water_bodies.data_vars["spatial_ref"].values)
Out[22]:
'32610'
- Inspect the Zarr coordinates
In [23]:
Copied!
water_bodies.coords
water_bodies.coords
Out[23]:
Coordinates: * time (time) datetime64[ns] 48B 2021-06-23T19:03:23 ... 2021-07-28T19:... * x (x) float64 44kB 6.37e+05 6.37e+05 6.37e+05 ... 6.916e+05 6.916e+05 * y (y) float64 58kB 4.483e+06 4.483e+06 ... 4.411e+06 4.411e+06
- List the values of the
time
coordinate:
In [24]:
Copied!
water_bodies.coords["time"].values
water_bodies.coords["time"].values
Out[24]:
array(['2021-06-23T19:03:23.000000000', '2021-07-08T19:03:25.000000000', '2021-07-13T19:03:24.000000000', '2021-07-18T19:03:25.000000000', '2021-07-23T19:03:24.000000000', '2021-07-28T19:03:25.000000000'], dtype='datetime64[ns]')
- Plot the water bodies detected on '2021-07-13T19:03:24.000000000'
In [25]:
Copied!
_ = (
water_bodies.isel(time=2)
.to_array("data")
.plot.imshow(
col="data",
size=4,
vmin=0,
vmax=1,
)
)
_ = (
water_bodies.isel(time=2)
.to_array("data")
.plot.imshow(
col="data",
size=4,
vmin=0,
vmax=1,
)
)
In [ ]:
Copied!