2024-09-30 15:11:52 +10:00
|
|
|
# Cal Wing
|
|
|
|
# Sep 2024
|
|
|
|
|
2024-09-30 19:30:28 +10:00
|
|
|
import os
|
|
|
|
|
2024-09-30 19:13:09 +10:00
|
|
|
import numpy as np
|
|
|
|
|
2024-09-30 15:11:52 +10:00
|
|
|
from nptdms import TdmsFile
|
|
|
|
from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC
|
|
|
|
|
2024-09-30 19:30:28 +10:00
|
|
|
# Folder correction
|
|
|
|
# Make sure the relevant folders folder exists
|
|
|
|
folders = ["./images"]
|
|
|
|
for folder in folders:
|
|
|
|
if not os.path.isdir(folder): os.mkdir(folder)
|
|
|
|
|
2024-09-30 16:45:52 +10:00
|
|
|
# Photo Diode Things
|
2024-09-30 19:30:28 +10:00
|
|
|
SHOT_PD = "x2s4111", 1, "PD", np.timedelta64(1146800, 'ns')
|
2024-09-30 15:11:52 +10:00
|
|
|
|
2024-09-30 16:45:52 +10:00
|
|
|
# PCB Things
|
2024-09-30 19:30:28 +10:00
|
|
|
SHOT_PCB_1 = "x2s3667", 0.0148 * 1000, "PCB", np.timedelta64(1643, 'us') # st1 - np.timedelta64(1608, 'us')
|
|
|
|
SHOT_PCB_2 = "x2s3668", 0.0148 * 1000, "PCB", np.timedelta64(1648600, 'ns') # st1 - np.timedelta64(1614, 'us')
|
2024-09-30 15:11:52 +10:00
|
|
|
|
2024-09-30 16:45:52 +10:00
|
|
|
# Shot DATA FILE
|
|
|
|
DATA_FILE_FMT = './data/{0}/databox/{0}.tdms'
|
2024-09-30 15:11:52 +10:00
|
|
|
|
2024-09-30 19:30:28 +10:00
|
|
|
TIME_OFFSET = np.timedelta64(-22, 'us'), np.timedelta64(33, 'us') # us
|
2024-09-30 15:11:52 +10:00
|
|
|
|
2024-09-30 16:45:52 +10:00
|
|
|
def main():
|
2024-09-30 15:11:52 +10:00
|
|
|
|
|
|
|
graphData = {
|
2024-09-30 19:30:28 +10:00
|
|
|
"title": "Shock response time of PCBs\nAt position st2",
|
2024-09-30 19:13:09 +10:00
|
|
|
"xLabel": "Time ($\\mu$s)",
|
|
|
|
"yLabel": "PCB Voltage Reading (mV)",
|
|
|
|
"grid": True,
|
2024-09-30 19:30:28 +10:00
|
|
|
"xLim": (-20, 20),
|
2024-09-30 16:45:52 +10:00
|
|
|
"plots": []
|
|
|
|
}
|
|
|
|
|
2024-09-30 19:13:09 +10:00
|
|
|
for df, scale, name, zero_p in [SHOT_PD, SHOT_PCB_1, SHOT_PCB_2]:
|
2024-09-30 16:45:52 +10:00
|
|
|
file_path = DATA_FILE_FMT.format(df)
|
|
|
|
data = TdmsFile.read(file_path)
|
|
|
|
|
|
|
|
channels = data.groups()[0].channels()
|
|
|
|
|
|
|
|
for channel in channels:
|
2024-09-30 19:13:09 +10:00
|
|
|
time = (channels[0][:] - channels[0][0]) # Convert to sec
|
|
|
|
|
|
|
|
time_range_i = [0, 0]
|
|
|
|
|
|
|
|
for i, value in enumerate(time):
|
|
|
|
if value >= zero_p + TIME_OFFSET[0]:
|
|
|
|
time_range_i[0] = i
|
|
|
|
break
|
|
|
|
|
|
|
|
for i, value in enumerate(time):
|
|
|
|
if value >= zero_p + TIME_OFFSET[1]:
|
|
|
|
time_range_i[1] = i
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
a = time > time[time_range_i[0]]
|
|
|
|
b = time < time[time_range_i[1]]
|
|
|
|
time_range = np.logical_and(a, b)
|
|
|
|
time_2 = time[time_range][:] - time[time_range][0] + TIME_OFFSET[0]
|
|
|
|
|
|
|
|
#print(time_range, a, b, time_range_i)
|
|
|
|
|
|
|
|
if channel.name == "st2" and df is not SHOT_PD[0]:
|
2024-09-30 16:45:52 +10:00
|
|
|
graphData["plots"].append({
|
2024-09-30 19:13:09 +10:00
|
|
|
"x": time_2,
|
|
|
|
"y": channel[time_range] * scale,
|
|
|
|
"label": f"{df} - {name}"
|
2024-09-30 16:45:52 +10:00
|
|
|
})
|
|
|
|
|
2024-09-30 19:13:09 +10:00
|
|
|
if channel.name == "st2" and df is SHOT_PD[0] and False:
|
2024-09-30 16:45:52 +10:00
|
|
|
graphData["plots"].append({
|
2024-09-30 19:13:09 +10:00
|
|
|
"x": time,
|
|
|
|
"y": channel[:] * scale,
|
|
|
|
"label": f"{df} - {name}"
|
2024-09-30 16:45:52 +10:00
|
|
|
})
|
2024-09-30 19:30:28 +10:00
|
|
|
|
|
|
|
graphData['plots'].append(
|
|
|
|
{
|
|
|
|
"x":0,
|
|
|
|
"type":"axvLine",
|
|
|
|
#"label":"Shock",
|
|
|
|
"color": UQC["dark_grey"],
|
|
|
|
"args": {
|
|
|
|
"linestyle": "--",
|
|
|
|
"zorder": -2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2024-09-30 15:11:52 +10:00
|
|
|
|
2024-09-30 19:30:28 +10:00
|
|
|
makeGraph(graphData, figSavePath="./images/{0}.png", showPlot=False, doProgramBlock=False)
|
2024-09-30 15:11:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|
2024-09-30 16:45:52 +10:00
|
|
|
#pltKeyClose()
|