Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions scripts/opera-rtc/choose_granules.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
from random import sample
import random

import requests
from shapely.geometry import Polygon, shape


session = requests.Session()

Expand Down Expand Up @@ -34,17 +36,39 @@ def get_attribute_values(granule, attribute_name: str) -> list[str]:


def choose_sample(candidates: list) -> None:
for granule in sample(candidates, 10):
random.seed(42)
for granule in random.sample(candidates, 10):
print(f'{granule["meta"]["native-id"]},{get_corresponding_burst_granule_name(granule)}')


def filter_extreme_terrain_sample(candidates: list) -> list:
with open('extreme_terrain.geojson') as f:
extreme_terrain = json.load(f)
geometries = [shape(feature['geometry']) for feature in extreme_terrain['features']]
filtered_candidates = []
for granule in candidates:
boundary = granule['umm']['SpatialExtent']['HorizontalSpatialDomain']['Geometry']['GPolygons'][0]['Boundary']
granule_geometry = Polygon([(pt['Longitude'], pt['Latitude']) for pt in boundary['Points']])
if any(geom.intersects(granule_geometry) for geom in geometries):
filtered_candidates.append(granule)
return filtered_candidates


def over_antimeridian(granule: dict) -> bool:
longitudes = [point['Longitude'] for poly in granule['umm']['SpatialExtent']['HorizontalSpatialDomain']['Geometry']['GPolygons'] for point in poly['Boundary']['Points']]
longitudes = [
point['Longitude']
for poly in granule['umm']['SpatialExtent']['HorizontalSpatialDomain']['Geometry']['GPolygons']
for point in poly['Boundary']['Points']
]
return min(longitudes) < -160 and 160 < max(longitudes)


def over_prime_meridian(granule: dict) -> bool:
longitudes = [point['Longitude'] for poly in granule['umm']['SpatialExtent']['HorizontalSpatialDomain']['Geometry']['GPolygons'] for point in poly['Boundary']['Points']]
longitudes = [
point['Longitude']
for poly in granule['umm']['SpatialExtent']['HorizontalSpatialDomain']['Geometry']['GPolygons']
for point in poly['Boundary']['Points']
]
return min(longitudes) < 0 < max(longitudes)


Expand All @@ -56,7 +80,7 @@ def main():
print('S1A')
choose_sample([g for g in granules if g['umm']['Platforms'][0]['ShortName'] == 'Sentinel-1A'])
print('S1B')
# choose_sample([g for g in granules if g['umm']['Platforms'][0]['ShortName'] == 'Sentinel-1B'])
choose_sample([g for g in granules if g['umm']['Platforms'][0]['ShortName'] == 'Sentinel-1B'])
print('IW1')
choose_sample([g for g in granules if 'IW1' in get_attribute_values(g, 'SUBSWATH_NAME')])
print('IW2')
Expand All @@ -79,6 +103,8 @@ def main():
choose_sample([g for g in granules if over_prime_meridian(g)])
print('antimeridian')
choose_sample([g for g in granules if over_antimeridian(g)])
print('extreme terrain')
choose_sample(filter_extreme_terrain_sample(granules))


if __name__ == '__main__':
Expand Down
14 changes: 14 additions & 0 deletions scripts/opera-rtc/extreme_terrain.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "FeatureCollection",
"name": "extreme_terrain",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -123.533649730993389, 40.299794170074641 ], [ -122.96633174912948, 40.307077898205705 ], [ -122.96123798498256, 39.85155893290883 ], [ -123.559755272246363, 39.881370166569987 ], [ -123.533649730993389, 40.299794170074641 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -127.194155991078205, 53.78915924532361 ], [ -127.117749528874327, 52.944239973438286 ], [ -128.212908820463468, 52.941170403193112 ], [ -128.233283877051178, 53.780130723008043 ], [ -127.194155991078205, 53.78915924532361 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 3 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -65.793922964029306, -18.018956465039317 ], [ -64.219949842629092, -18.062546495083271 ], [ -64.077324446515149, -20.093914126971761 ], [ -65.778641671588531, -20.065209234753272 ], [ -65.793922964029306, -18.018956465039317 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 4 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 9.960537429057796, 47.092162772998691 ], [ 11.942011682212103, 47.106032734146154 ], [ 11.987855559534436, 45.970849766061939 ], [ 9.914693551735461, 45.928349996811107 ], [ 9.960537429057796, 47.092162772998691 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 5 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 74.84999889675106, 35.881851296136439 ], [ 77.885882328319099, 35.832310531813782 ], [ 77.855319743437533, 34.60893880302541 ], [ 74.748123613812538, 34.58378052568807 ], [ 74.84999889675106, 35.881851296136439 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 6 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 94.899054579052745, 33.715409557239973 ], [ 99.809443216689644, 33.511792074345372 ], [ 99.890943443040456, 29.995737095612505 ], [ 94.878679522465049, 30.066296284463661 ], [ 94.899054579052745, 33.715409557239973 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 6 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 5.568439293370863, 62.312563852572133 ], [ 8.543197555175785, 62.326761339571874 ], [ 8.645072838114311, 60.589542636347346 ], [ 5.446188953844633, 60.694428932714814 ], [ 5.568439293370863, 62.312563852572133 ] ] ] ] } }
]
}
Loading