Last active
February 16, 2023 12:39
-
-
Save steveway/073fed8f79b8612ae13913066fe10fee to your computer and use it in GitHub Desktop.
Converts saved CSV files from Siglent Oscilloscopes to be opened with EasyWaveX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import argparse | |
| import csv | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("-i", "--input", help="Input file", required=True) | |
| parser.add_argument("-o", "--output", help="Output file", required=True) | |
| args = parser.parse_args() | |
| data_length = 0 | |
| frequency = 0 | |
| freq_unit = "undefined" | |
| amp = 0 | |
| offset = 0 | |
| phase = 0 | |
| data_values = [] | |
| with open(args.input, "r") as f: | |
| data = csv.reader(f, delimiter=",") | |
| for row in data: | |
| if row[0].startswith("Record"): | |
| data_length = int(row[1].split(":")[1]) | |
| elif row[0].startswith("Horizontal Units"): | |
| freq_unit = row[1] | |
| elif row[0].startswith("Horizontal Scale") and freq_unit != "undefined": | |
| if freq_unit == "s": | |
| frequency = 1 / float(row[1]) | |
| elif freq_unit == "ms": | |
| frequency = (1 / float(row[1])) * 1000 | |
| elif freq_unit == "us": | |
| frequency = (1 / float(row[1])) * 1000 * 1000 | |
| elif row[0].startswith("Vertical Offset"): | |
| offset = float(row[1].split(":")[1]) | |
| elif row[0].startswith("Vertical Scale"): | |
| amp = float(row[1].split(":")[1]) | |
| else: | |
| temp_data = None | |
| try: | |
| temp_data = [float(row[0]), float(row[1])] | |
| except: | |
| pass | |
| if temp_data: | |
| data_values.append(temp_data) | |
| with open(args.output, "w") as f: | |
| f.write("data length,{0}\n".format(data_length)) | |
| f.write("frequency,{0}\n".format(frequency)) | |
| f.write("amp,{0}\n".format(amp)) | |
| f.write("offset,{0}\n".format(offset)) | |
| f.write("phase,{0}\n".format(phase)) | |
| f.write("\n\n\n\n\n\n\nxpos,value\n") | |
| for i in range(len(data_values)): | |
| f.write("{0},{1}\n".format(data_values[i][0], data_values[i][1])) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment