Compare commits
2 Commits
cf2c826226
...
e57d04525e
Author | SHA1 | Date | |
---|---|---|---|
|
e57d04525e | ||
|
fe960d1dea |
@ -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')
|
||||
|
||||
|
6
main.py
6
main.py
@ -160,10 +160,12 @@ def genGraph(gData):
|
||||
gData = data[loaded_data[0]]
|
||||
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)
|
||||
input("foo")
|
||||
print("Done")
|
||||
|
||||
#print("Graphing Data")
|
||||
#genGraph(data[loaded_data[0]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user