summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnderwaater <onderwaa@esrf.fr>2015-10-08 11:47:21 +0200
committerOnderwaater <onderwaa@esrf.fr>2015-10-08 11:47:21 +0200
commit2b11266c824853c6ab129cdf99c8b6936b7cd158 (patch)
treed293a5914077fd310bd91fa1034b63667d91f117
parent753f1cbb2482ff75a183a53b7bbd3892ee3dd3d7 (diff)
cleanup
-rwxr-xr-xBINoculars/main.py1
-rw-r--r--BINoculars/space.py7
-rwxr-xr-xBINoculars/util.py23
-rwxr-xr-xprocessgui.py112
4 files changed, 58 insertions, 85 deletions
diff --git a/BINoculars/main.py b/BINoculars/main.py
index b9dd52f..8dc42d0 100755
--- a/BINoculars/main.py
+++ b/BINoculars/main.py
@@ -82,7 +82,6 @@ class Main(object):
else:
self.dispatcher.config.destination.store(self.result)
-
def process_job(self, job):
def generator():
res = self.projection.config.resolution
diff --git a/BINoculars/space.py b/BINoculars/space.py
index 9deb639..6e1ad48 100644
--- a/BINoculars/space.py
+++ b/BINoculars/space.py
@@ -586,8 +586,7 @@ class Space(object):
new.photons = numpy.transpose(self.photons, axes = newindices)
new.contributions = numpy.transpose(self.contributions, axes = newindices)
return new
-
-
+
def transform_coordinates(self, resolutions, labels, transformation):
# gather data and transform
intensity = self.get_masked()
@@ -611,10 +610,10 @@ class Space(object):
if isinstance(intensity, numpy.ma.core.MaskedArray):
mask = intensity.mask
intensity = intensity.data
+ valid = numpy.bitwise_and(numpy.isfinite(intensity), ~mask)
else:
- mask = numpy.zeros_like(intensity, dtype = numpy.bool)
+ valid = numpy.isfinite(intensity)
- valid = numpy.bitwise_and(numpy.isfinite(intensity), ~mask)
intensity = intensity[valid]
if not intensity.size:
return
diff --git a/BINoculars/util.py b/BINoculars/util.py
index f169050..d0ef403 100755
--- a/BINoculars/util.py
+++ b/BINoculars/util.py
@@ -787,7 +787,7 @@ def zpi_load(filename):
def serialize(space, command):
- # first 24 bytes contain length of the message
+ # first 48 bytes contain length of the message, whereby the first 8 give the length of the command, the second 8 the length of the configfile etc..
message = StringIO.StringIO()
message.write(struct.pack('QQQQQQ',0,0,0,0,0,0))
@@ -814,34 +814,25 @@ def serialize(space, command):
message.seek(0)
return message
-def packet_slicer(length, size = 1024):
+def packet_slicer(length, size = 1024):#limit the communication to 1024 bytes
packets = [size] * (length / size)
packets.append(length % size)
return packets
def socket_send(ip, port, mssg):
try:
- command, config, meta, axes, photons, contributions = struct.unpack('QQQQQQ',mssg.read(48))
+ mssglengths = struct.unpack('QQQQQQ',mssg.read(48))#the lengths of all the components
mssg.seek(0)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
sock.send(mssg.read(48))
- for packet in packet_slicer(command):
- sock.send(mssg.read(packet))
- for packet in packet_slicer(config):
- sock.send(mssg.read(packet))
- for packet in packet_slicer(meta):
- sock.send(mssg.read(packet))
- for packet in packet_slicer(axes):
- sock.send(mssg.read(packet))
- for packet in packet_slicer(photons):
- sock.send(mssg.read(packet))
- for packet in packet_slicer(contributions):
- sock.send(mssg.read(packet))
+ for l in mssglengths:
+ for packet in packet_slicer(l):
+ sock.send(mssg.read(packet))
sock.close()
- except socket.error:# in case of failure to send. The data will be saved anyway so any loss of communication is just unfortunate
+ except socket.error:# in case of failure to send. The data will be saved anyway so any loss of communication unfortunate but not critical
pass
diff --git a/processgui.py b/processgui.py
index e6d831e..e2a0e27 100755
--- a/processgui.py
+++ b/processgui.py
@@ -16,9 +16,6 @@ import glob
import BINoculars.util, BINoculars.main
import time
-
-
-
#--------------------------------------------CREATE MAIN WINDOW----------------------------------------
class Window(QtGui.QMainWindow):
@@ -51,7 +48,6 @@ class Window(QtGui.QMainWindow):
Create.setStatusTip('Create Configfile')
Create.triggered.connect(self.New_Config)
-
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(openFile)
@@ -79,7 +75,6 @@ class Window(QtGui.QMainWindow):
self.process = QtGui.QPushButton('run',self)
self.process.setStyleSheet("background-color: darkred")
self.connect(self.process, QtCore.SIGNAL("clicked()"),self.run)
-
self.wid = QtGui.QWidget()
self.CommandLayout = QtGui.QVBoxLayout()
@@ -98,7 +93,6 @@ class Window(QtGui.QMainWindow):
def removeConf(self):
self.ListCommand.removeRow(self.ListCommand.currentRow())
-
def Add_To_Liste(self,(command, cfg)):
row = self.ListCommand.rowCount()
@@ -113,11 +107,6 @@ class Window(QtGui.QMainWindow):
self.ListCommand.setItem(row, 0, self.item1)
self.ListCommand.setItem(row, 1, self.item2)
-
-
-
-
-
#We run the script and create a hdf5 file
def run(self):
maximum = self.ListCommand.rowCount()
@@ -149,17 +138,11 @@ class Window(QtGui.QMainWindow):
#we call the load function
def ShowFile(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '')
- for F in filename.split('/') :
- self.NameFile = []
- self.NameFile.append(F)
- self.NameFile.reverse()
- confwidget = Conf_Tab(self)
- newIndex = self.tab_widget.addTab(confwidget,self.NameFile[0])
+ confwidget = Conf_Tab(self)
+ confwidget.read_data(str(filename))
+ newIndex = self.tab_widget.addTab(confwidget, os.path.basename(str(filename)))
QtCore.QObject.connect(confwidget, QtCore.SIGNAL("command"),self.Add_To_Liste)
self.tab_widget.setCurrentIndex(newIndex)
- widget = self.tab_widget.currentWidget()
- widget.read_data(filename)
-
#we call the save function
def Save(self):
@@ -173,7 +156,6 @@ class Window(QtGui.QMainWindow):
self.tab_widget.addTab(widget,'New configfile')
QtCore.QObject.connect(widget, QtCore.SIGNAL("command"),self.Add_To_Liste)
-
#----------------------------------------------------------------------------------------------------
#-----------------------------------------CREATE TABLE-----------------------------------------------
class Table(QtGui.QWidget):
@@ -213,33 +195,31 @@ class Table(QtGui.QWidget):
self.table.removeRow(self.table.currentRow())
def get_keys(self):
- return list(self.table.item(index,0).text() for index in range(self.table.rowCount()))
+ return list(str(self.table.item(index,0).text()) for index in range(self.table.rowCount()))
- #Here we take all values on tables
+ #Here we take all values from tables
def getParam(self):
for index in range(self.table.rowCount()):
- key = str(self.table.item(index,0).text())
- comment = str(self.table.item(index,0).toolTip())
- if self.table.item(index,1):
- value = str(self.table.item(index, 1).text())
- else:
- value = str(self.table.cellWidget(index, 1).currentText())
- if self.table.item == None:
- value = str(self.table.item(index,1).text(""))
- yield key, value, comment
-
- #Here we put all values on tables
- def addData(self,cfg):
+ if not self.table.item == None:
+ key = str(self.table.item(index,0).text())
+ comment = str(self.table.item(index,0).toolTip())
+ if index == 0:
+ yield key, str(self.table.cellWidget(index, 1).currentText()), comment
+ elif self.table.item(index,1):
+ if len(str(self.table.item(index,1).text())) != 0 and self.table.item(index,0).textColor() == QtGui.QColor('black'):
+ yield key, str(self.table.item(index, 1).text()), comment
+
+ #Here we put all values in tables
+ def addData(self, cfg):
for item in cfg:
if item == 'type':
box = self.table.cellWidget(0,1)
value = cfg[item].split(':')
- if len(value)> 1 :
+ if len(value) > 1 :
box.setCurrentIndex(box.findText(value[1], QtCore.Qt.MatchFixedString))
-
else:
- box.setCurrentIndex(box.findText(cfg[item], QtCore.Qt.MatchFixedString))
- else:
+ box.setCurrentIndex(box.findText(cfg[item], QtCore.Qt.MatchFixedString))
+ elif item not in self.get_keys():
self.add_row()
row = self.table.rowCount()
for col in range(self.table.columnCount()):
@@ -249,22 +229,31 @@ class Table(QtGui.QWidget):
if col == 1:
newitem2 = QtGui.QTableWidgetItem(cfg[item])
self.table.setItem(row -1, col, newitem2)
-
-
-
-
+ else:
+ index = self.get_keys().index(item)
+ self.table.item(index, 1).setText(cfg[item])
- def addDataConf(self, items):
+
+ def addDataConf(self, options):
keys = self.get_keys()
- newconfigs = dict((item[0], '') for item in items if item[0] not in keys)
+ newconfigs = dict((option[0], '') for option in options if option[0] not in keys)
self.addData(newconfigs)
-
+ names = list(option[0] for option in options)
+
+ for index, key in enumerate(self.get_keys()):
+ if str(key) in names:
+ self.table.item(index, 0).setTextColor(QtGui.QColor('black'))
+ self.table.item(index, 0).setToolTip(options[names.index(key)][1])
+ elif str(key) == 'type':
+ self.table.item(index, 0).setTextColor(QtGui.QColor('black'))
+ else:
+ self.table.item(index, 0).setTextColor(QtGui.QColor('gray'))
+
def add_to_combo(self, items):
self.combobox.clear()
self.combobox.addItems(items)
-
#----------------------------------------------------------------------------------------------------
#-----------------------------------------CREATE CONFIG----------------------------------------------
class Conf_Tab(QtGui.QWidget):
@@ -288,7 +277,6 @@ class Conf_Tab(QtGui.QWidget):
self.connect(self.add, QtCore.SIGNAL("clicked()"), self.AddCommand)
self.scan = QtGui.QLineEdit()
self.scan.setToolTip('scan selection example: 820 824')
-
#the dispositon of all elements of the gui
Layout = QtGui.QGridLayout()
@@ -306,29 +294,28 @@ class Conf_Tab(QtGui.QWidget):
#Here we call all methods for selected an ellement on differents combobox
self.Dis.add_to_combo(QtCore.QStringList(BINoculars.util.get_dispatchers()))
self.select.activated['QString'].connect(self.DataCombo)
- self.Inp.combobox.activated['QString'].connect(self.DataTableInp)
- self.Pro.combobox.activated['QString'].connect(self.DataTableInpPro)
- self.Dis.combobox.activated['QString'].connect(self.DataTableInpDis)
-
+ self.Inp.combobox.activated.connect(self.DataTableInp)
+ self.Pro.combobox.activated.connect(self.DataTableInpPro)
+ self.Dis.combobox.activated.connect(self.DataTableInpDis)
def DataCombo(self,text):
self.Inp.add_to_combo(QtCore.QStringList(BINoculars.util.get_inputs(str(text))))
self.Pro.add_to_combo(QtCore.QStringList(BINoculars.util.get_projections(str(text))))
-
- def DataTableInp (self,text):
- #self.Inp.table.setRowCount(1)
+ self.DataTableInp()
+ self.DataTableInpPro()
+ self.DataTableInpDis()
+
+ def DataTableInp(self):
backend = str(self.select.currentText())
inp = BINoculars.util.get_input_configkeys(backend, str(self.Inp.combobox.currentText()))
self.Inp.addDataConf(inp)
- def DataTableInpPro (self,text):
- #self.Pro.table.setRowCount(1)
+ def DataTableInpPro(self):
backend = str(self.select.currentText())
proj = BINoculars.util.get_projection_configkeys(backend, str(self.Pro.combobox.currentText()))
self.Pro.addDataConf(proj)
- def DataTableInpDis (self,text):
- #self.Dis.table.setRowCount(1)
+ def DataTableInpDis(self):
backend = str(self.select.currentText())
disp = BINoculars.util.get_dispatcher_configkeys(str(self.Dis.combobox.currentText()))
self.Dis.addDataConf(disp)
@@ -377,7 +364,7 @@ class Conf_Tab(QtGui.QWidget):
return cfg
#This method take elements on a text file or the binocular script and put them on tables
- def read_data(self,filename):
+ def read_data(self, filename):
cfg = BINoculars.util.ConfigFile.fromtxtfile(str(filename))
input_type = cfg.input['type']
backend, value = input_type.strip(' ').split(':')
@@ -387,7 +374,6 @@ class Conf_Tab(QtGui.QWidget):
self.Inp.addData(cfg.input)
self.Pro.addData(cfg.projection)
-
#we add command on the DockWidget
def AddCommand(self):
scan = [str(self.scan.text())]
@@ -395,9 +381,6 @@ class Conf_Tab(QtGui.QWidget):
commandconfig = (scan , cfg)
self.emit(QtCore.SIGNAL('command'), commandconfig)
-
-
-
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
@@ -405,3 +388,4 @@ if __name__ == '__main__':
main.show()
sys.exit(app.exec_())
+