aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2024-10-14 00:55:26 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2024-10-14 00:55:26 +0200
commit9e5f1d17a4b0165bd4a3218ca24a159012ea49bd (patch)
tree1e17450dc197075899d27780ce1094d6dcbf4d98
parent61106b34eca95709d5c79eaf5376ea5158074abb (diff)
downloadmeteo_toolbox-9e5f1d17a4b0165bd4a3218ca24a159012ea49bd.tar.gz
misc
-rw-r--r--misc.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/misc.py b/misc.py
index dcbd2f8..6594d0f 100644
--- a/misc.py
+++ b/misc.py
@@ -2,12 +2,18 @@ import os
import numpy as np
import datetime
-def np_time_convert(dt64):
+def np_time_convert(dt64, func=datetime.datetime.utcfromtimestamp):
unix_epoch = np.datetime64(0, 's')
one_second = np.timedelta64(1, 's')
seconds_since_epoch = (dt64 - unix_epoch) / one_second
- return datetime.datetime.utcfromtimestamp(seconds_since_epoch)
+ return func(seconds_since_epoch)
+
+def np_time_convert_offset(init, step):
+ return np_time_convert(init) + np_time_convert(step, func=lambda x: datetime.timedelta(seconds=x))
+
+def np_time_list_convert_offset(init, steps):
+ return list(map(lambda x: np_time_convert_offset(init, x), steps))
def create_output_dir(path, clear=False):
if not os.path.exists(path):