|
15 | 15 | import os |
16 | 16 | import warnings |
17 | 17 | from typing import Any, Sequence, TypeVar |
| 18 | +from xml.etree import ElementTree |
18 | 19 |
|
19 | 20 | import fsspec |
20 | 21 | import numpy as np |
@@ -1234,3 +1235,105 @@ def open_sentinel1_dataset( |
1234 | 1235 | conventions.update_attributes(ds, group=metadata) |
1235 | 1236 |
|
1236 | 1237 | return ds |
| 1238 | + |
| 1239 | + |
| 1240 | +def make_sentinel1_stac_item( |
| 1241 | + item_id: str, |
| 1242 | + manifest_path: esa_safe.PathOrFileType, |
| 1243 | + annotation: esa_safe.PathOrFileType, |
| 1244 | + namespaces=esa_safe.SENTINEL1_NAMESPACES, |
| 1245 | +) -> dict[str, Any]: |
| 1246 | + manifest = ElementTree.parse(manifest_path).getroot() |
| 1247 | + |
| 1248 | + product_information = esa_safe.parse_tag(annotation, ".//productInformation") |
| 1249 | + image_information = esa_safe.parse_tag(annotation, ".//imageInformation") |
| 1250 | + |
| 1251 | + coordinates = [ |
| 1252 | + [float(v) for v in token.split(",")] |
| 1253 | + for token in esa_safe.findtext(manifest, ".//gml:coordinates").split() |
| 1254 | + ] |
| 1255 | + coordinates += coordinates[:1] |
| 1256 | + product_timeliness = esa_safe.findtext( |
| 1257 | + manifest, ".//s1sarl1:productTimelinessCategory" |
| 1258 | + ) |
| 1259 | + product_timeliness_map = { |
| 1260 | + "Fast-24h": { |
| 1261 | + "product:timeliness_category": "STC", |
| 1262 | + "product:timeliness": "PT24H", |
| 1263 | + }, |
| 1264 | + "NRT-3h": { |
| 1265 | + "product:timeliness_category": "NRT", |
| 1266 | + "product:timeliness": "PT3H", |
| 1267 | + }, |
| 1268 | + } |
| 1269 | + |
| 1270 | + stac_item = { |
| 1271 | + "type": "Feature", |
| 1272 | + "stac_version": "1.1.0", |
| 1273 | + "stac_extensions": [ |
| 1274 | + "https://stac-extensions.github.io/product/v0.1.0/schema.json", |
| 1275 | + "https://stac-extensions.github.io/processing/v1.2.0/schema.json", |
| 1276 | + "https://stac-extensions.github.io/sat/v1.0.0/schema.json", |
| 1277 | + "https://stac-extensions.github.io/view/v1.0.0/schema.json", |
| 1278 | + "https://stac-extensions.github.io/sar/v1.2.0/schema.json", |
| 1279 | + # "https://stac-extensions.github.io/eopf/v1.0.0/schema.json", |
| 1280 | + ], |
| 1281 | + "id": item_id, |
| 1282 | + "properties": { |
| 1283 | + "datetime": None, |
| 1284 | + "start_datetime": esa_safe.findtext(manifest, ".//safe:startTime") + "Z", |
| 1285 | + "end_datetime": esa_safe.findtext(manifest, ".//safe:stopTime") + "Z", |
| 1286 | + "created": manifest.find( |
| 1287 | + ".//safe:processing", namespaces=namespaces |
| 1288 | + ).attrib["stop"] |
| 1289 | + + "Z", |
| 1290 | + "platform": "sentinel-1" |
| 1291 | + + esa_safe.findtext(manifest, ".//safe:platform/safe:number").lower(), |
| 1292 | + "instruments": ["sar"], |
| 1293 | + "constellation": "sentinel-1", |
| 1294 | + "product:type": esa_safe.findtext(manifest, ".//s1sarl1:productType"), |
| 1295 | + "product:timeliness_category": product_timeliness_map[product_timeliness][ |
| 1296 | + "product:timeliness_category" |
| 1297 | + ], |
| 1298 | + "product:timeliness": product_timeliness_map[product_timeliness][ |
| 1299 | + "product:timeliness" |
| 1300 | + ], |
| 1301 | + "processing:software": manifest.find( |
| 1302 | + ".//safe:software", namespaces=namespaces |
| 1303 | + ).attrib, |
| 1304 | + "sat:platform_international_designator": esa_safe.findtext( |
| 1305 | + manifest, ".//safe:nssdcIdentifier" |
| 1306 | + ), |
| 1307 | + "sat:absolute_orbit": int( |
| 1308 | + esa_safe.findall(manifest, ".//safe:orbitNumber")[0] |
| 1309 | + ), |
| 1310 | + "sat:relative_orbit": int( |
| 1311 | + esa_safe.findall(manifest, ".//safe:relativeOrbitNumber")[0] |
| 1312 | + ), |
| 1313 | + "sat:orbit_state": esa_safe.findtext(manifest, ".//s1:pass").lower(), |
| 1314 | + "sat:anx_datetime": esa_safe.findtext(manifest, ".//s1:ascendingNodeTime") |
| 1315 | + + "Z", |
| 1316 | + "view:incidence_angle": image_information["incidenceAngleMidSwath"], |
| 1317 | + "sar:polarizations": esa_safe.findall( |
| 1318 | + manifest, ".//s1sarl1:transmitterReceiverPolarisation" |
| 1319 | + ), |
| 1320 | + "sar:instrument_mode": esa_safe.findtext( |
| 1321 | + manifest, ".//s1sarl1:instrumentMode/s1sarl1:mode" |
| 1322 | + ), |
| 1323 | + "sar:frequency_band": "C", |
| 1324 | + "sar:center_frequency": product_information["radarFrequency"] / 1e9, |
| 1325 | + "sar:pixel_spacing_range": image_information["rangePixelSpacing"], |
| 1326 | + "sar:pixel_spacing_azimuth": image_information["azimuthPixelSpacing"], |
| 1327 | + "sar:observation_direction": "right", |
| 1328 | + "sar:beam_ids": esa_safe.findall( |
| 1329 | + manifest, ".//s1sarl1:instrumentMode/s1sarl1:swath" |
| 1330 | + ), |
| 1331 | + "eopf:datatake_id": int( |
| 1332 | + esa_safe.findtext(manifest, ".//s1sarl1:missionDataTakeID") |
| 1333 | + ), |
| 1334 | + }, |
| 1335 | + "geometry": {"type": "Polygon", "coordinates": [coordinates]}, |
| 1336 | + "links": [], |
| 1337 | + "assets": {}, |
| 1338 | + } |
| 1339 | + return stac_item |
0 commit comments