flopy.discretization.modeltime module

class ModelTime(perlen: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], nstp: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], tsmult: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] = None, time_units: int | str | None = None, start_datetime: str | datetime | datetime64 | Timestamp | None = None, steady_state: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None = None)[source]

Bases: object

Simulation time discretization.

property datetimes: list[datetime.datetime]

Timestamp corresponding to the end of each time-step.

classmethod from_headers(headers: recarray) ModelTime[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: recarray | dict | DataFrame, time_units: int | str | None = None, start_datetime: str | datetime | datetime64 | Timestamp | None = None, steady_state: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None = None) ModelTime[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: int, kstp: int | None = None, start: bool = False) datetime[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 object

get_datetime_string(datetime_obj: str | datetime | datetime64 | Timestamp) str[source]

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

Returns:

str

Return type:

ISO 8601 compliant datetime string

get_elapsed_time(kper: int, kstp: int | None = None, start: bool = False) float[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: str | datetime | datetime64 | Timestamp | None = None, totim: float | None = None, forgive: bool = False) tuple[int | None, int | None][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: list[tuple[int, int]]

Stress period and time step index corresponding to each time step.

property nper: int

The number of stress periods in the simulation.

property nstp: ndarray[tuple[Any, ...], dtype[integer]]

Number of time steps per stress period.

static parse_datetime(datetime_obj: str | datetime | datetime64 | Timestamp | None) datetime[source]

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

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’

ModelTime 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 object

static parse_timeunits(units: int | str | None) str[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: list[tuple[float, int, float]]

Period data for the MF6 TDIS package. Returns a list of tuples (perlen, nstp, tsmult), 1 for each stress period.

property perlen: ndarray[tuple[Any, ...], dtype[floating]]

Stress period lengths.

property pertim: list[float]

Period time corresponding to the end of each time-step. This is the time elapsed since the start of stress period.

reverse() ModelTime[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: datetime

Start datetime.

property steady_state: ndarray[tuple[Any, ...], dtype[bool]] | None

Steady state flags.

property time_units: str

ModelTime units.

property totim: list[float]

Simulation time corresponding to the end of each time-step. This is the time elapsed since the start of the simulation.

property tslen: list[float]

Duration of each time step.

property tsmult: ndarray[tuple[Any, ...], dtype[floating]]

ModelTime step multipliers.