Skip to content

Commit

Permalink
Make robust to adding coarse DEM with no foreshore (e.g. landlocked)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepearson committed Nov 2, 2023
1 parent de1fa1b commit 5459b95
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/geofabrics/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,38 +1802,39 @@ def add_coarse_dems(
self.SOURCE_CLASSIFICATION["coarse DEM"],
)
# Ensure Coarse DEM values along the foreshore are less than zero
buffered_foreshore = geopandas.GeoDataFrame(
geometry=self.catchment_geometry.foreshore.buffer(
self.catchment_geometry.resolution * numpy.sqrt(2)
if self.catchment_geometry.foreshore.area.sum() > 0:
buffered_foreshore = geopandas.GeoDataFrame(
geometry=self.catchment_geometry.foreshore.buffer(
self.catchment_geometry.resolution * numpy.sqrt(2)
)
)
)
buffered_foreshore = buffered_foreshore.overlay(
self.catchment_geometry.full_land,
how="difference",
keep_geom_type=True,
)
# Clip DEM to buffered foreshore
mask = self._dem.z.rio.clip(
buffered_foreshore.geometry, drop=False
).notnull()
mask = (
mask
& (self._dem.z > 0)
& (
self._dem.data_source
== self.SOURCE_CLASSIFICATION["coarse DEM"]
buffered_foreshore = buffered_foreshore.overlay(
self.catchment_geometry.full_land,
how="difference",
keep_geom_type=True,
)
# Clip DEM to buffered foreshore
mask = self._dem.z.rio.clip(
buffered_foreshore.geometry, drop=False
).notnull()
mask = (
mask
& (self._dem.z > 0)
& (
self._dem.data_source
== self.SOURCE_CLASSIFICATION["coarse DEM"]
)
)
)

# Set any positive LiDAR foreshore points to zero
self._dem["data_source"] = self._dem.data_source.where(
~mask,
self.SOURCE_CLASSIFICATION["ocean bathymetry"],
)
self._dem["z"] = self._dem.z.where(
~mask,
0,
)
# Set any positive LiDAR foreshore points to zero
self._dem["data_source"] = self._dem.data_source.where(
~mask,
self.SOURCE_CLASSIFICATION["ocean bathymetry"],
)
self._dem["z"] = self._dem.z.where(
~mask,
0,
)

"""if chunk_size is None:
self._add_coarse_dem_no_chunking(
Expand Down

0 comments on commit 5459b95

Please sign in to comment.