Skip to content

Commit

Permalink
add eurodatacube items
Browse files Browse the repository at this point in the history
  • Loading branch information
baloola committed Jul 21, 2023
1 parent 5bd2da4 commit a4313e3
Show file tree
Hide file tree
Showing 64 changed files with 21,366 additions and 7 deletions.
115 changes: 115 additions & 0 deletions stac/stac-generator/collection_convertor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import requests
from datetime import datetime
from shapely.geometry import Polygon, mapping
import pystac

from pystac.extensions import datacube


def create_links(title):
self_href = f"https://fairicube.github.io/data-requests/{title}.json"
root_href = "https://fairicube.github.io/data-requests/catalog.json"
self_link = pystac.Link(
rel="self",
media_type="application/json",
target=self_href
)
root_link = pystac.Link(
rel=pystac.RelType("root"),
media_type=pystac.MediaType("application/json"),
target=root_href
)
parent_link = pystac.Link(
rel=pystac.RelType("parent"),
media_type=pystac.MediaType("application/json"),
target=root_href
)
return [self_link, root_link, parent_link]


catalog_url = "https://collections.eurodatacube.com/stac/index.json"
index_collection = requests.get(catalog_url).json()
index_catalog = pystac.Catalog(
id="index",
title="data-access catalog",
description="The stac catalog that contains all the generated datacube items."
)

for item in index_collection:

col = requests.get(item["link"]).json()
collection = pystac.Collection.from_dict(col)
extent = collection.extent.to_dict()

bbox = extent["spatial"]["bbox"][0]

footprint = Polygon(
[
[bbox[0], bbox[1]],
[bbox[0], bbox[3]],
[bbox[2], bbox[3]],
[bbox[2], bbox[1]],
]
)

date = extent["temporal"]["interval"][0][0]
if date is None:
date = '2000-01-01T00:00:00Z'
extra_fields = dict()
for field in collection.extra_fields:
if field not in ["type", "cube:dimensions"]:
extra_fields[field] = collection.extra_fields[field]

extra_fields.update(collection.summaries.to_dict())
providers_list = []
providers = collection.providers
for provider in providers:
providers_list.append(provider.to_dict())

extra_fields["providers"] = providers_list
extra_fields["description"] = collection.description
extra_fields["keywords"] = collection.keywords
extra_fields["title"] = collection.title
extra_fields["license"] = collection.license

versioned_ext = collection.stac_extensions
v1_schema = 'https://stac-extensions.github.io/datacube/v1.0.0/schema.json'
if v1_schema in versioned_ext:
versioned_ext.remove(v1_schema)
versioned_ext.append('https://stac-extensions.github.io/datacube/v2.0.0/schema.json')

feature = pystac.Item(
id=collection.id,
stac_extensions=versioned_ext,
datetime=datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ"),
bbox=bbox,
geometry=mapping(footprint),
properties=dict(),
assets=collection.assets
)
dimension_object = collection.extra_fields["cube:dimensions"]
dims = dict()
for dim in dimension_object.keys():

dimension = pystac.extensions.datacube.Dimension.from_dict(dimension_object[dim])

dims[dim] = dimension

item_datacube = datacube.DatacubeExtension.ext(feature)

item_datacube.dimensions = dims
feature.extra_fields = extra_fields
collection_links = collection.links
for link in collection_links:
if link.rel == "self":
collection_links.remove(link)
additional_links = create_links(feature.id)
collection_links.extend(additional_links)

feature.links = collection_links

index_catalog.add_item(feature)

index_catalog.normalize_and_save(
root_href="stac_dist/",
catalog_type=pystac.CatalogType.SELF_CONTAINED)
14 changes: 7 additions & 7 deletions stac/stac-generator/stac-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_axes(axes):

def create_links(title):
self_href = f"https://fairicube.github.io/data-requests/{title}.json"
root_href = "https://fairicube.github.io/data-requests/index.json"
root_href = "https://fairicube.github.io/data-requests/catalog.json"
self_link = pystac.Link(
rel="self",
media_type="application/json",
Expand Down Expand Up @@ -187,12 +187,12 @@ def insert_value(field, value_list, listed_fields, doc):

issues = client.execute(query_1)[
"organization"]["repository"]["issues"]["edges"]
index_catalog = pystac.Catalog(
id="index",
title="data-access catalog",
description="The stac catalog that contains all the generated datacube items."
)

# index_catalog = pystac.Catalog(
# id="index",
# title="data-access catalog",
# description="The stac catalog that contains all the generated datacube items."
# )
index_catalog = pystac.Catalog.from_file('./stac_dist/catalog.json')
for index, issue in enumerate(issues):
title = issue["node"]["title"].split("]: ")[-1].replace(" ", "_")
title = title.replace("–", "_")
Expand Down
164 changes: 164 additions & 0 deletions stac_dist/ALOS_PALSAR2_AGRICULTURE/ALOS_PALSAR2_AGRICULTURE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "ALOS_PALSAR2_AGRICULTURE",
"properties": {
"cube:dimensions": {
"x": {
"type": "spatial",
"axis": "x",
"extent": [
123.518,
106.11
]
},
"y": {
"type": "spatial",
"axis": "y",
"extent": [
8.85,
42.389
]
},
"t": {
"type": "temporal",
"extent": [
"2019-02-06T00:00:00Z",
"2020-10-16T00:00:00Z"
]
},
"bands": {
"type": "bands",
"values": [
"HH",
"HV"
]
}
},
"datetime": "2019-02-06T00:00:00Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-123.518,
8.85
],
[
-123.518,
42.389
],
[
106.11,
42.389
],
[
106.11,
8.85
],
[
-123.518,
8.85
]
]
]
},
"links": [
{
"rel": "root",
"href": "../catalog.json",
"type": "application/json",
"title": "data-access catalog"
},
{
"rel": "about",
"href": "https://collections.eurodatacube.com/alos-2-palsar-2-scansar-for-agriculture",
"type": "text/html",
"title": "Website describing the collection"
},
{
"rel": "about",
"href": "https://docs.sentinel-hub.com/api/latest/api/process/",
"type": "text/html",
"title": "Details about running Evalscripts"
},
{
"rel": "processing-expression",
"href": "https://raw.githubusercontent.com/eurodatacube/public-collections/main/collections/alos-2-palsar-2-scansar-for-agriculture/hh_script.js",
"type": "application/javascript",
"title": "Evalscript to generate HH imagery",
"sentinelhub:layer_name": "HH",
"sentinelhub:mosaicking_order": "mostRecent",
"sentinelhub:upsampling": "BICUBIC"
},
{
"rel": "processing-expression",
"href": "https://raw.githubusercontent.com/eurodatacube/public-collections/main/collections/alos-2-palsar-2-scansar-for-agriculture/hv_script.js",
"type": "application/javascript",
"title": "Evalscript to generate HV imagery",
"sentinelhub:layer_name": "HV",
"sentinelhub:mosaicking_order": "mostRecent",
"sentinelhub:upsampling": "BICUBIC"
},
{
"rel": "license",
"href": "",
"type": "text/html",
"title": "License"
},
{
"rel": "root",
"href": "https://fairicube.github.io/data-requests/catalog.json",
"type": "application/json",
"title": "data-access catalog"
},
{
"rel": "parent",
"href": "../catalog.json",
"type": "application/json",
"title": "data-access catalog"
}
],
"assets": {
"thumbnail": {
"href": "https://collections.eurodatacube.com/alos-2-palsar-2-scansar-for-agriculture/alos-2-palsar-2-scansar-for-agriculture.png",
"type": "image/png",
"title": "Thumbnail",
"roles": [
"thumbnail"
]
}
},
"bbox": [
-123.518,
8.85,
106.11,
42.389
],
"stac_extensions": [
"https://stac-extensions.github.io/datacube/v2.0.0/schema.json"
],
"datasource_type": "byoc-7c90e9bb-0842-4f37-bb34-37b467eb5c95",
"providers": [
{
"name": "Sentinel Hub",
"description": "",
"roles": [
"processor"
],
"url": "https://services.sentinel-hub.com"
}
],
"description": "This [ALOS-2 ScanSAR](https://alos-pasco.com/en/alos-2/spec/) L2.1 product contains geometrically corrected (orthorectified) \ndata in selected AOIs between 2019 and 2020 for NASA/ESA/JAXA EODashboard Hackathon. \nThe PALSAR-2 aboard the ALOS-2 is a Synthetic Aperture Radar (SAR), which emits microwave and receives the reflection \nfrom the ground to acquire information. Since it does not need other sources of light such as the sun, SAR has the \nadvantage of providing satellite images during day or night. For transmitting and receiving microwaves PALSAR-2 uses \nthe L-band, which is less affected by clouds and rains. This all-weather observing capability is suitable for \nmonitoring disasters rapidly. In addition, L-band microwave can reach to the ground partially penetrating through \nvegetation to obtain information about vegetation and ground surface.\nScanSAR is wide swath mode with 100m spatial resolution, 350km width swath, and dual polarization (HH/HV).\n",
"keywords": [
"open data",
"sentinel hub",
"raster",
"SAR",
"dashboard hackathon",
"JAXA"
],
"title": "ALOS-2 PALSAR-2 ScanSAR for Agriculture",
"license": ""
}
Loading

0 comments on commit a4313e3

Please sign in to comment.