Skip to content

Commit

Permalink
Change all time raster thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
robbibt committed Jan 16, 2023
1 parent 4add4e9 commit a9c267f
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 147 deletions.
24 changes: 12 additions & 12 deletions coastlines/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,14 @@ def contours_preprocess(
thresholded_ds = thresholded_ds.where(temporal_mask)

# Create all time layers by identifying pixels that are land in at
# least 15% and 50% of valid observations; the 15% layer is used to
# least 20% and 80% of valid observations; the 20% layer is used to
# identify pixels that contain land for even a small period of time;
# this is used for producing an all-time buffered "coastal" study area.
# The 50% layer is used to more conservatively identify pixels that
# are land for a majority of years; this is used for extracting
# rivers.
all_time_15 = thresholded_ds.mean(dim="year") > 0.15
all_time_50 = thresholded_ds.mean(dim="year") > 0.5
# The 80% layer is used to more conservatively identify pixels that
# are land for most of the time series years; this is used for extracting
# rivers as it better accounts for migrating/dynamic river channels.
all_time_20 = thresholded_ds.mean(dim="year") > 0.2
all_time_80 = thresholded_ds.mean(dim="year") > 0.8

# Identify narrow river and stream features using the `black_tophat`
# transform. To avoid narrow channels between islands and the
Expand All @@ -594,14 +594,14 @@ def contours_preprocess(
# Use a disk of size 8 to identify any rivers/streams smaller than
# approximately 240 m (e.g. 8 * 30 m = 240 m).
island_size = int(5000000 / (30 * 30)) # 5 km^2
sieved = xr.apply_ufunc(sieve, all_time_50.astype(np.int16), island_size)
rivers = xr.apply_ufunc(black_tophat, (sieved & all_time_50), disk(8)) == 1
sieved = xr.apply_ufunc(sieve, all_time_80.astype(np.int16), island_size)
rivers = xr.apply_ufunc(black_tophat, (sieved & all_time_80), disk(8)) == 1

# Create a river mask by eroding the all time layer to clip out river
# mouths, then expanding river features to include stream banks and
# account for migrating rivers
river_mouth_mask = xr.apply_ufunc(
binary_erosion, all_time_50.where(~rivers, True), disk(12)
binary_erosion, all_time_80.where(~rivers, True), disk(12)
)
rivers = rivers.where(river_mouth_mask, False)
river_mask = ~xr.apply_ufunc(binary_dilation, rivers, disk(4))
Expand All @@ -624,7 +624,7 @@ def contours_preprocess(
# "ocean", values of 1 representing "coastal", and values of 2
# representing non-coastal "inland" pixels.
coastal_mask = coastal_masking(
ds=all_time_15.where(~rivers, True), ocean_da=ocean_da, buffer=buffer_pixels
ds=all_time_20.where(~rivers, True), ocean_da=ocean_da, buffer=buffer_pixels
)

# Add rivers as "inland" pixels in the coastal mask
Expand Down Expand Up @@ -684,8 +684,8 @@ def contours_preprocess(
return (
masked_ds,
certainty_masks,
all_time_15,
all_time_50,
all_time_20,
all_time_80,
river_mask,
ocean_da,
thresholded_ds,
Expand Down
9 changes: 7 additions & 2 deletions data/raw/coastlines_development.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
"name": "coastlines_development",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "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": 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": 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": 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": 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 ] ] ] } }
]
}
Loading

0 comments on commit a9c267f

Please sign in to comment.