moved filereader to extra file

This commit is contained in:
Markus Rosenstihl 2014-09-24 22:07:14 +02:00
parent 737be85ee1
commit ffc817f306
8 changed files with 5601 additions and 34 deletions

29
QDS.py
View File

@ -28,6 +28,7 @@ from ui import QDSMain
from libmath.BDSlib import FunctionRegister, FitRoutine from libmath.BDSlib import FunctionRegister, FitRoutine
from data.data import Data from data.data import Data
from bds_io import bds_file_reader
class AppWindow(QMainWindow): class AppWindow(QMainWindow):
@ -442,8 +443,6 @@ class AppWindow(QMainWindow):
id_list = [ key.id_num for key in id_list = [ key.id_num for key in
self.function_registry.get_registered_functions() self.function_registry.get_registered_functions()
if key.id_string == 'hn'] if key.id_string == 'hn']
for k in self.function_registry.get_registered_functions():
print k.id_num,k.id_label
self.peakId = 1 self.peakId = 1
print id_list print id_list
while self.peakId in id_list: while self.peakId in id_list:
@ -551,31 +550,10 @@ class AppWindow(QMainWindow):
def openFile(self,path): def openFile(self,path):
print "opening: %s"%path print "opening: %s"%path
self.filepath=path self.filepath=path
# TODO analyze file (LF,MF, HF) and act accordingly Temp, _die_loss, _die_stor, _freq = bds_file_reader.FileReader.read_datafile(path)
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(self, "No temperature found in data set", "Temperature/K:", value=0.00)[0]
# mask the data to values > 0 (loglog plot)
self.setWindowTitle("%s - %.2f K"%(os.path.basename(path), Temp)) self.setWindowTitle("%s - %.2f K"%(os.path.basename(path), Temp))
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]
self.data.set_data(_freq, _die_stor, _die_loss) self.data.set_data(_freq, _die_stor, _die_loss)
self.data.meta["T"] = Temp self.data.meta["T"] = Temp
self.fit_boundary_imag.setRegion([np.log10(_freq.min()), np.log10(_freq.max())]) self.fit_boundary_imag.setRegion([np.log10(_freq.min()), np.log10(_freq.max())])
@ -596,7 +574,6 @@ class AppWindow(QMainWindow):
self.updatePlot() self.updatePlot()
def updatePlot(self): def updatePlot(self):
log10fmin, log10fmax = self.fit_boundary_imag.getRegion() log10fmin, log10fmax = self.fit_boundary_imag.getRegion()
self.data.set_fit_xlimits(10**log10fmin, 10**log10fmax) self.data.set_fit_xlimits(10**log10fmin, 10**log10fmax)

31
bds_io/bds_file_reader.py Normal file
View File

@ -0,0 +1,31 @@
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

View File

@ -1,12 +1,12 @@
# -*- encoding: utf8 -*- # -*- encoding: utf8 -*-
from math import libyaff from libmath import yafflib
from PyQt4.QtGui import QColor from PyQt4.QtGui import QColor
import numpy as np import numpy as np
from math.BDSMathlib import id_to_color from libmath.BDSlib import id_to_color
from data.container_base import BaseObject from container_base import BaseObject
from gui import ContainerWidgets from gui import ContainerWidgets
@ -94,7 +94,7 @@ class YAFF(BaseObject):
self.widget.on_model_changed.connect(self.change_model) self.widget.on_model_changed.connect(self.change_model)
self.widget.configuration_changed.connect(self.change_configuration) self.widget.configuration_changed.connect(self.change_configuration)
self.color = QColor(32, 120, 29, int(255*0.82)) self.color = QColor(32, 120, 29, int(255*0.82))
self._libyaff = libyaff.Yaff(self.widget.getYaffType()) self._libyaff = yafflib.Yaff(self.widget.getYaffType())
self.id_label = self._libyaff.label self.id_label = self._libyaff.label
self.id_string = "yaff" self.id_string = "yaff"
self._param_number = self._libyaff.params self._param_number = self._libyaff.params
@ -114,7 +114,7 @@ class YAFF(BaseObject):
self.updateData() self.updateData()
def change_model(self): def change_model(self):
self._libyaff = libyaff.Yaff(self.widget.getYaffType()) self._libyaff = yafflib.Yaff(self.widget.getYaffType())
self._selector_mask = self.widget.selector_mask self._selector_mask = self.widget.selector_mask
self.id_label = self._libyaff.label self.id_label = self._libyaff.label
self.param_number = self._libyaff.params self.param_number = self._libyaff.params

View File

@ -3,7 +3,7 @@ from PyQt4.QtGui import QColor
import numpy as np import numpy as np
import pyqtgraph as pg import pyqtgraph as pg
from math.BDSMathlib import FitFunctionCreator from libmath.BDSlib import FitFunctionCreator
class Data: class Data:

View File

@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
from math import libyaff import yafflib
__author__ = 'markusro' __author__ = 'markusro'
@ -194,7 +194,7 @@ class Functions(QObject):
"static": (self.static_cmplx, 1), "static": (self.static_cmplx, 1),
"yaff": (self.yaff, 8) "yaff": (self.yaff, 8)
} }
self.YAFF = libyaff.Yaff() self.YAFF = yafflib.Yaff()
def hn_cmplx( self, p, x ): def hn_cmplx( self, p, x ):
om = 2*np.pi*x om = 2*np.pi*x

5559
ui/images_rc.py Normal file

File diff suppressed because it is too large Load Diff