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

various filling tools: output datatype depends on flat_increment/small_num #185

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
breach_depressions output datatype
  • Loading branch information
jfbourdon committed Aug 24, 2021
commit 081088b14b1b07304d687c544fa649925bbb2404
16 changes: 10 additions & 6 deletions whitebox-tools-app/src/tools/hydro_analysis/breach_depressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ use std::path;
/// dependent upon the elevation range in the input DEM and is generally a very small elevation value (e.g.
/// 0.001). It may be necessary to override the default elevation increment value in landscapes where there
/// are extensive flat areas resulting from depression filling (and along breach channels). Values in the range
/// 0.00001 to 0.01 are generally appropriate. increment values that are too large can result in obvious artifacts
/// 0.00001 to 0.01 are generally appropriate. Increment values that are too large can result in obvious artifacts
/// along flattened sites, which may extend beyond the flats, and values that are too small (i.e. smaller than the
/// numerical precision) may result in the presence of grid cells with no downslope neighbour in the
/// output DEM. The output DEM will always use 64-bit floating point values for storing elevations because of
/// the need to precisely represent small elevation differences along flats. Therefore, if the input DEM is stored
/// at a lower level of precision (e.g. 32-bit floating point elevations), this may result in a doubling of
/// the size of the DEM.
/// output DEM. If a flat increment value isn't specified, the output DEM will use 64-bit floating point values in order
/// to make sure that the very small elevation increment value determined will be accurately stored. Consequently,
/// it may double the storage requirements as DEMs are often stored with 32-bit precision. However, if a flat increment
/// value is specified, the output DEM will keep the same data type as the input assuming the user chose its value wisely.
///
/// In comparison with the `BreachDepressionsLeastCost` tool, this breaching method often provides a less
/// satisfactory, higher impact, breaching solution and is often less efficient. **It has been provided to users for
Expand Down Expand Up @@ -360,7 +360,11 @@ impl WhiteboxTool for BreachDepressions {
}

let mut output = Raster::initialize_using_file(&output_file, &input);
output.configs.data_type = DataType::F64;
if !flat_increment.is_nan() || flat_increment == 0f64 {
output.configs.data_type = input.configs.data_type; // Assume the user knows what he's doing
} else {
output.configs.data_type = DataType::F64; // Don't take any chances and promote to 64-bit
}
let background_val = (i32::min_value() + 1) as f64;
output.reinitialize_values(background_val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl WhiteboxTool for BreachDepressionsLeastCost {
let mut output = Raster::initialize_using_file(&output_file, &input);

let small_num = if !flat_increment.is_nan() || flat_increment == 0f64 {
output.configs.data_type = input.configs.data_type; // Assume the user know what he's doing
output.configs.data_type = input.configs.data_type; // Assume the user knows what he's doing
flat_increment
} else {
let elev_digits = (input.configs.maximum as i32).to_string().len();
Expand Down