Temperture dialog works now, fixes T7

This commit is contained in:
Markus Rosenstihl 2016-07-05 11:55:55 +02:00
parent 2b254f2ee6
commit c49a752ebd

View File

@ -1,28 +1,33 @@
import numpy as np
import re
from PyQt4.QtGui import QInputDialog
from PyQt4 import QtCore
class FileReader:
@staticmethod
def read_datafile( path ):
# TODO analyze file (LF,MF, HF) and act accordingly
print "Skipping first 4 lines!"
data = np.loadtxt(path, skiprows=4)
numpat = re.compile('\d+\.\d+')
print "successfully read %s"%path
try:
Temp = None
for line in open(path).readlines():
for i,line in enumerate(open(path).readlines()):
print "Searching for temperature in %s (Line with 'Fixed or 'Temp', with float, i.e. 273.15K or 273.15)"%path
if re.search("Fixed", line) or re.search("Temp", line):
print "Found line containing 'Fixed' or 'Temp':"
print "Found line containing 'Fixed' or 'Temp' (line %i):"%i
print line
Temp = float(re.search(numpat, line).group())
print "Temperature found in file:", Temp
break
print "Search temperature in file name %s (float +'K')"%path
search_temp_in_filename = re.search('\d+\.\d+K', path)
if search_temp_in_filename:
Temp = float(search_temp_in_filename.group()[:-1])
if Temp == None: raise ValueError
except:
Temp = QInputDialog.getDouble( "No temperature found in data set", "Temperature/K:", value=0.00)[0]
Temp = QInputDialog.getDouble(None, "No temperature found in data set", "Temperature/K:", value=0.00)[0]
# mask the data to values > 0 (loglog plot)
mask = (data[:, 1] > 0) & (data[:, 2] > 0) # & (data[:,2]>1e-3) & (data[:,0] > 1e-2)
_freq = data[mask, 0]