Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue #1525 repeat stress args #1544

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

Merged
merged 6 commits into from
May 28, 2025
Merged

Conversation

JoerivanEngelen
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen commented May 27, 2025

Fixes #1525

Description

Add support to directly provide repeat_stresses as dictionary. As issue states: Simplifies API for users a lot, as they don't need to search for the obscure utility function get_period_stess.

Checklist

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example

@JoerivanEngelen JoerivanEngelen requested a review from Manangka May 27, 2025 15:42
@@ -71,6 +71,10 @@ class BoundaryCondition(Package, abc.ABC):
"""

def __init__(self, allargs: Mapping[str, GridDataArray | float | int | bool | str]):
if "repeat_stress" in allargs.keys() and isinstance(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this have to be called before the base constructor?
Can't we do the same as we do for concentration?

Copy link
Contributor Author

@JoerivanEngelen JoerivanEngelen May 28, 2025

Choose a reason for hiding this comment

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

No unfortunately not, the repeat_stress data has to be converted from a dict to a xr.DataArray of the right shape, before it can be merged to a xr.Dataset.

The "concentration" logic is more concise if we do it after the call to super().__init__(): The call expand_transient_auxiliary_variables(self) HAS to be done after super.__init__(). The deletion of variables could also be moved before the merge to a dataset, but that would require two if statements just for the concentration, hence why I moved everything after super.__init__().

I added some comments in the code to explain this.

np.datetime64("2000-01-03"),
np.datetime64("2000-01-04"),
]
time_da = xr.DataArray([1, 2], dims=["time"], coords={"time": globaltimes[:2]})
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does [1, 2] mean?
Could you assign it to a variable before using it?

meaningful_name = [1, 2]
time_da = xr.DataArray(meaningful_name , dims=["time"], coords={"time": globaltimes[:2]})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've given it a more meaningful name and data: Now as seasonal factors, that better represents how repeat_stresses are used in practice: To set seasonal boundary conditions, in this case a summer and winter stage.

Copy link

@JoerivanEngelen JoerivanEngelen enabled auto-merge May 28, 2025 12:59
@JoerivanEngelen JoerivanEngelen disabled auto-merge May 28, 2025 14:36
@JoerivanEngelen JoerivanEngelen merged commit d8124ad into master May 28, 2025
6 of 7 checks passed
@JoerivanEngelen JoerivanEngelen deleted the issue_#1525_repeat_stress_args branch May 28, 2025 14: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.

[FEATURE] repeat_stress argument should support a dict of datetimes
2 participants