33
44import numpy as np
55from attrs import Converter , define
6- from flopy .discretization .modeltime import ModelTime
7- from numpy .typing import NDArray
6+ from numpy .typing import ArrayLike , NDArray
87from xattree import ROOT , xattree
98
109from flopy4 .mf6 .converter import structure_array
1110from flopy4 .mf6 .package import Package
1211from flopy4 .mf6 .spec import array , dim , field
12+ from flopy4 .mf6 .utils .time import Time
1313
1414
1515@xattree
@@ -42,9 +42,9 @@ class PeriodData:
4242 converter = Converter (structure_array , takes_self = True , takes_field = True ),
4343 )
4444
45- def to_time (self ) -> ModelTime :
46- """Convert to a `ModelTime ` object."""
47- return ModelTime (
45+ def to_time (self ) -> Time :
46+ """Convert to a `Time ` object."""
47+ return Time (
4848 nper = self .nper ,
4949 time_units = self .time_units ,
5050 start_date_time = self .start_date_time ,
@@ -54,8 +54,8 @@ def to_time(self) -> ModelTime:
5454 )
5555
5656 @classmethod
57- def from_time (cls , time : ModelTime ) -> "Tdis" :
58- """Create a time discretization from a `ModelTime` ."""
57+ def from_time (cls , time : Time ) -> "Tdis" :
58+ """Create a time discretization from a `Time` object ."""
5959 return cls (
6060 nper = time .nper ,
6161 time_units = None if time .time_units in [None , "unknown" ] else time .time_units ,
@@ -64,3 +64,33 @@ def from_time(cls, time: ModelTime) -> "Tdis":
6464 nstp = time .nstp ,
6565 tsmult = time .tsmult ,
6666 )
67+
68+ @classmethod
69+ def from_timestamps (
70+ cls ,
71+ timestamps : ArrayLike ,
72+ nstp : Optional [ArrayLike ] = None ,
73+ tsmult : Optional [ArrayLike ] = None ,
74+ ) -> "Tdis" :
75+ """
76+ Create a time discretization from timestamps.
77+
78+ Parameters
79+ ----------
80+ timestamps : sequence of datetime-likes
81+ Stress period start times
82+ nstp : int or sequence of int, optional
83+ Number of timesteps per stress period. If scalar, applied to all periods.
84+ If None, defaults to 1 for all periods.
85+ tsmult : float or sequence of float, optional
86+ Timestep multiplier per stress period. If scalar, applied to all periods.
87+ If None, defaults to 1.0 for all periods.
88+
89+ Returns
90+ -------
91+ Tdis
92+ Time discretization object
93+ """
94+
95+ time = Time .from_timestamps (timestamps , nstp = nstp , tsmult = tsmult )
96+ return cls .from_time (time )
0 commit comments