Compare commits

...

2 Commits

Author SHA1 Message Date
Cal Wing
e57d04525e Use seconds now 2024-10-15 21:25:37 +10:00
Cal Wing
fe960d1dea Chris fix error handle 2024-10-15 21:22:40 +10:00
2 changed files with 14 additions and 12 deletions

View File

@ -126,8 +126,8 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold
import numpy as np import numpy as np
import copy import copy
print ('-'*60) print('-'*60)
print ("Running Canny shock finder version {0}".format(VERSION_STRING)) print("Running Canny shock finder version {0}".format(VERSION_STRING))
# do some basic input checking # do some basic input checking
if not isinstance(sigma, (float, int)): 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] start_time = time_list[0]
if post_shock_pressure: 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 # 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 # 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 = post_shock_pressure * gaussian_first_derivative_max
#post_suppression_threshold = 0.5 * post_shock_pressure * gaussian_max/2.0 #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: 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, # 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) # 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: else:
derivative_threshold = post_shock_pressure / 2.5 * np.exp(-6) / 10.0 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... # make the input data arrays incase they didn't come in that way...
time_list = np.array(time_list) 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 first_value_uncertainty = None
if auto_derivative: if auto_derivative:
print ("Doing auto-derivative!") print("Doing auto-derivative!")
# remove points which have the same gradient on either side # remove points which have the same gradient on either side
for i in range(0,len(first_order_data)-1): 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]): if np.sign(second_order_data[i-1]) == np.sign(second_order_data[i+1]):
suppressed_data[i] = 0 suppressed_data[i] = 0
else: else:
print ("Not doing auto-derivative!") print("Not doing auto-derivative!")
for i in range(0,len(first_order_data)-1): for i in range(0,len(first_order_data)-1):
# check the gradients on either side using the second order data # check the gradients on either side using the second order data
@ -476,7 +476,7 @@ def canny_shock_finder(time_list, pressure_list, sigma = 4, derivative_threshold
mplt.show() mplt.show()
except Exception as e: except Exception as e:
print ("{0}: {1}".format(type(e).__name__, e.message)) print (e)
print ("There was an issue plotting the result.") print ("There was an issue plotting the result.")
mplt.close('all') mplt.close('all')

View File

@ -160,10 +160,12 @@ def genGraph(gData):
gData = data[loaded_data[0]] gData = data[loaded_data[0]]
x2_time, scope_time, x2_timestamps = process_data(gData) x2_time, scope_time, x2_timestamps = process_data(gData)
x2_out = canny_shock_finder(x2_timestamps, (gData["x2"][4][:] - gData["x2"][4][0]) * 0.0148) time = (gData["x2"][0][:] - gData["x2"][0][0]).astype('int')
x2_out = canny_shock_finder(time, (gData["x2"][4][:] - gData["x2"][4][0]) * 0.0148)
print(x2_out) print(x2_out)
input("foo") print("Done")
#print("Graphing Data") #print("Graphing Data")
#genGraph(data[loaded_data[0]]) #genGraph(data[loaded_data[0]])