diff --git a/post_process/animate/__main__.py b/post_process/animate/__main__.py index 852785d..37e5726 100644 --- a/post_process/animate/__main__.py +++ b/post_process/animate/__main__.py @@ -5,12 +5,13 @@ parser = argparse.ArgumentParser( ) parser.add_argument('var', type=str, help='OpenFoam variable to display') -parser.add_argument('-c', '--config', type=str, - default='config.ini', - help='Configuration file (default config.ini)') +parser.add_argument('-c', '--config', type=Path, default='config.ini', + help='configuration file (default config.ini)') +parser.add_argument('-l', '--log-level', default='info', type=str, + help='log level') args = parser.parse_args() if args.var == 'alpha.water': import alpha_water - alpha_water.animate(args.config) + alpha_water.animate(args.config, args.log_level) diff --git a/post_process/animate/alpha_water.py b/post_process/animate/alpha_water.py index 85da6ee..1870957 100644 --- a/post_process/animate/alpha_water.py +++ b/post_process/animate/alpha_water.py @@ -19,19 +19,21 @@ import pandas as pd mpl.use('agg') import fluidfoam -#import stl -def animate(config_path): +def animate(config_path, log_level): tt0 = time() config = configparser.ConfigParser() config.read(config_path) + logging.basicConfig( + filename=config.get('main', 'log_file', fallback=None), + level=log_level + ) log = logging.getLogger('alpha_water') - logging.basicConfig(encoding='utf-8', level=config['main']['logging']) log.info('Starting') - root = Path(config['main']['root']).expanduser() + root = Path(config.get('main', 'root')).expanduser() t = [] @@ -61,13 +63,13 @@ def animate(config_path): alpha_water['y'] = mesh[2] with pd.HDFStore( - config['data']['path'], + config.get('data', 'path'), mode='r', ) as hdf: bathy = hdf.get('bathy') rubble = hdf.get('rubble') blocs = {} - for bloc in config['data']['blocs'].split(','): + for bloc in config.get('data', 'blocs', fallback='').split(','): blocs[bloc] = hdf.get(bloc) log.info('Starting plot') @@ -132,6 +134,6 @@ def animate(config_path): blit=True, repeat=True ) - ani.save(config['main']['out']) + ani.save(config.get('main', 'out')) log.info('Program ended successfully') diff --git a/post_process/config.example.ini b/post_process/config.example.ini index be7d9c9..575eb68 100644 --- a/post_process/config.example.ini +++ b/post_process/config.example.ini @@ -1,7 +1,7 @@ [main] -logging = INFO root = /home/masterccce/OpenFOAM/work/artha out = out/anim.mp4 +#log_file = openfoam.log [data] path = ../bathymetry/3_pd/data.hdf