Skip to content

Commit

Permalink
Merge pull request #6 from jonhealy1/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jonhealy1 authored Feb 24, 2022
2 parents d0b9f1d + 85942fc commit 08773d4
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ pybase-install:

.PHONY: install
install: pybase-install
pip install -e ./stac_fastapi/mongo[dev,server]
pip install -e ./stac_fastapi/mongo[dev,server]

.PHONY: ingest
ingest:
python3 data_loader/data_loader.py
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.3.2
59 changes: 59 additions & 0 deletions data_loader/data_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Database ingestion script."""
import json
import os

import click
import requests

DATA_DIR = os.path.join(os.path.dirname(__file__), "setup_data/")
STAC_API_BASE_URL = "http://localhost:8083"


def load_data(filename):
"""Load json data."""
with open(os.path.join(DATA_DIR, filename)) as file:
return json.load(file)


def load_collection(collection_id):
"""Load stac collection into the database."""
collection = load_data("collection.json")
collection["id"] = collection_id
try:
resp = requests.post(f"{STAC_API_BASE_URL}/collections", json=collection)
if resp.status_code == 200:
print(f"Status code: {resp.status_code}")
print(f"Added collection: {collection['id']}")
elif resp.status_code == 409:
print(f"Status code: {resp.status_code}")
print(f"Collection: {collection['id']} already exists")
except requests.ConnectionError:
click.secho("failed to connect")


def load_items():
"""Load stac items into the database."""
feature_collection = load_data("sentinel-s2-l2a-cogs_0_100.json")
collection = "test-collection"
load_collection(collection)

for feature in feature_collection["features"]:
try:
feature["stac_extensions"] = []
feature["stac_version"] = "1.0.0"
feature["collection"] = collection
resp = requests.post(
f"{STAC_API_BASE_URL}/collections/{collection}/items", json=feature
)

if resp.status_code == 200:
print(f"Status code: {resp.status_code}")
print(f"Added item: {feature['id']}")
elif resp.status_code == 409:
print(f"Status code: {resp.status_code}")
print(f"Item: {feature['id']} already exists")
except requests.ConnectionError:
click.secho("failed to connect")


load_items()
93 changes: 93 additions & 0 deletions data_loader/setup_data/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"id":"sentinel-s2-l2a-cogs",
"stac_version":"1.0.0-beta.2",
"description":"Sentinel-2a and Sentinel-2b imagery, processed to Level 2A (Surface Reflectance) and converted to Cloud-Optimized GeoTIFFs",
"links":[
{"rel":"self","href":"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs"},
{"rel":"license","href":"https://sentinel.esa.int/documents/247904/690755/Sentinel_Data_Legal_Notice"},
{"rel":"about","href":"https://github.com/stac-utils/stac-sentinel"},
{"rel":"parent","href":"https://earth-search.aws.element84.com/v0/"},
{"rel":"root","href":"https://earth-search.aws.element84.com/v0/"},
{"rel":"items","href":"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items"}
],
"stac_extensions":["item-assets"],
"title":"Sentinel 2 L2A COGs",
"keywords":["sentinel","earth observation","esa"],
"providers":[
{"name":"ESA","roles":["producer"],"url":"https://earth.esa.int/web/guest/home"},
{"name":"Sinergise","roles":["processor"],"url":"https://registry.opendata.aws/sentinel-2/"},
{"name":"AWS","roles":["host"],"url":"http://sentinel-pds.s3-website.eu-central-1.amazonaws.com/"},
{"name":"Element 84","roles":["processor"],"url":"https://element84.com"}
],
"summaries":{
"platform":["sentinel-2a","sentinel-2b"],
"constellation":["sentinel-2"],
"instruments":["msi"],
"gsd":[10],
"view:off_nadir":[0]
},
"item_assets":{
"thumbnail":{
"title":"Thumbnail",
"type":"image/png",
"roles":["thumbnail"]
},
"overview":{
"title":"True color image",
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
"roles":["overview"],
"gsd":10,
"eo:bands":[
{"name":"B04","common_name":"red","center_wavelength":0.6645,"full_width_half_max":0.038},
{"name":"B03","common_name":"green","center_wavelength":0.56,"full_width_half_max":0.045},
{"name":"B02","common_name":"blue","center_wavelength":0.4966,"full_width_half_max":0.098}
]
},
"info":{
"title":"Original JSON metadata",
"type":"application/json",
"roles":["metadata"]
},
"metadata":{
"title":"Original XML metadata",
"type":"application/xml",
"roles":["metadata"]
},
"visual":{
"title":"True color image",
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
"roles":["overview"],
"gsd":10,
"eo:bands":[
{"name":"B04","common_name":"red","center_wavelength":0.6645,"full_width_half_max":0.038},
{"name":"B03","common_name":"green","center_wavelength":0.56,"full_width_half_max":0.045},
{"name":"B02","common_name":"blue","center_wavelength":0.4966,"full_width_half_max":0.098}
]
},
"B01":{
"title":"Band 1 (coastal)",
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
"roles":["data"],
"gsd":60,
"eo:bands":[
{"name":"B01","common_name":"coastal","center_wavelength":0.4439,"full_width_half_max":0.027}
]
},
"B02":{
"title":"Band 2 (blue)",
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
"roles":["data"],
"gsd":10,
"eo:bands":[
{"name":"B02","common_name":"blue","center_wavelength":0.4966,"full_width_half_max":0.098}
]
},
"B03":{
"title":"Band 3 (green)",
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
"roles":["data"],
"gsd":10,
"eo:bands":[
{"name":"B03","common_name":"green","center_wavelength":0.56,"full_width_half_max":0.045}
]
},"B04":{"title":"Band 4 (red)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":10,"eo:bands":[{"name":"B04","common_name":"red","center_wavelength":0.6645,"full_width_half_max":0.038}]},"B05":{"title":"Band 5","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":20,"eo:bands":[{"name":"B05","center_wavelength":0.7039,"full_width_half_max":0.019}]},"B06":{"title":"Band 6","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":20,"eo:bands":[{"name":"B06","center_wavelength":0.7402,"full_width_half_max":0.018}]},"B07":{"title":"Band 7","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":20,"eo:bands":[{"name":"B07","center_wavelength":0.7825,"full_width_half_max":0.028}]},"B08":{"title":"Band 8 (nir)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":10,"eo:bands":[{"name":"B08","common_name":"nir","center_wavelength":0.8351,"full_width_half_max":0.145}]},"B8A":{"title":"Band 8A","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":20,"eo:bands":[{"name":"B8A","center_wavelength":0.8648,"full_width_half_max":0.033}]},"B09":{"title":"Band 9","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":60,"eo:bands":[{"name":"B09","center_wavelength":0.945,"full_width_half_max":0.026}]},"B11":{"title":"Band 11 (swir16)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":20,"eo:bands":[{"name":"B11","common_name":"swir16","center_wavelength":1.6137,"full_width_half_max":0.143}]},"B12":{"title":"Band 12 (swir22)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"],"gsd":20,"eo:bands":[{"name":"B12","common_name":"swir22","center_wavelength":2.22024,"full_width_half_max":0.242}]},"AOT":{"title":"Aerosol Optical Thickness (AOT)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"]},"WVP":{"title":"Water Vapour (WVP)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"]},"SCL":{"title":"Scene Classification Map (SCL)","type":"image/tiff; application=geotiff; profile=cloud-optimized","roles":["data"]}},"extent":{"spatial":{"bbox":[[-180,-90,180,90]]},"temporal":{"interval":[["2015-06-27T10:25:31.456000Z",null]]}},"license":"proprietary"}
1 change: 1 addition & 0 deletions data_loader/setup_data/sentinel-s2-l2a-cogs_0_100.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stac_fastapi/mongo/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
keywords="STAC FastAPI COG",
author=u"Arturo Engineering",
author_email="[email protected]",
url="https://github.com/jonhealy1/stac-fastapi-nosql",
url="https://github.com/jonhealy1/stac-fastapi-mongo",
license="MIT",
packages=find_namespace_packages(exclude=["alembic", "tests", "scripts"]),
zip_safe=False,
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/mongo/stac_fastapi/mongo/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""library version."""
__version__ = "2.3.1"
__version__ = "2.3.2"

0 comments on commit 08773d4

Please sign in to comment.