Thesis/main.py

84 lines
2.4 KiB
Python
Raw Normal View History

2024-10-15 15:11:10 +10:00
# Cal Wing (c.wing@uq.net.au) - Oct 2024
# Thesis Graphing
2024-09-30 19:30:28 +10:00
import os
2024-09-30 19:13:09 +10:00
import numpy as np
2024-10-15 15:11:10 +10:00
import pandas as pd
import yaml
2024-09-30 19:13:09 +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-10-15 15:11:10 +10:00
# Load Data
DATA_PATH = "./data"
DATA_INFO = "_info.yaml"
2024-09-30 16:45:52 +10:00
2024-10-15 15:11:10 +10:00
data_to_load = [
"x2s5823"
]
2024-09-30 16:45:52 +10:00
2024-10-15 15:11:10 +10:00
data = {}
2024-09-30 19:13:09 +10:00
2024-10-15 15:11:10 +10:00
for dp in data_to_load:
data_path = f"{DATA_PATH}/{dp}/"
data_info_path = data_path + DATA_INFO
if not os.path.exists(data_info_path):
print(f"[ERR] Could not find data info file: '{data_info_path}'")
print(f"[WARN] Not Loading Data '{dp}'")
continue
2024-09-30 19:30:28 +10:00
2024-10-15 15:11:10 +10:00
with open(data_info_path, 'r') as file:
# Load data info (Cal)
dataInfo = yaml.safe_load(file)
x2_shot = dataInfo["shot-info"]["name"]
x2_tdms_data = TdmsFile.read(data_path + dataInfo["shot-info"]['tdms'])
x2_channels = x2_tdms_data.groups()[0].channels()
if dataInfo["probe-info"]["data-record"]["type"] == "scope":
scope_data_path = data_path + dataInfo["probe-info"]["data-record"]["data"]
scope_config_path = data_path + dataInfo["probe-info"]["data-record"]["config"]
# Generate Headers
with open(scope_data_path, 'r') as dfile:
scope_header = []
header_lines = []
for i, line in enumerate(dfile):
if i > 1: break
header_lines.append(line.strip().split(","))
for i, name in enumerate(header_lines[0]):
if name == "x-axis":
name = "Time"
if header_lines[1][i] in ["second", "Volt"]:
outStr = f"{name} [{header_lines[1][i][0]}]"
else:
outStr = f"{name} [{header_lines[1][i]}]"
scope_header.append(outStr)
scope_data = pd.read_csv(scope_data_path, names=scope_header, skiprows=1)
data[x2_shot] = {
"info": dataInfo,
"probes": scope_data,
"x2": x2_channels,
"x2-tdms": x2_tdms_data
2024-09-30 19:30:28 +10:00
}
2024-10-15 15:11:10 +10:00
loaded_data = data.keys()
2024-10-15 15:11:10 +10:00
print("Loaded Data")