Deltares / imod-python

🐍🧰 Make massive MODFLOW models
https://deltares.github.io/imod-python/
MIT License
17 stars 3 forks source link

choose datetime object for simulation.from_imod5_data times argument #1111

Open luitjansl opened 2 months ago

luitjansl commented 2 months ago

a review comment on the PR for issue #1068 says:

"I realize we are diverting from the public API. There are a lot of different types of objects in Python to describe time & calendars, which are all still commonly used. See this scheme https://stackoverflow.com/a/21916253

Modflow6Simulation.create_time_discretization accepts a lot of these, and internally converts these to np.datetime64. We use the function imod.util.time.to_datetime_internal() for this. I don't think np.datetime64 has the required year attribute for that. Quickest way would be using the line from to_datetime_internal: year = time.astype("datetime64[Y]").astype(int) + 1970.

It is probably worth a separate issue to align the from_imod5_implementation with create_time_discreatization."

luitjansl commented 2 months ago

It turned out that we need a larger effort to allign the datetime format throughout imod-python. If we convert all datetimes to np.datetime64 or cftime, we run into issues when using a function like expand_repetitions. It only supports (python) datetime objects (because it makes use of a .year property not available on all datetime types).