diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2023-11-07 00:02:48 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2023-11-07 00:02:48 +0100 |
commit | 6eb5ee144d5e730616f13d3d14129f0205282d90 (patch) | |
tree | df13306ef7e0ca43d07b7529b246501f75ad50d8 /run.py | |
parent | d5bf2513c2cff126b9f37290caf6fe8ad30e6d66 (diff) | |
download | meteo_toolbox-6eb5ee144d5e730616f13d3d14129f0205282d90.tar.gz |
aggregator refactor
Diffstat (limited to 'run.py')
-rwxr-xr-x | run.py | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -9,6 +9,20 @@ 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'] + + ret[aggregator] = {} + ret[aggregator]['module'] = __import__(classname, fromlist=[None]) + ret[aggregator]['config'] = aggconf + ret[aggregator]['config']['name'] = aggregator + + return ret + # 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') @@ -43,6 +57,8 @@ conf = None with open(FILE, 'r') as f: conf = yaml.safe_load(f) +aggregators = create_aggregators(conf['aggregator']) + index = [] for plotter in conf['plotter']: @@ -50,17 +66,9 @@ for plotter in conf['plotter']: del plotter['module'] if 'aggregator' in plotter: - aggname = plotter['aggregator'] + agg = aggregators[plotter['aggregator']] + plotter['data'] = agg['module'].load_data(**agg['config']) del plotter['aggregator'] - aggconf = conf['aggregator'][aggname] - classname = aggconf['module'] - # We should prbly not delete it like in the plotter, since it is not a deepcopy - # and may be used again. - - agg = __import__(classname, fromlist=[None]) - - # TODO: figure out a way to use **aggconf instead. - plotter['data'] = agg.load_data(aggname, aggconf) mod = __import__(modname, fromlist=[None]) index.extend(mod.run(**plotter)) |