Skip to content

Commit 989c3de

Browse files
authored
Merge pull request #32 from stac-utils/ingest_data
Ingest sample data
2 parents 2997ae4 + 8512326 commit 989c3de

File tree

5 files changed

+261
-0
lines changed

5 files changed

+261
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ docs-image:
5151
docs: docs-image
5252
docker-compose -f docker-compose.docs.yml \
5353
run docs
54+
55+
.PHONY: ingest
56+
ingest:
57+
python3 data_loader/data_loader.py

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ docker-compose up
3131
```
3232
make test
3333
```
34+
35+
## Ingest sample data
36+
37+
```
38+
make ingest
39+
```

data_loader/data_loader.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Database ingestion script."""
2+
import json
3+
import os
4+
5+
import click
6+
import requests
7+
8+
DATA_DIR = os.path.join(os.path.dirname(__file__), "setup_data/")
9+
STAC_API_BASE_URL = "http://localhost:8083"
10+
11+
12+
def load_data(filename):
13+
"""Load json data."""
14+
with open(os.path.join(DATA_DIR, filename)) as file:
15+
return json.load(file)
16+
17+
18+
def load_collection(collection_id):
19+
"""Load stac collection into the database."""
20+
collection = load_data("collection.json")
21+
collection["id"] = collection_id
22+
try:
23+
resp = requests.post(f"{STAC_API_BASE_URL}/collections", json=collection)
24+
if resp.status_code == 200:
25+
print(f"Status code: {resp.status_code}")
26+
print(f"Added collection: {collection['id']}")
27+
elif resp.status_code == 409:
28+
print(f"Status code: {resp.status_code}")
29+
print(f"Collection: {collection['id']} already exists")
30+
except requests.ConnectionError:
31+
click.secho("failed to connect")
32+
33+
34+
def load_items():
35+
"""Load stac items into the database."""
36+
feature_collection = load_data("sentinel-s2-l2a-cogs_0_100.json")
37+
collection = "test-collection"
38+
load_collection(collection)
39+
40+
for feature in feature_collection["features"]:
41+
try:
42+
feature["collection"] = collection
43+
resp = requests.post(
44+
f"{STAC_API_BASE_URL}/collections/{collection}/items", json=feature
45+
)
46+
if resp.status_code == 200:
47+
print(f"Status code: {resp.status_code}")
48+
print(f"Added item: {feature['id']}")
49+
elif resp.status_code == 409:
50+
print(f"Status code: {resp.status_code}")
51+
print(f"Item: {feature['id']} already exists")
52+
except requests.ConnectionError:
53+
click.secho("failed to connect")
54+
55+
56+
load_items()
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
{
2+
"id":"sentinel-s2-l2a-cogs",
3+
"stac_version":"1.0.0",
4+
"description":"Sentinel-2a and Sentinel-2b imagery, processed to Level 2A (Surface Reflectance) and converted to Cloud-Optimized GeoTIFFs",
5+
"links":[
6+
{"rel":"self","href":"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs"},
7+
{"rel":"license","href":"https://sentinel.esa.int/documents/247904/690755/Sentinel_Data_Legal_Notice"},
8+
{"rel":"about","href":"https://github.com/stac-utils/stac-sentinel"},
9+
{"rel":"parent","href":"https://earth-search.aws.element84.com/v0/"},
10+
{"rel":"root","href":"https://earth-search.aws.element84.com/v0/"},
11+
{"rel":"items","href":"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items"}
12+
],
13+
"stac_extensions":["https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"],
14+
"title":"Sentinel 2 L2A COGs",
15+
"keywords":["sentinel","earth observation","esa"],
16+
"providers":[
17+
{"name":"ESA","roles":["producer"],"url":"https://earth.esa.int/web/guest/home"},
18+
{"name":"Sinergise","roles":["processor"],"url":"https://registry.opendata.aws/sentinel-2/"},
19+
{"name":"AWS","roles":["host"],"url":"http://sentinel-pds.s3-website.eu-central-1.amazonaws.com/"},
20+
{"name":"Element 84","roles":["processor"],"url":"https://element84.com"}
21+
],
22+
"summaries":{
23+
"platform":["sentinel-2a","sentinel-2b"],
24+
"constellation":["sentinel-2"],
25+
"instruments":["msi"],
26+
"gsd":[10],
27+
"view:off_nadir":[0]
28+
},
29+
"item_assets":{
30+
"thumbnail":{
31+
"title":"Thumbnail",
32+
"type":"image/png",
33+
"roles":["thumbnail"]
34+
},
35+
"overview":{
36+
"title":"True color image",
37+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
38+
"roles":["overview"],
39+
"gsd":10,
40+
"eo:bands":[
41+
{"name":"B04","common_name":"red","center_wavelength":0.6645,"full_width_half_max":0.038},
42+
{"name":"B03","common_name":"green","center_wavelength":0.56,"full_width_half_max":0.045},
43+
{"name":"B02","common_name":"blue","center_wavelength":0.4966,"full_width_half_max":0.098}
44+
]
45+
},
46+
"info":{
47+
"title":"Original JSON metadata",
48+
"type":"application/json",
49+
"roles":["metadata"]
50+
},
51+
"metadata":{
52+
"title":"Original XML metadata",
53+
"type":"application/xml",
54+
"roles":["metadata"]
55+
},
56+
"visual":{
57+
"title":"True color image",
58+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
59+
"roles":["overview"],
60+
"gsd":10,
61+
"eo:bands":[
62+
{"name":"B04","common_name":"red","center_wavelength":0.6645,"full_width_half_max":0.038},
63+
{"name":"B03","common_name":"green","center_wavelength":0.56,"full_width_half_max":0.045},
64+
{"name":"B02","common_name":"blue","center_wavelength":0.4966,"full_width_half_max":0.098}
65+
]
66+
},
67+
"B01":{
68+
"title":"Band 1 (coastal)",
69+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
70+
"roles":["data"],
71+
"gsd":60,
72+
"eo:bands":[
73+
{"name":"B01","common_name":"coastal","center_wavelength":0.4439,"full_width_half_max":0.027}
74+
]
75+
},
76+
"B02":{
77+
"title":"Band 2 (blue)",
78+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
79+
"roles":["data"],
80+
"gsd":10,
81+
"eo:bands":[
82+
{"name":"B02","common_name":"blue","center_wavelength":0.4966,"full_width_half_max":0.098}
83+
]
84+
},
85+
"B03":{
86+
"title":"Band 3 (green)",
87+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
88+
"roles":["data"],
89+
"gsd":10,
90+
"eo:bands":[
91+
{"name":"B03","common_name":"green","center_wavelength":0.56,"full_width_half_max":0.045}
92+
]
93+
},
94+
"B04":{
95+
"title":"Band 4 (red)",
96+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
97+
"roles":["data"],
98+
"gsd":10,
99+
"eo:bands":[
100+
{"name":"B04","common_name":"red","center_wavelength":0.6645,"full_width_half_max":0.038}
101+
]},
102+
"B05":{
103+
"title":"Band 5",
104+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
105+
"roles":["data"],
106+
"gsd":20,
107+
"eo:bands":[
108+
{"name":"B05","center_wavelength":0.7039,"full_width_half_max":0.019}
109+
]
110+
},
111+
"B06":{
112+
"title":"Band 6",
113+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
114+
"roles":["data"],
115+
"gsd":20,
116+
"eo:bands":[
117+
{"name":"B06","center_wavelength":0.7402,"full_width_half_max":0.018}
118+
]
119+
},
120+
"B07":{
121+
"title":"Band 7",
122+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
123+
"roles":["data"],
124+
"gsd":20,
125+
"eo:bands":[
126+
{"name":"B07","center_wavelength":0.7825,"full_width_half_max":0.028}
127+
]
128+
},
129+
"B08":{
130+
"title":"Band 8 (nir)",
131+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
132+
"roles":["data"],
133+
"gsd":10,
134+
"eo:bands":[
135+
{"name":"B08","common_name":"nir","center_wavelength":0.8351,"full_width_half_max":0.145}
136+
]
137+
},
138+
"B8A":{
139+
"title":"Band 8A",
140+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
141+
"roles":["data"],
142+
"gsd":20,
143+
"eo:bands":[
144+
{"name":"B8A","center_wavelength":0.8648,"full_width_half_max":0.033}
145+
]
146+
},
147+
"B09":{
148+
"title":"Band 9",
149+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
150+
"roles":["data"],
151+
"gsd":60,
152+
"eo:bands":[
153+
{"name":"B09","center_wavelength":0.945,"full_width_half_max":0.026}
154+
]
155+
},
156+
"B11":{
157+
"title":"Band 11 (swir16)",
158+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
159+
"roles":["data"],
160+
"gsd":20,
161+
"eo:bands":[
162+
{"name":"B11","common_name":"swir16","center_wavelength":1.6137,"full_width_half_max":0.143}
163+
]
164+
},
165+
"B12":{
166+
"title":"Band 12 (swir22)",
167+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
168+
"roles":["data"],
169+
"gsd":20,
170+
"eo:bands":[
171+
{"name":"B12","common_name":"swir22","center_wavelength":2.22024,"full_width_half_max":0.242}
172+
]
173+
},
174+
"AOT":{
175+
"title":"Aerosol Optical Thickness (AOT)",
176+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
177+
"roles":["data"]},
178+
"WVP":{
179+
"title":"Water Vapour (WVP)",
180+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
181+
"roles":["data"]
182+
},
183+
"SCL":{
184+
"title":"Scene Classification Map (SCL)",
185+
"type":"image/tiff; application=geotiff; profile=cloud-optimized",
186+
"roles":["data"]
187+
}
188+
},
189+
"extent":{
190+
"spatial":{"bbox":[[-180,-90,180,90]]},
191+
"temporal":{"interval":[["2015-06-27T10:25:31.456000Z",null]]}
192+
},
193+
"license":"proprietary"
194+
}

data_loader/setup_data/sentinel-s2-l2a-cogs_0_100.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)