aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xhorizontal.py12
-rw-r--r--misc.py8
-rwxr-xr-xrun.py3
-rwxr-xr-xvertical_from_grib.py11
4 files changed, 26 insertions, 8 deletions
diff --git a/horizontal.py b/horizontal.py
index 280599f..02e45b1 100755
--- a/horizontal.py
+++ b/horizontal.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
+import os
+
import xarray as xr
import numpy as np
@@ -30,13 +32,14 @@ config = {
]
}
-def run(source, plots):
+def run(source, plots, output='.'):
+ misc.create_output_dir(output)
data = xr.load_dataset(source, engine='cfgrib')
for plot in plots:
- _plot(data, **plot)
+ _plot(data, output, **plot)
-def _plot(data, name, layers, area = None):
+def _plot(data, output, name, layers, area = None):
for step in data.coords['step']:
this_step = data.sel(step=step)
@@ -68,7 +71,8 @@ def _plot(data, name, layers, area = None):
pc.panels = [panel]
pc.draw()
#pc.show()
- pc.save(f'{name}_{init_for_filename}+{hours_since_init_str}.png')
+ outname = f'{name}_{init_for_filename}+{hours_since_init_str}.png'
+ pc.save(os.path.join(output, outname))
def _layer(data, layertype, **kwargs):
layertypes={
diff --git a/misc.py b/misc.py
index 90417f1..dcbd2f8 100644
--- a/misc.py
+++ b/misc.py
@@ -1,3 +1,4 @@
+import os
import numpy as np
import datetime
@@ -7,3 +8,10 @@ def np_time_convert(dt64):
seconds_since_epoch = (dt64 - unix_epoch) / one_second
return datetime.datetime.utcfromtimestamp(seconds_since_epoch)
+
+def create_output_dir(path, clear=False):
+ if not os.path.exists(path):
+ os.makedirs(path)
+ elif clear:
+ raise Exception('clear not implemented')
+
diff --git a/run.py b/run.py
index e1b6ad0..7439bfb 100755
--- a/run.py
+++ b/run.py
@@ -2,6 +2,7 @@
import sys
import yaml
+import matplotlib.pyplot as plt
FILE = 'config.yaml'
if len(sys.argv) > 1:
@@ -17,3 +18,5 @@ for plotter in conf['plotter']:
mod = __import__(modname)
mod.run(**plotter)
+
+ plt.close('all')
diff --git a/vertical_from_grib.py b/vertical_from_grib.py
index 9251410..934b248 100755
--- a/vertical_from_grib.py
+++ b/vertical_from_grib.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+import os
import datetime
@@ -23,13 +24,14 @@ config = {
]
}
-def run(source, plots):
+def run(source, plots, output='.'):
+ misc.create_output_dir(output)
data = xr.load_dataset(source, engine='cfgrib')
for plot in plots:
- _plot(data, **plot)
+ _plot(data, output, **plot)
-def _plot(data, lat, lon, name, analysis=None):
+def _plot(data, output, lat, lon, name, analysis=None):
for_temp = data.sel(latitude=lat, longitude = lon, method='nearest')
for_temp = for_temp[['r', 't', 'u', 'v']]
@@ -65,7 +67,8 @@ def _plot(data, lat, lon, name, analysis=None):
init_for_filename = init.strftime('%Y-%m-%d-%HUTC')
- skt.plot(filename=f'skewt_{name}_{init_for_filename}+{hours_since_init_str}.png')
+ outname = f'skewt_{name}_{init_for_filename}+{hours_since_init_str}.png'
+ skt.plot(filename=os.path.join(output, outname))
if __name__ == '__main__':
run(**config)