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

Checking (sub)basin dimensions when delineating (sub)basin geometry/mask #236

Closed
shartgring opened this issue Feb 2, 2024 · 1 comment · Fixed by #263
Closed

Checking (sub)basin dimensions when delineating (sub)basin geometry/mask #236

shartgring opened this issue Feb 2, 2024 · 1 comment · Fixed by #263
Assignees
Labels
bug Something isn't working enhancement New feature or request workflows Issue linked to the workflows
Milestone

Comments

@shartgring
Copy link
Collaborator

shartgring commented Feb 2, 2024

Kind of request

Adding new functionality

Enhancement Description

It is possible that a user provides region settings that result in a basin being generated consisting of only 1 cell. For example, when only -r "{'subbasin': [x, y] is provided without strord settings. Later in the workflow, this will likely cause errors resulting in failed model building.

Use case

Consider the following log:

2024-02-02 11:31:02,337 - build - log - DEBUG - Writing log messages to new file C:\Users\hartgrin\OneDrive - Stichting Deltares\Projecten\PROMISCES\wflow_danube_SPARTACUS\hydromt.log.
2024-02-02 11:31:02,338 - build - log - INFO - HydroMT version: 0.9.2
2024-02-02 11:31:02,338 - build - main - INFO - Building instance of wflow model at C:\Users\hartgrin\OneDrive - Stichting Deltares\Projecten\PROMISCES\wflow_danube_SPARTACUS.
2024-02-02 11:31:02,339 - build - main - INFO - User settings:
2024-02-02 11:31:02,699 - build - data_catalog - INFO - Reading data catalog deltares_data v2024.1.30
2024-02-02 11:31:02,699 - build - data_catalog - INFO - Parsing data catalog from https://raw.githubusercontent.com/Deltares/hydromt/main/data/catalogs/deltares_data.yml
2024-02-02 11:31:03,082 - build - model_api - INFO - Initializing wflow model from hydromt_wflow (v0.4.1).
2024-02-02 11:31:03,083 - build - data_catalog - INFO - Parsing data catalog from C:\Users\hartgrin\.conda\envs\promisces\Lib\site-packages\hydromt_wflow\data\parameters_data.yml
2024-02-02 11:31:03,093 - build - model_api - DEBUG - Setting model config options.
2024-02-02 11:31:03,096 - build - model_api - DEBUG - Default config read from C:\Users\hartgrin\.conda\envs\promisces\Lib\site-packages\hydromt_wflow\data\wflow\wflow_sbm.toml
2024-02-02 11:31:03,096 - build - model_api - INFO - setup_basemaps.region: {'subbasin': [18.8813, 47.19553], 'bounds': [3.251953, 43.213183, 24.56543, 50.162824]}
2024-02-02 11:31:03,097 - build - model_api - INFO - setup_basemaps.res: 0.00833
2024-02-02 11:31:03,097 - build - model_api - INFO - setup_basemaps.hydrography_fn: merit_hydro
2024-02-02 11:31:03,097 - build - model_api - INFO - setup_basemaps.basin_index_fn: merit_hydro_index
2024-02-02 11:31:03,097 - build - model_api - INFO - setup_basemaps.upscale_method: ihu
2024-02-02 11:31:03,098 - build - wflow - INFO - Preparing base hydrography basemaps.
2024-02-02 11:31:03,339 - build - rasterdataset - INFO - Reading merit_hydro raster data from p:\wflow_global\hydromt\topography\merit_hydro\*.vrt
2024-02-02 11:31:05,449 - build - basin_mask - DEBUG - Parsed region (kind=subbasin): {'bounds': [3.251953, 43.213183, 24.56543, 50.162824], 'xy': [18.8813, 47.19553]}
2024-02-02 11:31:33,751 - build - basin_mask - WARNING - Loading very large spatial domain to derive a subbasin. Provide initial 'bounds' if this takes too long.
2024-02-02 11:36:00,078 - build - basin_mask - INFO - subbasin bbox: [18.8808, 47.1950, 18.8817, 47.1958]
2024-02-02 11:36:02,733 - build - wflow - DEBUG - Adding basins vector to geoms.
2024-02-02 11:36:02,739 - build - basemaps - DEBUG - Mask in dataset assumed to represent subbasins.
2024-02-02 11:36:02,740 - build - basemaps - DEBUG - (Sub)basin at original resolution has 1 cells.
2024-02-02 11:36:02,842 - build - basemaps - DEBUG - Burn subbasin outlet in upstream area data.
2024-02-02 11:36:04,070 - build - basemaps - INFO - Upscale flow direction data: 10x, ihu method.
2024-02-02 11:36:27,822 - build - main - ERROR - module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
Traceback (most recent call last):
  File "C:\Users\hartgrin\AppData\Roaming\Python\Python311\site-packages\hydromt\cli\main.py", line 221, in build
    mod.build(region, opt=opt)
  File "C:\Users\hartgrin\AppData\Roaming\Python\Python311\site-packages\hydromt\models\model_api.py", line 246, in build
    self._run_log_method(method, **kwargs)
  File "C:\Users\hartgrin\AppData\Roaming\Python\Python311\site-packages\hydromt\models\model_api.py", line 188, in _run_log_method
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hartgrin\.conda\envs\promisces\Lib\site-packages\hydromt_wflow\wflow.py", line 240, in setup_basemaps
    ds_base, _ = workflows.hydrography(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hartgrin\.conda\envs\promisces\Lib\site-packages\hydromt_wflow\workflows\basemaps.py", line 157, in hydrography
    ).astype(np.bool)
             ^^^^^^^
  File "C:\Users\hartgrin\AppData\Roaming\Python\Python311\site-packages\numpy\__init__.py", line 338, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

It may be nice to 'catch' these errors and provide a warning when a model consisting of 1 by 1 cell is generated (or n_x by n_y where n_x,y < 3). For example, in the form of an if-statement that may produce the log:

 - build - basin_mask - WARNING  - Basin dimensions are {n_x} cells by {n_y} cells. Consider using 'strord' argument to correctly delineate subbasin geometry

Additional Context

I was not sure whether this would fit better under hydromt core or wflow, my guess was wflow ;)

@shartgring shartgring added enhancement New feature or request needs refinement issue still needs refinement labels Feb 2, 2024
@shartgring shartgring changed the title Checking subbasin size when deliniating basin geometry/mask Checking subbasin dimensions when delineating basin geometry/mask Feb 2, 2024
@shartgring shartgring changed the title Checking subbasin dimensions when delineating basin geometry/mask Checking (sub)basin dimensions when delineating (sub)basin geometry/mask Feb 2, 2024
@hboisgon
Copy link
Contributor

That's a good suggestion @shartgring ! I think hydromt wflow is a good place for it

@hboisgon hboisgon added setup methods Issue related to existing or new setup methods bug Something isn't working workflows Issue linked to the workflows and removed setup methods Issue related to existing or new setup methods labels Feb 13, 2024
@hboisgon hboisgon added this to the 2024 - Q1 milestone Feb 13, 2024
@dalmijn dalmijn assigned dalmijn and unassigned dalmijn Feb 29, 2024
@hboisgon hboisgon self-assigned this Apr 3, 2024
@hboisgon hboisgon modified the milestones: 2024 - Q1, 0.6 release Apr 8, 2024
@alimeshgi alimeshgi removed the needs refinement issue still needs refinement label Apr 10, 2024
@hboisgon hboisgon mentioned this issue Apr 11, 2024
4 tasks
hboisgon added a commit that referenced this issue May 7, 2024
* remove deprecated calls to np.bool #261

* earlier error message if subbasin is too small #236

* add test

* update changelog

* bugfix test

* address review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request workflows Issue linked to the workflows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants