Skip to content

Commit 41c7d04

Browse files
committed
Catch error when Geodata is empty
1 parent a9c267f commit 41c7d04

File tree

4 files changed

+320
-555
lines changed

4 files changed

+320
-555
lines changed

coastlines/vector.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,17 @@ def contours_preprocess(
611611
# and values of 1 and 2 for mainland/island pixels. We extract ocean
612612
# pixels (value 0), then erode these by 10 pixels to ensure we only
613613
# use high certainty deeper water ocean regions for identifying ocean
614-
# pixels in our satellite imagery
615-
dc = datacube.Datacube()
616-
geodata_da = dc.load(
617-
product="geodata_coast_100k",
618-
like=combined_ds.odc.geobox.compat,
619-
).land.squeeze("time")
620-
ocean_da = xr.apply_ufunc(binary_erosion, geodata_da == 0, disk(10))
614+
# pixels in our satellite imagery. If no Geodata data exists (e.g.
615+
# over remote ocean waters, use an all True array to represent ocean.
616+
try:
617+
dc = datacube.Datacube()
618+
geodata_da = dc.load(
619+
product="geodata_coast_100k",
620+
like=combined_ds.odc.geobox.compat,
621+
).land.squeeze("time")
622+
ocean_da = xr.apply_ufunc(binary_erosion, geodata_da == 0, disk(10))
623+
except AttributeError:
624+
ocean_da = odc.geo.xr.xr_zeros(combined_ds.odc.geobox) == 0
621625

622626
# Use all time and Geodata 100K data to produce the buffered coastal
623627
# study area. The output has values of 0 representing non-coastal

data/raw/coastlines_development.geojson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"name": "coastlines_development",
44
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
55
"features": [
6-
{ "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 ] ] ] } },
6+
{ "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 ] ] ] } },
77
{ "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 ] ] ] } },
88
{ "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 ] ] ] } },
99
{ "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 ] ] ] } },
1010
{ "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 ] ] ] } },
1111
{ "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 ] ] ] } },
12+
{ "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 ] ] ] } },
1213
{ "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 ] ] ] } },
1314
{ "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 ] ] ] } }
1415
]

0 commit comments

Comments
 (0)