Subcatchment masking - #885
Conversation
SouthEndMusic
left a comment
There was a problem hiding this comment.
Some general comments. I don't understand everything well enough to approve the PR
| represents your entire catchment, and all cells that have a value are interpreted as active | ||
| cells. You can update this to another layer which contains a subset of the original data. | ||
|
|
||
| Alternatively, you can also point this to a layer with subcatchment information (e.g. based |
There was a problem hiding this comment.
| Alternatively, you can also point this to a layer with subcatchment information (e.g. based | |
| Alternatively, you can point this to a layer with subcatchment information (e.g. based |
| When using this functionality, please take the following points into account: | ||
|
|
||
| - Ensure that all upstream regions are included (unless you make use of external inflows) | ||
| - When using water demand and allocation: ensure that there are no allocations area's with |
There was a problem hiding this comment.
| - When using water demand and allocation: ensure that there are no allocations area's with | |
| - When using water demand and allocation: ensure that there are no allocation areas with |
|
|
||
| - Ensure that all upstream regions are included (unless you make use of external inflows) | ||
| - When using water demand and allocation: ensure that there are no allocations area's with | ||
| the same IDs outside your active domain (a warning is shown in the logging) |
There was a problem hiding this comment.
| the same IDs outside your active domain (a warning is shown in the logging) | |
| the same ID outside your active domain (a warning is shown in the logging) |
| - When using local_inertial for routing: a ghost node will be added at the end of each river | ||
| section (with a set distance and water level). This might cause some difference in the | ||
| results, as it no longer contains the "real" downstream boundary condition. If this is | ||
| important, ensure that the gauges for evaluation have sufficient downstream pixels in your |
There was a problem hiding this comment.
Does pixel here refer to a cell? I feel that's a better word to refer to the concept
There was a problem hiding this comment.
Thanks, yes cell is indeed a better word!
| config, | ||
| "land_water_allocation_area__count", | ||
| LandHydrologySBM; | ||
| metadata = ParameterMetadata(; type = Int, allow_missing = true), |
There was a problem hiding this comment.
Why not add this to a standard name map?
There was a problem hiding this comment.
It is already part of the standard names, but I needed to overwrite the metadata in order to get the full array (so not only for the active cells, as is done in the lines above this change).
vers-w
left a comment
There was a problem hiding this comment.
LGTM and good to have this functionality!
See my comments below.
| represents your entire catchment, and all cells that have a value are interpreted as active | ||
| cells. You can update this to another layer which contains a subset of the original data. | ||
|
|
||
| Alternatively, you can point this to a layer with subcatchment information (e.g. based on |
There was a problem hiding this comment.
| Alternatively, you can point this to a layer with subcatchment information (e.g. based on | |
| Alternatively, you can point `subbasin_location__count` to a layer with subcatchment information (e.g. based on |
| ```toml | ||
| [input] | ||
| subbasin_location__count = "subcatchment_gauges_obs" | ||
| subbasin_active_area__count = [1016, 1013, 1011, 206, 203, 503] |
There was a problem hiding this comment.
This is more in line with the already used subbasin_location__count entry:
| subbasin_active_area__count = [1016, 1013, 1011, 206, 203, 503] | |
| subbasin_active_location__count = [1016, 1013, 1011, 206, 203, 503] |
| - When writing output at specific cells (`index`) and/or x-y positions (`coordinate`): this | ||
| can cause unreliable results and/or give errors. If you need output at specific locations, |
There was a problem hiding this comment.
I guess this means a check is not performed for index and coordinate (removing entries that are not part of active indices)? If that's the case maybe add this at the start. I think the "this can cause unreliable results" is a bit unclear.
There was a problem hiding this comment.
This was indeed not checked. I adjusted the code to show a warning rather than an error, which means that this message is no longer relevant, and users are a bit more flexible with using the same toml file
| - Fixed a bug where the maximum subsurface flow was not adjusted for subdaily timesteps | ||
| (only when using `layered` or `layered_exponential` profiles) |
There was a problem hiding this comment.
Nice catch!
Note that this also needs fixing in the release v1 branch and these lines need then to be moved below v1.0.3 in the changelog.
| # find the node id of the downstream cell | ||
| to_node = searchsortedfirst(indices, to_index) | ||
| if to_node > length(indices) || indices[to_node] != to_index | ||
| @warn "Invalid drainage direction value at node `$from_node` (LDD=`$ldd_val`), assuming pit" |
There was a problem hiding this comment.
| @warn "Invalid drainage direction value at node `$from_node` (LDD=`$ldd_val`), assuming pit" | |
| @warn "Invalid drainage direction value at node `$from_node` (LDD=`$ldd_val`), assign pit value at node" |
| config; | ||
| indices = indices, |
There was a problem hiding this comment.
| config; | |
| indices = indices, | |
| config, | |
| indices, |
| # update 2d map to only include active cells, and convert to missing for inactive cells | ||
| map_2d = mask_to_indices(map_2d, indices; fill_value = missing) |
There was a problem hiding this comment.
Suggest to remove this part and add indices as argument to ncread function.
| end | ||
|
|
||
| "Mask a 2D array, keeping only values at the given `indices` and setting the rest to `fill_value`." | ||
| function mask_to_indices( |
There was a problem hiding this comment.
As suggested for the io.jl part to remove this function (and use indices directly in ncread), I think this is now only used for the river location. It is not clear to me why a Union type is required? I would suggest to either not make fill_value optional and use the correct type in the function call (based on array_2d), so you only need eltype(array_2d) or to make use of the metadata of the parameter that has the required type and fill information.
There was a problem hiding this comment.
the function is removed and incorporated with ncread
| sel=network.indices, | ||
| ) | ||
| replace!(x -> ismissing(x) ? 0 : x, reservoirs) | ||
| # check if any reservoirs are found in the active model domain, if not disable reservoir model component |
There was a problem hiding this comment.
Nice to have this check! For consistency would be good if reservoir network info is also adapted if reservoirs are not found in the active model domain.
And probably good to have a similar check for drains?
There was a problem hiding this comment.
I have added a similar check for drains!
| ``` | ||
|
|
||
| ::: {.callout-important} | ||
| When using this functionality, please take the following points into account: |
There was a problem hiding this comment.
Just wondering: any considerations needed when running with multiple threads/this works fine with this functionality?
There was a problem hiding this comment.
Not in particular; since the new outlets are assumed pits, the multithreading recognizes them as individual basins
| results, as it no longer contains the "real" downstream boundary condition. If this is | ||
| important, ensure that the gauges for evaluation have sufficient downstream cells in your | ||
| selected model domain. |
There was a problem hiding this comment.
Is it not better (easier) to recommend to add boundary conditions at these points?
There was a problem hiding this comment.
yes true, added that as well!
| can cause unreliable results and/or give errors. If you need output at specific locations, | ||
| use the `map` functionality instead, as this will still write output at the targeted | ||
| locations when running only a subsection of your model. | ||
| ::: |
There was a problem hiding this comment.
Probably good to add what a user needs to take into account for the Darcy based groundwater flow concept?
also made the output writing when using coordinates or index values a bit more relaxed, to throw a warning rather than an error when invalid cells are selected
vers-w
left a comment
There was a problem hiding this comment.
LGTM, except for the failing tests ;-)!
Issue addressed
(only when using
layeredorlayered_exponentialprofiles)Explanation
Explain how you addressed the bug/feature request, what choices you made and why.
Checklist
masterAdditional Notes (optional)
Note that for the testing, I decided to use the landuse map, as no subcatchment map was present in the example models.