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

Update(ModelTime): refactor ModelTime and add new features #2367

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

jlarsen-usgs
Copy link
Contributor

  • refactor call signature to accept perlen, nstp, and tsmult as parameters

  • added methods:

    • set_start_datetime(): allows user to set/reset the start_datetime
    • set_time_units(): allows user to set/reset the time_units
    • timeunits_from_user_input(): uses fuzzy string logic to parse user supplied time units
    • datetime_from_user_input(): converts many types of datetime representation to a standard datetime object
    • get_totim(): allows user to get the totim value at the end of a stress period or stress period/time step combination
    • get_datetime(): allows user to get the datetime value at the end of a stress period or stress period/time step combination
    • intersect(): method that allows for time intersection. Method accepts datetime representations or totim and returns either the zero based stress period or the stress period and time step combination
  • added testing for ModelTime

  • updated FloPy model classes for ModelTime changes

* refactor call signature to accept perlen, nstp, and tsmult as parameters
* added methods:
   - `set_start_datetime()`: allows user to set/reset the start_datetime
   - `set_time_units()`: allows user to set/reset the time_units
   - `timeunits_from_user_input()`: uses fuzzy string logic to parse user supplied time units
   - `datetime_from_user_input()`: converts many types of datetime representation to a standard datetime object
   - `get_totim()`: allows user to get the totim value at the end of a stress period or stress period/time step combination
   - `get_datetime()`: allows user to get the datetime value at the end of a stress period or stress period/time step combination
   - `intersect()`: method that allows for time intersection. Method accepts datetime representations or totim and returns either the zero based stress period or the stress period and time step combination

* added testing for ModelTime
* updated FloPy model classes for ModelTime changes
* add get_datetime_string() method to ModelTime to format ISO 8601 compliant date times
@wpbonelli
Copy link
Member

will this close #1915?

@jlarsen-usgs
Copy link
Contributor Author

@wpbonelli

This will close #1915. The TemporalReference class had very few uses and it's functionality has been 1) replaced and 2) improved on in this PR.

@langevin-usgs langevin-usgs marked this pull request as draft November 14, 2024 17:21
Copy link
Contributor

@langevin-usgs langevin-usgs left a comment

Choose a reason for hiding this comment

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

Hey Josh, I had a bunch of little comments, many just about terminology. Just thought I'd bring them up for discussion before they get burned in. I think what you've done here will be widely used.

One thing to consider: we have adaptive time stepping now, which doesn't fit the mold of nstp/tsmult. Not sure how we should handle it, but I think we should leave space for it somehow. Unfortunately, we don't know the time stepping information until after the simulation runs, but we could have ModelTime load the information. We can modify ATS to write time step information, which might be helpful.

Is there a way to get a list of datetimes that correspond to the end of each time step? Seems like this would be great for making plots?

flopy/discretization/modeltime.py Outdated Show resolved Hide resolved

return dt

def intersect(self, datetime_obj=None, totim=None, kper_kstp=False, forgrive=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def intersect(self, datetime_obj=None, totim=None, kper_kstp=False, forgrive=False):
def intersect(self, datetime_obj=None, totim=None, kper_kstp=False, forgive=False):

Note that forgive is misspelled in a few places.

Also, I wonder if intersect is the best name for this? Would this be better explained with find?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the forgive flag.

We should think about the naming here, because I think that this is going to be one of the more used methods of the class. I'm not sure that find is quite right for the method name

flopy/discretization/modeltime.py Show resolved Hide resolved
flopy/discretization/modeltime.py Outdated Show resolved Hide resolved
flopy/discretization/modeltime.py Show resolved Hide resolved
flopy/discretization/modeltime.py Show resolved Hide resolved
flopy/discretization/modeltime.py Outdated Show resolved Hide resolved
flopy/discretization/modeltime.py Outdated Show resolved Hide resolved
flopy/discretization/modeltime.py Outdated Show resolved Hide resolved
flopy/discretization/modeltime.py Outdated Show resolved Hide resolved
@jlarsen-usgs jlarsen-usgs requested a review from aleaf December 4, 2024 16:22
if modeltime.start_datetime != start_datetime:
raise AssertionError("start_datetime improperly stored")

result = modeltime.intersect("3/06/2024 23:59:59")
Copy link
Contributor

Choose a reason for hiding this comment

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

I know intersect is used elsewhere, but consider renaming this method to say what it does, for example get_kstpkper() (if I'm understanding this correctly)

autotest/test_modeltime.py Outdated Show resolved Hide resolved
autotest/test_modeltime.py Outdated Show resolved Hide resolved
@aleaf
Copy link
Contributor

aleaf commented Dec 19, 2024

I think that's all I have for now. Thanks for putting this together @jlarsen-usgs. Is there a way to see test coverage or is that turned off for draft requests?

@jlarsen-usgs
Copy link
Contributor Author

jlarsen-usgs commented Jan 13, 2025

Added datetimes method to get datetime list.

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 70.63830% with 69 lines in your changes missing coverage. Please review.

Project coverage is 76.3%. Comparing base (bb9824e) to head (98eee8d).
Report is 35 commits behind head on develop.

Files with missing lines Patch % Lines
flopy/discretization/modeltime.py 70.0% 68 Missing ⚠️
flopy/export/netcdf.py 85.7% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #2367     +/-   ##
=========================================
+ Coverage     68.4%   76.3%   +7.8%     
=========================================
  Files          294     293      -1     
  Lines        59390   59996    +606     
=========================================
+ Hits         40652   45798   +5146     
+ Misses       18738   14198   -4540     
Files with missing lines Coverage Δ
flopy/mbase.py 72.6% <100.0%> (+2.8%) ⬆️
flopy/mf6/mfmodel.py 83.9% <ø> (+27.9%) ⬆️
flopy/mfusg/mfusgdisu.py 83.6% <ø> (+1.5%) ⬆️
flopy/modflow/mf.py 69.3% <ø> (+1.1%) ⬆️
flopy/modflow/mfdis.py 91.8% <ø> (+4.0%) ⬆️
flopy/mt3d/mt.py 77.0% <ø> (+1.1%) ⬆️
flopy/seawat/swt.py 81.7% <ø> (+3.7%) ⬆️
flopy/utils/__init__.py 100.0% <ø> (ø)
flopy/export/netcdf.py 49.1% <85.7%> (+0.5%) ⬆️
flopy/discretization/modeltime.py 74.0% <70.0%> (+24.0%) ⬆️

... and 240 files with indirect coverage changes

@jlarsen-usgs jlarsen-usgs marked this pull request as ready for review January 14, 2025 01:48
headings are: perlen, nstp, tsmult
temporal_reference : TemporalReference
contains start time and time units information
perlen : list, np.ndarray
Copy link
Member

Choose a reason for hiding this comment

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

Could the type be ArrayLike? As implemented, can a scalar be provided (also for nstp and tsmult) indicating a sim with a single period?

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.

4 participants