From 9ed036199f39b5a4f694e44a192dec3129c6d83e Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 28 Sep 2023 15:24:33 +0200 Subject: create index files --- horizontal.py | 14 ++++++++++++++ vertical_from_grib.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/horizontal.py b/horizontal.py index 02e45b1..a81b372 100755 --- a/horizontal.py +++ b/horizontal.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import os +import json import xarray as xr @@ -40,6 +41,7 @@ def run(source, plots, output='.'): _plot(data, output, **plot) def _plot(data, output, name, layers, area = None): + index = [] for step in data.coords['step']: this_step = data.sel(step=step) @@ -74,6 +76,18 @@ def _plot(data, output, name, layers, area = None): outname = f'{name}_{init_for_filename}+{hours_since_init_str}.png' pc.save(os.path.join(output, outname)) + index.append( + { + 'file': outname, + 'init': init_str, + 'valid': valid_str, + 'valid_offset': hours_since_init_str + } + ) + + with open(os.path.join(output, f'{name}.index.json'), 'w') as f: + f.write(json.dumps(index, indent=4)) + def _layer(data, layertype, **kwargs): layertypes={ 'raster': { diff --git a/vertical_from_grib.py b/vertical_from_grib.py index 934b248..8aa851a 100755 --- a/vertical_from_grib.py +++ b/vertical_from_grib.py @@ -2,6 +2,7 @@ import os import datetime +import json import xarray as xr from metpy.units import units @@ -34,6 +35,7 @@ def run(source, plots, output='.'): 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']] + index = [] for step in for_temp.coords['step']: this_step = for_temp.sel(step=step) @@ -70,5 +72,17 @@ def _plot(data, output, lat, lon, name, analysis=None): outname = f'skewt_{name}_{init_for_filename}+{hours_since_init_str}.png' skt.plot(filename=os.path.join(output, outname)) + index.append( + { + 'file': outname, + 'init': init_str, + 'valid': valid_str, + 'valid_offset': hours_since_init_str + } + ) + + with open(os.path.join(output, f'skewt_{name}.index.json'), 'w') as f: + f.write(json.dumps(index, indent=4)) + if __name__ == '__main__': run(**config) -- cgit v1.2.3