Do for st2
This commit is contained in:
		
							
								
								
									
										62
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								main.py
									
									
									
									
									
								
							| @@ -1,55 +1,79 @@ | |||||||
| # Cal Wing | # Cal Wing | ||||||
| # Sep 2024 | # Sep 2024 | ||||||
|  |  | ||||||
|  | import numpy as np | ||||||
|  |  | ||||||
| from nptdms import TdmsFile | from nptdms import TdmsFile | ||||||
|  |  | ||||||
| from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC | from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC | ||||||
|  |  | ||||||
| # Photo Diode Things | # Photo Diode Things | ||||||
| SHOT_PD = "x2s4111" | SHOT_PD = "x2s4111", 1, "PD", np.timedelta64(1146, 'us') #np.timedelta64(1146800, 'ns') | ||||||
|  |  | ||||||
| # PCB Things | # PCB Things | ||||||
| SHOT_PCB_1 = "x2s3667" | SHOT_PCB_1 = "x2s3667", 0.0148 * 1000, "PCB", np.timedelta64(1643, 'us') | ||||||
| SHOT_PCB_2 = "x2s3668" | SHOT_PCB_2 = "x2s3668", 0.0148 * 1000, "PCB", np.timedelta64(1648600, 'ns') | ||||||
|  |  | ||||||
| # Shot DATA FILE | # Shot DATA FILE | ||||||
| DATA_FILE_FMT = './data/{0}/databox/{0}.tdms' | DATA_FILE_FMT = './data/{0}/databox/{0}.tdms' | ||||||
|  |  | ||||||
|  | TIME_OFFSET = np.timedelta64(-10, 'us'), np.timedelta64(15, 'us') # us | ||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|  |  | ||||||
|     graphData = { |     graphData = { | ||||||
|  |             "title": "Shock response time of PCBs", | ||||||
|  |             "xLabel": "Time ($\\mu$s)", | ||||||
|  |             "yLabel": "PCB Voltage Reading (mV)", | ||||||
|  |             "grid": True, | ||||||
|  |             "xLim": (-10, 15), | ||||||
|             "plots": [] |             "plots": [] | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     for df in [SHOT_PD, SHOT_PCB_1, SHOT_PCB_2]: |     for df, scale, name, zero_p in [SHOT_PD, SHOT_PCB_1, SHOT_PCB_2]: | ||||||
|         file_path = DATA_FILE_FMT.format(df) |         file_path = DATA_FILE_FMT.format(df) | ||||||
|         data = TdmsFile.read(file_path) |         data = TdmsFile.read(file_path) | ||||||
|  |  | ||||||
|         channels = data.groups()[0].channels() |         channels = data.groups()[0].channels() | ||||||
|  |  | ||||||
|         for channel in channels: |         for channel in channels: | ||||||
|             if df is SHOT_PD and channel.name == "st2": |             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]: | ||||||
|                 graphData["plots"].append({ |                 graphData["plots"].append({ | ||||||
|                     "x": channels[0][:] - channels[0][0], |                     "x": time_2, | ||||||
|                     "y": channel[:], |                     "y": channel[time_range] * scale, | ||||||
|                     "label": f"{df} - PD - st2" |                     "label": f"{df} - {name}" | ||||||
|                 }) |                 }) | ||||||
|  |  | ||||||
|             #if df is SHOT_PD and channel.name == "photodiode": |             if channel.name == "st2" and df is SHOT_PD[0] and False: | ||||||
|             #    graphData["plots"].append({ |  | ||||||
|             #        "x": channels[0][:] - channels[0][0], |  | ||||||
|             #        "y": channel[:], |  | ||||||
|             #        "label": f"{df} - PD - photodiode" |  | ||||||
|             #    }) |  | ||||||
|  |  | ||||||
|             if df is not SHOT_PD and channel.name == "st2": |  | ||||||
|                 graphData["plots"].append({ |                 graphData["plots"].append({ | ||||||
|                     "x": channels[0][:] - channels[0][0], |                     "x": time, | ||||||
|                     "y": channel[:] * 0.0148 * 10, |                     "y": channel[:] * scale, | ||||||
|                     "label": f"{df} - PCB" |                     "label": f"{df} - {name}" | ||||||
|                 }) |                 }) | ||||||
|   |   | ||||||
|  |  | ||||||
|     makeGraph(graphData, showPlot=True, doProgramBlock=True) |     makeGraph(graphData, showPlot=True, doProgramBlock=True) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user