-
Notifications
You must be signed in to change notification settings - Fork 24
Ingest sample data #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
447a401
add collection.json
jonhealy1 d9df526
add sentinel data
jonhealy1 f73f6de
create data loader
jonhealy1 8a72a56
move files
jonhealy1 5ee6c60
ingest data from makefile
jonhealy1 1981e8a
update readme
jonhealy1 eee0581
create docstrings
jonhealy1 ec86ec0
run pre-commit
jonhealy1 c23161d
update data_loader
jonhealy1 2a30267
use real sentinel 2 collection
jonhealy1 8b314e4
remove code - change stac items version extensions
jonhealy1 879aa92
update sentinel collection
jonhealy1 1fdbfba
add updated sentinel stac items
jonhealy1 8512326
format collection.json
jonhealy1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,9 @@ docker-compose up | |
``` | ||
make test | ||
``` | ||
|
||
## Ingest sample data | ||
|
||
``` | ||
make ingest | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""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["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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
{ | ||
"id":"sentinel-s2-l2a-cogs", | ||
"stac_version":"1.0.0", | ||
"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":["https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"], | ||
"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" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Transactions Extension defines that either an Item or ItemCollection can be posted to /collections/{cid}/items -- if stac-fastapi doesn't support this, there should be a bug filed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, apparently stac-fastapi does not support this. It does, however, have a bulk_items endpoint. But, that doesn't work with the code in transactions.py because of a bug. I'll create a PR for that bug and put my code for bulk_items somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just assumed that stac-fastapi was following the spec before
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this pr, then update the code when the bulk transactions endpoint is fixed? Or should we wait?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd wait -- this is fine for loading locally