From 33f9756191a69c9107aa5d45a1dbbb392e607801 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Tue, 9 Aug 2016 14:08:47 +0100 Subject: [PATCH] Coloured warning messages. --- gprMax/gprMax.py | 2 +- gprMax/input_cmds_multiuse.py | 14 ++++++++------ gprMax/input_cmds_singleuse.py | 4 +++- gprMax/optimisation_taguchi.py | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gprMax/gprMax.py b/gprMax/gprMax.py index a6f7ba14..19334190 100644 --- a/gprMax/gprMax.py +++ b/gprMax/gprMax.py @@ -375,7 +375,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace): # Check to see if numerical dispersion might be a problem resolution = dispersion_check(G) if resolution and max((G.dx, G.dy, G.dz)) > resolution: - print('\nWARNING: Potential numerical dispersion in the simulation. Check the spatial discretisation against the smallest wavelength present. Suggested resolution should be less than {:g}m'.format(resolution)) + print(Fore.RED + '\nWARNING: Potential numerical dispersion in the simulation. Check the spatial discretisation against the smallest wavelength present. Suggested resolution should be less than {:g}m'.format(resolution) + Style.RESET_ALL) # If geometry information to be reused between model runs else: diff --git a/gprMax/input_cmds_multiuse.py b/gprMax/input_cmds_multiuse.py index 54bc0235..5d61a4bc 100644 --- a/gprMax/input_cmds_multiuse.py +++ b/gprMax/input_cmds_multiuse.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with gprMax. If not, see . +from colorama import init, Fore, Style +init() import numpy as np from gprMax.constants import z0, floattype @@ -88,7 +90,7 @@ def process_multicmds(multicmds, G): resistance = float(tmp[4]) check_coordinates(xcoord, ycoord, zcoord) if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]: - print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n') + print(Fore.RED + "WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n' + Style.RESET_ALL) if resistance < 0: raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires a source resistance of zero or greater') @@ -147,7 +149,7 @@ def process_multicmds(multicmds, G): zcoord = G.calculate_coord('z', tmp[3]) check_coordinates(xcoord, ycoord, zcoord) if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]: - print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n') + print(Fore.RED + "WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n' + Style.RESET_ALL) # Check if there is a waveformID in the waveforms list if not any(x.ID == tmp[4] for x in G.waveforms): @@ -206,7 +208,7 @@ def process_multicmds(multicmds, G): zcoord = G.calculate_coord('z', tmp[3]) check_coordinates(xcoord, ycoord, zcoord) if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]: - print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n') + print(Fore.RED + "WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n' + Style.RESET_ALL) # Check if there is a waveformID in the waveforms list if not any(x.ID == tmp[4] for x in G.waveforms): @@ -269,7 +271,7 @@ def process_multicmds(multicmds, G): check_coordinates(xcoord, ycoord, zcoord) if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]: - print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n') + print(Fore.RED + "WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n' + Style.RESET_ALL) if resistance <= 0 or resistance >= z0: raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires a resistance greater than zero and less than the impedance of free space, i.e. 376.73 Ohms') @@ -327,7 +329,7 @@ def process_multicmds(multicmds, G): zcoord = round_value(float(tmp[2]) / G.dz) check_coordinates(xcoord, ycoord, zcoord) if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]: - print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n') + print(Fore.RED + "WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n' + Style.RESET_ALL) r = Rx() r.xcoord = xcoord @@ -380,7 +382,7 @@ def process_multicmds(multicmds, G): check_coordinates(xf, yf, zf, name='upper') if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]: - print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n') + print(Fore.RED + "WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n' + Style.RESET_ALL) if xs > xf or ys > yf or zs > zf: raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower coordinates should be less than the upper coordinates') if dx < 0 or dy < 0 or dz < 0: diff --git a/gprMax/input_cmds_singleuse.py b/gprMax/input_cmds_singleuse.py index 56d6fb18..a283e81d 100644 --- a/gprMax/input_cmds_singleuse.py +++ b/gprMax/input_cmds_singleuse.py @@ -21,6 +21,8 @@ import psutil import decimal as d import sys +from colorama import init, Fore, Style +init() import numpy as np from gprMax.constants import c, floattype @@ -82,7 +84,7 @@ def process_singlecmds(singlecmds, G): if G.messages: print('Number of threads: {}'.format(G.nthreads)) if G.nthreads > psutil.cpu_count(logical=False): - print('\nWARNING: You have specified more threads ({}) than available physical CPU cores ({}). This may lead to degraded performance.'.format(G.nthreads, psutil.cpu_count(logical=False))) + print(Fore.RED + '\nWARNING: You have specified more threads ({}) than available physical CPU cores ({}). This may lead to degraded performance.'.format(G.nthreads, psutil.cpu_count(logical=False)) + Style.RESET_ALL) # Spatial discretisation cmd = '#dx_dy_dz' diff --git a/gprMax/optimisation_taguchi.py b/gprMax/optimisation_taguchi.py index cf648a73..d427538a 100644 --- a/gprMax/optimisation_taguchi.py +++ b/gprMax/optimisation_taguchi.py @@ -270,7 +270,7 @@ def construct_OA(optparams): else: # THIS CASE NEEDS FURTHER TESTING - print('\nTaguchi optimisation, WARNING: Optimising more than 7 parameters is currently an experimental feature!') + print(Fore.RED + '\nTaguchi optimisation, WARNING: Optimising more than 7 parameters is currently an experimental feature!' + Style.RESET_ALL) p = int(np.ceil(np.log(k * (s - 1) + 1) / np.log(s)))