-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improve time discretization #257
Conversation
- add new simplified set_ds_time() function - deprecate old set_ds_time() by renaming to set_ds_time_deprecated() - rename functions ds_time_idx_from_model and ds_time_idx_from_modeltime to make clear they return a time index
- handle new dataset time discretization - add message if no STO pkg is created because model is steady state
- allow overriding of stored nstp and tsmult. - use utilility methods to obtain nstp and tsmult from ds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! some comments from me nothing big.
- steady, nstp, tsmult become data variables with dim time - add docstring to ds_time_idx_from_tdis_settings - add TODO comments for next hydropandas release
- steady, nstp, tsmult become data variables with dim time - add docstring to ds_time_idx_from_tdis_settings - add TODO comments for next hydropandas release
I liked the original method because of the following default values:
Multiple steady state stress periods is probably only useful in transport calculations, so I think a transient run for multiple stress periods should be the default. With the above default values the starting conditions of the transient run are determined by a steady-state run of 10 years. To get the same behavior of the new method would require a few lines of code from the user. Also, the method Therefore, I would be more in favor of fixing/improving the original method, in which we:
|
Thanks for the review! I'm a bit biased, but i find the old code almost unreadable, so I'd be in favor of modifying this PR further to modify the defaults to what you suggest. I agree we most often want to default to one steady state period and then subsequent transient periods. That's something we can implement with an extra keyword argument? And then explicitly entering the 10 year period isn't that much effort on the part of the user, just subtract 10 years from So to reproduce current behavior it would become something like this (with these values being default for the steady keyword args):
or in the pandas case: time = pd.date_range("2020-01-01", "2025-01-01", "MS")
nlmod.time.set_ds_time(time, start=time[0] - pd.Timedelta(3652, "D"), steady=False, steady_start=True) |
- add steady_start kwarg to set_ds_time - modify set_ds_time_deprecated, also set steady, nstp, and tsmult in ds
The old code was complicated, because it needed to support It is a good idea to set the length of the steady-state start period more explicit. I can work with your proposed code: |
Alright, sounds good! As for perlen, its still supported but you have to take the cumulative sum in this new function. # set ds time with perlen
perlen = [100, 100]
ds = nlmod.time.set_ds_time(ds, np.cumsum(perlen), start="2020") # note the cumsum |
I added perlen, also because it is requested in issue #124, and set a default value for I would remove the log-message at the start of the method, as this will get annoying, I think. |
Nice! My thoughts on these additions:
So in short, I'm for perlen always array-like, and getting rid of the steady defaults and forcing the user to pick something. Perhaps we can get @OnnoEbbens to weigh in and help us pick a way to go :). |
@OnnoEbbens agrees with you, and I agree that removing the default value for start is clearer to the user. |
I fixed some bugs relating to previous changes and the new pandas version. They are not really related to this pull request, but were needed to test all the notebooks for the time-related changes. I think this PR is ready to be merged. |
We use a newer version of modpath, so this is not a problem anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one fix for nb 11, for the rest all good to go!
This PR aims to simplify and improve the handling of time discretization in nlmod.
To add time index to your model dataset use
nlmod.time.set_ds_time()
*.*NOTE: this function replaces the old function with the same name, but works differently, so this is a minor breaking change. The old function can still be called through
nlmod.time.set_ds_time_deprecated()
for now.The arguments to
nlmod.time.set_ds_time()
are:time
is an array-like with the timestamps at the end of each stress period (note that this does not include the starting time of the model)start
is the start datetime of the modelsteady
is an array-like indicating whether a stress period is steady-state (True or 1) or transient (False or 0). The default is steady-state for all timesteps.nstp
andtsmult
are optional arguments to indicate the number of time steps per stress period and the timestep multiplier. These are used when writing the Modflow6 TDIS file.A function has been added to convert flopy TDIS period data settings (
perlen
,nstp
,tsmult
) into a time index:EDIT: Some additional comments on this PR after @OnnoEbbens review:
The variables
steady
,nstp
andtsmult
are now stored as data variables in the model dataset with dimension time. This should make them more visible and easier to modify for users as well.A check is included whether the first entry of the time array (after conversion to a datetime object) is equal to or lies before the start datetime. This should help users figure out if they've made a mistake when assigning these variables.