Complete refactor
This commit is contained in:
		@@ -28,6 +28,6 @@ probe-info:
 | 
				
			|||||||
    trigger:
 | 
					    trigger:
 | 
				
			||||||
      type: "channel"
 | 
					      type: "channel"
 | 
				
			||||||
      channel: 4
 | 
					      channel: 4
 | 
				
			||||||
      alignment-offset: 601 # us [TODO] Make this auto-magic
 | 
					      alignment-offset: 0 # 601 # us [TODO] Make this auto-magic
 | 
				
			||||||
      delay: 100 # us
 | 
					      delay: 100 # us
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@ probe-info:
 | 
				
			|||||||
    trigger: # Redundant?
 | 
					    trigger: # Redundant?
 | 
				
			||||||
      type: "channel"
 | 
					      type: "channel"
 | 
				
			||||||
      channel: 4
 | 
					      channel: 4
 | 
				
			||||||
      alignment-offset: 601 # us [TODO] Make this auto-magic
 | 
					      alignment-offset: 0 # 601 # us [TODO] Make this auto-magic
 | 
				
			||||||
      delay: 100 # us
 | 
					      delay: 100 # us
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ probe-info:
 | 
				
			|||||||
    trigger: # Redundant?
 | 
					    trigger: # Redundant?
 | 
				
			||||||
      type: "channel"
 | 
					      type: "channel"
 | 
				
			||||||
      channel: 4
 | 
					      channel: 4
 | 
				
			||||||
      alignment-offset: 601 # us [TODO] Make this auto-magic
 | 
					      alignment-offset: 0 # 601 # us [TODO] Make this auto-magic
 | 
				
			||||||
      delay: 100 # us
 | 
					      delay: 100 # us
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										81
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								main.py
									
									
									
									
									
								
							@@ -111,9 +111,14 @@ def load_data(data_to_load: list[str]) -> dict:
 | 
				
			|||||||
        # === Process the data ===
 | 
					        # === Process the data ===
 | 
				
			||||||
        # Generate X2 time arrays
 | 
					        # Generate X2 time arrays
 | 
				
			||||||
        time_data = x2_channels[0]
 | 
					        time_data = x2_channels[0]
 | 
				
			||||||
        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
 | 
					        ns_time = time_data[:].as_datetime64('ns') 
 | 
				
			||||||
        x2_time_us = x2_time_seconds * 1000 # Scale to ms
 | 
					        x2_time_seconds = (ns_time - ns_time[0]) # timedelta64[ns]
 | 
				
			||||||
 | 
					        x2_time_us = x2_time_seconds.astype("float64") / 1000 # Scale to us
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #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_us = x2_time_seconds * 1000 # Scale to us
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # --- Un Scale Data ---
 | 
					        # --- Un Scale Data ---
 | 
				
			||||||
        for channel, vScale in TUNNEL_INFO["volt-scale"].items():
 | 
					        for channel, vScale in TUNNEL_INFO["volt-scale"].items():
 | 
				
			||||||
@@ -142,9 +147,9 @@ def load_data(data_to_load: list[str]) -> dict:
 | 
				
			|||||||
        if dataInfo["probe-info"]["data-record"]["type"] == "scope":
 | 
					        if dataInfo["probe-info"]["data-record"]["type"] == "scope":
 | 
				
			||||||
            trigger_info = dataInfo["probe-info"]["data-record"]["trigger"] # Get the scope trigger info
 | 
					            trigger_info = dataInfo["probe-info"]["data-record"]["trigger"] # Get the scope trigger info
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            scope_time  = (scope_data[:, 0] - scope_data[0, 0]) * 1000 # to us
 | 
					            # Calc the scope time & apply any manual offsets
 | 
				
			||||||
 | 
					            scope_time  = (scope_data[:, 0] - scope_data[0, 0]) * 1e6 # to us
 | 
				
			||||||
            scope_time -= trigger_info["alignment-offset"] # manual offset delay
 | 
					            scope_time -= trigger_info["alignment-offset"] # manual offset delay
 | 
				
			||||||
            scope_time += trigger_info["delay"] # us delay from the actual trigger signal to the scope received trigger
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Trigger Alignment
 | 
					            # Trigger Alignment
 | 
				
			||||||
            scope_trigger_volts = (scope_data[:, 3] - scope_data[0:SAMPLES_TO_AVG, 3].mean()) # Use a mean here too
 | 
					            scope_trigger_volts = (scope_data[:, 3] - scope_data[0:SAMPLES_TO_AVG, 3].mean()) # Use a mean here too
 | 
				
			||||||
@@ -155,13 +160,16 @@ def load_data(data_to_load: list[str]) -> dict:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            scope_time += scope_alignment
 | 
					            scope_time += scope_alignment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Offset any trigger delays
 | 
				
			||||||
 | 
					            scope_time += trigger_info["delay"] # us delay from the actual trigger signal to the scope received trigger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            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]["data"]["scope"] = {}
 | 
					            data[x2_shot]["data"]["scope"] = {}
 | 
				
			||||||
            for i, header in enumerate(scope_header):
 | 
					            for i, header in enumerate(scope_header):
 | 
				
			||||||
                if i == 0: continue # Don't record time
 | 
					                if i == 0: continue # Don't record time
 | 
				
			||||||
                data[x2_shot]["data"]["scope"][header] = scope_data[i]
 | 
					                data[x2_shot]["data"]["scope"][header] = scope_data[:, i]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Return the data & the successfully loaded data keys  
 | 
					    # Return the data & the successfully loaded data keys  
 | 
				
			||||||
@@ -173,56 +181,39 @@ print("Loaded Data")
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#[TODO] Refactor
 | 
					#[TODO] Refactor
 | 
				
			||||||
def genGraph(gData: dict, showPlot: bool = True):
 | 
					def genGraph(gData: dict, showPlot: bool = True):
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    graphData = {
 | 
					    graphData = {
 | 
				
			||||||
        "title": f"Shock response Time\nFor {gData['info']['long_name']}",
 | 
					        "title": f"Shock response Time\nFor {gData['info']['long_name']}",
 | 
				
			||||||
        "xLabel": "Time (ns)",
 | 
					        "xLabel": "Time ($\\mu$s)",
 | 
				
			||||||
        "yLabel": "Voltage Reading (V)",
 | 
					        "yLabel": "Voltage Reading (V)",
 | 
				
			||||||
        "grid": True,
 | 
					        "grid": True,
 | 
				
			||||||
        "plots": [
 | 
					        "plots": []
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                "x": x2_time,
 | 
					 | 
				
			||||||
                "y": (gData["x2"][4][:] - gData["x2"][4][0]) * 0.0148,
 | 
					 | 
				
			||||||
                "label": "ST1"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                "x": x2_time,
 | 
					 | 
				
			||||||
                "y": (gData["x2"][6][:] - gData["x2"][6][0]) * 0.0148,
 | 
					 | 
				
			||||||
                "label": "ST3"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                "x": x2_time,
 | 
					 | 
				
			||||||
                "y": (gData["x2"][16][:] - gData["x2"][16][0])/1000,
 | 
					 | 
				
			||||||
                "label": "Trigger"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                "x": scope_time,
 | 
					 | 
				
			||||||
                "y": (gData["probes"][:, 1] - gData["probes"][0, 1]),
 | 
					 | 
				
			||||||
                "label": "ST2-G1"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                "x": scope_time,
 | 
					 | 
				
			||||||
                "y": (gData["probes"][:, 2] - gData["probes"][0, 2]),
 | 
					 | 
				
			||||||
                "label": "ST2-G2"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                "x": scope_time,
 | 
					 | 
				
			||||||
                "y": (gData["probes"][:, 3] - gData["probes"][0, 3]),
 | 
					 | 
				
			||||||
                "label": "ST2-Trigger"
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for label in ["st1", "st3", "trigbox"]:
 | 
				
			||||||
 | 
					        graphData["plots"].append({
 | 
				
			||||||
 | 
					            "x": gData["time"]["x2"],
 | 
				
			||||||
 | 
					            "y": gData["data"]["x2"][label],
 | 
				
			||||||
 | 
					            "label": label
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for label, d in [("1 [V]", "G1"),("2 [V]", "G1"), ("4 [V]", "Gauge Trigger")]:
 | 
				
			||||||
 | 
					        graphData["plots"].append({
 | 
				
			||||||
 | 
					            "x": gData["time"]["scope"],
 | 
				
			||||||
 | 
					            "y": gData["data"]["scope"][label],
 | 
				
			||||||
 | 
					            "label": d
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    makeGraph(graphData, doProgramBlock=False, showPlot=showPlot, figSavePath="./images/{0}.png")
 | 
					    makeGraph(graphData, doProgramBlock=False, showPlot=showPlot, figSavePath="./images/{0}.png")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#print("Graphing showPlot=showPlot, Data")
 | 
					print("Graphing showPlot=showPlot, Data")
 | 
				
			||||||
#genGraph(data[loaded_data[0]], showPlot=False)
 | 
					genGraph(data[loaded_data[0]], showPlot=False)
 | 
				
			||||||
#genGraph(data[loaded_data[1]], showPlot=False)
 | 
					genGraph(data[loaded_data[1]], showPlot=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from pprint import pprint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pprint(data[loaded_data[0]])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#x2_out = canny_shock_finder(x2_time, (gData["raw-data"]["x2"][16][:] - gData["raw-data"]["x2"][16][0]))
 | 
					#x2_out = canny_shock_finder(x2_time, (gData["raw-data"]["x2"][16][:] - gData["raw-data"]["x2"][16][0]))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user