flopy.discretization.modeltime module

class ModelTime(perlen, nstp, tsmult=None, time_units=None, start_datetime=None, steady_state=None)[source]

Bases: object

Class for MODFLOW simulation time

Parameters:
  • perlen (ArrayLike[float]) – list or numpy array of stress-period lengths

  • nstp (ArrayLike[int]) – list or numpy array of number of time-steps per stress period

  • tsmult (list, np.ndarray) – list or numpy array of timestep mult information

  • time_units (ArrayLike[float] or None) – string or pre-mf6 integer representation (ITMUNI) of time units

  • start_datetime (various objects) – user supplied datetime representation. Please see the ModelTime.parse_datetime documentation for a list of the supported representation types

  • steady_state (list, np.ndarray) – optional list or numpy array of boolean flags that identify whether a stress period is steady-state or transient

property datetimes

Returns a list of datetime objects for all time steps

classmethod from_headers(headers: recarray)[source]

Instantiate a ModelTime class from a head or budget file header array.

Parameters:

headers (np.recarray) – head or budget file header array

Return type:

ModelTime object

classmethod from_perioddata(perioddata, time_units=None, start_datetime=None, steady_state=None)[source]

Instantiate a ModelTime class from a TDIS perioddata array.

Parameters:
  • perioddata (np.recarray, dict, or pandas dataframe) – TDIS perioddata recarray, pandas dataframe or dictionary of lists/arrays. recarray or dictionary must have the keys “perlen”, “nstp”, and “tsmult”.

  • time_units (int or str) – string or pre-mf6 integer representation (ITMUNI) of time units

  • start_datetime (various objects) – user supplied datetime representation. Please see the ModelTime.parse_datetime documentation for a list of the supported representation types

  • steady_state (list, np.ndarray) – optional list or numpy array of boolean flags that identify whether a stress period is steady-state or transient

Return type:

ModelTime object

get_datetime(kper, kstp=None, start=False)[source]

Method to get the datetime at the end or start of a given stress period or stress period and time step combination

Parameters:
  • kper (int) – zero based modflow stress period number

  • kstp (int) – zero based timestep number

  • start (bool) – boolean flag to get the datetime value at the start of a stress period. Default is False and returns the datetime at the end of a stress period

Return type:

datetime.datetime object

get_datetime_string(datetime_obj)[source]

Method to get a standardized ISO 8601 compliant datetime string

Parameters:

datetime_obj (various objects) – user supplied datetime representation. Please see the ModelTime.parse_datetime documentation for a list of the supported representation types

get_elapsed_time(kper, kstp=None, start=False)[source]

Method to get the total simulation time at the end or beginning of a given stress-period or stress-period and time-step combination

Parameters:
  • kper (int) – zero based stress-period number

  • kstp (int or None) – optional zero based time-step number

  • start (bool) – Boolean flag to get totim at the start of the kper/kstp combination. Default is False and returns totim at the end of a kper/kstp combination

Returns:

totim

Return type:

float

intersect(datetime_obj=None, totim=None, forgrive=False)[source]

Method to intersect a datetime or totim value with the model and get the model stress-period and time-step associated with that time.

Parameters:
  • datetime_obj (various objects) – user supplied datetime representation. Please see the ModelTime.parse_datetime documentation for a list of the supported representation types

  • totim (float) – optional total time elapsed from the beginning of the model

  • forgive (bool) – optional flag to forgive time intersections that are outside of the model time domain. Default is False

Returns:

tuple

Return type:

(kper, kstp)

property kper_kstp

Returns a list of kper, kstp tuples that correspond to totim

property nper

Returns the number of stress periods

property nstp

Returns a list or array of number of time steps per stress period

static parse_datetime(datetime_obj)[source]

Method to create a datetime.datetime object from a variety of user inputs including the following:

datetime.datetime objects numpy.datetime64 objects pandas.Timestamp objects string objects

Supported formats for string objects representing November 12th, 2024 are as follows:

‘11/12/2024’ ‘11-12-2024’ ‘2024/11/12’ ‘2024-11-12’

Time can also be represented in the string object. Example formats representing 2:31 pm on November 12th, 2024 are as follows:

‘2024-11-12T14:31:00’ ‘2024/11/12T14:31:00’ ‘11-12-2024t14:31:00’ ‘11/12/2024t14:31:00’ ‘2024-11-12 14:31:00’ ‘2024/11/12 14:31:00’ ‘11-12-2024 14:31:00’ ‘11/12/2024 14:31:00’

Parameters:

datetime_obj (various formats) – a user-supplied representation of date or datetime

Return type:

datetime.datetime object

static parse_timeunits(units)[source]

Method to get a normalized time unit string from user input. User input can be either a string representation or ITMUNI integer. String representations use “sequence scoring” to fuzzy match to the normalized time unit.

Parameters:

units (str or int) – string or pre-mf6 integer representation (ITMUNI) of time units

Returns:

str

Return type:

standardized unit string

property perioddata

Returns a tuple of period data for the MF6 TDIS package containing records of [(perlen, nstp, tsmult), ….] for each stress period

property perlen

Returns a list or array of stress-period lengths

property pertim

Returns a list of pertim values at the end of each time-step

reverse()[source]

Get a new instance with stress periods and time steps in reverse order.

Return type:

ModelTime object with reversed order of stress periods and time steps.

property start_datetime

Returns a datetime.datetime object of the model start time

property steady_state

Returns a boolean that indicates either steady-state or transient stress period

property time_units

Returns a normalized string representation of the time units

property totim

Returns a list of totim values at the end of each time-step

property tslen

Method to get a list of time step lengths for the entire model period

property tsmult

Returns the time step multiplier value for each stress period