Skip to content

Couple riCouple river junction node to nearest river locations. This tool can reduce a lot of manual configuration time if client has hundred and thousand river junction needed to be configured.#112

Merged
wuwwen merged 13 commits into
mainfrom
couple_river_junction_to_river
Mar 17, 2026

Conversation

@wuwwen
Copy link
Copy Markdown
Collaborator

@wuwwen wuwwen commented Feb 16, 2026

…reduce a lot of manual configuration time if client has hundred and thousand river junction needed to be configured.

…reduce a lot of mannual configuration time if client has hundrad and thousand river junction needed to be configured.
@wuwwen wuwwen requested a review from ryan-kipawa February 16, 2026 11:26
@wuwwen
Copy link
Copy Markdown
Collaborator Author

wuwwen commented Feb 16, 2026

Hi @ryan-kipawa, I made a tool. This tool is to couple river junction node to nearest river location. The purpose here is to reduce the manual configuration work for Modelers. Can you please review it? There is a build error. I don't know how to fix it. I haven't add clr reference in the init.py file. I don't want mikepluspy to load it at the first place.

@ryan-kipawa
Copy link
Copy Markdown
Collaborator

I'll take a look. Which versions of MIKE+ is the tool relevant for?

Copy link
Copy Markdown
Collaborator

@ryan-kipawa ryan-kipawa left a comment

Choose a reason for hiding this comment

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

I had always considers tools to be a sub-package that exposes tools available in MIKE+. This appears to be a tool that would only be available in MIKE+Py. Do you have more context on the long term vision of this tool?


clr.AddReference("ThinkGeo.Core")

from ThinkGeo.Core import BaseShape # noqa: E402
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is our static type checker (mypy) that fails in the build system. It doesn't recognize dynamically created modules. You'll need to make mypy ignore the pattern ThinkGeo.* similar to other pythonnet imports:

"DHI.*",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@ryan-kipawa fixed. And the utility class has been added.

Comment thread mikeplus/tools/couple_river_junction_tool.py Outdated
@wuwwen
Copy link
Copy Markdown
Collaborator Author

wuwwen commented Feb 18, 2026

I'll take a look. Which versions of MIKE+ is the tool relevant for?

It can work in the previous release version.

@wuwwen
Copy link
Copy Markdown
Collaborator Author

wuwwen commented Feb 20, 2026

@ryan-kipawa get_nearest_river_at method has been added. I will move the couple_river_junction_tool to notebook after you decide where to put the BeginTransaction and EndTransaction.

Copy link
Copy Markdown
Collaborator

@ryan-kipawa ryan-kipawa left a comment

Choose a reason for hiding this comment

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

@ryan-kipawa get_nearest_river_at method has been added. I will move the couple_river_junction_tool to notebook after you decide where to put the BeginTransaction and EndTransaction.

I think it makes sense to add begin_transaction() and end_transaction() to the Database class here:

class Database:

@wuwwen
Copy link
Copy Markdown
Collaborator Author

wuwwen commented Mar 5, 2026

@ryan-kipawa I have updated the script for this PR. Can you review it again?

Comment thread mikeplus/database.py Outdated
)

def begin_transaction(self):
"""Begin the data transaction."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add an example to the docstring to provide context on how this would be used

Comment thread mikeplus/database.py

def begin_transaction(self):
"""Begin the data transaction."""
if not self._is_open:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should raise an error instead of silently returning

Comment thread mikeplus/database.py
commit : bool
true is to commit the data into database, false is to cancel the commit.
"""
if not self._is_open:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens in the case where a user opens the database, starts the database, and then calls close() without ending the transaction?

I think a sensible default is to auto-commit (i.e. assume transactions will always be applied when calling end_transaction or close, unless the user explicitly wants to discard the changes). It is probably most common that a user will want to commit changes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@ryan-kipawa The database will be locked when the "begin transaction" happens. So "begin transaction" should always go with "end transaction".

Comment thread mikeplus/database.py Outdated

self._data_table_container.BeginTransaction()

def end_transaction(self, commit: bool):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider default to true (see comment below)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is an error in this notebook - it should run cleanly

from DHI.Amelia.Infrastructure.Interface.UtilityHelper import GeoAPIHelper # noqa: E402


class SpatialAnalysisUtil:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since the class only holds static methods, they can simply exist in the module itself

@wuwwen
Copy link
Copy Markdown
Collaborator Author

wuwwen commented Mar 16, 2026

@ryan-kipawa Thank you for all the comments. I have uploaded another version. Please check.

@wuwwen wuwwen merged commit 1a723c3 into main Mar 17, 2026
4 checks passed
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.

2 participants