Coverage for C:\src\imod-python\imod\msw\timeutil.py: 33%

1 import numpy as np

2 import pandas as pd

3

4

5 def to_metaswap_timeformat(times):

6 """

7 Convert times to MetaSWAP's own time format, which consists of a year as

8 integer and the number of days since the start of the year as float.

9

10 Returns

11 -------

12 tuple

13 Consists of the year as integer and the number of days since the

14 start of the year as float.

15

16 """

17

18 # TODO: Also support cftime

19 times = pd.DatetimeIndex(times)

20

21 year = times.year

22

23 # MetaSWAP requires a days since start year

24 days_since_start_year = times.day_of_year.astype(np.float64) - 1.0

25 # Behind the decimal is the time since start day

26 time_since_start_day = times.hour / 24 + times.minute / 1440 + times.second / 86400

27

28 time_since_start_year = days_since_start_year + time_since_start_day

29

30 return year, time_since_start_year