Correct for scope triggering

This commit is contained in:
Cal Wing 2024-10-23 03:59:15 +10:00
parent 30376abeb9
commit ab3547b26c

18
main.py
View File

@ -136,6 +136,7 @@ def load_data(data_path: str, data={}) -> dict:
"probes": None, # This may be x2 but may not - ie a scope was used "probes": None, # This may be x2 but may not - ie a scope was used
"trigger_index": None, "trigger_index": None,
"probe_uncert": None, #s "probe_uncert": None, #s
"x2-dt": None, #
}, },
"data": { "data": {
"x2": {}, # Only pop channels with a voltage scale in ./tunnel-info.yaml "x2": {}, # Only pop channels with a voltage scale in ./tunnel-info.yaml
@ -151,6 +152,7 @@ def load_data(data_path: str, data={}) -> dict:
ns_time = time_data[:].as_datetime64('ns') ns_time = time_data[:].as_datetime64('ns')
x2_time_seconds = (ns_time - ns_time[0]) # timedelta64[ns] x2_time_seconds = (ns_time - ns_time[0]) # timedelta64[ns]
x2_time_us = x2_time_seconds.astype("float64") / 1000 # Scale to us x2_time_us = x2_time_seconds.astype("float64") / 1000 # Scale to us
x2_time_dt = np.diff(x2_time_us).mean() / 1000 # Scale to s
#second_fractions = np.array(time_data[:].second_fractions, dtype=int) # 2^-64 ths of a second #second_fractions = np.array(time_data[:].second_fractions, dtype=int) # 2^-64 ths of a second
#x2_time_seconds = (second_fractions - second_fractions[0]) / (2**(-64)) # 0 time data and convert to seconds #x2_time_seconds = (second_fractions - second_fractions[0]) / (2**(-64)) # 0 time data and convert to seconds
@ -177,6 +179,7 @@ def load_data(data_path: str, data={}) -> dict:
"x2": x2_time_us, "x2": x2_time_us,
"trigger_index": x2_trigger_index, "trigger_index": x2_trigger_index,
"probes": x2_time_us, # Until otherwise overridden - probe time is x2 time "probes": x2_time_us, # Until otherwise overridden - probe time is x2 time
"x2-dt": x2_time_dt
} }
# Setup custom scaling on the gauge values # Setup custom scaling on the gauge values
@ -220,6 +223,7 @@ def load_data(data_path: str, data={}) -> dict:
data[x2_shot]["time"]["scope"] = scope_time data[x2_shot]["time"]["scope"] = scope_time
data[x2_shot]["time"]["scope-offset"] = scope_alignment data[x2_shot]["time"]["scope-offset"] = scope_alignment
data[x2_shot]["time"]["scope-dt"] = np.diff(scope_time).mean() / 1e6
data[x2_shot]["data"]["scope"] = {} data[x2_shot]["data"]["scope"] = {}
for i, header in enumerate(scope_header): for i, header in enumerate(scope_header):
@ -234,7 +238,7 @@ def load_data(data_path: str, data={}) -> dict:
if "scope" in data_locs: if "scope" in data_locs:
data[x2_shot]["data"]["probes"] = [data[x2_shot]["data"]["scope"][1], data[x2_shot]["data"]["scope"][2]] data[x2_shot]["data"]["probes"] = [data[x2_shot]["data"]["scope"][1], data[x2_shot]["data"]["scope"][2]]
data[x2_shot]["time"]["probes"] = data[x2_shot]["time"]["scope"] data[x2_shot]["time"]["probes"] = data[x2_shot]["time"]["scope"]
data[x2_shot]["time"]["probe_uncert"] = scope_data_info["time-uncert"] data[x2_shot]["time"]["probe_uncert"] = max(scope_data_info["time-uncert"], data[x2_shot]["time"]["scope-dt"])
# Find Shock Times # Find Shock Times
# X2 - Canning Edge # X2 - Canning Edge
@ -500,6 +504,7 @@ def load_ref_data(x2_shot: str, data_path: str, data={}) -> dict:
ns_time = time_data[:].as_datetime64('ns') ns_time = time_data[:].as_datetime64('ns')
x2_time_seconds = (ns_time - ns_time[0]) # timedelta64[ns] x2_time_seconds = (ns_time - ns_time[0]) # timedelta64[ns]
x2_time_us = x2_time_seconds.astype("float64") / 1000 # Scale to us x2_time_us = x2_time_seconds.astype("float64") / 1000 # Scale to us
x2_time_dt = np.diff(x2_time_us).mean() / 1000 # Scale to s
# --- Un Scale Data --- # --- Un Scale Data ---
for channel, vScale in TUNNEL_INFO["volt-scale"].items(): for channel, vScale in TUNNEL_INFO["volt-scale"].items():
@ -521,6 +526,7 @@ def load_ref_data(x2_shot: str, data_path: str, data={}) -> dict:
data[x2_shot]["time"] = { data[x2_shot]["time"] = {
"x2": x2_time_us, "x2": x2_time_us,
"trigger_index": x2_trigger_index, "trigger_index": x2_trigger_index,
"x2-dt": x2_time_dt
} }
@ -1070,6 +1076,14 @@ def genX2CompGraphs(gData: dict, showPlot: bool = True):
makeGraph(graphData, doProgramBlock=False, showPlot=showPlot, figSavePath=f"./images/signal_comp-{gData['info']['shot-info']['name']}.png") makeGraph(graphData, doProgramBlock=False, showPlot=showPlot, figSavePath=f"./images/signal_comp-{gData['info']['shot-info']['name']}.png")
print("-")
scopeTime = gData["time"]["scope"]
scopeData = gData["data"]["scope"]
x2Time = gData["time"]["x2"]
#x2Data = gData["data"]["x2"]
pass
print("Loading Data") print("Loading Data")
@ -1118,5 +1132,5 @@ genX2CompGraphs(data["x2s5832"], 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
pltKeyClose() #pltKeyClose()
print("Done") print("Done")