From 2d975a254487a5a987134f269b8f8df9f4ab7584 Mon Sep 17 00:00:00 2001 From: craig-warren Date: Thu, 9 Apr 2020 14:52:04 +0100 Subject: [PATCH] More work on logging exceptions/warnings and coloured logging. --- gprMax/config.py | 6 +++--- gprMax/model_build_run.py | 8 ++++---- gprMax/user_inputs.py | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gprMax/config.py b/gprMax/config.py index a6c753a7..9f326c23 100644 --- a/gprMax/config.py +++ b/gprMax/config.py @@ -187,7 +187,7 @@ class SimulationConfig: if args.mpi and args.geometry_fixed: logger.exception('The geometry fixed option cannot be used with MPI.') - raise + raise ValueError # General settings for the simulation # inputfilepath: path to inputfile location @@ -238,7 +238,7 @@ class SimulationConfig: self.general['precision'] = 'double' if self.general['cuda']: logger.exception('The CUDA-based solver cannot currently be used with models that contain sub-grids.') - raise + raise ValueError except AttributeError: self.general['subgrid'] = False @@ -273,7 +273,7 @@ class SimulationConfig: if not found: logger.exception(f'GPU with device ID {deviceID} does not exist') - raise + raise ValueError def _set_precision(self): """Data type (precision) for electromagnetic field output. diff --git a/gprMax/model_build_run.py b/gprMax/model_build_run.py index 9984fd88..7095b99d 100644 --- a/gprMax/model_build_run.py +++ b/gprMax/model_build_run.py @@ -106,7 +106,7 @@ class ModelBuildRun: # Write files for any geometry views and geometry object outputs if not (G.geometryviews or G.geometryobjectswrite) and config.sim_config.args.geometry_only: - logger.warning(Fore.RED + f'\nNo geometry views or geometry objects found.' + Style.RESET_ALL) + logger.warning('\nNo geometry views or geometry objects found.') for i, geometryview in enumerate(G.geometryviews): logger.info('') geometryview.set_filename() @@ -171,13 +171,13 @@ class ModelBuildRun: # Check to see if numerical dispersion might be a problem results = dispersion_analysis(gb.grid) if results['error']: - logger.warning(Fore.RED + f"\nNumerical dispersion analysis [{gb.grid.name}] not carried out as {results['error']}" + Style.RESET_ALL) + logger.warning(f"\nNumerical dispersion analysis [{gb.grid.name}] not carried out as {results['error']}") elif results['N'] < config.get_model_config().numdispersion['mingridsampling']: logger.exception(f"\nNon-physical wave propagation in [{gb.grid.name}] detected. Material '{results['material'].ID}' has wavelength sampled by {results['N']} cells, less than required minimum for physical wave propagation. Maximum significant frequency estimated as {results['maxfreq']:g}Hz") raise ValueError elif (results['deltavp'] and np.abs(results['deltavp']) > config.get_model_config().numdispersion['maxnumericaldisp']): - logger.warning(Fore.RED + f"\n[{gb.grid.name}] has potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {results['deltavp']:.2f}% in material '{results['material'].ID}' whose wavelength sampled by {results['N']} cells. Maximum significant frequency estimated as {results['maxfreq']:g}Hz" + Style.RESET_ALL) + logger.warning(f"\n[{gb.grid.name}] has potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {results['deltavp']:.2f}% in material '{results['material'].ID}' whose wavelength sampled by {results['N']} cells. Maximum significant frequency estimated as {results['maxfreq']:g}Hz") elif results['deltavp']: logger.info(f"\nNumerical dispersion analysis [{gb.grid.name}]: estimated largest physical phase-velocity error is {results['deltavp']:.2f}% in material '{results['material'].ID}' whose wavelength sampled by {results['N']} cells. Maximum significant frequency estimated as {results['maxfreq']:g}Hz") @@ -259,7 +259,7 @@ class ModelBuildRun: if config.sim_config.general['cpu']: logger.basic(f'CPU solver using: {config.get_model_config().ompthreads} OpenMP thread(s) on {platform.node()}\n') if config.get_model_config().ompthreads > config.sim_config.hostinfo['physicalcores']: - logger.warning(Fore.RED + f"You have specified more threads ({config.get_model_config().ompthreads}) than available physical CPU cores ({config.sim_config.hostinfo['physicalcores']}). This may lead to degraded performance." + Style.RESET_ALL) + logger.warning(f"You have specified more threads ({config.get_model_config().ompthreads}) than available physical CPU cores ({config.sim_config.hostinfo['physicalcores']}). This may lead to degraded performance.") # Print information about any GPU in use elif config.sim_config.general['cuda']: logger.basic(f"GPU solver using: {config.get_model_config().cuda['gpu'].deviceID} - {config.get_model_config().cuda['gpu'].name} on {platform.node()}\n") diff --git a/gprMax/user_inputs.py b/gprMax/user_inputs.py index d9d00b32..552cadaa 100644 --- a/gprMax/user_inputs.py +++ b/gprMax/user_inputs.py @@ -20,8 +20,7 @@ import logging import gprMax.config as config import numpy as np -from colorama import Fore, Style, init -init() + from .subgrids.base import SubGridBase from .utilities import round_value @@ -174,5 +173,5 @@ class SubgridUserInput(MainGridUserInput): # the OS non-working region. if (np.less(p_t, self.inner_bound).any() or np.greater(p_t, self.outer_bound).any()): - logger.warning(Fore.RED + f"'{cmd_str}' this object traverses the Outer Surface. This is an advanced feature." + Style.RESET_ALL) + logger.warning(f"'{cmd_str}' this object traverses the Outer Surface. This is an advanced feature.") return p_t