You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of BreachDepressionLeastCost will not always give the same result even thought the same inputs are used. I found that if the DEM contains two pit cells with the same elevation, the order in which they will be process isn't always the same which can lead to different breaching solutions.
The code below reproduce the issue when used with this small DEM (dem.zip):
importosfromosgeoimportgdalimportnumpyasnpimportsubprocesspath_wbt=R"C:\Temp\whitebox_tools.exe"outdir="C:\Temp"path_DEM=R"C:\Temp\dem.sdat"max_iter=20defload_raster(path_raster):
driver=gdal.GetDriverByName("SAGA")
ds=gdal.Open(path_raster)
band=ds.GetRasterBand(1)
arr=band.ReadAsArray()
returnarr# BreachDepressionsLeastCost command linecmd_raw=" ".join([
path_wbt,
"--run=BreachDepressionsLeastCost",
f"--dem={path_DEM}",
"--min_dist",
])
# Run first iteration which will be used as a referenceii=0outBDLC_ori=os.path.join(outdir, f"dem_BDLC_{ii}.sdat")
print(cmd_raw+f" --output={outBDLC_ori}")
subprocess.run(f"{cmd_raw} --output={outBDLC_ori}")
arr_ori=load_raster(outBDLC_ori)
# Rerun breaching until differences with the reference are foundwhileii<max_iter:
ii+=1outBDLC=os.path.join(outdir, f"dem_BDLC_{ii}.sdat")
subprocess.run(f"{cmd_raw} --output={outBDLC}")
arr_ii=load_raster(outBDLC)
nb_diff=np.sum(arr_ori!=arr_ii)
print(f"{ii}/{max_iter} - Pixel differences: {nb_diff}")
ifnb_diff:
print("Differences found!")
breakelse:
os.remove(outBDLC)
os.remove(outBDLC[:-4] +"sgrd")
Description
The current implementation of BreachDepressionLeastCost will not always give the same result even thought the same inputs are used. I found that if the DEM contains two pit cells with the same elevation, the order in which they will be process isn't always the same which can lead to different breaching solutions.
The code below reproduce the issue when used with this small DEM (dem.zip):
Metadata
The text was updated successfully, but these errors were encountered: