From fe960d1dead5bfc7dbb01cbc02ccac6535ce6bd3 Mon Sep 17 00:00:00 2001 From: Cal Wing <20716204+calw20@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:22:40 +1000 Subject: [PATCH] Chris fix error handle --- canny_shock_finder.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/canny_shock_finder.py b/canny_shock_finder.py index a0e8e77..2f97c41 100644 --- a/canny_shock_finder.py +++ b/canny_shock_finder.py @@ -126,8 +126,8 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold import numpy as np import copy - print ('-'*60) - print ("Running Canny shock finder version {0}".format(VERSION_STRING)) + print('-'*60) + print("Running Canny shock finder version {0}".format(VERSION_STRING)) # do some basic input checking if not isinstance(sigma, (float, int)): @@ -148,7 +148,7 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold start_time = time_list[0] if post_shock_pressure: - print ("Using post-shock pressure scaling so the post_suppression_threshold will be calculated using a post-shock pressure estimate.") + print("Using post-shock pressure scaling so the post_suppression_threshold will be calculated using a post-shock pressure estimate.") # we need to calculate our post_suppression_threshold here based on the expected post-shock pressure and the # scaling caused by the first order gaussian data based on the maximum of the Gaussian @@ -178,10 +178,10 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold post_suppression_threshold = post_shock_pressure * gaussian_first_derivative_max #post_suppression_threshold = 0.5 * post_shock_pressure * gaussian_max/2.0 - print ("Calculated post_suppression_threshold is {0}".format(post_suppression_threshold)) + print("Calculated post_suppression_threshold is {0}".format(post_suppression_threshold)) if calculate_automatic_derivative_threshold: - print ("Calculating automatic derivative threshold as the user has asked for this.") + print("Calculating automatic derivative threshold as the user has asked for this.") # this commented out code here was my original model, based on the actual second derivative of the Gaussian, # but it didn't seem to work too well (it got too small at very high sigma values, i.e. above 6 or so) @@ -199,7 +199,7 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold else: derivative_threshold = post_shock_pressure / 2.5 * np.exp(-6) / 10.0 - print ("Calculated derivative_threshold is {0}.".format(derivative_threshold)) + print("Calculated derivative_threshold is {0}.".format(derivative_threshold)) # make the input data arrays incase they didn't come in that way... time_list = np.array(time_list) @@ -224,14 +224,14 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold first_value_uncertainty = None if auto_derivative: - print ("Doing auto-derivative!") + print("Doing auto-derivative!") # remove points which have the same gradient on either side for i in range(0,len(first_order_data)-1): if np.sign(second_order_data[i-1]) == np.sign(second_order_data[i+1]): suppressed_data[i] = 0 else: - print ("Not doing auto-derivative!") + print("Not doing auto-derivative!") for i in range(0,len(first_order_data)-1): # check the gradients on either side using the second order data @@ -345,7 +345,7 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold try: # this is mainly so the code doesn't bail out if one closes a window before it has loaded properly import matplotlib.pyplot as mplt - + figure, (data_ax, convolution_ax) = mplt.subplots(2,1, sharex=True, figsize = (14,8)) data_ax.plot(time_list*plot_time_scale, pressure_list, '-o', label = 'original data') @@ -476,7 +476,7 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold mplt.show() except Exception as e: - print ("{0}: {1}".format(type(e).__name__, e.message)) + print (e) print ("There was an issue plotting the result.") mplt.close('all')