Skip to content

Add model.to_fews(region_dir) - #2161

Merged
visr merged 6 commits into
mainfrom
to_fews
Mar 21, 2025
Merged

Add model.to_fews(region_dir)#2161
visr merged 6 commits into
mainfrom
to_fews

Conversation

@visr

@visr visr commented Mar 18, 2025

Copy link
Copy Markdown
Member

This adds a function model.to_fews(region_dir) that converts the network and results to files that Delft-FEWS can directly handle. It is marked as experimental for now.

@gijsber is working on a Delft-FEWS configuration that can be used to visualize model results, to complement our existing tools. We'll likely add this configuration to this monorepo since it is generic. #2159 also pertains to this work.

What is especially nice is the spatio-temporal support of Delft-FEWS, so we can make visualizations like this:

image

In theory we can support similar functionality with QGIS, but looking at the plots in #1369 this would likely need work in QGIS itself. So this is really a quick win to be able to inspect models better.

@visr
visr requested a review from evetion March 18, 2025 14:56
Comment thread python/ribasim/ribasim/model.py Outdated
Comment thread python/ribasim/ribasim/utils.py

@evetion evetion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some minor comments. Note that your test requires a model that has been run (as it needs arrow files), so it fails on our default Python tests.

Comment thread python/ribasim/ribasim/model.py Outdated
raise FileNotFoundError("Model must be written to disk.")
return FilePath(toml_path)

def _results_dir(self) -> DirectoryPath:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a public method with @Property? And another property with has_run or has_results?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have model.toml_path and model.results_path, which both error if they don't exist. model.results_dir returns the results_dir config entry, which is "results" by default.

I didn't add has_run or has_results yet as I don't think there's much of a need for it yet, but we could always consider it in another PR?

Comment thread python/ribasim/ribasim/model.py Outdated
Comment thread python/ribasim/ribasim/model.py
Comment thread python/ribasim/ribasim/model.py Outdated
Comment thread python/ribasim/ribasim/model.py Outdated
Comment thread python/ribasim/ribasim/model.py
Comment thread python/ribasim/tests/test_model.py Outdated
Comment thread python/ribasim/ribasim/model.py
visr and others added 2 commits March 19, 2025 10:08
Co-authored-by: Maarten Pronk <git@evetion.nl>
Co-authored-by: Maarten Pronk <git@evetion.nl>
@gijsber

gijsber commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

REGION_HOME is indeed and interval variable which is the root folder of the Fews-application. everything Fews is relative to this root. At what path exactly REGION_HOME resides is up to the user (could be c:\fews or burried deep insde your One Drive folder, but it should not be on a network drive given the high frequent IO

@gijsber

gijsber commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

image

@gijsber

gijsber commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

Hi @visr , I my latest update (posted in my Bulletin) I now also expect a separate shape file for the Areas:
{ModelId}Areas.shp next to the Nodes and Links

@visr

visr commented Mar 19, 2025

Copy link
Copy Markdown
Member Author

Great. Does the config work if there are no areas?

@gijsber

gijsber commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

I guess it gives an error at that moment.
Easiest workaround is ..in case no area polygons are defined, write the Areas.shp with the content of Nodes.shp or even better only the Basin nodes.

@visr

visr commented Mar 21, 2025

Copy link
Copy Markdown
Member Author

@evetion maybe a quick check since I changed quite a lot?

@visr
visr requested a review from evetion March 21, 2025 09:43
@evetion

evetion commented Mar 21, 2025

Copy link
Copy Markdown
Member

@evetion maybe a quick check since I changed quite a lot?

LGTM

@visr
visr merged commit e3a50a5 into main Mar 21, 2025
@visr
visr deleted the to_fews branch March 21, 2025 11:52
visr added a commit that referenced this pull request Mar 21, 2025
This adds a function `model.to_fews(region_dir)` that converts the
network and results to files that Delft-FEWS can directly handle. It is
marked as experimental for now.

@gijsber is working on a Delft-FEWS configuration that can be used to
visualize model results, to complement our existing tools. We'll likely
add this configuration to this monorepo since it is generic. #2159 also
pertains to this work.

What is especially nice is the spatio-temporal support of Delft-FEWS, so
we can make visualizations like this:


![image](https://github.com/user-attachments/assets/2e61bf82-0d7d-4558-a645-755d7e763b74)

In theory we can support similar functionality with QGIS, but looking at
the plots in #1369 this would
likely need work in QGIS itself. So this is really a quick win to be
able to inspect models better.

---------

Co-authored-by: Maarten Pronk <git@evetion.nl>
@visr visr mentioned this pull request Apr 14, 2025
visr added a commit that referenced this pull request Apr 15, 2025
## [v2025.3.0] - 2025-04-14

The only breaking change in this release is to disallow connecting a
single FlowBoundary to multiple Basins.
There are large improvements in the ability to visualize results on the
map in QGIS.
We also welcome the Junction node to the family, which will help laying
out networks in a recognizable manner.

### Added
- Add spatio-temporal results layers to QGIS.
[#2208](#2208)
- Add topological (straight line) link view toggle to QGIS.
[#2208](#2208)
- Added [Junction](https://ribasim.org/reference/node/junction.html)
node type. [#2175](#2175)
- Write results and log bottlenecks also on an interrupt or crash.
[#2191](#2191)
[#2200](#2200)
- Log computation time and save it to `solver_stats.arrow`.
[#2209](https://github.com/Deltares/Ribasim/pull/)
- Experimental support for writing the model network and results into
files used by Delft-FEWS,
[`model.to_fews`](`https://ribasim.org/reference/python/Model.html#ribasim.Model.to_fews`).
[#2161](#2161)
- Document
[`results/concentration.arrow`](https://ribasim.org/reference/usage.html#concentration---concentration.arrow).
[#2165](#2165)

### Changed
- Allow max 1 outflow neighbour for FlowBoundary.
[#2192](#2192)
- Automatic differentiation is enabled by default again, `autodiff =
true`, leading to better performance.
[#2137](#2137)
[#2183](#2183)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants