Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unneeded dask values calls to allow lazy execution #207

Merged
merged 32 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3a3d2c8
Removed unneeded dask values calls to allow lazy execution
rosepearson Oct 9, 2023
bcbaaed
fixup: Format Python code with Black
invalid-email-address Oct 9, 2023
4adc05c
another move away from low level calls to higher level dask calls. Al…
rosepearson Oct 10, 2023
dffccf7
merged in changes - set up for bestter parallelisation with Dask
rosepearson Oct 10, 2023
54cfe24
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
d3c4d9d
Changes to remove Dask bottlenecks in add_coarse DEMs
rosepearson Oct 10, 2023
b95cb84
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
bda5b78
Fixed typos
rosepearson Oct 10, 2023
7202d14
update client with for the roughness stage
rosepearson Oct 10, 2023
27f21ed
Fixed typos
rosepearson Oct 10, 2023
59ed745
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
5be595d
Fixed typos
rosepearson Oct 10, 2023
9292a88
Merge branch '206-dask-values-bottlenecks' of github.com:rosepearson/…
rosepearson Oct 10, 2023
ed2772b
Fixed typos
rosepearson Oct 10, 2023
18d9a3a
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
8415dd4
Fixed typos
rosepearson Oct 10, 2023
fb4145b
Merge branch '206-dask-values-bottlenecks' of github.com:rosepearson/…
rosepearson Oct 10, 2023
0467fe0
remove dem compute and prepare for dask with pandas
rosepearson Oct 10, 2023
d833727
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
3cb184c
Add back in compute for roughness for now. Remove later.
rosepearson Oct 10, 2023
596dd00
Re-removed the compute in roughness and corrected the buffer amount
rosepearson Oct 10, 2023
3af3782
removed accidentially added lical changes to the examples
rosepearson Oct 10, 2023
4f938ca
Moved for more dask compatability
rosepearson Oct 10, 2023
98d7d9e
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
7c9b3fe
Updated roughness use of Dask further
rosepearson Oct 10, 2023
d776f73
fixup: Format Python code with Black
invalid-email-address Oct 10, 2023
512f635
Updated tests and fixed any issues found during the test updates
rosepearson Oct 11, 2023
642b142
fixup: Format Python code with Black
invalid-email-address Oct 11, 2023
7fb2e2d
Updated package version
rosepearson Oct 11, 2023
72688fd
Updated dem
rosepearson Oct 11, 2023
9c2ea99
Merge branch '206-dask-values-bottlenecks' of github.com:rosepearson/…
rosepearson Oct 11, 2023
4426585
jfix error
rosepearson Oct 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "geofabrics"
version = "1.0.0"
version = "1.0.1"
description = "A package for creating geofabrics for flood modelling."
readme = "README.md"
authors = [{ name = "Rose pearson", email = "[email protected]" }]
Expand Down
249 changes: 130 additions & 119 deletions src/geofabrics/dem.py

Large diffs are not rendered by default.

182 changes: 92 additions & 90 deletions src/geofabrics/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import abc
import logging
import distributed
import dask.dataframe
import rioxarray
import copy
import geopandas
Expand Down Expand Up @@ -870,16 +871,6 @@ def run(self):
elevation_range=self.get_instruction_general("elevation_range"),
)

# Load in LiDAR tiles
self.raw_dem.add_lidar(
lidar_datasets_info=lidar_datasets_info,
lidar_classifications_to_keep=self.get_instruction_general(
"lidar_classifications_to_keep"
),
chunk_size=self.get_processing_instructions("chunk_size"),
metadata=self.create_metadata(),
) # Note must be called after all others if it is to be complete

# Setup Dask cluster and client - LAZY SAVE LIDAR DEM
cluster_kwargs = {
"n_workers": self.get_processing_instructions("number_of_cores"),
Expand All @@ -892,8 +883,32 @@ def run(self):
print("Dask client:", client)
print("Dask dashboard:", client.dashboard_link)

# Load in LiDAR tiles
self.raw_dem.add_lidar(
lidar_datasets_info=lidar_datasets_info,
lidar_classifications_to_keep=self.get_instruction_general(
"lidar_classifications_to_keep"
),
chunk_size=self.get_processing_instructions("chunk_size"),
metadata=self.create_metadata(),
) # Note must be called after all others if it is to be complete

# Add a coarse DEM if significant area without LiDAR and a coarse DEM
if self.check_vector_or_raster(key="coarse_dems", api_type="raster"):
coarse_dem_paths = self.get_vector_or_raster_paths(
key="coarse_dems", data_type="raster"
)

# Add coarse DEMs if there are any and if area
self.raw_dem.add_coarse_dems(
coarse_dem_paths=coarse_dem_paths,
area_threshold=area_threshold,
buffer_cells=self.get_instruction_general("lidar_buffer"),
chunk_size=self.get_processing_instructions("chunk_size"),
)

# compute and save raw DEM
logging.info("In processor.DemGenerator - write out the raw DEM from LiDAR")
logging.info("In processor.DemGenerator - write out the raw DEM to netCDF")
try:
self.raw_dem.dem.to_netcdf(
self.get_instruction_path("raw_dem"),
Expand All @@ -910,46 +925,6 @@ def run(self):
)
raise caught_exception

# Add a coarse DEM if significant area without LiDAR and a coarse DEM
if self.check_vector_or_raster(key="coarse_dems", api_type="raster"):
coarse_dem_paths = self.get_vector_or_raster_paths(
key="coarse_dems", data_type="raster"
)

# Add coarse DEMs if there are any and if area
self.raw_dem.add_coarse_dems(
coarse_dem_paths=coarse_dem_paths,
area_threshold=area_threshold,
buffer_cells=self.get_instruction_general("lidar_buffer"),
chunk_size=self.get_processing_instructions("chunk_size"),
)

# Run dask a second time over the coarse DEM if added
cluster = distributed.LocalCluster(**cluster_kwargs)
with cluster, distributed.Client(cluster) as client:
print("Dask client:", client)
print("Dask dashboard:", client.dashboard_link)

# compute and save raw DEM
logging.info(
"In processor.DemGenerator - write out the raw DEM from Coarse"
)
try:
self.raw_dem.dem.to_netcdf(
self.get_instruction_path("raw_dem"),
format="NETCDF4",
engine="netcdf4",
)
except (Exception, KeyboardInterrupt) as caught_exception:
pathlib.Path(self.get_instruction_path("raw_dem")).unlink()
logging.info(
f"Caught error {caught_exception} and deleting"
"partially created netCDF output "
f"{self.get_instruction_path('raw_dem')}"
" before re-raising error."
)
raise caught_exception

if self.debug:
# Record the parameter used during execution - append to existing
with open(
Expand Down Expand Up @@ -1106,27 +1081,50 @@ def run(self):
# create the catchment geometry object
self.catchment_geometry = self.create_catchment()

# setup the hydrologically conditioned DEM generator
self.hydrologic_dem = dem.HydrologicallyConditionedDem(
catchment_geometry=self.catchment_geometry,
raw_dem_path=self.get_instruction_path("raw_dem"),
interpolation_method=self.get_instruction_general(
key="interpolation", subkey="no_data"
),
)
# Setup Dask cluster and client - LAZY SAVE LIDAR DEM
cluster_kwargs = {
"n_workers": self.get_processing_instructions("number_of_cores"),
"threads_per_worker": 1,
"processes": True,
"memory_limit": self.get_processing_instructions("memory_limit"),
}
cluster = distributed.LocalCluster(**cluster_kwargs)
with cluster, distributed.Client(cluster) as client:
print("Dask client:", client)
print("Dask dashboard:", client.dashboard_link)

# Check for and add any bathymetry information
self.add_bathymetry(
area_threshold=area_threshold,
catchment_dirs=self.get_instruction_path("extents"),
)
# setup the hydrologically conditioned DEM generator
self.hydrologic_dem = dem.HydrologicallyConditionedDem(
catchment_geometry=self.catchment_geometry,
raw_dem_path=self.get_instruction_path("raw_dem"),
interpolation_method=self.get_instruction_general(
key="interpolation", subkey="no_data"
),
)

# fill combined dem - save results
self.hydrologic_dem.dem.to_netcdf(
self.get_instruction_path("result_dem"),
format="NETCDF4",
engine="netcdf4",
)
# Check for and add any bathymetry information
self.add_bathymetry(
area_threshold=area_threshold,
catchment_dirs=self.get_instruction_path("extents"),
)

# fill combined dem - save results
logging.info("In processor.DemGenerator - write out the raw DEM to netCDF")
try:
self.hydrologic_dem.dem.to_netcdf(
self.get_instruction_path("result_dem"),
format="NETCDF4",
engine="netcdf4",
)
except (Exception, KeyboardInterrupt) as caught_exception:
pathlib.Path(self.get_instruction_path("raw_dem")).unlink()
logging.info(
f"Caught error {caught_exception} and deleting"
"partially created netCDF output "
f"{self.get_instruction_path('raw_dem')}"
" before re-raising error."
)
raise caught_exception
if self.debug:
# Record the parameter used during execution - append to existing
with open(
Expand Down Expand Up @@ -1172,26 +1170,6 @@ def run(self):
# Get LiDAR data file-list - this may involve downloading lidar files
lidar_datasets_info = self.get_lidar_datasets_info()

# setup the roughness DEM generator
self.roughness_dem = dem.RoughnessDem(
catchment_geometry=self.catchment_geometry,
hydrological_dem_path=self.get_instruction_path("result_dem"),
elevation_range=self.get_instruction_general("elevation_range"),
interpolation_method=self.get_instruction_general(
key="interpolation", subkey="no_data"
),
)

# Load in LiDAR tiles
self.roughness_dem.add_lidar(
lidar_datasets_info=lidar_datasets_info,
lidar_classifications_to_keep=self.get_instruction_general(
"lidar_classifications_to_keep"
),
chunk_size=self.get_processing_instructions("chunk_size"),
metadata=self.create_metadata(),
) # Note must be called after all others if it is to be complete

# Setup Dask cluster and client
cluster_kwargs = {
"n_workers": self.get_processing_instructions("number_of_cores"),
Expand All @@ -1203,6 +1181,27 @@ def run(self):
with cluster, distributed.Client(cluster) as client:
print("Dask client:", client)
print("Dask dashboard:", client.dashboard_link)

# setup the roughness DEM generator
self.roughness_dem = dem.RoughnessDem(
catchment_geometry=self.catchment_geometry,
hydrological_dem_path=self.get_instruction_path("result_dem"),
elevation_range=self.get_instruction_general("elevation_range"),
interpolation_method=self.get_instruction_general(
key="interpolation", subkey="no_data"
),
)

# Load in LiDAR tiles
self.roughness_dem.add_lidar(
lidar_datasets_info=lidar_datasets_info,
lidar_classifications_to_keep=self.get_instruction_general(
"lidar_classifications_to_keep"
),
chunk_size=self.get_processing_instructions("chunk_size"),
metadata=self.create_metadata(),
) # Note must be called after all others if it is to be complete

# save results
try:
self.roughness_dem.dem.to_netcdf(
Expand Down Expand Up @@ -2685,6 +2684,9 @@ def sample_location_down_slope(row):

return sampled_multipoints

"""open_waterways = dask.dataframe.from_pandas( # To incorporate later
open_waterways,
npartitions=self.get_processing_instructions("number_of_cores"))"""
open_waterways["points"] = open_waterways.apply(
lambda row: sample_location_down_slope(row=row),
axis=1,
Expand Down
2 changes: 1 addition & 1 deletion src/geofabrics/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Contains the package version information
"""

__version__ = "1.0.0"
__version__ = "1.0.1"
4 changes: 2 additions & 2 deletions tests/test_dem_generation_local_1/data/benchmark_dem.nc
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_dem_generation_local_3/data/benchmark_dem.nc
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_many_stages_local/data/benchmark_geofabric.nc
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_many_stages_multiple_1/data/benchmark.nc
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/test_many_stages_multiple_2/data/benchmark.nc
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/test_many_stages_wellington/data/benchmark.nc
Git LFS file not shown
3 changes: 0 additions & 3 deletions tests/test_many_stages_wellington/data/benchmark_geofabric.nc

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_many_stages_wellington/instruction.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"extents": "catchment.geojson",
"result_dem": "test_dem.nc",
"result_geofabric": "test_geofabric.nc",
"benchmark_geofabric": "benchmark_geofabric.nc"
"benchmark": "benchmark.nc"
},
"datasets": {
"lidar": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def test_result_geofabric_windows(self):

# Load in benchmark
file_path = (
self.cache_dir
/ self.instructions["roughness"]["data_paths"]["benchmark_geofabric"]
self.cache_dir / self.instructions["roughness"]["data_paths"]["benchmark"]
)
with rioxarray.rioxarray.open_rasterio(file_path, masked=True) as benchmark:
benchmark.load()
Expand Down Expand Up @@ -165,8 +164,7 @@ def test_result_geofabric_linux(self):

# load in benchmark
file_path = (
self.cache_dir
/ self.instructions["roughness"]["data_paths"]["benchmark_geofabric"]
self.cache_dir / self.instructions["roughness"]["data_paths"]["benchmark"]
)
with rioxarray.rioxarray.open_rasterio(file_path, masked=True) as benchmark:
benchmark.load()
Expand Down