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

Apply overrides in Storage and its superclasses #81

Merged
merged 21 commits into from
Oct 10, 2024
Merged

Conversation

liuly12
Copy link
Collaborator

@liuly12 liuly12 commented Mar 5, 2024

Apply overrides in Storage, Groundwater, QueueGroundwater, River, Riverreservoir and update the tests

@liuly12 liuly12 linked an issue Mar 5, 2024 that may be closed by this pull request
Copy link
Collaborator

@barneydobson barneydobson left a comment

Choose a reason for hiding this comment

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

Looks good - just some suggestions, nothing big

wsimod/nodes/nodes.py Outdated Show resolved Hide resolved
wsimod/nodes/nodes.py Outdated Show resolved Hide resolved
@@ -394,7 +449,6 @@ class River(Storage):
# TODO non-day timestep
def __init__(
self,
depth=2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure it's a great idea to remove arguments. As there will be many config files that specify depth for River nodes, and these will crash. Instead I would suggest to allow depth as an argument and have something like the following:

print('warning: the depth parameter is unused by River nodes because it is intended for capacity to be unbounded. It may be removed in a future version.')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added - see commit 07e196b

@@ -490,16 +543,6 @@ def __init__(
)
self.muptNpar = 0.001 # [kg/m2/day] nitrogen macrophyte uptake rate
self.muptPpar = 0.0001 # 0.01, # [kg/m2/day] phosphorus macrophyte uptake rate
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see that these aren't used - but I guess they were used in CatchWat? Are we likely to need them again? If so, maybe just copy this excerpt into #2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

probably not as they are for the solids and we haven't decided which sedimentation-resuspension model we are going to integrate ... plus these parameters are not performing very well in previous case studies

wsimod/nodes/storage.py Outdated Show resolved Hide resolved
@liuly12 liuly12 requested a review from dalonsoa April 10, 2024 09:12
Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

Same comment than in #79 . The overrides look ok, but there's no reason to use pop while you can get the same thing with get. I do not see any reason for modifying the overrides dictionary.

@barneydobson barneydobson marked this pull request as ready for review October 1, 2024 13:54
@liuly12
Copy link
Collaborator Author

liuly12 commented Oct 2, 2024

The purpose to pop the overrides dict is to examine whether all intended overrides in the dict have been accomplished. If there are residual items left in the overridies, a warning will be reported through the following lines in the node.py, which provides a diagnosis message to the users to check.

    def apply_overrides(self, overrides: Dict[str, Any] = {}) -> None:
        """Apply overrides to the node.

        The Node does not have any overwriteable parameters. So if any
        overrides are passed up to the node, this means that there are unused
        parameters from the Node subclass, which is flagged.

        Args:
            overrides (dict, optional): Dictionary of overrides. Defaults to {}.
        """
        if len(overrides) > 0:
            print(f"No override behaviour defined for: {overrides.keys()}")

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

I believe we already had this pop vs get discussion somewhere else and I was happy with the explanation, so feel free to go ahead with it.

Having said that, I would suggest to replace all print statements with a proper logger. That might be a task for a different PR, though.

wsimod/nodes/storage.py Outdated Show resolved Hide resolved
Comment on lines 640 to 643
print(
"ERROR: specifying area is depreciated in overrides \
for river, please specify length and width instead"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use exceptions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added runtime errors - is this what is meant?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exactly. You could also use ValueError. There are several built-in exception you can sue. Pick the most appropriate one for each case. https://docs.python.org/3/library/exceptions.html

Comment on lines 646 to 649
print(
"ERROR: specifying capacity is depreciated in overrides \
for river, it is always set as unbounded capacity"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Comment on lines 510 to 513
print(
"warning: the depth parameter is unused by River nodes because it is \
intended for capacity to be unbounded. It may be removed in a future version."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

@liuly12 liuly12 merged commit 08b0328 into main Oct 10, 2024
21 checks passed
@liuly12 liuly12 deleted the storage-overrides branch October 10, 2024 09:36
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.

Storage overrides
3 participants