STAC API queries with Python and httpx¶
This notebook aims to demonstrate how eoAPI can be used to analyze Maxar's high-resolution satellite data to assess the Kahramanmaras earthquakes' impact.
Requirements: httpx ipyleaflet
Maxar Open Data¶
Pre and post-event high-resolution satellite imagery in support of emergency planning, risk assessment, monitoring of staging areas and emergency response, damage assessment, and recovery. These images are generated using the Maxar ARD pipeline, tiled on an organized grid in analysis-ready cloud-optimized formats.
STAC and COGs¶
Maxar releases open data for select sudden-onset major crisis events. In addition to making the data (as nice COGs) freely available on AWS, they also add STAC (static) metadata alongside the images. Having the STAC items already created makes ingestion into the PgSTAC database easy (we don't have to produce the items ourselves and thus have to read the images).
To learn more about ingesting the Maxar OpenData STAC catalog into PgSTAC see https://github.com/vincentsarago/MAXAR_opendata_to_pgstac.
!python -m pip install httpx ipyleaflet
stac_endpoint = "https://stac.eoapi.dev"
Collection¶
If you look in https://stac.eoapi.dev/collections response, you'll find one collection for the Kahramanmaras earthquake named MAXAR_Kahramanmaras_turkey_earthquake_23.
import json
from datetime import datetime
import httpx
import ipyleaflet
# list the collections and find the collection_id associated to the `kahramanmaras` event
collections = httpx.get(f"{stac_endpoint}/collections").json()
collection_names = ([c["id"] for c in collections["collections"]])
print(f"Number of collections: {len(collection_names)}")
print(f"Collection names: {collection_names}")
Number of collections: 35 Collection names: ['MAXAR_BayofBengal_Cyclone_Mocha_May_23', 'MAXAR_New_Zealand_Flooding22', 'MAXAR_ghana_explosion22', 'MAXAR_kentucky_flooding_7_29_2022', 'UMBRA_2023', 'MAXAR_Emilia_Romagna_Italy_flooding_may23', 'MAXAR_Gambia_flooding_8_11_2022', 'MAXAR_Hurricane_Fiona_9_19_2022', 'MAXAR_Hurricane_Ian_9_26_2022', 'MAXAR_Hurricane_Idalia_Florida_Aug23', 'MAXAR_India_Floods_Oct_2023', 'MAXAR_Indonesia_Earthquake22', 'MAXAR_Kahramanmaras_turkey_earthquake_23', 'MAXAR_Kalehe_DRC_Flooding_5_8_23', 'MAXAR_Libya_Floods_Sept_2023', 'MAXAR_Marshall_Fire_21_Update', 'MAXAR_Maui_Hawaii_fires_Aug_23', 'MAXAR_McDougallCreekWildfire_BC_Canada_Aug_23', 'MAXAR_Morocco_Earthquake_Sept_2023', 'MAXAR_NWT_Canada_Aug_23', 'MAXAR_Nepal_Earthquake_Nov_2023', 'MAXAR_New_Zealand_Flooding23', 'MAXAR_Sudan_flooding_8_22_2022', 'MAXAR_afghanistan_earthquake22', 'MAXAR_cyclone_emnati22', 'MAXAR_pakistan_flooding22', 'MAXAR_shovi_georgia_landslide_8Aug23', 'MAXAR_southafrica_flooding22', 'MAXAR_tonga_volcano21', 'MAXAR_volcano_indonesia21', 'MAXAR_yellowstone_flooding22', 'noaa-hrrr-prs-conus', 'noaa-hrrr-nat-conus', 'noaa-hrrr-subh-conus', 'noaa-hrrr-sfc-conus']
Lest focus on the data acquired for the M7.8 and M7.5 Kahramanmaras earthquakes in Turkey on February 6, 2023.
More on the event: https://www.usgs.gov/news/featured-story/m78-and-m75-kahramanmaras-earthquake-sequence-near-nurdagi-turkey-turkiye
Collection's Name: MAXAR_Kahramanmaras_turkey_earthquake_23
Let's check the collection's metadata:
collection_id = "MAXAR_Kahramanmaras_turkey_earthquake_23"
collection_info = httpx.get(f"{stac_endpoint}/collections/{collection_id}").json()
print(collection_info)
geojson = {
"type": "FeatureCollection",
"features": [
{
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [[
[bbox[0], bbox[1]],
[bbox[2], bbox[1]],
[bbox[2], bbox[3]],
[bbox[0], bbox[3]],
[bbox[0], bbox[1]],
]]
},
'properties': {}
}
for bbox in collection_info["extent"]["spatial"]["bbox"]
]
}
mainbbox = collection_info["extent"]["spatial"]["bbox"][0]
m = ipyleaflet.leaflet.Map(
center=((mainbbox[1] + mainbbox[3]) / 2,(mainbbox[0] + mainbbox[2]) / 2),
zoom=7
)
geo_json = ipyleaflet.leaflet.GeoJSON(data=geojson)
m.add_layer(geo_json)
m
{'id': 'MAXAR_Kahramanmaras_turkey_earthquake_23', 'type': 'Collection', 'links': [{'rel': 'items', 'type': 'application/geo+json', 'href': 'https://stac.eoapi.dev/collections/MAXAR_Kahramanmaras_turkey_earthquake_23/items'}, {'rel': 'parent', 'type': 'application/json', 'href': 'https://stac.eoapi.dev/'}, {'rel': 'root', 'type': 'application/json', 'href': 'https://stac.eoapi.dev/'}, {'rel': 'self', 'type': 'application/json', 'href': 'https://stac.eoapi.dev/collections/MAXAR_Kahramanmaras_turkey_earthquake_23'}], 'title': 'Turkey and Syria Earthquake 2023', 'extent': {'spatial': {'bbox': [[35.302597, 35.875122, 40.310497, 38.47292570695286], [37.2976, 36.98959965805714, 37.47444448907068, 37.015901889979396], [37.29774464331677, 36.9896650792383, 37.457524034308584, 37.117494], [36.141868, 36.26635032674398, 36.244766, 36.393881], [36.14285540815239, 36.27356734921313, 36.244766, 36.393881], [36.902291, 37.557316, 36.958307, 37.596933], [36.624329, 36.345093, 36.735901, 36.434875], [36.564514, 35.875122, 36.675476, 35.964905], [36.82959060906311, 36.49276872321792, 37.05643641437666, 36.624878], [36.219925, 37.046738, 36.2736536401914, 37.09977], [37.29845588418028, 36.99314320511006, 37.451239755133756, 37.117494], [36.120792028864706, 36.14015655174187, 36.229566, 36.274482719340426], [38.733704, 37.115112, 38.846497, 37.204895], [36.52492568949533, 36.93517400388012, 36.72863746116338, 37.06533191094125], [36.75204714549616, 36.50431672606769, 36.99751367665573, 36.68516122654125], [36.984131, 36.535095, 37.095886, 36.624878], [37.015293359106195, 36.59325358233272, 37.155547, 36.733161], [36.03156315869698, 36.06630343440598, 36.29371596181921, 36.36321464638132], [36.66417067763287, 36.893916206160746, 36.94135503156023, 37.75292284596646], [36.036838063589464, 36.4652144103136, 36.27718132402165, 36.722983669639376], [38.665964936097254, 37.04277780314956, 38.94765149264787, 37.29842755492842], [36.28243347151518, 35.885955, 36.395818, 35.91849849773082], [36.72270807760239, 37.65133933817404, 36.9793372183526, 37.79360976480217], [37.2086027984948, 36.881200182870394, 37.44697269340033, 37.26814965132743], [38.21733111168587, 37.97251565108862, 38.409942390844414, 38.09743204047995], [36.101348035914086, 36.76332547049597, 36.35006037398585, 37.41402735975632], [37.70435909472475, 37.26157993157078, 38.05014092021386, 37.671077037448654], [36.44806059380522, 36.22653163722294, 36.66070588836183, 36.40326083358293], [37.01238203496642, 36.43038760493783, 37.31047812435665, 36.658668804068476], [36.907266976936285, 36.91571544705779, 37.196434355565295, 37.75365980936115], [38.06015901091088, 38.21578061676832, 38.514428711330694, 38.47292570695286], [35.83991709050044, 35.9705643562241, 36.10847691997119, 36.17602181808681], [36.105150480151075, 36.27875001883506, 36.29594418508315, 36.41108994278732], [37.12404392170605, 37.35089079249487, 37.35525581234215, 37.5239390669561], [36.6730422579986, 36.89045223710193, 36.91347807060852, 37.78150025530812], [38.0536304324591, 37.41090295448065, 38.29096023713685, 37.58653325515288], [36.43724012011105, 36.24764802911114, 36.66897323882865, 36.40705503478506], [36.875450454679346, 36.896755071405416, 37.1056071352593, 37.76069174411886], [36.21137593252559, 36.255251436293435, 36.51064099676639, 36.647496845069654], [36.211769692001056, 36.075668813861, 36.44235468786762, 36.252806635855656], [37.14711752539602, 37.37434549247727, 37.33228793498362, 37.49587783519038], [38.21853995071469, 37.44943435925765, 38.41192931836562, 37.583882015377775], [36.202057998869144, 36.08390040008945, 36.45085162597366, 36.233179179599425], [36.233731890265176, 36.09191875516428, 36.42100329746004, 36.22189139397725], [37.34847971373171, 36.989585, 37.481124, 37.11508889563412], [36.219925, 37.046738, 36.289395, 37.09977], [36.098953, 36.127932, 36.244766, 36.393881], [38.238107, 37.731408, 38.315815, 37.786996], [38.042463765821005, 37.61816582040614, 38.45685512435119, 37.90150133428409], [37.18508732537049, 36.93624019118607, 37.57628185978109, 37.20300563112067], [36.70782972919, 37.31458599226506, 37.094357387346356, 37.6388459951458], [36.074011762291256, 36.99645281441965, 36.43039951083553, 37.135050489529895], [35.968135480519166, 36.08290230501916, 36.36857878735416, 36.32611087960102], [38.70465012519544, 37.07660046856506, 38.893745912810424, 37.27151792513816], [40.143822, 37.856098, 40.310497, 37.980469], [38.265734, 38.325282, 38.364036, 38.364057], [40.14692993954917, 37.856098, 40.310497, 37.980469], [35.31641318680286, 36.960976, 35.368635, 37.008584], [35.302597, 36.960976, 35.36398424807608, 37.008584], [38.45306702857648, 37.94082755698512, 38.657175176272865, 38.07998553098428], [36.19771383328533, 36.289375731514305, 36.244766, 36.393881], [37.5349349182917, 37.628945467548746, 37.75370005291414, 37.872636243463944], [38.07315289705838, 37.380707112687496, 38.265428996422365, 37.510271067760094], [38.2218091717765, 37.38740327001574, 38.405563602481934, 37.53170888512031], [36.479697307813865, 37.09779831915633, 36.67267878878018, 37.2659270008341], [38.073629038992614, 37.6594826423537, 38.47610470922022, 37.822928477886215], [37.41476153956851, 37.317027074723, 37.75820367105651, 37.66896109246899], [36.56528740012546, 36.87524918186195, 36.71349084791951, 37.36166156925326], [36.01872866649527, 36.35620582718621, 36.3008169441504, 36.81207927785697], [38.39407950596177, 37.704004721321084, 38.54284528399045, 37.80549833312407], [37.127176401642046, 37.30651913415134, 37.45752114315339, 37.692537568633696], [37.04960614445558, 36.63191806453216, 37.205072570194794, 36.746574586631844], [35.32861203895262, 36.92457322406428, 35.524038262221666, 37.054124418665666], [36.53976967540979, 36.94435109019758, 36.720503605651295, 37.09419588532061], [36.566276833224975, 36.95893269570756, 36.769122320104394, 37.2221669589583], [36.39431428595146, 37.16743689744272, 36.597739259691394, 37.27632822643855], [36.804077, 36.465088, 36.915894, 36.554871]]}, 'temporal': {'interval': [['2021-02-28T08:10:22Z', '2023-03-11T08:29:15Z']]}}, 'license': 'CC-BY-NC-4.0', 'renders': {'visual': {'title': 'Visual Image', 'assets': ['visual'], 'asset_bidx': 'visual|1,2,3', 'minmax_zoom': [8, 22]}}, 'description': "Maxar OpenData | A devastating magnitude 7.8 earthquake struck the Turkish province of Kahramanmaras, approximately 23 kilometers east of Nurdagi in the Gaziantep province near the Syrian border, at 4:17 a.m. local time on Monday, February 6, 2023, followed by a 7.5 magnitude aftershock nine hours later. More than 6,000 people have died in Turkey and Syria, and tens of thousands of people have been injured. Those numbers are expected to increase as search and rescue activities continue. At least 13 million people in the region have been impacted by the earthquake and aftershock. Turkey's president declared a three-month state of emergency in the 10 provinces hardest hit by the earthquake.", 'item_assets': {'visual': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['visual'], 'title': 'Visual Image'}, 'data-mask': {'type': 'application/geopackage+sqlite3', 'roles': ['data-mask'], 'title': 'Data Mask'}, 'cloud-mask': {'type': 'application/geopackage+sqlite3', 'roles': ['cloud'], 'title': 'Cloud Polygons'}, 'ms_analytic': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'title': 'Multispectral Image'}, 'pan_analytic': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'title': 'Panchromatic Image'}, 'cloud-mask-raster': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['cloud', 'cloud-shadow'], 'title': 'Cloud/Cloud Shadow Coverage Raster'}, 'cloud-shadow-mask': {'type': 'application/geopackage+sqlite3', 'roles': ['cloud-shadow'], 'title': 'Cloud Shadow Polygons'}, 'building-centroids': {'type': 'application/geopackage+sqlite3', 'roles': ['building-centroids'], 'title': 'Building Centroids'}, 'building-footprints': {'type': 'application/geopackage+sqlite3', 'roles': ['building-footprints'], 'title': 'Building Footprints'}}, 'stac_version': '1.0.0', 'stac_extensions': ['https://stac-extensions.github.io/item-assets/v1.0.0/schema.json', 'https://stac-extensions.github.io/render/v1.0.0/schema.json']}
Map(center=[37.17402385347643, 37.806546999999995], controls=(ZoomControl(options=['position', 'zoom_in_text',…
Each collection can have spatial and temporal extents. As for the spatial extent, a collection can have multiple temporal extents, but its first one represents the combined min/max of all the intervals.
print(collection_info["extent"]["temporal"])
{'interval': [['2021-02-28T08:10:22Z', '2023-03-11T08:29:15Z']]}
Items¶
In this section, we will:
List all items for a specific collection using the
/collections/{collection_id}/itemsendpointTalk about the
limitparameterVisualize all items on a map
Talk about the item metadata
List the Assets available for one Item
items = httpx.get(f"{stac_endpoint}/collections/{collection_id}/items").json()
print(f"Nb Items in Db: {items['context']['matched']}") # This is only available if CONTEXT=ON
print(f"Returned {len(items['features'])} Items")
Nb Items in Db: 2115 Returned 10 Items
As you can see below, the /items endpoints returned only 10 items. To return more data, we need to either use the paging mechanism.
kahramanmaras_items = []
url = f"{stac_endpoint}/collections/{collection_id}/items"
while True:
items = httpx.get(url, params={"limit": 100}).json()
kahramanmaras_items.extend(items["features"])
next_link = list(filter(lambda link: link["rel"] == "next", items["links"]))
if next_link:
url = next_link[0]["href"]
else:
break
print(f"Nb Items: {len(kahramanmaras_items)}")
Nb Items: 2115
m = ipyleaflet.leaflet.Map(
center=((mainbbox[1] + mainbbox[3]) / 2,(mainbbox[0] + mainbbox[2]) / 2),
zoom=7
)
event_date = datetime(2023, 2, 6, hour=0, minute=0)
# Use a styling function to show where we have before/after items
def style_function(feature):
d = datetime.strptime(feature["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ")
return {
"fillOpacity": 0.1,
"weight": 0.1,
# Blue for pre-event / red for post-event
"fillColor": "#0000ff" if d < event_date else "#ff0000"
}
geo_json = ipyleaflet.leaflet.GeoJSON(data={"type": "FeatureCollection", "features": kahramanmaras_items}, style_callback=style_function)
m.add_layer(geo_json)
m
Map(center=[37.17402385347643, 37.806546999999995], controls=(ZoomControl(options=['position', 'zoom_in_text',…
Item metadata¶
Each item should have an id, a geometry, some links to Assets, and a set of properties.
Item specification: https://github.com/radiantearth/stac-spec/blob/master/item-spec/item-spec.md
item = kahramanmaras_items[0]
print("Item example:")
print(json.dumps(item, indent=4))
Item example:
{
"id": "37_031133210001_10300100E49E8000",
"bbox": [
36.387245559111236,
36.092041667396806,
36.42079643694594,
36.11834923545021
],
"type": "Feature",
"links": [
{
"rel": "collection",
"type": "application/json",
"href": "https://stac.eoapi.dev/collections/MAXAR_Kahramanmaras_turkey_earthquake_23"
},
{
"rel": "parent",
"type": "application/json",
"href": "https://stac.eoapi.dev/collections/MAXAR_Kahramanmaras_turkey_earthquake_23"
},
{
"rel": "root",
"type": "application/json",
"href": "https://stac.eoapi.dev/"
},
{
"rel": "self",
"type": "application/geo+json",
"href": "https://stac.eoapi.dev/collections/MAXAR_Kahramanmaras_turkey_earthquake_23/items/37_031133210001_10300100E49E8000"
}
],
"assets": {
"visual": {
"href": "s3://maxar-opendata/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-visual.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"roles": [
"visual"
],
"title": "Visual Image",
"eo:bands": [
{
"name": "BAND_R",
"common_name": "red",
"description": "Red"
},
{
"name": "BAND_G",
"common_name": "green",
"description": "Green"
},
{
"name": "BAND_B",
"common_name": "blue",
"description": "Blue"
}
],
"alternate": {
"public": {
"href": "https://maxar-opendata.s3.amazonaws.com/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-visual.tif",
"title": "Public Access"
}
},
"proj:bbox": [
264843.75,
3994843.75,
270156.25,
4000156.25
],
"proj:shape": [
17408,
17408
],
"proj:transform": [
0.30517578125,
0.0,
264843.75,
0.0,
-0.30517578125,
4000156.25,
0.0,
0.0,
1.0
]
},
"data-mask": {
"href": "s3://maxar-opendata/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-data-mask.gpkg",
"type": "application/geopackage+sqlite3",
"roles": [
"data-mask"
],
"title": "Data Mask",
"alternate": {
"public": {
"href": "https://maxar-opendata.s3.amazonaws.com/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-data-mask.gpkg",
"title": "Public Access"
}
}
},
"cloud-mask": {
"type": "application/geopackage+sqlite3",
"roles": [
"cloud"
],
"title": "Cloud Polygons"
},
"ms_analytic": {
"href": "s3://maxar-opendata/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-ms.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"roles": [
"data"
],
"title": "Multispectral Image",
"eo:bands": [
{
"name": "BAND_C",
"common_name": "coastal",
"description": "Coastal Blue"
},
{
"name": "BAND_B",
"common_name": "blue",
"description": "Blue"
},
{
"name": "BAND_G",
"common_name": "green",
"description": "Green"
},
{
"name": "BAND_Y",
"common_name": "yellow",
"description": "Yellow"
},
{
"name": "BAND_R",
"common_name": "red",
"description": "Red"
},
{
"name": "BAND_RE",
"common_name": "rededge",
"description": "Red Edge 1"
},
{
"name": "BAND_N",
"common_name": "nir08",
"description": "Near Infrared 1"
},
{
"name": "BAND_N2",
"common_name": "nir09",
"description": "Near Infrared 2"
}
],
"alternate": {
"public": {
"href": "https://maxar-opendata.s3.amazonaws.com/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-ms.tif",
"title": "Public Access"
}
},
"proj:bbox": [
264843.75,
3994843.75,
270156.25,
4000156.25
],
"proj:shape": [
2779,
2779
],
"proj:transform": [
1.9116588700971573,
0.0,
264843.75,
0.0,
-1.9116588700971573,
4000156.25,
0.0,
0.0,
1.0
]
},
"pan_analytic": {
"href": "s3://maxar-opendata/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-pan.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"roles": [
"data"
],
"title": "Panchromatic Image",
"eo:bands": [
{
"name": "BAND_P",
"description": "Pan"
}
],
"alternate": {
"public": {
"href": "https://maxar-opendata.s3.amazonaws.com/events/Kahramanmaras-turkey-earthquake-23/ard/37/031133210001/2023-03-11/10300100E49E8000-pan.tif",
"title": "Public Access"
}
},
"proj:bbox": [
264843.75,
3994843.75,
270156.25,
4000156.25
],
"proj:shape": [
11116,
11116
],
"proj:transform": [
0.4779147175242893,
0.0,
264843.75,
0.0,
-0.4779147175242893,
4000156.25,
0.0,
0.0,
1.0
]
},
"cloud-mask-raster": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"roles": [
"cloud",
"cloud-shadow"
],
"title": "Cloud/Cloud Shadow Coverage Raster"
},
"cloud-shadow-mask": {
"type": "application/geopackage+sqlite3",
"roles": [
"cloud-shadow"
],
"title": "Cloud Shadow Polygons"
},
"building-centroids": {
"type": "application/geopackage+sqlite3",
"roles": [
"building-centroids"
],
"title": "Building Centroids"
},
"building-footprints": {
"type": "application/geopackage+sqlite3",
"roles": [
"building-footprints"
],
"title": "Building Footprints"
}
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
36.387245559111236,
36.11762172115687
],
[
36.38807914445892,
36.09246165938945
],
[
36.40855030738972,
36.09229578729594
],
[
36.420731654920246,
36.092041667396806
],
[
36.42079643694594,
36.11834923545021
],
[
36.387245559111236,
36.11762172115687
]
]
]
},
"collection": "MAXAR_Kahramanmaras_turkey_earthquake_23",
"properties": {
"gsd": 0.48,
"quadkey": "031133210001",
"datetime": "2023-03-11T08:29:15Z",
"platform": "WV02",
"utm_zone": 37,
"grid:code": "MXRA-Z37-031133210001",
"proj:bbox": [
264843.75,
3997237.548828125,
267866.2109375,
4000156.25
],
"proj:epsg": 32637,
"catalog_id": "10300100E49E8000",
"view:azimuth": 175.5,
"proj:geometry": {
"type": "Polygon",
"coordinates": [
[
[
264843.75,
4000156.25
],
[
264843.75,
3997362.6708984375
],
[
266686.70654296875,
3997294.921875
],
[
267782.89794921875,
3997237.548828125
],
[
267866.2109375,
4000156.25
],
[
264843.75,
4000156.25
]
]
]
},
"tile:data_area": 8.5,
"view:off_nadir": 12.4,
"tile:clouds_area": 0.0,
"view:sun_azimuth": 152.0,
"view:sun_elevation": 46.5,
"tile:clouds_percent": 0,
"ard_metadata_version": "0.0.1",
"view:incidence_angle": 76.1
},
"stac_version": "1.0.0",
"stac_extensions": [
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/raster/v1.1.0/schema.json",
"https://stac-extensions.github.io/grid/v1.0.0/schema.json",
"https://stac-extensions.github.io/alternate-assets/v1.1.0/schema.json"
]
}
print("Item Id", item["id"])
print("Item Assets:", list(item["assets"].keys()))
print("Item Properties:")
print(json.dumps(item["properties"], indent=4))
Item Id 37_031133210001_10300100E49E8000
Item Assets: ['visual', 'data-mask', 'cloud-mask', 'ms_analytic', 'pan_analytic', 'cloud-mask-raster', 'cloud-shadow-mask', 'building-centroids', 'building-footprints']
Item Properties:
{
"gsd": 0.48,
"quadkey": "031133210001",
"datetime": "2023-03-11T08:29:15Z",
"platform": "WV02",
"utm_zone": 37,
"grid:code": "MXRA-Z37-031133210001",
"proj:bbox": [
264843.75,
3997237.548828125,
267866.2109375,
4000156.25
],
"proj:epsg": 32637,
"catalog_id": "10300100E49E8000",
"view:azimuth": 175.5,
"proj:geometry": {
"type": "Polygon",
"coordinates": [
[
[
264843.75,
4000156.25
],
[
264843.75,
3997362.6708984375
],
[
266686.70654296875,
3997294.921875
],
[
267782.89794921875,
3997237.548828125
],
[
267866.2109375,
4000156.25
],
[
264843.75,
4000156.25
]
]
]
},
"tile:data_area": 8.5,
"view:off_nadir": 12.4,
"tile:clouds_area": 0.0,
"view:sun_azimuth": 152.0,
"view:sun_elevation": 46.5,
"tile:clouds_percent": 0,
"ard_metadata_version": "0.0.1",
"view:incidence_angle": 76.1
}
Find acquisition times¶
Every item should have either a datetime or a start/end_datetime property. For the Maxar dataset, we are assuming that datetime is acquisition times.
datetimes = {item["properties"]["datetime"] for item in kahramanmaras_items}
print("Dates:", sorted(list(datetimes))[0:10])
Dates: ['2021-02-28T08:10:22Z', '2021-02-28T08:10:23Z', '2021-08-17T11:16:54Z', '2021-08-18T08:13:11Z', '2021-08-18T08:13:12Z', '2021-09-09T08:36:18Z', '2021-09-09T08:36:19Z', '2021-09-09T08:36:20Z', '2021-09-27T08:40:11Z', '2021-09-27T08:40:12Z']
Let's sort the items in two categories: before and after the event.
event_date = datetime(2023, 2, 6, hour=0, minute=0)
pre_items = list(
filter(
lambda item: datetime.strptime(item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ") < event_date,
kahramanmaras_items
)
)
post_items = list(
filter(
lambda item: datetime.strptime(item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ") >= event_date,
kahramanmaras_items
)
)
print("PRE event items:", len(pre_items))
print("POST event items:", len(post_items))
PRE event items: 229 POST event items: 1886
# Same but using the STAC API
pre_items_api = httpx.post(
f"{stac_endpoint}/search",
data=json.dumps(
{
"filter-lang": 'cql2-json',
"filter": {
"op": 'and',
"args": [
{
"op": "in",
"args": [{"property": "collection"}, [collection_id]]
},
{
"op": "lt",
"args": [
{"property": "datetime"}, "2023-02-06T00:00:00Z"
]
}
],
},
}
)
).json()
print(f"Nb Items in Db: {pre_items_api['context']['matched']}") # This is only available if CONTEXT=ON
Nb Items in Db: 229
Asset visualization¶
So we have 2115 items for the MAXAR_Kahramanmaras_turkey_earthquake_23 collection, and each item has 4 assets (this is also found at the collection level in the item_assets extension).