Professional Documents
Culture Documents
# program: pump_data_convert.py
# author: Tom Irvine
# Email: tom@irvinemail.org
# version: 1.0
# date: October 1, 2018
# description: Data conversion utility
# The input file must have three columns: date, time & amplitude
# Line Example: 09/20/2018 08:23:56 0.1765432
#
# The output file will have two columns: time(sec) & amplitude
# The time will start at zero.
#
###########################################################################
import sys
if sys.version_info[0] == 2:
print ("Python 2.x")
import Tkinter as tk
from tkFileDialog import askopenfilename
from tkFileDialog import asksaveasfilename
if sys.version_info[0] == 3:
print ("Python 3.x")
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import asksaveasfilename
import os
import re
import numpy as np
import datetime
import calendar
###########################################################################
def read_three_columns_from_dialog(label):
"""
Read data from file using a dialog box
"""
while(1):
root = tk.Tk() ; root.withdraw()
input_file_path = askopenfilename(parent=root,title=label)
file_path = input_file_path.rstrip('\n')
#
if not os.path.exists(file_path):
print ("This file doesn't exist")
#
if os.path.exists(file_path):
print ("This file exists")
print (" ")
infile = open(file_path,"rb")
lines = infile.readlines()
infile.close()
a = []
b = []
c = []
num=0
for line in lines:
#
if sys.version_info[0] == 3:
line = line.decode(encoding='UTF‐8')
return a,b,c,num
###############################################################################
print(" ")
print("The input file must have three columns: date, time & amplitude")
a,b,c,num=read_three_columns_from_dialog('Select Input File')
t = np.zeros((num,1))
h, m, s = b[i].split(':')
t[i]=tep + float(h)*3600 + float(m)*60 + float(s)
t=t‐t[0]
###############################################################################
if(len(t)==len(c)):
nn=len(t)
outfile.close()
print(' conversion complete')
else:
print(' length error' )