diff --git a/docs/api/cli.rst b/docs/api/cli.rst index 4a4886c6e..9bf8fe5c1 100644 --- a/docs/api/cli.rst +++ b/docs/api/cli.rst @@ -20,11 +20,6 @@ Command Line Interface :prog: hydromt update :nested: full -.. _clip_api: - -.. click:: hydromt.cli.main:clip - :prog: hydromt clip - :nested: full .. _export_api: diff --git a/docs/guides/advanced_user/model_clip.rst b/docs/guides/advanced_user/model_clip.rst deleted file mode 100644 index 4aa99dd0a..000000000 --- a/docs/guides/advanced_user/model_clip.rst +++ /dev/null @@ -1,66 +0,0 @@ -.. _model_clip: - -Clipping a model -================ - -The ``clip`` method allows to clip a subregion from an existing model, including all -static maps, static geometries and forcing data. - -**Steps in brief:** - -1) You have an **existing model** schematization ready -2) Define your **model subregion**, see the overview of :ref:`region options `. -3) **Clip** your model using the CLI or Python interface - -.. NOTE:: - - This method is not yet implemented for all plugins. Please check the documentation of the respective - :ref:`plugin` for more information on whether the clip method is available. - -.. _cli_clip: - -From CLI --------- - -**Example usage** - -The ``hydromt clip`` command line interface (CLI) method can be run from the command line after the right conda environment is activated. - -The following example clips a ``subbasin`` region (based on its outflow location) from an existing Wflow model -at `/path/to/model_root` and saves the output to `/path/to/model_destination`. The subbasin is defined based -on an outflow location snapped to a stream order 4 river which is based on a map called wflow_streamorder -of the Wflow model. - -.. code-block:: console - - hydromt clip wflow /path/to/model_root /path/to/model_destination "{'subbasin': [-7.24, 62.09], 'wflow_streamorder': 4}" - - -**Overview of options** - -To check all options see :ref: the CLI API , or do: - -.. code-block:: console - - hydromt clip --help - -.. _python_clip: - -From Python ------------ - -.. NOTE:: - - A general clip method for the model class is currently not yet available and its signature might change in the future. - -**Example usage** - -.. code-block:: python - - from hydromt_wflow import WflowModel - mod = WflowModel(r'/path/to/model_root', mode='r') # initialize model with default logger in read mode - mod.read() - mod.clip_grid(region={'subbasin': [-7.24, 62.09], 'wflow_streamorder': 4}) - mod.clip_forcing() - mod.root.set(r'path/to/model_destination') # change root to output directory - mod.write() diff --git a/docs/guides/core_dev/contributing.rst b/docs/guides/core_dev/contributing.rst index 8e15f5f66..f033a4812 100644 --- a/docs/guides/core_dev/contributing.rst +++ b/docs/guides/core_dev/contributing.rst @@ -242,8 +242,8 @@ should be created with model-specific data readers, writers and setup methods as by arguments which end with ``_fn`` (short for filename) which refer to a source in the data catalog based on the source name or a file based on the (relative) path to the file. Within a model method the data is read by calling any ``DataCatalog.get_`` method which work for both source and file names. -- The Model class currently contains three high-level methods (:py:meth:`~hydromt.Model.build`, - :py:meth:`~hydromt.Model.update` and :py:meth:`~hydromt.Model.clip` which are common for all model plugins and +- The Model class currently contains two high-level methods (:py:meth:`~hydromt.Model.build`, + :py:meth:`~hydromt.Model.update` is are common for all model plugins and exposed through the CLI. This list of methods might be extended going forward. - A Model child class implementation for a specific model kernel can be exposed to HydroMT as a plugin by specifying a ``hydromt.models`` `entry-point `_ in the pyproject.toml file of a package. diff --git a/docs/guides/user_guide/hydromt_intro.rst b/docs/guides/user_guide/hydromt_intro.rst index 848aeaa93..b1c4e6d01 100644 --- a/docs/guides/user_guide/hydromt_intro.rst +++ b/docs/guides/user_guide/hydromt_intro.rst @@ -73,8 +73,7 @@ Finally user can interact with HydroMT through the following interfaces: - **Command Line Interface (CLI)** The :ref:`CLI ` is a high-level interface to HydroMT. It is used to run HydroMT commands such as - :ref:`build `, :ref:`update ` or :ref:`clip `. - + :ref:`build `, :ref:`update ` - **Python Interface** While most common functionalities can be called through the CLI, the :ref:`Python interface ` offers more flexibility for advanced users. diff --git a/docs/guides/user_guide/model_overview.rst b/docs/guides/user_guide/model_overview.rst index 1333372ff..35e129f6d 100644 --- a/docs/guides/user_guide/model_overview.rst +++ b/docs/guides/user_guide/model_overview.rst @@ -10,10 +10,6 @@ HydroMT has the following high-level functionality for setting up models from ra * :ref:`building a model `: building a model from scratch. * :ref:`updating a model `: adding or changing model components of an existing model. -* :ref:`clipping a model `: changing the spatial domain of an existing model (e.g. select subbasins from a larger model). - -The building and clipping methods required the user to provide a :ref:`region ` of interest. HydroMT provides -several options to define a region based on a geospatial or hydrographic region. The exact process of building or updating a model can be configured in a single configuration :ref:`.yaml file `. This file describes the full pipeline of model methods and their arguments. The methods vary for the diff --git a/docs/guides/user_guide/terminology.rst b/docs/guides/user_guide/terminology.rst index 662b51b5b..4bb5e429d 100644 --- a/docs/guides/user_guide/terminology.rst +++ b/docs/guides/user_guide/terminology.rst @@ -8,7 +8,7 @@ HydroMT and this documentation use a specific terminology to describe specific o ============================== ====================================================================================== Term Explanation ============================== ====================================================================================== -Command Line Interface (CLI) high-level interface to HydroMT *build*, *update*, *clip*, *check* and *export* methods. +Command Line Interface (CLI) high-level interface to HydroMT *build*, *update*, *check* and *export* methods. Configuration (HydroMT) (.yaml) file describing the complete pipeline with all methods and their arguments to *build* or *update* a model. Data catalog A set of data sources available for HydroMT. It is build up from *yaml* files containing @@ -33,6 +33,6 @@ Model plugin (Plugin) Package that links the HydroMT Model cl Plugins are installed separately from HydroMT and are not part of the HydroMT core package. Plugins are the most common way of using HydroMT to build and update specific models. Model kernel The model software to execute a model simulation. This is *not* part of any HydroMT plugin. -Region Argument of the *build* and *clip* CLI methods that specifies the region of interest where +Region Argument of the *build*CLI methods that specifies the region of interest where the model should be prepared / which spatial subregion should be clipped. ============================== ====================================================================================== diff --git a/docs/overview/use_case_examples.rst b/docs/overview/use_case_examples.rst index 0a773d63d..6aaad8a2d 100644 --- a/docs/overview/use_case_examples.rst +++ b/docs/overview/use_case_examples.rst @@ -49,8 +49,7 @@ HydroMT was used to prepare the updated national hydrologic models for Indonesia Cooperation Program between the Netherlands and Indonesia. As this is a large scale domain, seven models corresponding to the different Indonesian regions (BaliNusaTenggara, Java, Kalimantan, Maluku, Papua, Sumatra, Sulawesi) were derived at three different resolutions and integrated to the IWRM Indonesia Instrument in Delft-FEWS (using a new export to FEWS -function from HydroMT). The clipping functionality of HydroMT can also be used to prepare sub-models for use in specific -projects and to connect to existing RIBASIM models (using RIBASIM components within HydroMT). +function from HydroMT). .. image:: ../_static/wflow_indonesia.png diff --git a/examples/working_with_models_basics.ipynb b/examples/working_with_models_basics.ipynb index 3ee921c2c..92fcb90b2 100644 --- a/examples/working_with_models_basics.ipynb +++ b/examples/working_with_models_basics.ipynb @@ -17,7 +17,6 @@ "\n", "- **building** a model: building a model from scratch.\n", "- **updating** a model: adding or changing model components of an existing model.\n", - "- **clipping** a model: changing the spatial domain of an existing model (e.g. select subbasins from a larger model).\n", "\n", "Here we show how to build and update a hypothetical distributed model from the command line interface (CLI) based on the generic HydroMT **Model**." ] @@ -32,79 +31,27 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Usage: hydromt [OPTIONS] COMMAND [ARGS]...\n", - "\n", - " Command line interface for hydromt models.\n", - "\n", - "Options:\n", - " --version Show the version and exit.\n", - " --models Print available model plugins and exit.\n", - " --components Print available component plugins and exit.\n", - " --plugins Print available component plugins and exit.\n", - " --help Show this message and exit.\n", - "\n", - "Commands:\n", - " build Build models\n", - " check Validate config / data catalog / region\n", - " clip Clip models.\n", - " export Export data\n", - " update Update models\n", - "\u001b[0m" - ] - } - ], + "outputs": [], "source": [ "!hydromt --help" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Model plugins:\n", - "\t- model (hydromt 1.0.0a0)\n", - "\u001b[0m" - ] - } - ], + "outputs": [], "source": [ "!hydromt --models" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Component plugins:\n", - "\t- ConfigComponent (hydromt 1.0.0a0)\n", - "\t- DatasetsComponent (hydromt 1.0.0a0)\n", - "\t- GeomsComponent (hydromt 1.0.0a0)\n", - "\t- GridComponent (hydromt 1.0.0a0)\n", - "\t- MeshComponent (hydromt 1.0.0a0)\n", - "\t- SpatialDatasetsComponent (hydromt 1.0.0a0)\n", - "\t- TablesComponent (hydromt 1.0.0a0)\n", - "\t- VectorComponent (hydromt 1.0.0a0)\n", - "\u001b[0m" - ] - } - ], + "outputs": [], "source": [ "!hydromt --components" ] @@ -142,7 +89,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.9.19" }, "vscode": { "interpreter": { diff --git a/hydromt/cli/main.py b/hydromt/cli/main.py index 55c2484f5..bc114bb4d 100644 --- a/hydromt/cli/main.py +++ b/hydromt/cli/main.py @@ -598,72 +598,5 @@ def export( log._wait_and_remove_file_handlers(logger) # Release locks on logs -## CLIP - - -@main.command(short_help="Clip models.") -@click.argument( - "MODEL", - type=str, -) -@arg_root -@click.argument( - "MODEL_DESTINATION", - type=click.Path(resolve_path=True, dir_okay=True, file_okay=False), -) -@click.argument( - "REGION", - type=str, - callback=_utils.parse_json, -) -@quiet_opt -@verbose_opt -@click.pass_context -def clip(ctx, model, model_root, model_destination, region, quiet, verbose): - """Create a new model based on clipped region of an existing model. - - If the existing model contains forcing, they will also be clipped to the new model. - - Example usage: - -------------- - - Example usage to clip a wflow model for a subbasin derived from point coordinates - snapped to cells with upstream area >= 50 km2 - hydromt clip wflow /path/to/model_root /path/to/model_destination "{'subbasin': [-7.24, 62.09], 'wflow_uparea': 50}" - - Example usage basin based on ID from model_root basins map - hydromt clip wflow /path/to/model_root /path/to/model_destination "{'basin': 1}" - - Example usage basins whose outlets are inside a geometry - hydromt clip wflow /path/to/model_root /path/to/model_destination "{'outlet': 'geometry.geojson'}" - - All available option in the clip_grid function help. - - """ # noqa: E501 - log_level = max(10, 30 - 10 * (verbose - quiet)) - log._setuplog(join(model_destination, "hydromt-clip.log"), log_level=log_level) - logger.info(f"Clipping instance of {model} model.") - logger.info(f"Region: {region}") - - if model != "wflow": - raise NotImplementedError("Clip function only implemented for wflow model.") - try: - mod = PLUGINS.model_plugins[model](root=model_root, mode="r") - logger.info("Reading model to clip") - mod.read() - mod.root.set(model_destination, mode="w") - logger.info("Clipping grid") - mod.clip_grid(region) - logger.info("Clipping forcing") - mod.clip_forcing() - logger.info("Writting clipped model") - mod.write() - except Exception as e: - logger.exception(e) # catch and log errors - raise - finally: - log._wait_and_remove_file_handlers(logger) # Release locks on logs - - if __name__ == "__main__": main() diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 88b186e79..0511d5efb 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -55,14 +55,6 @@ def test_cli_update_help(): assert r.output.startswith("Usage: main update [OPTIONS] MODEL MODEL_ROOT") -def test_cli_clip_help(): - r = CliRunner().invoke(hydromt_cli, ["clip", "--help"]) - assert r.exit_code == 0 - assert r.output.startswith( - "Usage: main clip [OPTIONS] MODEL MODEL_ROOT MODEL_DESTINATION" - ) - - @pytest.fixture() def _reset_log_level() -> Generator[None, None, None]: yield @@ -116,16 +108,6 @@ def test_cli_update_unknown_model(tmpdir): ) -@pytest.mark.usefixtures("_reset_log_level") -def test_cli_clip_unknown_model(tmpdir): - with pytest.raises(NotImplementedError): - _ = CliRunner().invoke( - hydromt_cli, - ["clip", "test_model", str(tmpdir), str(tmpdir), "{'bbox': [1,2,3,4]}"], - catch_exceptions=False, - ) - - @pytest.mark.usefixtures("_reset_log_level") def test_export_cli_deltares_data(tmpdir): r = CliRunner().invoke(