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

ModelComponent Class #769

Merged
merged 69 commits into from
Mar 12, 2024
Merged

ModelComponent Class #769

merged 69 commits into from
Mar 12, 2024

Conversation

Tjalling-dejong
Copy link
Contributor

Issue addressed

Fixes #671

Explanation

Creating a model component subclass for grid model first. The idea is to make a general ModelComponent class that will replace the different model classess with subclasses of ModelComponent.

Checklist

  • Updated tests or added new tests
  • Branch is up to date with main
  • Tests & pre-commit hooks pass
  • Updated documentation if needed
  • Updated changelog.rst if needed
  • For predefined catalogs: update the catalog version in the file itself, the references in data/predefined_catalogs.yml, and the changelog in data/changelog.rst

Additional Notes (optional)

Add any additional notes or information that may be helpful.

Copy link
Contributor

@savente93 savente93 left a comment

Choose a reason for hiding this comment

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

Looking good Tjalling. I think this is nice for a first try and we'll see about polishing some things when we start integrating it with the rest and moving over tests.

hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
Copy link
Contributor

@hboisgon hboisgon left a comment

Choose a reason for hiding this comment

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

Hi @Tjalling-dejong , very nice first implementation of the Grid ModelComponent!
I think it's almost ready, I just added a few answers to Sam and asked to rename the setup methods but for the rest almost ready to merge I think :)
Just one thing, but before you merge, I think we don't need the v1 folder and maybe rename grid.py script to grid_component.py

hydromt/models/v1/model_utils.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
tests/model/model_components/test_grid_model_componet.py Outdated Show resolved Hide resolved
hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
Copy link
Contributor

@DirkEilander DirkEilander left a comment

Choose a reason for hiding this comment

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

Some quick suggestions:

  • we need to initialize a component with the model rather than just root to be able to acces the model region, data catalog, etc.. Using a model property that calls the weak_ref to model we can avoid circular dependencies, see also discussion New `ModelComponent` class #636
  • it would be good to keep the 'just in time reading' we have currently. This is achieved by creating a data property which calls _initialize_data if _data is None. In most other methods we can than simply use data rather than _data, see also current implementation for grid, maps, geoms, etc.
  • Both the model and data properties should land in the generic ModelComponent class

hydromt/models/v1/grid.py Outdated Show resolved Hide resolved
@DirkEilander DirkEilander changed the base branch from main to v1 February 12, 2024 17:23
Copy link
Contributor

@hboisgon hboisgon left a comment

Choose a reason for hiding this comment

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

Almost there @Tjalling-dejong ! Just a few minor suggestions before this is finalized and can be merged :)

After this PR it would be good to harmonise and finalise the link of GridComponent to ModelRegionComponent and to update and link GridComponent to Model so that we can create gridded models again.

docs/dev/migrating-to-v1.rst Outdated Show resolved Hide resolved
docs/dev/migrating-to-v1.rst Outdated Show resolved Hide resolved
hydromt/io/readers.py Outdated Show resolved Hide resolved
hydromt/io/readers.py Show resolved Hide resolved
hydromt/io/writers.py Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
Copy link
Contributor

@savente93 savente93 left a comment

Choose a reason for hiding this comment

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

I broadly agree with Hélène's comments so once you resolve those I'm happy for it to be merged. Nearly there!

Tjalling-dejong and others added 16 commits March 11, 2024 09:37
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Copy link
Contributor

@deltamarnix deltamarnix left a comment

Choose a reason for hiding this comment

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

Good busy! Looks like a solid PR. I assume we can get those tests up and running as soon as the Model class is also ready.

Copy link
Contributor

@hboisgon hboisgon left a comment

Choose a reason for hiding this comment

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

Great work @Tjalling-dejong ! Looking good now :)
I still have a couple of very little comments but at the level of for example an argument that you forgot to remove from the docstrings. So would be great if you could still update before merging. But I approve already as they are quite minor.
Great job!

hydromt/models/__init__.py Show resolved Hide resolved
hydromt/models/components/grid.py Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
hydromt/models/components/grid.py Outdated Show resolved Hide resolved
Tjalling-dejong and others added 4 commits March 12, 2024 09:09
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
Co-authored-by: hboisgon <45457510+hboisgon@users.noreply.github.com>
@Tjalling-dejong Tjalling-dejong merged commit 46f0348 into v1 Mar 12, 2024
10 checks passed
@Tjalling-dejong Tjalling-dejong deleted the model_components branch March 12, 2024 08:22
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.

New ModelComponent class
5 participants