Skip to content

Commit

Permalink
add function
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha committed Aug 4, 2024
1 parent b5c4e13 commit 4500869
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/python_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ PYBIND11_MODULE( _viewshed, m )
"saveVisibilityRaster",
[]( const std::shared_ptr<Viewshed> v, const py::object path )
{ v->saveVisibilityRaster( get_absolute_path( path, "path" ) ); },
"Save visibility raster" );
"Save visibility raster" )
.def( "calculationTime", &Viewshed::parseLastedSeconds, "Seconds that processing of last operation lasted." );

// inverseviewshed
py::class_<InverseViewshed, std::shared_ptr<InverseViewshed>>( m, "InverseViewshed",
Expand Down Expand Up @@ -142,5 +143,8 @@ PYBIND11_MODULE( _viewshed, m )
"saveVisibilityRaster",
[]( const std::shared_ptr<InverseViewshed> v, const py::object path )
{ v->saveVisibilityRaster( get_absolute_path( path, "path" ) ); },
"Save visibility raster" );
"Save visibility raster" )
.def( "calculationTime", &InverseViewshed::parseLastedSeconds,
"Seconds that processing of last operation lasted." );
;
}
31 changes: 30 additions & 1 deletion tests/test_viewshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,33 @@ def test_viewshed_visibility_raster(
v.calculateVisibilityMask()
v.saveVisibilityRaster(visibility_raster)

assert visibility_raster.exists()
assert visibility_raster.exists()

def test_viewshed_calculation_time(
work_folder: Path,
dem: viewshed.ProjectedSquareCellRaster,
viewpoint: viewshed.Point,
mask: viewshed.ProjectedSquareCellRaster,
fn_print_percent_done,
fn_print_timing,
file_messages_percent,
file_messages_timing,
) -> None:
algs = viewshed.VisibilityAlgorithms(False)

v = viewshed.Viewshed(viewpoint, dem, algs)
assert isinstance(v, viewshed.Viewshed)

visibility_raster = work_folder / "visibility_raster.tif"

v.calculateVisibilityMask()
time_visibility_mask = v.calculationTime()

assert time_visibility_mask < 0.00001

v.calculate()
time_visibility = v.calculationTime()

assert time_visibility < 0.02

assert time_visibility > time_visibility_mask

0 comments on commit 4500869

Please sign in to comment.