Skip to content

Commit

Permalink
Update use of save_dem and mask roughness instead of clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepearson committed Jan 5, 2024
1 parent 872dc73 commit e25257e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
31 changes: 13 additions & 18 deletions src/geofabrics/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def __del__(self):

@property
def dem(self):
"""Return the combined DEM from tiles and any interpolated offshore values"""
"""Return the positivelly indexed DEM from tiles"""

# Ensure positively increasing indices as required by some programs
self._dem = self._ensure_positive_indexing(self._dem)
Expand Down Expand Up @@ -1285,15 +1285,6 @@ def __init__(
self.buffer_cells = buffer_cells
self._dem = None

@property
def dem(self):
"""Return the combined DEM from tiles"""

# Ensure positively increasing indices as required by some programs
self._dem = self._ensure_positive_indexing(self._dem)

return self._dem

def _set_up_chunks(self) -> (list, list):
"""Define the chunks to break the catchment into when reading in and
downsampling LiDAR.
Expand Down Expand Up @@ -1385,7 +1376,9 @@ def add_lidar(
"""

# Check valid inputs
self._check_valid_inputs(lidar_datasets_info=lidar_datasets_info)
self._check_valid_inputs(
lidar_datasets_info=lidar_datasets_info
)

# create dictionary defining raster options
raster_options = {
Expand Down Expand Up @@ -2046,9 +2039,10 @@ def __init__(
)

# Clip to the catchment extents to ensure performance
hydrological_dem = hydrological_dem.rio.clip(
self.catchment_geometry.catchment.geometry, drop=True
)
catchment = self.catchment_geometry.catchment
hydrological_dem = hydrological_dem.rio.clip_box(**catchment.bounds.iloc[0])
mask = clip_mask(hydrological_dem.z, catchment.geometry, self.chunk_size)
hydrological_dem = hydrological_dem.where(mask)

self.temp_folder = temp_folder
self.interpolation_method = interpolation_method
Expand Down Expand Up @@ -2095,7 +2089,9 @@ def add_lidar(
"""

# Check valid inputs
self._check_valid_inputs(lidar_datasets_info=lidar_datasets_info)
self._check_valid_inputs(
lidar_datasets_info=lidar_datasets_info
)

# create dictionary defining raster options
raster_options = {
Expand Down Expand Up @@ -2168,9 +2164,8 @@ def add_lidar(
# If any NaN remain apply nearest neighbour interpolation
if numpy.isnan(self._dem.zo.data).any():
self._dem["zo"] = self._dem.zo.rio.interpolate_na(method="nearest")
self._dem = self._dem.rio.clip(
self.catchment_geometry.catchment.geometry, drop=True
)
mask = clip_mask(self._dem.z, self.catchment_geometry.catchment.geometry, self.chunk_size)
self._dem = self._dem.where(mask)

def _add_tiled_lidar_chunked(
self,
Expand Down
1 change: 0 additions & 1 deletion src/geofabrics/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,6 @@ def run(self):
)
self.roughness_dem.save_dem(
filename=self.get_instruction_path("result_geofabric"),
dem=self.roughness_dem.dem,
)
logging.info(
"In processor.RoughnessLengthGenerator - clean folder for "
Expand Down

0 comments on commit e25257e

Please sign in to comment.