Skip to content

Commit

Permalink
Catch error when Geodata is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
robbibt committed Jan 25, 2023
1 parent a9c267f commit 41c7d04
Show file tree
Hide file tree
Showing 4 changed files with 320 additions and 555 deletions.
18 changes: 11 additions & 7 deletions coastlines/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,17 @@ def contours_preprocess(
# and values of 1 and 2 for mainland/island pixels. We extract ocean
# pixels (value 0), then erode these by 10 pixels to ensure we only
# use high certainty deeper water ocean regions for identifying ocean
# pixels in our satellite imagery
dc = datacube.Datacube()
geodata_da = dc.load(
product="geodata_coast_100k",
like=combined_ds.odc.geobox.compat,
).land.squeeze("time")
ocean_da = xr.apply_ufunc(binary_erosion, geodata_da == 0, disk(10))
# pixels in our satellite imagery. If no Geodata data exists (e.g.
# over remote ocean waters, use an all True array to represent ocean.
try:
dc = datacube.Datacube()
geodata_da = dc.load(
product="geodata_coast_100k",
like=combined_ds.odc.geobox.compat,
).land.squeeze("time")
ocean_da = xr.apply_ufunc(binary_erosion, geodata_da == 0, disk(10))
except AttributeError:
ocean_da = odc.geo.xr.xr_zeros(combined_ds.odc.geobox) == 0

# Use all time and Geodata 100K data to produce the buffered coastal
# study area. The output has values of 0 representing non-coastal
Expand Down
3 changes: 2 additions & 1 deletion data/raw/coastlines_development.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"name": "coastlines_development",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 6 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 149.695938608467088, -37.492548051212026 ], [ 149.693144400896585, -37.574089636650719 ], [ 149.768588005300415, -37.577632900307499 ], [ 149.818185189676967, -37.562240624449011 ], [ 149.830759123744286, -37.553934118475283 ], [ 149.818464610434035, -37.48445550765247 ], [ 149.737991432403334, -37.484344644804459 ], [ 149.695938608467088, -37.492548051212026 ] ] ] } },
{ "type": "Feature", "properties": { "id": 9 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 149.972811444544021, -36.679471492288926 ], [ 149.97041229888066, -36.710551292054923 ], [ 150.00445017797955, -36.711512942281225 ], [ 150.005574777509281, -36.667805811387879 ], [ 149.973261284355857, -36.67021125116235 ], [ 149.972811444544021, -36.679471492288926 ] ] ] } },
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 129.808772974409294, -13.522771535514741 ], [ 129.871062780837775, -13.522362326041147 ], [ 129.873798481795802, -13.6248472833701 ], [ 129.774261054631353, -13.626483410274908 ], [ 129.808772974409294, -13.522771535514741 ] ] ] } },
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 122.249386759416581, -17.214313335776648 ], [ 122.186886514452851, -17.185566411563052 ], [ 122.148586701040756, -17.249085110350848 ], [ 122.208772122116898, -17.283046587937186 ], [ 122.249386759416581, -17.214313335776648 ] ] ] } },
{ "type": "Feature", "properties": { "id": 3 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 132.611126280669453, -11.61081146005043 ], [ 132.610520468361358, -11.687203249183282 ], [ 132.710782405348084, -11.686906622697229 ], [ 132.710479499194008, -11.686016741333162 ], [ 132.710025139962994, -11.610218043672749 ], [ 132.611126280669453, -11.61081146005043 ] ] ] } },
{ "type": "Feature", "properties": { "id": 4 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 152.012966156172297, -24.416619325370696 ], [ 151.986652156714598, -24.416246604760904 ], [ 152.002674458606606, -24.449201499566822 ], [ 152.008112685161223, -24.458197381090113 ], [ 152.0276435203142, -24.447923925849551 ], [ 152.012966156172297, -24.416619325370696 ] ] ] } },
{ "type": "Feature", "properties": { "id": 5 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 141.607135554879449, -12.428496162747486 ], [ 141.610209183207019, -12.39820553756258 ], [ 141.79378862058951, -12.400661665467194 ], [ 141.780655845008113, -12.598712687091243 ], [ 141.632004002256963, -12.594622262913241 ], [ 141.555163294067995, -12.579350769650771 ], [ 141.600988298224365, -12.449233655194789 ], [ 141.607135554879449, -12.428496162747486 ] ] ] } },
{ "type": "Feature", "properties": { "id": 6 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 149.695938608467088, -37.492548051212026 ], [ 149.693144400896585, -37.574089636650719 ], [ 149.768588005300415, -37.577632900307499 ], [ 149.818185189676967, -37.562240624449011 ], [ 149.830759123744286, -37.553934118475283 ], [ 149.818464610434035, -37.48445550765247 ], [ 149.737991432403334, -37.484344644804459 ], [ 149.695938608467088, -37.492548051212026 ] ] ] } },
{ "type": "Feature", "properties": { "id": 7 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 147.753134816589125, -37.942890125061354 ], [ 147.821662757255893, -37.943330839584526 ], [ 147.815305935032995, -37.975055338548088 ], [ 147.750620029775661, -37.976982600810167 ], [ 147.753134816589125, -37.942890125061354 ] ] ] } },
{ "type": "Feature", "properties": { "id": 8 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 145.185450161059464, -38.363443382983867 ], [ 145.186288423330637, -38.382556540880202 ], [ 145.214020933467964, -38.388360683795526 ], [ 145.219329927851931, -38.382775573597662 ], [ 145.216326154713641, -38.375437616515619 ], [ 145.20228526167179, -38.364538829257768 ], [ 145.185450161059464, -38.363443382983867 ] ] ] } }
]
Expand Down
Loading

0 comments on commit 41c7d04

Please sign in to comment.