aboutsummaryrefslogtreecommitdiff
path: root/metchart/misc.py
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2024-10-15 00:05:51 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2024-10-15 00:05:51 +0200
commit244e7a27a9a6dca97e0a21bd29bd49e463e243e5 (patch)
tree8ff73800edf228df24ed219d926aa6c0813d6847 /metchart/misc.py
parent185a43cede974de9ac18bec6312f892a7929346f (diff)
parent32863e21fa16e949fc20c4588e84b90916265367 (diff)
downloadmeteo_toolbox-244e7a27a9a6dca97e0a21bd29bd49e463e243e5.tar.gz
Merge branch 'package_python'
Diffstat (limited to 'metchart/misc.py')
-rw-r--r--metchart/misc.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/metchart/misc.py b/metchart/misc.py
new file mode 100644
index 0000000..6594d0f
--- /dev/null
+++ b/metchart/misc.py
@@ -0,0 +1,23 @@
+import os
+import numpy as np
+import datetime
+
+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 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):
+ os.makedirs(path)
+ elif clear:
+ raise Exception('clear not implemented')
+