Compare commits

...

2 Commits

Author SHA1 Message Date
Cal Wing
a04be0889a fidel with canning values 2024-10-17 20:57:31 +10:00
Cal Wing
764c617780 try to do better canning edge 2024-10-17 20:48:43 +10:00

51
main.py
View File

@ -29,9 +29,9 @@ with open(TUNNEL_INFO_FILE, 'r') as file:
TUNNEL_INFO = yaml.safe_load(file) TUNNEL_INFO = yaml.safe_load(file)
data_to_load = [ data_to_load = [
"x2s5823", #"x2s5823",
"x2s5824", #"x2s5824",
"x2s5827", #"x2s5827",
"x2s5829", "x2s5829",
] ]
@ -192,32 +192,38 @@ def load_data(data_to_load: list[str]) -> dict:
probeCh2 = data[x2_shot]["data"]["scope"][2] probeCh2 = data[x2_shot]["data"]["scope"][2]
#[HACK] For detection #[HACK] For detection
TIME_OFFSET = 50 #us
if i > 0: if i > 0:
privPoint = dataInfo["probe-info"]["locations"][i-1] privPoint = dataInfo["probe-info"]["locations"][i-1]
offset = data[x2_shot]["shock-point"][f"{privPoint}-g1"][0] + 150 #[i-1] + 25 time_offset = data[x2_shot]["shock-point"][f"{privPoint}-g1"][1] + TIME_OFFSET
else: post_pres = 0.03
offset = 0 sigma = 7
doPlot = True
else: # These work for the first probe int he chain
time_offset = None
post_pres = 0.03
sigma = 2
doPlot = False
shock_point = np.where(probeCh1[offset:] >= 0.3)[0] + offset shock_point = np.where(probeCh1 >= 0.3)[0]
first_value = scope_time[shock_point] first_value = scope_time[shock_point]
first_value, first_value_uncertainty, _, _ = canny_shock_finder(scope_time[offset:], probeCh1[offset:], plot=False, sigma=2, post_shock_pressure=0.02, print_func=None) first_value, first_value_uncertainty, _, _ = canny_shock_finder(scope_time, probeCh1, sigma=sigma, post_suppression_threshold=post_pres, plot=doPlot, start_time=time_offset, print_func=None)
shock_point = np.where(scope_time[offset:] >= first_value)[0][0] + offset # [BUG] Seems to give n+1 shock_point = np.where(scope_time >= first_value)[0][0] # [BUG] Seems to give n+1
data[x2_shot]["shock-point"][f"{probe}-g1"] = shock_point, first_value data[x2_shot]["shock-point"][f"{probe}-g1"] = shock_point, first_value
#[HACK] For detection #[HACK] For detection
if i > 0: if i > 0:
privPoint = dataInfo["probe-info"]["locations"][i-1] time_offset = data[x2_shot]["shock-point"][f"{privPoint}-g2"][1] + TIME_OFFSET
offset = data[x2_shot]["shock-point"][f"{privPoint}-g2"][0] + 150 #[i-1] + 25
else:
offset = 0 shock_point = np.where(probeCh2 >= 0.3)[0] # + offset
shock_point = np.where(probeCh2[offset:] >= 0.3)[0] + offset
first_value = scope_time[shock_point] first_value = scope_time[shock_point]
first_value, first_value_uncertainty, _, _ = canny_shock_finder(scope_time[offset:], probeCh2[offset:], plot=False, sigma=2, post_shock_pressure=0.02, print_func=None) first_value, first_value_uncertainty, _, _ = canny_shock_finder(scope_time, probeCh2, sigma=sigma, post_suppression_threshold=post_pres, plot=doPlot, start_time=time_offset, print_func=None)
shock_point = np.where(scope_time[offset:] >= first_value)[0][0] + offset # [BUG] Seems to give n+1 shock_point = np.where(scope_time >= first_value)[0][0] # [BUG] Seems to give n+1
data[x2_shot]["shock-point"][f"{probe}-g2"] = shock_point, first_value data[x2_shot]["shock-point"][f"{probe}-g2"] = shock_point, first_value
# Calculate Shock Speeds # Calculate Shock Speeds
@ -266,6 +272,8 @@ def genGraph(gData: dict, showPlot: bool = True):
"plots": [] "plots": []
} }
lims = []
for label in gData["info"]["pcb-refs"] + ["trigbox"]: for label in gData["info"]["pcb-refs"] + ["trigbox"]:
graphData["plots"].append({ graphData["plots"].append({
"x": gData["time"]["x2"], "x": gData["time"]["x2"],
@ -281,6 +289,7 @@ def genGraph(gData: dict, showPlot: bool = True):
"colour": "gray", "colour": "gray",
"args":{"zorder":2, "linestyle":"--"} "args":{"zorder":2, "linestyle":"--"}
}) })
lims.append(gData["shock-point"][label][1]) # [TODO this but better]
for label, d in [("1 [V]", "G1"),("2 [V]", "G2"), ("4 [V]", "Gauge Trigger")]: for label, d in [("1 [V]", "G1"),("2 [V]", "G2"), ("4 [V]", "Gauge Trigger")]:
@ -306,13 +315,21 @@ def genGraph(gData: dict, showPlot: bool = True):
"args":{"zorder":2, "linestyle":"--"} "args":{"zorder":2, "linestyle":"--"}
}) })
lims.append(gData["shock-point"][f"{probe}-g2"][1])
lims.append(gData["shock-point"][f"{probe}-g1"][1])
if len(lims) > 1:
OFFSET = 10
#graphData["xLim"] = (float(min(lims) - OFFSET), float(max(lims) + OFFSET))
makeGraph(graphData, doProgramBlock=False, showPlot=showPlot, figSavePath="./images/{0}.png") makeGraph(graphData, doProgramBlock=False, showPlot=showPlot, figSavePath="./images/{0}.png")
print("Graphing Data") print("Graphing Data")
for shot in loaded_data: for shot in loaded_data:
if shot != loaded_data[-1]: continue #if shot != loaded_data[-1]: continue
genGraph(data[shot], showPlot=False) genGraph(data[shot], showPlot=False)
# This forces matplotlib to hang until I tell it to close all windows # This forces matplotlib to hang until I tell it to close all windows