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

Refactor threedigrid_to_ogr function #997

Merged
merged 19 commits into from
Jun 3, 2024
Merged

Conversation

hoanphungt
Copy link
Contributor

No description provided.

@hoanphungt
Copy link
Contributor Author

@leendertvanwolfswinkel Could you take a look at this PR please? I couldn't manage to make it work although I think that I am very close now. Since you have more experience with this, maybe you could spot some error in my logic I hope.

@leendertvanwolfswinkel
Copy link
Collaborator

Had a quick look. Some comments:

  • threedigrid_to_ogr should have an source layer (e.g. src_ds: ogr.DataSource) and a target layer (e.g. tgt_ds: ogr.DataSource). The creation of the target datasource is taken care of by the tools that call threedigrid_to_ogr(). I don't think we want to change that. I think it is not even possible to return a ogr.DataSource that is created in the method that returns it. the python object ogr.DataSource is just a thin wrapper around a C object, but this object is garbage-collected when returning from the function (I think).
  • The function should not return anything, it should just add attributes and features to the target layer
  • The target layer should not be a layer in the gridadmin.gpkg; it should be a memory layer.

Hope this helps

@hoanphungt
Copy link
Contributor Author

ah thanks! that sounds better indeed. I am actually moving this way so good to hear it from you too.

@hoanphungt
Copy link
Contributor Author

I still keep the old threedigrid_to_ogr function in the threedigrid_ogr.py file as the old function is still being used somewhere else in the code base for the processing algorithm.

@leendertvanwolfswinkel
Copy link
Collaborator

Can you please replace all usages of the function?

@@ -99,11 +99,13 @@ def __init__(

def run(self):
grid_admin = str(self.result.parent().path.with_suffix('.h5'))
grid_admin_gpkg = str(self.result.parent().path.with_suffix('.gpkg'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this assume that the gridadmin.gpkg is always in the same directory as gridadmin.h5. Because that is not necessarily the case always

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it grabs the griadmin.gpkg file from the parent directory of the threedi result file. For example in here:

.../threedi_results_analysis/{name_of_the_simulation}/gridadmin.gpkg

Copy link
Collaborator

@leendertvanwolfswinkel leendertvanwolfswinkel left a comment

Choose a reason for hiding this comment

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

Hi Hoan,

I now realize that this ticket has impact on more parts of the code than I originally thought, sorry for that. Also I somehow didn't think about the crucial need for subsetting in threedigrid_to_ogr.

After you implement the suggested changes, I will functionally test all the affected tools:

  • Result aggregation
  • Watershed analysis
  • Cross-sectional discharge

Could you please give those a try as well before passing the ticket to Ready for testing?

attributes=attributes,
attr_data_types=attr_data_types,
include_all_threedigrid_attributes=True
ids=gauge_line_ids,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leendertvanwolfswinkel is gauge_line_ids the correct value to pass into the ids argument?

@hoanphungt
Copy link
Contributor Author

@leendertvanwolfswinkel I refactored it again. Could you please take another look?

@hoanphungt hoanphungt removed the request for review from benvanbasten-ns April 24, 2024 09:46
… tool (#1007)

* Update threedigrid_ogr.py

* Update cross_sectional_discharge.py

* WIP - Flowlines in watershed tool still to be fixed

* Only show the correct marker when browsing result sets

* No longer clear results when toggling smoothing

* flake8

* Update CHANGES.rst
@hoanphungt hoanphungt merged commit 0168d88 into refactor Jun 3, 2024
1 check passed
@hoanphungt hoanphungt deleted the hoan-threedigrid-to-ogr branch June 3, 2024 08:52
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