From 663edde231af9ad4a782c5438027ef7f839806ea Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 14 Oct 2024 02:23:10 +0200 Subject: package with python --- aggregator/__init__.py | 0 aggregator/dwd_icon.py | 149 ----------------------------- aggregator/wyoming_sounding.py | 108 --------------------- metchart/aggregator/__init__.py | 0 metchart/aggregator/dwd_icon.py | 149 +++++++++++++++++++++++++++++ metchart/aggregator/misc.py | 23 +++++ metchart/aggregator/wyoming_sounding.py | 108 +++++++++++++++++++++ metchart/misc.py | 23 +++++ metchart/modifier/__init__.py | 0 metchart/modifier/merge.py | 4 + metchart/plotter/__init__.py | 0 metchart/plotter/debug_data.py | 4 + metchart/plotter/horizontal.py | 123 ++++++++++++++++++++++++ metchart/plotter/meteogram.py | 164 ++++++++++++++++++++++++++++++++ metchart/plotter/vertical_from_grib.py | 101 ++++++++++++++++++++ metchart/run.py | 110 +++++++++++++++++++++ metchart/skewt.py | 118 +++++++++++++++++++++++ misc.py | 23 ----- modifier/__init__.py | 0 modifier/merge.py | 4 - plotter/__init__.py | 0 plotter/debug_data.py | 4 - plotter/horizontal.py | 123 ------------------------ plotter/meteogram.py | 164 -------------------------------- plotter/vertical_from_grib.py | 101 -------------------- pyproject.toml | 24 +++++ run.py | 106 --------------------- skewt.py | 118 ----------------------- 28 files changed, 951 insertions(+), 900 deletions(-) delete mode 100644 aggregator/__init__.py delete mode 100755 aggregator/dwd_icon.py delete mode 100755 aggregator/wyoming_sounding.py create mode 100644 metchart/aggregator/__init__.py create mode 100755 metchart/aggregator/dwd_icon.py create mode 100644 metchart/aggregator/misc.py create mode 100755 metchart/aggregator/wyoming_sounding.py create mode 100644 metchart/misc.py create mode 100644 metchart/modifier/__init__.py create mode 100644 metchart/modifier/merge.py create mode 100644 metchart/plotter/__init__.py create mode 100644 metchart/plotter/debug_data.py create mode 100755 metchart/plotter/horizontal.py create mode 100755 metchart/plotter/meteogram.py create mode 100755 metchart/plotter/vertical_from_grib.py create mode 100755 metchart/run.py create mode 100644 metchart/skewt.py delete mode 100644 misc.py delete mode 100644 modifier/__init__.py delete mode 100644 modifier/merge.py delete mode 100644 plotter/__init__.py delete mode 100644 plotter/debug_data.py delete mode 100755 plotter/horizontal.py delete mode 100755 plotter/meteogram.py delete mode 100755 plotter/vertical_from_grib.py create mode 100644 pyproject.toml delete mode 100755 run.py delete mode 100644 skewt.py diff --git a/aggregator/__init__.py b/aggregator/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/aggregator/dwd_icon.py b/aggregator/dwd_icon.py deleted file mode 100755 index 6df905c..0000000 --- a/aggregator/dwd_icon.py +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env python3 - -import requests -import datetime -import pytz -import requests -import os - -from multiprocessing import cpu_count -from multiprocessing.pool import ThreadPool - -import subprocess - -import xarray as xr - -import misc - -BASE='https://opendata.dwd.de/weather/nwp' - -def get_current_run(): - # we allow up to 3h of slack for DWD to upload the latest run - tz = pytz.timezone('UTC') - now = datetime.datetime.now(datetime.timezone.utc) - corrected = now - datetime.timedelta(hours=3) - - run = int(corrected.hour / 6) * 6 - - return (f'{run:02d}', corrected.strftime('%Y%m%d')) - -def download_url(args): - url, dest = args - r = requests.get(url) - try: - with open(dest, 'wb') as f: - f.write(r.content) - print(f'Downloaded {dest}') - except Exception as e: - print(f'Failed to download {dest}:\n', e) - -def unpack_bz2(dest): - res = subprocess.run(['bzip2', '-df', dest]) - if res.returncode != 0: - print(f'There was an error unpacking {dest}:', res.stderr) - -def download_dwd_gribs( - date, run, target, output, model, steps, model_long, - pressure_level_parameters, parameter_caps_in_filename, - single_level_parameters, pressure_levels -): - misc.create_output_dir(output) - - to_download = [] - - for step in steps: - step_str = f'{step:03d}' - - for parameter in pressure_level_parameters: - parameter2 = parameter.upper() if parameter_caps_in_filename else parameter - - for level in pressure_levels: - filename = f'{model_long}_regular-lat-lon_pressure-level_{date}{run}_{step_str}_{level}_{parameter2}.grib2.bz2' - URL = f'{BASE}/{model}/grib/{run}/{parameter}/{filename}' - - to_download.append((URL, os.path.join(output, filename))) - - for parameter in single_level_parameters: - parameter2 = parameter.upper() if parameter_caps_in_filename else parameter - filename = f'{model_long}_regular-lat-lon_single-level_{date}{run}_{step_str}_{parameter2}.grib2.bz2' - URL = f'{BASE}/{model}/grib/{run}/{parameter}/{filename}' - - to_download.append((URL, os.path.join(output, filename))) - - - for _ in ThreadPool(cpu_count()).imap_unordered(download_url, to_download): - pass - - print('Done Downloading. Uncompressing...') - - for _ in ThreadPool(cpu_count()).imap_unordered(unpack_bz2, [dest for _, dest in to_download]): - pass - - downloaded_gribs = [dest.removesuffix('.bz2') for _, dest in to_download] - - res = subprocess.run(['grib_copy'] + downloaded_gribs + [target]) - if res.returncode != 0: - print('grib_copy failed with: ', res.stderr) - - res = subprocess.run(['rm', '-f'] + downloaded_gribs) - if res.returncode != 0: - print('rm failed with: ', res.stderr) - -def clean_output_dir(directory, target): - to_delete = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))] - if target in to_delete: - del to_delete[to_delete.index(target)] - - for f in to_delete: - os.unlink(os.path.join(directory, f)) - -def load_data(name, output, description = None, clean = False, force_filename = None, **kwargs): - target = force_filename - - if target is None: - run, date = get_current_run() - filename = f'{name}_{date}_{run}.grib2' - target = os.path.join(output, filename) - - if not os.path.exists(target): - download_dwd_gribs(date, run, target, output, **kwargs) - else: - print(f'{target} already exists. Using the cached version.') - - if clean: - clean_output_dir(output, filename) - - # we drop heightAboveGround to allow 2m and 10m values to be merged down to one dataset - ds = xr.load_dataset(target, engine='cfgrib', drop_variables='heightAboveGround') - - if description is not None: - ds.attrs['_description'] = description - return ds - - -debug_config = { - 'output':'dwd_icon-eu', - 'model':'icon-eu', - 'model_long':'icon-eu_europe', - 'clean': True, - 'parameter_caps_in_filename':True, - 'pressure_level_parameters': [ - 't', - 'relhum', - 'u', - 'v', - 'fi', - 'clc' - ], - 'single_level_parameters': [ - 'pmsl', - 't_2m', - 'relhum_2m' - ], - 'pressure_levels':[ 1000, 950, 925, 900, 875, 850, 825, 800, 775, 700, 600, 500, 400, 300, 250, 200, 150, 100 ], - 'steps':[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] -} - -if __name__ == '__main__': - load_data('test_icon_eu', **debug_config) - diff --git a/aggregator/wyoming_sounding.py b/aggregator/wyoming_sounding.py deleted file mode 100755 index 111e219..0000000 --- a/aggregator/wyoming_sounding.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python3 -import os -import datetime -import requests - -import csv - -import xarray as xr - -import numpy as np - -from metpy.units import units -import metpy.calc as mpcalc - -import misc - -def get_current_run(): - date=(datetime.date.today() - datetime.timedelta(days = 1)).strftime('%Y-%m-%d') - # TODO we also want noon - hour='23:00:00' - return (hour, date) - -def download_wyoming_csv(station, date, hour, target): - url=f'http://weather.uwyo.edu/cgi-bin/bufrraob.py?datetime={date}%20{hour}&id={station}&type=TEXT:CSV' - result = requests.get(url) - - if result.status_code >= 400: - raise Exception('Failed to Download sounding csv!') - - with open(target, 'w') as f: - f.write(result.text) - -def load_wyoming_csv(filepath, hour, date): - p = [] - T = [] - Td = [] - wind_speed = [] - wind_dir = [] - r = [] - - with open(filepath,'r', newline='') as f: - reader = csv.reader(f) - next(reader) # Skip header - for row in reader: - if sum(map(lambda s : len(s.strip()) == 0, row)): - # skip any line with empty values - continue - - if float(row[3]) in p: # Skip double p entries - continue - - p.append(float(row[3])) - T.append(float(row[5])) - Td.append(float(row[6])) - r.append(float(row[8])) - wind_speed.append(float(row[12])) - wind_dir.append(float(row[11])) - - T = T * units.degC - Td = Td * units.degC - wind_speed = wind_speed * units.knots - wind_dir = wind_dir * units.degrees - u, v = mpcalc.wind_components(wind_speed, wind_dir) - - time = np.datetime64(f'{date}T{hour}') - - # recreate the structure a DWD GRIB produces - return xr.Dataset( - { - "t": (["step", "isobaricInhPa"], [T.to(units.kelvin).magnitude]), - "td": (["step", "isobaricInhPa"], [Td.to(units.kelvin).magnitude]), - "r": (["step", "isobaricInhPa"], [r]), - "u": (["step", "isobaricInhPa"], [u.to('m/s').magnitude]), - "v": (["step", "isobaricInhPa"], [v.to('m/s').magnitude]), - }, - coords={ - "isobaricInhPa": p, - "step": [np.timedelta64(0, 'ns')], - "valid_time": (['step'], [time]), - "time": time, - }, - attrs={ - "source": "uwyo.edu", - } - ) - -def load_data(name, output, station): - hour, date = get_current_run() - misc.create_output_dir(output) - - target = os.path.join(output, f'{name}_{date}_{hour}.csv') - - if not os.path.exists(target): - download_wyoming_csv(station, date, hour, target) - else: - print(f'{target} alreasy exists. Using the cached version.') - - return load_wyoming_csv(target, hour, date) - -config_debug = { - 'output': 'wyoming_test', - 'station': '10548' -} - -if __name__ == '__main__': - ds = load_data('test_wyoming_sounding', **config_debug) - print(ds) - print(ds.coords['step']) diff --git a/metchart/aggregator/__init__.py b/metchart/aggregator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/metchart/aggregator/dwd_icon.py b/metchart/aggregator/dwd_icon.py new file mode 100755 index 0000000..ed5c149 --- /dev/null +++ b/metchart/aggregator/dwd_icon.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 + +import requests +import datetime +import pytz +import requests +import os + +from multiprocessing import cpu_count +from multiprocessing.pool import ThreadPool + +import subprocess + +import xarray as xr + +from . import misc + +BASE='https://opendata.dwd.de/weather/nwp' + +def get_current_run(): + # we allow up to 3h of slack for DWD to upload the latest run + tz = pytz.timezone('UTC') + now = datetime.datetime.now(datetime.timezone.utc) + corrected = now - datetime.timedelta(hours=3) + + run = int(corrected.hour / 6) * 6 + + return (f'{run:02d}', corrected.strftime('%Y%m%d')) + +def download_url(args): + url, dest = args + r = requests.get(url) + try: + with open(dest, 'wb') as f: + f.write(r.content) + print(f'Downloaded {dest}') + except Exception as e: + print(f'Failed to download {dest}:\n', e) + +def unpack_bz2(dest): + res = subprocess.run(['bzip2', '-df', dest]) + if res.returncode != 0: + print(f'There was an error unpacking {dest}:', res.stderr) + +def download_dwd_gribs( + date, run, target, output, model, steps, model_long, + pressure_level_parameters, parameter_caps_in_filename, + single_level_parameters, pressure_levels +): + misc.create_output_dir(output) + + to_download = [] + + for step in steps: + step_str = f'{step:03d}' + + for parameter in pressure_level_parameters: + parameter2 = parameter.upper() if parameter_caps_in_filename else parameter + + for level in pressure_levels: + filename = f'{model_long}_regular-lat-lon_pressure-level_{date}{run}_{step_str}_{level}_{parameter2}.grib2.bz2' + URL = f'{BASE}/{model}/grib/{run}/{parameter}/{filename}' + + to_download.append((URL, os.path.join(output, filename))) + + for parameter in single_level_parameters: + parameter2 = parameter.upper() if parameter_caps_in_filename else parameter + filename = f'{model_long}_regular-lat-lon_single-level_{date}{run}_{step_str}_{parameter2}.grib2.bz2' + URL = f'{BASE}/{model}/grib/{run}/{parameter}/{filename}' + + to_download.append((URL, os.path.join(output, filename))) + + + for _ in ThreadPool(cpu_count()).imap_unordered(download_url, to_download): + pass + + print('Done Downloading. Uncompressing...') + + for _ in ThreadPool(cpu_count()).imap_unordered(unpack_bz2, [dest for _, dest in to_download]): + pass + + downloaded_gribs = [dest.removesuffix('.bz2') for _, dest in to_download] + + res = subprocess.run(['grib_copy'] + downloaded_gribs + [target]) + if res.returncode != 0: + print('grib_copy failed with: ', res.stderr) + + res = subprocess.run(['rm', '-f'] + downloaded_gribs) + if res.returncode != 0: + print('rm failed with: ', res.stderr) + +def clean_output_dir(directory, target): + to_delete = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))] + if target in to_delete: + del to_delete[to_delete.index(target)] + + for f in to_delete: + os.unlink(os.path.join(directory, f)) + +def load_data(name, output, description = None, clean = False, force_filename = None, **kwargs): + target = force_filename + + if target is None: + run, date = get_current_run() + filename = f'{name}_{date}_{run}.grib2' + target = os.path.join(output, filename) + + if not os.path.exists(target): + download_dwd_gribs(date, run, target, output, **kwargs) + else: + print(f'{target} already exists. Using the cached version.') + + if clean: + clean_output_dir(output, filename) + + # we drop heightAboveGround to allow 2m and 10m values to be merged down to one dataset + ds = xr.load_dataset(target, engine='cfgrib', drop_variables='heightAboveGround') + + if description is not None: + ds.attrs['_description'] = description + return ds + + +debug_config = { + 'output':'dwd_icon-eu', + 'model':'icon-eu', + 'model_long':'icon-eu_europe', + 'clean': True, + 'parameter_caps_in_filename':True, + 'pressure_level_parameters': [ + 't', + 'relhum', + 'u', + 'v', + 'fi', + 'clc' + ], + 'single_level_parameters': [ + 'pmsl', + 't_2m', + 'relhum_2m' + ], + 'pressure_levels':[ 1000, 950, 925, 900, 875, 850, 825, 800, 775, 700, 600, 500, 400, 300, 250, 200, 150, 100 ], + 'steps':[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] +} + +if __name__ == '__main__': + load_data('test_icon_eu', **debug_config) + diff --git a/metchart/aggregator/misc.py b/metchart/aggregator/misc.py new file mode 100644 index 0000000..6594d0f --- /dev/null +++ b/metchart/aggregator/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') + diff --git a/metchart/aggregator/wyoming_sounding.py b/metchart/aggregator/wyoming_sounding.py new file mode 100755 index 0000000..617d462 --- /dev/null +++ b/metchart/aggregator/wyoming_sounding.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +import os +import datetime +import requests + +import csv + +import xarray as xr + +import numpy as np + +from metpy.units import units +import metpy.calc as mpcalc + +from .. import misc + +def get_current_run(): + date=(datetime.date.today() - datetime.timedelta(days = 1)).strftime('%Y-%m-%d') + # TODO we also want noon + hour='23:00:00' + return (hour, date) + +def download_wyoming_csv(station, date, hour, target): + url=f'http://weather.uwyo.edu/cgi-bin/bufrraob.py?datetime={date}%20{hour}&id={station}&type=TEXT:CSV' + result = requests.get(url) + + if result.status_code >= 400: + raise Exception('Failed to Download sounding csv!') + + with open(target, 'w') as f: + f.write(result.text) + +def load_wyoming_csv(filepath, hour, date): + p = [] + T = [] + Td = [] + wind_speed = [] + wind_dir = [] + r = [] + + with open(filepath,'r', newline='') as f: + reader = csv.reader(f) + next(reader) # Skip header + for row in reader: + if sum(map(lambda s : len(s.strip()) == 0, row)): + # skip any line with empty values + continue + + if float(row[3]) in p: # Skip double p entries + continue + + p.append(float(row[3])) + T.append(float(row[5])) + Td.append(float(row[6])) + r.append(float(row[8])) + wind_speed.append(float(row[12])) + wind_dir.append(float(row[11])) + + T = T * units.degC + Td = Td * units.degC + wind_speed = wind_speed * units.knots + wind_dir = wind_dir * units.degrees + u, v = mpcalc.wind_components(wind_speed, wind_dir) + + time = np.datetime64(f'{date}T{hour}') + + # recreate the structure a DWD GRIB produces + return xr.Dataset( + { + "t": (["step", "isobaricInhPa"], [T.to(units.kelvin).magnitude]), + "td": (["step", "isobaricInhPa"], [Td.to(units.kelvin).magnitude]), + "r": (["step", "isobaricInhPa"], [r]), + "u": (["step", "isobaricInhPa"], [u.to('m/s').magnitude]), + "v": (["step", "isobaricInhPa"], [v.to('m/s').magnitude]), + }, + coords={ + "isobaricInhPa": p, + "step": [np.timedelta64(0, 'ns')], + "valid_time": (['step'], [time]), + "time": time, + }, + attrs={ + "source": "uwyo.edu", + } + ) + +def load_data(name, output, station): + hour, date = get_current_run() + misc.create_output_dir(output) + + target = os.path.join(output, f'{name}_{date}_{hour}.csv') + + if not os.path.exists(target): + download_wyoming_csv(station, date, hour, target) + else: + print(f'{target} alreasy exists. Using the cached version.') + + return load_wyoming_csv(target, hour, date) + +config_debug = { + 'output': 'wyoming_test', + 'station': '10548' +} + +if __name__ == '__main__': + ds = load_data('test_wyoming_sounding', **config_debug) + print(ds) + print(ds.coords['step']) 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') + diff --git a/metchart/modifier/__init__.py b/metchart/modifier/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/metchart/modifier/merge.py b/metchart/modifier/merge.py new file mode 100644 index 0000000..1fb7fda --- /dev/null +++ b/metchart/modifier/merge.py @@ -0,0 +1,4 @@ +import xarray as xr + +def run(data): + return xr.merge(data) diff --git a/metchart/plotter/__init__.py b/metchart/plotter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/metchart/plotter/debug_data.py b/metchart/plotter/debug_data.py new file mode 100644 index 0000000..560d13c --- /dev/null +++ b/metchart/plotter/debug_data.py @@ -0,0 +1,4 @@ +def run(data, **kwargs): + print(data) + + return [] diff --git a/metchart/plotter/horizontal.py b/metchart/plotter/horizontal.py new file mode 100755 index 0000000..89945c3 --- /dev/null +++ b/metchart/plotter/horizontal.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +import os +import json + +import xarray as xr + +import numpy as np +import matplotlib.pyplot as plt +from metpy.plots import MapPanel, PanelContainer, RasterPlot, ContourPlot + +from . import misc + +config = { + 'source': 'dwd_icon-eu/combined.grib2', + 'plots': [ + { + 'name':'r_t-750', + 'area': None, + 'layers': [ + { + 'layertype': 'raster', + 'field': 'r', + 'level': 750, + }, + { + 'layertype': 'contour', + 'field': 't', + 'level': 750, + 'contours': 5, + 'clabels': True + }, + ] + }, + ] +} + +def run(data, plots, output='.'): + misc.create_output_dir(output) + index = [] + + for plot in plots: + index.append(_plot(data, output, **plot)) + + return index + +def _plot(data, output, name, layers, area = None): + index = [] + + for step in data.coords['step']: + this_step = data.sel(step=step) + + map_layers = [] + + for layer in layers: + map_layers.append(_layer(this_step, **layer)) + + valid = misc.np_time_convert(step.valid_time.values) + init = misc.np_time_convert(step.time.values) + + valid_str = valid.strftime('%d %b %Y - %HUTC') + init_str = init.strftime('%d %b %Y - %HUTC') + hours_since_init_str = str(int(this_step.step.values / np.timedelta64(1,'h'))).zfill(2) + init_for_filename = init.strftime('%Y-%m-%d-%HUTC') + + panel = MapPanel() + if area is not None: + panel.area = area + panel.projection = 'mer' + panel.layers = ['coastline', 'borders'] + panel.plots = map_layers + panel.left_title = f'{name} VALID: {valid_str} (INIT +{hours_since_init_str}) INIT: {init_str}' + if '_description' in data.attrs: + panel.right_title = data.attrs['_description'] + + pc = PanelContainer() + pc.size = (12.8, 9.6) + #pc.figure.layout='constrained' + pc.panels = [panel] + pc.draw() + #pc.show() + outname = f'{name}_{init_for_filename}+{hours_since_init_str}.png' + pc.save(os.path.join(output, outname)) + plt.close('all') + + index.append( + { + 'file': outname, + 'init': init_str, + 'valid': valid_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', 'list_title': 'INIT+' } + +def _layer(data, layertype, **kwargs): + layertypes={ + 'raster': { + 'obj': RasterPlot, + 'defaults': { + 'colorbar': 'vertical', + } + }, + 'contour': { + 'obj': ContourPlot, + 'defaults': {} + } + } + + args = layertypes[layertype]['defaults'] | kwargs + + ret = layertypes[layertype]['obj'](**args) + ret.data = data + + return ret + +if __name__ == '__main__': + run(**config) diff --git a/metchart/plotter/meteogram.py b/metchart/plotter/meteogram.py new file mode 100755 index 0000000..8335247 --- /dev/null +++ b/metchart/plotter/meteogram.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python3 +import os +import json + +import numpy as np + +import matplotlib.pyplot as plt + +import metpy.calc as mpcalc + +from .. import misc + +HEIGHT = 13 + +def run(data, plots, output='.', name='meteogram'): + misc.create_output_dir(output) + index = [] + + for plot in plots: + index.append(_plot(data, output, **plot)) + + 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) + counter += size + return counter, ret + +def _add_cloudcov(ax, data): + ax.set_ylabel('Pressure level [hPa]') + + clc = ax.contourf(data.valid_time, data.isobaricInhPa, data.ccl.transpose(), cmap='clcov', vmin=0, vmax=100, levels=9) + + # use Format parameter for n/8 + plt.colorbar(clc, label='cloudcov', extendfrac=None, ticks=[100*n/8 for n in range(9)], format=lambda x,_: f'{int(x/12.5)}/8', pad=0.0, fraction=0.015) + + cf = ax.contour(data.valid_time, data.isobaricInhPa, data.t.metpy.convert_units('degC').transpose()) + ax.clabel(cf, inline=True, fontsize=10) + + ax.barbs( + data.valid_time, + data.isobaricInhPa, + data.u.metpy.convert_units('kt').transpose(), + data.v.metpy.convert_units('kt').transpose() + ) + + ax.invert_yaxis() + +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='Temperature (850hPa)') + ax.set_ylabel('Temperature [degC]') + ax.legend(loc='lower right') + +def _add_mslp(ax, data): + ax.plot(data.valid_time, data.prmsl.metpy.convert_units('hPa').transpose(), color='black', label='Temperature (2m)') + ax.set_ylabel('Mean Sea Level Pressure [hPa]') + +def _add_convective_clouds(ax, data): + # TODO: ADD HBAS_CON, HTOP_CON + # If none: -500m + ax.set_ylim(0, 14) + ax.set_ylabel('Convective Clouds Height [km]') + ax.bar(data.valid_time, alpha=0.5, + bottom=data.HBAS_CON.metpy.convert_units('km').transpose(), + height=(data.HTOP_CON.metpy.convert_units('km')-data.HBAS_CON.metpy.convert_units('km')).transpose(), + align='edge', width=np.timedelta64(3, 'h')) + +def _add_precip(ax, data): + ax.set_ylabel('Total precipitation [mm]') + ax.set_ylim(0, 30) + ax.bar(data.valid_time[:-1], data.tp.diff('step').transpose(), width=np.timedelta64(3, 'h'), + align='edge', alpha=0.7, color='green') + + ax_p = ax.twinx() + ax_p.set_ylabel('Snow depth [m]') + ax_p.set_ylim(bottom=0) + ax_p.plot(data.valid_time, data.sde.transpose(), color='blue') + +def _add_surface_wind(ax, data): + ax.plot(data.valid_time, mpcalc.wind_speed(data.u10.transpose(), data.v10.transpose()), color='black', label='Wind (10m)') + ax.plot(data.valid_time, data.fg10.transpose(), color='red', label='Gust (10m)') + + ax_b = ax.twinx() + ax_b.barbs( + data.valid_time, + [1 for _ in data.valid_time], + data.u10.metpy.convert_units('kt').transpose(), + data.v10.metpy.convert_units('kt').transpose() + ) + ax_b.axis('off') + + ax.set_ylabel('Wind Speed [m/s]') + ax.legend(loc='lower right') + +def _plot(data, output, name, lat, lon): + data = data.sel(latitude=lat, longitude = lon, method='nearest') + + fig = plt.figure(figsize=(12, 12), layout="constrained") + + sp_cnt, spec = _get_next_subplot(4) + ax = fig.add_subplot(HEIGHT,1,spec) + _add_cloudcov(ax, data) + + sp_cnt, spec2 = _get_next_subplot(2,sp_cnt) + ax2 = fig.add_subplot(HEIGHT,1,spec2,sharex=ax) + _add_temp_dewpoint(ax2, data) + + sp_cnt, spec3 = _get_next_subplot(2,sp_cnt) + ax3 = fig.add_subplot(HEIGHT,1,spec3,sharex=ax) + #ax3.legend(loc='lower right') + _add_mslp(ax3, data) + + ax4 = ax3.twinx() + _add_convective_clouds(ax4, data) + + sp_cnt, spec4 = _get_next_subplot(2,sp_cnt) + ax5 = fig.add_subplot(HEIGHT,1,spec4,sharex=ax) + _add_precip(ax5, data) + + sp_cnt, spec5 = _get_next_subplot(2,sp_cnt) + ax6 = fig.add_subplot(HEIGHT,1,spec5,sharex=ax) + _add_surface_wind(ax6, data) + + ### Info Lines + sp_cnt, spec5 = _get_next_subplot(1,sp_cnt) + ax_text = fig.add_subplot(HEIGHT, 1, spec5) + + info_lines = [] + init = misc.np_time_convert(data.time.values) + init_str = init.strftime('%d %b %Y - %HUTC') + init_for_filename = init.strftime('%Y-%m-%d-%HUTC') + + info_lines.append(f'{name}') + info_lines.append(f"INIT : {init_str}") + info_lines.append(f"LAT {lat} LON {lon}") + + if '_description' in data.attrs: + info_lines.append(data.attrs['_description']) + + ax_text.text(0, 0, '\n'.join(info_lines), ha='left', va='center', + size=10, fontfamily='monospace') + ax_text.axis("off") + + ### Output + + outname = f'{name}_{init_for_filename}.png' + plt.savefig(os.path.join(output, outname)) + plt.close('all') + + return ( + { + 'file': outname, + 'init': init_str, + 'valid': init_str, + 'valid_offset': '00', + 'display_name': name, + 'id': name + }) diff --git a/metchart/plotter/vertical_from_grib.py b/metchart/plotter/vertical_from_grib.py new file mode 100755 index 0000000..c632b0b --- /dev/null +++ b/metchart/plotter/vertical_from_grib.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +import os + +import datetime +import json + +import matplotlib.pyplot as plt + +import xarray as xr +from metpy.units import units +import metpy.calc as mpcalc +import numpy as np + +import skewt + +from . import misc + +config = { + 'source':'dwd_icon-eu/combined.grib2', + 'plots':[ + { + 'lat':47.9626, + 'lon':11.9964, + 'name':'Antersberg', + 'analysis':'lcl' + }, + ] +} + +def run(data, plots, output='.'): + misc.create_output_dir(output) + index = [] + + for plot in plots: + index.append(_plot(data, output, **plot)) + + return index + +def _plot(data, output, name, lat=None, lon=None, analysis=None): + for_temp = data[['r', 't', 'u', 'v']] + + if not (lat is None and lon is None): + for_temp = for_temp.sel(latitude=lat, longitude=lon, method='nearest') + + index = [] + + for step in for_temp.coords['step']: + this_step = for_temp.sel(step=step) + + p = this_step.coords['isobaricInhPa'].values * units.hPa + T = this_step.t.values * units.K + relHum = this_step.r.values * units.percent + Td = mpcalc.dewpoint_from_relative_humidity(T, relHum) + u = this_step.u.values * (units.m / units.s) + v = this_step.v.values * (units.m / units.s) + + valid = misc.np_time_convert(step.valid_time.values) + init = misc.np_time_convert(step.time.values) + + valid_str = valid.strftime('%d %b %Y - %HUTC') + init_str = init.strftime('%d %b %Y - %HUTC') + hours_since_init_str = str(int(this_step.step.values / np.timedelta64(1,'h'))).zfill(2) + + skt = skewt.Skewt(p=p, T=T, Td=Td) + skt.addWindUV(u, v) + skt.addInfo(f'{name} INIT+' + hours_since_init_str) + skt.addInfo(f"VALID: {valid_str}") + skt.addInfo(f"INIT : {init_str}") + skt.addInfo(f"LAT {lat} LON {lon}") + + if analysis is not None: + skt.addAnalysis(shade=True, analysis=analysis) + + if '_description' in data.attrs: + skt.addInfo(data.attrs['_description']) + + init_for_filename = init.strftime('%Y-%m-%d-%HUTC') + + outname = f'skewt_{name}_{init_for_filename}+{hours_since_init_str}.png' + skt.plot(filename=os.path.join(output, outname)) + + plt.close('all') + + index.append( + { + 'file': outname, + 'init': init_str, + 'valid': valid_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', 'list_title': 'Location'} + +if __name__ == '__main__': + run(**config) diff --git a/metchart/run.py b/metchart/run.py new file mode 100755 index 0000000..17a0a97 --- /dev/null +++ b/metchart/run.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 + +import sys +import yaml +import json +import matplotlib.pyplot as plt +import matplotlib as mpl +from matplotlib.colors import LinearSegmentedColormap + +from metpy.units import units + +def create_aggregators(cfg): + ret = {} + for aggregator in cfg: + aggconf = cfg[aggregator] + classname = aggconf['module'] + del aggconf['module'] + + module = __import__(classname, fromlist=[None]) + + ret[aggregator] = module.load_data(name=aggregator, **aggconf) + + return ret + +def create_modifiers(aggregators, cfg): + # naming is scuffed + ret = {} + for modifier in cfg: + mod = cfg[modifier] + modname = mod['module'] + del mod['module'] + + if 'aggregator' in mod: + if type(mod['aggregator']) == list: + mod['data'] = [] + for ag in mod['aggregator']: + mod['data'].append(aggregators[ag]) + + del mod['aggregator'] + else: + mod['data'] = aggregators[mod['aggregator']] + del mod['aggregator'] + + pymod = __import__(modname, fromlist=[None]) + ret[modifier] = pymod.run(**mod) + + return ret + +def main(): + mpl.use('agg') + + # Define custom gpm and gpdm units. The default gpm in metpy is aliased to meter. + # We need the correct definition + units.define('_gpm = 9.80665 * J/kg') + units.define('_gpdm = 10 * _gpm') + + # Define custom colormap + clcov_cmap = { + 'red': ( + (0.0, 0.0, 0.0), + (0.1, 0.9, 0.9), + (1.0, 0.3, 0.3), + ), + 'green': ( + (0.0, 0.5, 0.5), + (0.1, 0.9, 0.9), + (1.0, 0.3, 0.3), + ), + 'blue': ( + (0.0, 0.9, 0.9), + (0.1, 0.9, 0.9), + (1.0, 0.3, 0.3), + ), + } + + mpl.colormaps.register(LinearSegmentedColormap('clcov', clcov_cmap)) + + FILE = 'config.yaml' + if len(sys.argv) > 1: + FILE = sys.argv[1] + + conf = None + with open(FILE, 'r') as f: + conf = yaml.safe_load(f) + + aggregators = create_aggregators(conf['aggregator']) + + if 'modifier' in conf: + aggregators.update(create_modifiers(aggregators, conf['modifier'])) + + index = [] + + for plotter in conf['plotter']: + modname = plotter['module'] + del plotter['module'] + + if 'aggregator' in plotter: + plotter['data'] = aggregators[plotter['aggregator']] + del plotter['aggregator'] + + mod = __import__(modname, fromlist=[None]) + index.extend(mod.run(**plotter)) + + plt.close('all') + + with open(conf['index'], 'w') as f: + f.write(json.dumps(index, indent=4)) + +if __name__ == '__main__': + main() diff --git a/metchart/skewt.py b/metchart/skewt.py new file mode 100644 index 0000000..e674d09 --- /dev/null +++ b/metchart/skewt.py @@ -0,0 +1,118 @@ +import matplotlib.gridspec as gridspec +import matplotlib.pyplot as plt + +import numpy as np + +import metpy.calc as mpcalc +from metpy.cbook import get_test_data +from metpy.plots import add_metpy_logo, Hodograph, SkewT +from metpy.units import units + +class Skewt: + def __init__(self, p, T, Td, max_barbs=20, title=None): + self._p = p + self._T = T + self._Td = Td + + self._info_lines = [] + + self.barb_div = int(max(len(p)/max_barbs,1)) + + + # Create a new figure. The dimensions here give a good aspect ratio + self._fig = plt.figure(figsize=(9, 9)) + plt.rcParams["font.family"] = "monospace" + #self._fig = plt.figure() + + if title is not None: + plt.suptitle(title, x=0, y=0, va='bottom', ha='left') + + # Grid for plots + self._gs = gridspec.GridSpec(3, 3) + self._skew = SkewT(self._fig, rotation=45, subplot=self._gs[:, :2]) + + # Plot the data using normal plotting functions, in this case using + # log scaling in Y, as dictated by the typical meteorological plot + self._skew.plot(p, T, 'r') + self._skew.plot(p, Td, 'b') + + plt.xlabel('$T$ $[^o C]$') + plt.ylabel('$p$ $[hPa]$') + + def addWindUV(self, u, v): + self._u = u + self._v = v + + ax = self._fig.add_subplot(self._gs[0, -1]) + h = Hodograph(ax, component_range=max(u + v).magnitude) + h.add_grid(increment=20) + h.plot_colormapped(u, v, self._p) + plt.tight_layout() + plt.xlabel('$m/s$') + plt.ylabel('$m/s$') + + self._skew.plot_barbs(self._p[::self.barb_div], u[::self.barb_div], v[::self.barb_div]) + + def addInfo(self, line): + self._info_lines.append(line) + + def addAnalysis(self, analysis='ccl', shade=False): + f = {'ccl': self._cclAnalysis, 'lcl': self._lclAnalysis} + + lvl, parcel = f[analysis]() + + self._skew.plot(self._p, parcel, 'y') + self._skew.plot(lvl[0], lvl[1], 'o', markerfacecolor='red', linewidth=1) + + # TODO why exception on cape_cin()? + # ValueError: zero-size array to reduction operation minimum which has no identity + # https://github.com/Unidata/MetPy/pull/3132 + try: + cape, cin = mpcalc.cape_cin(self._p, self._T, self._Td, parcel, which_el='top') + self.addInfo(f'CAPE {int(cape.magnitude)} $J/kg$ CIN {int(cin.magnitude)} $J/kg$') + except ValueError: + print('CAPE/CIN Failed with ValueError') + self.addInfo('CAPE #### CIN ####') + + if shade: + self._skew.shade_cape(self._p,self._T,parcel) + self._skew.shade_cin(self._p,self._T,parcel) + + def _cclAnalysis(self): + #p = np.arange(max(self._p).magnitude, min(self._p).magnitude, -50) * units.hPa + + ccl = mpcalc.ccl(self._p,self._T,self._Td) + ccl_ground=mpcalc.dry_lapse(self._p[:1], ccl[1], ccl[0]) + ccl_ground_parcel= mpcalc.parcel_profile(self._p, ccl_ground[0], self._Td[0]) + + return (ccl, ccl_ground_parcel) + + def _lclAnalysis(self): + ground_parcel= mpcalc.parcel_profile(self._p, self._T[0], self._Td[0]) + lcl = mpcalc.lcl(self._p[0],self._T[0],self._Td[0]) + + return (lcl, ground_parcel) + + def _buildInfoBox(self): + ax = self._fig.add_subplot(self._gs[1,-1]) + ax.text(0, 0, '\n'.join(self._info_lines), ha='left', va='center', + size=10, fontfamily='monospace') + ax.axis("off") + + def plot(self, filename=None): + self._buildInfoBox() + + # Add the relevant special lines + #self._skew.ax.set_ylim(max(self._p), min(self._p)) + self._skew.ax.set_ylim(1000, 100) + self._skew.plot_dry_adiabats(linewidth=1) + self._skew.plot_moist_adiabats(linewidth=1) + self._skew.plot_mixing_lines(linewidth=1) + + # Good bounds for aspect ratio + self._skew.ax.set_xlim(-30, 40) + + if filename is not None: + plt.savefig(filename) + else: + plt.show() diff --git a/misc.py b/misc.py deleted file mode 100644 index 6594d0f..0000000 --- a/misc.py +++ /dev/null @@ -1,23 +0,0 @@ -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') - diff --git a/modifier/__init__.py b/modifier/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/modifier/merge.py b/modifier/merge.py deleted file mode 100644 index 692287d..0000000 --- a/modifier/merge.py +++ /dev/null @@ -1,4 +0,0 @@ -import xarray as xr - -def run(data): - return xr.merge(data) diff --git a/plotter/__init__.py b/plotter/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/plotter/debug_data.py b/plotter/debug_data.py deleted file mode 100644 index 560d13c..0000000 --- a/plotter/debug_data.py +++ /dev/null @@ -1,4 +0,0 @@ -def run(data, **kwargs): - print(data) - - return [] diff --git a/plotter/horizontal.py b/plotter/horizontal.py deleted file mode 100755 index 218fd33..0000000 --- a/plotter/horizontal.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env python3 -import os -import json - -import xarray as xr - -import numpy as np -import matplotlib.pyplot as plt -from metpy.plots import MapPanel, PanelContainer, RasterPlot, ContourPlot - -import misc - -config = { - 'source': 'dwd_icon-eu/combined.grib2', - 'plots': [ - { - 'name':'r_t-750', - 'area': None, - 'layers': [ - { - 'layertype': 'raster', - 'field': 'r', - 'level': 750, - }, - { - 'layertype': 'contour', - 'field': 't', - 'level': 750, - 'contours': 5, - 'clabels': True - }, - ] - }, - ] -} - -def run(data, plots, output='.'): - misc.create_output_dir(output) - index = [] - - for plot in plots: - index.append(_plot(data, output, **plot)) - - return index - -def _plot(data, output, name, layers, area = None): - index = [] - - for step in data.coords['step']: - this_step = data.sel(step=step) - - map_layers = [] - - for layer in layers: - map_layers.append(_layer(this_step, **layer)) - - valid = misc.np_time_convert(step.valid_time.values) - init = misc.np_time_convert(step.time.values) - - valid_str = valid.strftime('%d %b %Y - %HUTC') - init_str = init.strftime('%d %b %Y - %HUTC') - hours_since_init_str = str(int(this_step.step.values / np.timedelta64(1,'h'))).zfill(2) - init_for_filename = init.strftime('%Y-%m-%d-%HUTC') - - panel = MapPanel() - if area is not None: - panel.area = area - panel.projection = 'mer' - panel.layers = ['coastline', 'borders'] - panel.plots = map_layers - panel.left_title = f'{name} VALID: {valid_str} (INIT +{hours_since_init_str}) INIT: {init_str}' - if '_description' in data.attrs: - panel.right_title = data.attrs['_description'] - - pc = PanelContainer() - pc.size = (12.8, 9.6) - #pc.figure.layout='constrained' - pc.panels = [panel] - pc.draw() - #pc.show() - outname = f'{name}_{init_for_filename}+{hours_since_init_str}.png' - pc.save(os.path.join(output, outname)) - plt.close('all') - - index.append( - { - 'file': outname, - 'init': init_str, - 'valid': valid_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', 'list_title': 'INIT+' } - -def _layer(data, layertype, **kwargs): - layertypes={ - 'raster': { - 'obj': RasterPlot, - 'defaults': { - 'colorbar': 'vertical', - } - }, - 'contour': { - 'obj': ContourPlot, - 'defaults': {} - } - } - - args = layertypes[layertype]['defaults'] | kwargs - - ret = layertypes[layertype]['obj'](**args) - ret.data = data - - return ret - -if __name__ == '__main__': - run(**config) diff --git a/plotter/meteogram.py b/plotter/meteogram.py deleted file mode 100755 index 724e9b2..0000000 --- a/plotter/meteogram.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env python3 -import os -import json - -import numpy as np - -import matplotlib.pyplot as plt - -import metpy.calc as mpcalc - -import misc - -HEIGHT = 13 - -def run(data, plots, output='.', name='meteogram'): - misc.create_output_dir(output) - index = [] - - for plot in plots: - index.append(_plot(data, output, **plot)) - - 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) - counter += size - return counter, ret - -def _add_cloudcov(ax, data): - ax.set_ylabel('Pressure level [hPa]') - - clc = ax.contourf(data.valid_time, data.isobaricInhPa, data.ccl.transpose(), cmap='clcov', vmin=0, vmax=100, levels=9) - - # use Format parameter for n/8 - plt.colorbar(clc, label='cloudcov', extendfrac=None, ticks=[100*n/8 for n in range(9)], format=lambda x,_: f'{int(x/12.5)}/8', pad=0.0, fraction=0.015) - - cf = ax.contour(data.valid_time, data.isobaricInhPa, data.t.metpy.convert_units('degC').transpose()) - ax.clabel(cf, inline=True, fontsize=10) - - ax.barbs( - data.valid_time, - data.isobaricInhPa, - data.u.metpy.convert_units('kt').transpose(), - data.v.metpy.convert_units('kt').transpose() - ) - - ax.invert_yaxis() - -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='Temperature (850hPa)') - ax.set_ylabel('Temperature [degC]') - ax.legend(loc='lower right') - -def _add_mslp(ax, data): - ax.plot(data.valid_time, data.prmsl.metpy.convert_units('hPa').transpose(), color='black', label='Temperature (2m)') - ax.set_ylabel('Mean Sea Level Pressure [hPa]') - -def _add_convective_clouds(ax, data): - # TODO: ADD HBAS_CON, HTOP_CON - # If none: -500m - ax.set_ylim(0, 14) - ax.set_ylabel('Convective Clouds Height [km]') - ax.bar(data.valid_time, alpha=0.5, - bottom=data.HBAS_CON.metpy.convert_units('km').transpose(), - height=(data.hcct.metpy.convert_units('km')-data.HBAS_CON.metpy.convert_units('km')).transpose(), - align='edge', width=np.timedelta64(3, 'h')) - -def _add_precip(ax, data): - ax.set_ylabel('Total precipitation [mm]') - ax.set_ylim(0, 30) - ax.bar(data.valid_time[:-1], data.tp.diff('step').transpose(), width=np.timedelta64(3, 'h'), - align='edge', alpha=0.7, color='green') - - ax_p = ax.twinx() - ax_p.set_ylabel('Snow depth [m]') - ax_p.set_ylim(bottom=0) - ax_p.plot(data.valid_time, data.sde.transpose(), color='blue') - -def _add_surface_wind(ax, data): - ax.plot(data.valid_time, mpcalc.wind_speed(data.u10.transpose(), data.v10.transpose()), color='black', label='Wind (10m)') - ax.plot(data.valid_time, data.fg10.transpose(), color='red', label='Gust (10m)') - - ax_b = ax.twinx() - ax_b.barbs( - data.valid_time, - [1 for _ in data.valid_time], - data.u10.metpy.convert_units('kt').transpose(), - data.v10.metpy.convert_units('kt').transpose() - ) - ax_b.axis('off') - - ax.set_ylabel('Wind Speed [m/s]') - ax.legend(loc='lower right') - -def _plot(data, output, name, lat, lon): - data = data.sel(latitude=lat, longitude = lon, method='nearest') - - fig = plt.figure(figsize=(12, 12), layout="constrained") - - sp_cnt, spec = _get_next_subplot(4) - ax = fig.add_subplot(HEIGHT,1,spec) - _add_cloudcov(ax, data) - - sp_cnt, spec2 = _get_next_subplot(2,sp_cnt) - ax2 = fig.add_subplot(HEIGHT,1,spec2,sharex=ax) - _add_temp_dewpoint(ax2, data) - - sp_cnt, spec3 = _get_next_subplot(2,sp_cnt) - ax3 = fig.add_subplot(HEIGHT,1,spec3,sharex=ax) - #ax3.legend(loc='lower right') - _add_mslp(ax3, data) - - ax4 = ax3.twinx() - _add_convective_clouds(ax4, data) - - sp_cnt, spec4 = _get_next_subplot(2,sp_cnt) - ax5 = fig.add_subplot(HEIGHT,1,spec4,sharex=ax) - _add_precip(ax5, data) - - sp_cnt, spec5 = _get_next_subplot(2,sp_cnt) - ax6 = fig.add_subplot(HEIGHT,1,spec5,sharex=ax) - _add_surface_wind(ax6, data) - - ### Info Lines - sp_cnt, spec5 = _get_next_subplot(1,sp_cnt) - ax_text = fig.add_subplot(HEIGHT, 1, spec5) - - info_lines = [] - init = misc.np_time_convert(data.time.values) - init_str = init.strftime('%d %b %Y - %HUTC') - init_for_filename = init.strftime('%Y-%m-%d-%HUTC') - - info_lines.append(f'{name}') - info_lines.append(f"INIT : {init_str}") - info_lines.append(f"LAT {lat} LON {lon}") - - if '_description' in data.attrs: - info_lines.append(data.attrs['_description']) - - ax_text.text(0, 0, '\n'.join(info_lines), ha='left', va='center', - size=10, fontfamily='monospace') - ax_text.axis("off") - - ### Output - - outname = f'{name}_{init_for_filename}.png' - plt.savefig(os.path.join(output, outname)) - plt.close('all') - - return ( - { - 'file': outname, - 'init': init_str, - 'valid': init_str, - 'valid_offset': '00', - 'display_name': name, - 'id': name - }) diff --git a/plotter/vertical_from_grib.py b/plotter/vertical_from_grib.py deleted file mode 100755 index 8e4fd60..0000000 --- a/plotter/vertical_from_grib.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python3 -import os - -import datetime -import json - -import matplotlib.pyplot as plt - -import xarray as xr -from metpy.units import units -import metpy.calc as mpcalc -import numpy as np - -import skewt - -import misc - -config = { - 'source':'dwd_icon-eu/combined.grib2', - 'plots':[ - { - 'lat':47.9626, - 'lon':11.9964, - 'name':'Antersberg', - 'analysis':'lcl' - }, - ] -} - -def run(data, plots, output='.'): - misc.create_output_dir(output) - index = [] - - for plot in plots: - index.append(_plot(data, output, **plot)) - - return index - -def _plot(data, output, name, lat=None, lon=None, analysis=None): - for_temp = data[['r', 't', 'u', 'v']] - - if not (lat is None and lon is None): - for_temp = for_temp.sel(latitude=lat, longitude=lon, method='nearest') - - index = [] - - for step in for_temp.coords['step']: - this_step = for_temp.sel(step=step) - - p = this_step.coords['isobaricInhPa'].values * units.hPa - T = this_step.t.values * units.K - relHum = this_step.r.values * units.percent - Td = mpcalc.dewpoint_from_relative_humidity(T, relHum) - u = this_step.u.values * (units.m / units.s) - v = this_step.v.values * (units.m / units.s) - - valid = misc.np_time_convert(step.valid_time.values) - init = misc.np_time_convert(step.time.values) - - valid_str = valid.strftime('%d %b %Y - %HUTC') - init_str = init.strftime('%d %b %Y - %HUTC') - hours_since_init_str = str(int(this_step.step.values / np.timedelta64(1,'h'))).zfill(2) - - skt = skewt.Skewt(p=p, T=T, Td=Td) - skt.addWindUV(u, v) - skt.addInfo(f'{name} INIT+' + hours_since_init_str) - skt.addInfo(f"VALID: {valid_str}") - skt.addInfo(f"INIT : {init_str}") - skt.addInfo(f"LAT {lat} LON {lon}") - - if analysis is not None: - skt.addAnalysis(shade=True, analysis=analysis) - - if '_description' in data.attrs: - skt.addInfo(data.attrs['_description']) - - init_for_filename = init.strftime('%Y-%m-%d-%HUTC') - - outname = f'skewt_{name}_{init_for_filename}+{hours_since_init_str}.png' - skt.plot(filename=os.path.join(output, outname)) - - plt.close('all') - - index.append( - { - 'file': outname, - 'init': init_str, - 'valid': valid_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', 'list_title': 'Location'} - -if __name__ == '__main__': - run(**config) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..53cd3e7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[project] +name = "metchart" +version = "0.0.1" +dependencies = [ + "metpy", + "xarray", + "cfgrib", + "pyyaml", + "cartopy" +] +description = "declarative weather chart plotter" +readme = "Readme.md" + +[project.scripts] +metchart = "metchart.run:main" + +[tool.setuptools.packages.find] +include = [ + "metchart" +] + +[build-system] +requires = ['setuptools >= 61.0'] +build-backend = "setuptools.build_meta" diff --git a/run.py b/run.py deleted file mode 100755 index 28362d9..0000000 --- a/run.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import yaml -import json -import matplotlib.pyplot as plt -import matplotlib as mpl -from matplotlib.colors import LinearSegmentedColormap - -from metpy.units import units - -def create_aggregators(cfg): - ret = {} - for aggregator in cfg: - aggconf = cfg[aggregator] - classname = aggconf['module'] - del aggconf['module'] - - module = __import__(classname, fromlist=[None]) - - ret[aggregator] = module.load_data(name=aggregator, **aggconf) - - return ret - -def create_modifiers(aggregators, cfg): - # naming is scuffed - ret = {} - for modifier in cfg: - mod = cfg[modifier] - modname = mod['module'] - del mod['module'] - - if 'aggregator' in mod: - if type(mod['aggregator']) == list: - mod['data'] = [] - for ag in mod['aggregator']: - mod['data'].append(aggregators[ag]) - - del mod['aggregator'] - else: - mod['data'] = aggregators[mod['aggregator']] - del mod['aggregator'] - - pymod = __import__(modname, fromlist=[None]) - ret[modifier] = pymod.run(**mod) - - return ret - -mpl.use('agg') - -# Define custom gpm and gpdm units. The default gpm in metpy is aliased to meter. -# We need the correct definition -units.define('_gpm = 9.80665 * J/kg') -units.define('_gpdm = 10 * _gpm') - -# Define custom colormap -clcov_cmap = { - 'red': ( - (0.0, 0.0, 0.0), - (0.1, 0.9, 0.9), - (1.0, 0.3, 0.3), - ), - 'green': ( - (0.0, 0.5, 0.5), - (0.1, 0.9, 0.9), - (1.0, 0.3, 0.3), - ), - 'blue': ( - (0.0, 0.9, 0.9), - (0.1, 0.9, 0.9), - (1.0, 0.3, 0.3), - ), -} - -mpl.colormaps.register(LinearSegmentedColormap('clcov', clcov_cmap)) - -FILE = 'config.yaml' -if len(sys.argv) > 1: - FILE = sys.argv[1] - -conf = None -with open(FILE, 'r') as f: - conf = yaml.safe_load(f) - -aggregators = create_aggregators(conf['aggregator']) - -if 'modifier' in conf: - aggregators.update(create_modifiers(aggregators, conf['modifier'])) - -index = [] - -for plotter in conf['plotter']: - modname = plotter['module'] - del plotter['module'] - - if 'aggregator' in plotter: - plotter['data'] = aggregators[plotter['aggregator']] - del plotter['aggregator'] - - mod = __import__(modname, fromlist=[None]) - index.extend(mod.run(**plotter)) - - plt.close('all') - -with open(conf['index'], 'w') as f: - f.write(json.dumps(index, indent=4)) diff --git a/skewt.py b/skewt.py deleted file mode 100644 index e674d09..0000000 --- a/skewt.py +++ /dev/null @@ -1,118 +0,0 @@ -import matplotlib.gridspec as gridspec -import matplotlib.pyplot as plt - -import numpy as np - -import metpy.calc as mpcalc -from metpy.cbook import get_test_data -from metpy.plots import add_metpy_logo, Hodograph, SkewT -from metpy.units import units - -class Skewt: - def __init__(self, p, T, Td, max_barbs=20, title=None): - self._p = p - self._T = T - self._Td = Td - - self._info_lines = [] - - self.barb_div = int(max(len(p)/max_barbs,1)) - - - # Create a new figure. The dimensions here give a good aspect ratio - self._fig = plt.figure(figsize=(9, 9)) - plt.rcParams["font.family"] = "monospace" - #self._fig = plt.figure() - - if title is not None: - plt.suptitle(title, x=0, y=0, va='bottom', ha='left') - - # Grid for plots - self._gs = gridspec.GridSpec(3, 3) - self._skew = SkewT(self._fig, rotation=45, subplot=self._gs[:, :2]) - - # Plot the data using normal plotting functions, in this case using - # log scaling in Y, as dictated by the typical meteorological plot - self._skew.plot(p, T, 'r') - self._skew.plot(p, Td, 'b') - - plt.xlabel('$T$ $[^o C]$') - plt.ylabel('$p$ $[hPa]$') - - def addWindUV(self, u, v): - self._u = u - self._v = v - - ax = self._fig.add_subplot(self._gs[0, -1]) - h = Hodograph(ax, component_range=max(u + v).magnitude) - h.add_grid(increment=20) - h.plot_colormapped(u, v, self._p) - plt.tight_layout() - plt.xlabel('$m/s$') - plt.ylabel('$m/s$') - - self._skew.plot_barbs(self._p[::self.barb_div], u[::self.barb_div], v[::self.barb_div]) - - def addInfo(self, line): - self._info_lines.append(line) - - def addAnalysis(self, analysis='ccl', shade=False): - f = {'ccl': self._cclAnalysis, 'lcl': self._lclAnalysis} - - lvl, parcel = f[analysis]() - - self._skew.plot(self._p, parcel, 'y') - self._skew.plot(lvl[0], lvl[1], 'o', markerfacecolor='red', linewidth=1) - - # TODO why exception on cape_cin()? - # ValueError: zero-size array to reduction operation minimum which has no identity - # https://github.com/Unidata/MetPy/pull/3132 - try: - cape, cin = mpcalc.cape_cin(self._p, self._T, self._Td, parcel, which_el='top') - self.addInfo(f'CAPE {int(cape.magnitude)} $J/kg$ CIN {int(cin.magnitude)} $J/kg$') - except ValueError: - print('CAPE/CIN Failed with ValueError') - self.addInfo('CAPE #### CIN ####') - - if shade: - self._skew.shade_cape(self._p,self._T,parcel) - self._skew.shade_cin(self._p,self._T,parcel) - - def _cclAnalysis(self): - #p = np.arange(max(self._p).magnitude, min(self._p).magnitude, -50) * units.hPa - - ccl = mpcalc.ccl(self._p,self._T,self._Td) - ccl_ground=mpcalc.dry_lapse(self._p[:1], ccl[1], ccl[0]) - ccl_ground_parcel= mpcalc.parcel_profile(self._p, ccl_ground[0], self._Td[0]) - - return (ccl, ccl_ground_parcel) - - def _lclAnalysis(self): - ground_parcel= mpcalc.parcel_profile(self._p, self._T[0], self._Td[0]) - lcl = mpcalc.lcl(self._p[0],self._T[0],self._Td[0]) - - return (lcl, ground_parcel) - - def _buildInfoBox(self): - ax = self._fig.add_subplot(self._gs[1,-1]) - ax.text(0, 0, '\n'.join(self._info_lines), ha='left', va='center', - size=10, fontfamily='monospace') - ax.axis("off") - - def plot(self, filename=None): - self._buildInfoBox() - - # Add the relevant special lines - #self._skew.ax.set_ylim(max(self._p), min(self._p)) - self._skew.ax.set_ylim(1000, 100) - self._skew.plot_dry_adiabats(linewidth=1) - self._skew.plot_moist_adiabats(linewidth=1) - self._skew.plot_mixing_lines(linewidth=1) - - # Good bounds for aspect ratio - self._skew.ax.set_xlim(-30, 40) - - if filename is not None: - plt.savefig(filename) - else: - plt.show() -- cgit v1.2.3 From 24c55cae5bef64a98cc30917d548d2ee703d876d Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 14 Oct 2024 02:26:19 +0200 Subject: gitignore --- .gitignore | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/.gitignore b/.gitignore index 77f7ec4..d753af1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,142 @@ __pycache__ *.png *.idx web/data/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ -- cgit v1.2.3 From 32863e21fa16e949fc20c4588e84b90916265367 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 14 Oct 2024 02:34:11 +0200 Subject: structure cleanup --- config.yaml | 136 --------------------------------------------------- examples/config.yaml | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 1 + requirements.txt | 5 -- testsetup.sh | 6 +++ 5 files changed, 143 insertions(+), 141 deletions(-) delete mode 100644 config.yaml create mode 100644 examples/config.yaml delete mode 100644 requirements.txt create mode 100644 testsetup.sh diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 4f2a23b..0000000 --- a/config.yaml +++ /dev/null @@ -1,136 +0,0 @@ ---- -index: web/data/index.json -aggregator: - icon_eu_other: - module: aggregator.dwd_icon - output: dwd_icon_cache - model: icon-eu - model_long: icon-eu_europe - parameter_caps_in_filename: true - pressure_level_parameters: - - t - - relhum - - u - - v - - fi - - clc - single_level_parameters: - - pmsl - - t_2m - - relhum_2m - - hbas_con - - htop_con - - htop_dc - - tot_prec - - h_snow - pressure_levels: [1000, 950, 925, 900, 875, 850, 825, 800, 775, 700, 600, 500, 400, 300, 250, 200, 150, 100] - steps: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72] - description: FORECAST DWD ICON-EU - icon_eu_10m_params: - module: aggregator.dwd_icon - output: dwd_icon_cache - model: icon-eu - model_long: icon-eu_europe - parameter_caps_in_filename: true - pressure_level_parameters: [] - single_level_parameters: - - u_10m - - v_10m - - vmax_10m - pressure_levels: [1000, 950, 925, 900, 875, 850, 825, 800, 775, 700, 600, 500, 400, 300, 250, 200, 150, 100] - steps: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72] - description: FORECAST DWD ICON-EU -modifier: - icon_eu: - module: modifier.merge - aggregator: - - icon_eu_other - - icon_eu_10m_params -plotter: - - module: plotter.meteogram - aggregator: icon_eu - output: web/data - plots: - - name: meteogram_antersberg - lat: 47.96 - lon: 11.99 - - name: meteogram_munich - lat: 48.16 - lon: 11.57 - - - module: 'plotter.vertical_from_grib' - aggregator: icon_eu - output: web/data - plots: - - lat: 47.96 - lon: 11.99 - name: skewt_antersberg - analysis: lcl - - lat: 11.57 - lon: 48.16 - name: skewt_munich - analysis: lcl - - module: 'plotter.horizontal' - aggregator: icon_eu - output: web/data - plots: - - name: dry_con_top - area: null - layers: - - layertype: raster - field: HTOP_DC - - name: t_fi_850 - area: null - layers: - - layertype: raster - field: t - level: 850 - plot_units: degC - colormap: jet - - layertype: contour - field: z - level: 850 - plot_units: '_gpdm' - contours: 5 - clabels: true - - name: t_fi_500 - area: null - layers: - - layertype: raster - field: t - level: 500 - plot_units: degC - colormap: jet - - layertype: contour - field: z - level: 500 - plot_units: '_gpdm' - contours: 5 - clabels: true - - name: t_fi_200 - area: null - layers: - - layertype: raster - field: t - level: 200 - plot_units: degC - colormap: jet - - layertype: contour - field: z - level: 200 - plot_units: '_gpdm' - contours: 5 - clabels: true - - name: pmsl_t850 - area: null - layers: - - layertype: raster - field: t - level: 850 - plot_units: degC - colormap: jet - - layertype: contour - field: prmsl - plot_units: 'hPa' - contours: 10 - clabels: true diff --git a/examples/config.yaml b/examples/config.yaml new file mode 100644 index 0000000..4f2a23b --- /dev/null +++ b/examples/config.yaml @@ -0,0 +1,136 @@ +--- +index: web/data/index.json +aggregator: + icon_eu_other: + module: aggregator.dwd_icon + output: dwd_icon_cache + model: icon-eu + model_long: icon-eu_europe + parameter_caps_in_filename: true + pressure_level_parameters: + - t + - relhum + - u + - v + - fi + - clc + single_level_parameters: + - pmsl + - t_2m + - relhum_2m + - hbas_con + - htop_con + - htop_dc + - tot_prec + - h_snow + pressure_levels: [1000, 950, 925, 900, 875, 850, 825, 800, 775, 700, 600, 500, 400, 300, 250, 200, 150, 100] + steps: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72] + description: FORECAST DWD ICON-EU + icon_eu_10m_params: + module: aggregator.dwd_icon + output: dwd_icon_cache + model: icon-eu + model_long: icon-eu_europe + parameter_caps_in_filename: true + pressure_level_parameters: [] + single_level_parameters: + - u_10m + - v_10m + - vmax_10m + pressure_levels: [1000, 950, 925, 900, 875, 850, 825, 800, 775, 700, 600, 500, 400, 300, 250, 200, 150, 100] + steps: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72] + description: FORECAST DWD ICON-EU +modifier: + icon_eu: + module: modifier.merge + aggregator: + - icon_eu_other + - icon_eu_10m_params +plotter: + - module: plotter.meteogram + aggregator: icon_eu + output: web/data + plots: + - name: meteogram_antersberg + lat: 47.96 + lon: 11.99 + - name: meteogram_munich + lat: 48.16 + lon: 11.57 + + - module: 'plotter.vertical_from_grib' + aggregator: icon_eu + output: web/data + plots: + - lat: 47.96 + lon: 11.99 + name: skewt_antersberg + analysis: lcl + - lat: 11.57 + lon: 48.16 + name: skewt_munich + analysis: lcl + - module: 'plotter.horizontal' + aggregator: icon_eu + output: web/data + plots: + - name: dry_con_top + area: null + layers: + - layertype: raster + field: HTOP_DC + - name: t_fi_850 + area: null + layers: + - layertype: raster + field: t + level: 850 + plot_units: degC + colormap: jet + - layertype: contour + field: z + level: 850 + plot_units: '_gpdm' + contours: 5 + clabels: true + - name: t_fi_500 + area: null + layers: + - layertype: raster + field: t + level: 500 + plot_units: degC + colormap: jet + - layertype: contour + field: z + level: 500 + plot_units: '_gpdm' + contours: 5 + clabels: true + - name: t_fi_200 + area: null + layers: + - layertype: raster + field: t + level: 200 + plot_units: degC + colormap: jet + - layertype: contour + field: z + level: 200 + plot_units: '_gpdm' + contours: 5 + clabels: true + - name: pmsl_t850 + area: null + layers: + - layertype: raster + field: t + level: 850 + plot_units: degC + colormap: jet + - layertype: contour + field: prmsl + plot_units: 'hPa' + contours: 10 + clabels: true diff --git a/pyproject.toml b/pyproject.toml index 53cd3e7..3dbfe5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ dependencies = [ ] description = "declarative weather chart plotter" readme = "Readme.md" +license = {"file" = "LICENSE"} [project.scripts] metchart = "metchart.run:main" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 5b491b3..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -metpy -xarray -cfgrib -pyyaml -cartopy diff --git a/testsetup.sh b/testsetup.sh new file mode 100644 index 0000000..abe19dc --- /dev/null +++ b/testsetup.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +[ ! -f venv/bin/activate ] && python -m virtualenv venv +source venv/bin/activate + +pip install -e . -- cgit v1.2.3