diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2024-07-22 23:28:21 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2024-07-22 23:28:21 +0200 |
commit | 61106b34eca95709d5c79eaf5376ea5158074abb (patch) | |
tree | a6db4ee4bd5b33b518cb02b675b076ade3290466 | |
parent | 46c1add9b4d31adf2ed4803c0b74a99df5856922 (diff) | |
download | meteo_toolbox-61106b34eca95709d5c79eaf5376ea5158074abb.tar.gz |
slightly changed index
-rwxr-xr-x | plotter/horizontal.py | 6 | ||||
-rwxr-xr-x | plotter/meteogram.py | 24 | ||||
-rwxr-xr-x | plotter/vertical_from_grib.py | 6 | ||||
-rw-r--r-- | web/index.js | 19 | ||||
-rw-r--r-- | web/style.css | 4 |
5 files changed, 32 insertions, 27 deletions
diff --git a/plotter/horizontal.py b/plotter/horizontal.py index d75236b..218fd33 100755 --- a/plotter/horizontal.py +++ b/plotter/horizontal.py @@ -87,14 +87,16 @@ def _plot(data, output, name, layers, area = None): 'file': outname, 'init': init_str, 'valid': valid_str, - 'valid_offset': hours_since_init_str + 'valid_offset': hours_since_init_str, + 'display_name': name, + 'id': name } ) with open(os.path.join(output, f'{name}.index.json'), 'w') as f: f.write(json.dumps(index, indent=4)) - return { 'name': name, 'indexfile': f'{name}.index.json' } + return { 'name': name, 'indexfile': f'{name}.index.json', 'list_title': 'INIT+' } def _layer(data, layertype, **kwargs): layertypes={ diff --git a/plotter/meteogram.py b/plotter/meteogram.py index f05502f..724e9b2 100755 --- a/plotter/meteogram.py +++ b/plotter/meteogram.py @@ -12,14 +12,17 @@ import misc HEIGHT = 13 -def run(data, plots, output='.'): +def run(data, plots, output='.', name='meteogram'): misc.create_output_dir(output) index = [] for plot in plots: index.append(_plot(data, output, **plot)) - return index + with open(os.path.join(output, f'{name}.index.json'), 'w') as f: + f.write(json.dumps(index, indent=4)) + + return [{ 'name': name, 'indexfile': f'{name}.index.json', 'list_title': 'Location' }] def _get_next_subplot(size, counter=0): ret = (counter + 1, counter + size) @@ -50,7 +53,7 @@ def _add_temp_dewpoint(ax, data): ### Temp + Dewpoint ax.plot(data.valid_time, data.t2m.metpy.convert_units('degC').transpose(), color='red', label='Temperature (2m)') ax.plot(data.valid_time, mpcalc.dewpoint_from_relative_humidity(data.t2m, data.r2).transpose(), color='blue', label='Dewpoint (2m)') - ax.plot(data.valid_time, data.sel(isobaricInhPa=850.0).t.metpy.convert_units('degC').transpose(), color='grey', label='Tempreature (850hPa)') + ax.plot(data.valid_time, data.sel(isobaricInhPa=850.0).t.metpy.convert_units('degC').transpose(), color='grey', label='Temperature (850hPa)') ax.set_ylabel('Temperature [degC]') ax.legend(loc='lower right') @@ -150,17 +153,12 @@ def _plot(data, output, name, lat, lon): plt.savefig(os.path.join(output, outname)) plt.close('all') - index = [] - index.append( + return ( { 'file': outname, 'init': init_str, 'valid': init_str, - 'valid_offset': '00' - } - ) - - with open(os.path.join(output, f'{name}.index.json'), 'w') as f: - f.write(json.dumps(index, indent=4)) - - return { 'name': name, 'indexfile': f'{name}.index.json' } + 'valid_offset': '00', + 'display_name': name, + 'id': name + }) diff --git a/plotter/vertical_from_grib.py b/plotter/vertical_from_grib.py index ff454b3..8e4fd60 100755 --- a/plotter/vertical_from_grib.py +++ b/plotter/vertical_from_grib.py @@ -86,14 +86,16 @@ def _plot(data, output, name, lat=None, lon=None, analysis=None): 'file': outname, 'init': init_str, 'valid': valid_str, - 'valid_offset': hours_since_init_str + 'valid_offset': hours_since_init_str, + 'display_name': name, + 'id': name } ) with open(os.path.join(output, f'skewt_{name}.index.json'), 'w') as f: f.write(json.dumps(index, indent=4)) - return {'name': name, 'indexfile': f'skewt_{name}.index.json'} + return {'name': name, 'indexfile': f'skewt_{name}.index.json', 'list_title': 'Location'} if __name__ == '__main__': run(**config) diff --git a/web/index.js b/web/index.js index e7c619d..d3c2742 100644 --- a/web/index.js +++ b/web/index.js @@ -17,18 +17,18 @@ function httpGetAsync(url, callback) xmlHttp.send(null); } -function loadIndexFromJson(raw_text) { +function loadIndexFromJson(raw_text, title) { index_obj = JSON.parse(raw_text) //TODO pass index here. that would be cleaner than public vars. - build_interface(index_obj); + build_interface(index_obj, title); } -function build_indexlist(index_obj) { +function build_indexlist(index_obj, display_name) { div = document.createElement('div'); div.classList.add('index'); title = document.createElement('h4'); - title.innerText = 'INIT+'; + title.innerText = display_name; div.appendChild(title); list = document.createElement('ul'); @@ -41,7 +41,7 @@ function build_indexlist(index_obj) { a.setAttribute('href', '');// data_dir + '/' + map.file); a.setAttribute('mapfile', map.file); a.onclick = indexlink_click; - a.innerText = map.valid_offset; + a.innerText = map.display_name; a.id = map.file; li = document.createElement('li'); @@ -62,7 +62,9 @@ function indexlink_click(e) { function productlink_click(e) { clear_interface(); - httpGetAsync(data_dir + '/' + this.getAttribute('indexfile'), loadIndexFromJson); + var list_title = this.getAttribute('list_title'); + + httpGetAsync(data_dir + '/' + this.getAttribute('indexfile'), function(a){ loadIndexFromJson(a,list_title);}); return false; } @@ -78,8 +80,8 @@ function build_mapframe() { return div; } -function build_interface(index_obj) { - index = build_indexlist(index_obj); +function build_interface(index_obj, display_name) { + index = build_indexlist(index_obj, display_name); mapframe = build_mapframe(); document.body.appendChild(index); @@ -111,6 +113,7 @@ function build_product_index(raw_text) { a.classList.add('link'); a.setAttribute('href', '');// data_dir + '/' + map.file); a.setAttribute('indexfile', product.indexfile); + a.setAttribute('list_title', product.list_title); a.onclick = productlink_click; a.innerText = product.name; a.id = product.indexfile; diff --git a/web/style.css b/web/style.css index a16c0f5..13ab34c 100644 --- a/web/style.css +++ b/web/style.css @@ -1,7 +1,7 @@ :root { --dummy: white; - --indexwidth: 100px; - --productindex-width: 250px; + --indexwidth: 250px; + --productindex-width: 150px; } body { |