qdsfit/fileio/bds_file_reader.py

31 lines
1.3 KiB
Python

import numpy as np
import re
from PyQt4.QtGui import QInputDialog
class FileReader:
@staticmethod
def read_datafile( path ):
# TODO analyze file (LF,MF, HF) and act accordingly
data = np.loadtxt(path, skiprows=4)
numpat = re.compile('\d+\.\d+')
try:
Temp = None
for line in open(path).readlines():
if re.search("Fixed", line) or re.search("Temp", line):
print "Found line containing 'Fixed' or 'Temp':"
print line
Temp = float(re.search(numpat, line).group())
print "Temperature found in file:", Temp
break
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]
# 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]
_die_stor = data[mask, 1]
_die_loss = data[mask, 2]
return Temp, _die_loss, _die_stor, _freq