Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self.transform_data_series:
if self.sequential_file_mode:
self.transformation_queue.addItem('masking')
self.transform_list += ['masking']
self.log.appendPlainText('Add masking to transformations queue')
qt.QCoreApplication.processEvents()
else:
total = len(self.data_series)
if not total:
message = "Could not transform image if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
return
for i in range(len(self.data_series)):
if self.data_series[i].shape != self.mask.shape:
message = "Mask and image have different shapes, skipping image %d" % i
qt.QMessageBox.warning(self, 'Warning', message)
self.log.appendPlainText(message)
else:
self.data_series[i] = self.mask * self.data_series[i]
self.progressBar.setValue((float(i + 1) / (total)) * 100.)
self.log.appendPlainText('Applying mask to data series: image %d' % i)
qt.QCoreApplication.processEvents()
iid = self.imgDict[str(self.images_list.currentText())]
self.select_new_image(None, imgID=iid)
else:
if self.data.any():
self.data = self.mask * self.data
iid = self.imgDict[str(self.images_list.currentText())]
self.data_series[iid] = self.data[:]
self.on_draw()
message = 'Binary boolean mask loaded and applied'
self.statusBar().showMessage(message, 2000)
else:
endian = '>'
img = fabio.binaryimage.binaryimage()
img.read(fname, dim1, dim2, offset, bytecode, endian)
self.mask = img.data[:]
if self.transform_data_series:
if self.sequential_file_mode:
self.transformation_queue.addItem('masking')
self.transform_list += ['masking']
self.log.appendPlainText('Add masking to transformations queue')
qt.QCoreApplication.processEvents()
else:
total = len(self.data_series)
if not total:
message = "Could not transform image if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
return
for i in range(len(self.data_series)):
if self.data_series[i].shape != self.mask.shape:
message = "Mask and image have different shapes, skipping image %d" % i
qt.QMessageBox.warning(self, 'Warning', message)
self.log.appendPlainText(message)
else:
self.data_series[i] = self.mask * self.data_series[i]
self.progressBar.setValue((float(i + 1) / (total)) * 100.)
self.log.appendPlainText('Applying mask to data series: image %d' % i)
qt.QCoreApplication.processEvents()
iid = self.imgDict[str(self.images_list.currentText())]
self.select_new_image(None, imgID=iid)
else:
if self.data.any():
self.data = self.mask * self.data
def binary_block_info(self):
if str(self.lineEdit.text()) != '' and str(self.lineEdit_2.text()) != '' and str(self.lineEdit_3.text()) != '':
self.dim1 = int(str(self.lineEdit.text()))
self.dim2 = int(str(self.lineEdit_2.text()))
self.offset = int(str(self.lineEdit_3.text()))
else:
message = "All informations are mandatory, please fill the blanks"
qt.QMessageBox.warning(self, 'Warning', message)
return
self.bytecode = str(self.comboBox.currentText())
self.endian = str(self.comboBox_2.currentText())
self.accept()
def open_h5_data_series(self): # TODO batch mode compatibility
fname = qt.QFileDialog.getOpenFileName(self, 'Select and open series of files')
if isinstance(fname, tuple):
# PyQt5 compatibility
fname = fname[0]
fname = str(fname)
self.h5_loaded = True
if self.filecheckBox.checkState():
self.filecheckBox.stateChanged.disconnect()
self.filecheckBox.setCheckState(False)
self.sequential_file_mode = False
self.filecheckBox.stateChanged.connect(self.sequential_option)
message = 'Sequential file mode is not compatible with hdf5 input file: option removed'
qt.QMessageBox.warning(self, 'Message', message)
if fname:
self.data_series = []
self.header_series = []
self.sequential_file_list = []
self.sequential_file_dict = {}
self.imagelistWidget.clear()
self.headerTextEdit.clear()
with Nexus(fname, 'r') as nxs:
entry = nxs.get_entries()[0]
nxdata = nxs.get_class(entry, class_type="NXdata")[0]
dataset = nxdata.get("data", numpy.zeros(shape=(1, 1, 1)))
total = dataset.shape[0]
imgDict = {}
extract_fname = os.path.basename(os.path.splitext(fname)[0])
self.images_list.clear()
safeiid = 0
def _open(self, filename):
"""Returns a fabio image if the file can be loaded, else display a
dialog to help decoding the file. Else return None."""
try:
img = fabio.open(filename)
except Exception as _:
message = 'Automatic format recognition procedure failed or '\
'pehaps you are trying to open a binary data block...\n\n'\
'Switch to manual procedure.'
qt.QMessageBox.warning(self, 'Message', message)
dial = BinDialog(self)
dim1, dim2, offset, bytecode, endian = dial.exec_()
if dim1 is not None and dim2 is not None:
if endian == 'Short':
endian = '<'
else:
endian = '>'
img = fabio.binaryimage.binaryimage()
img.read(filename, dim1, dim2, offset, bytecode, endian)
img.header = {'Info': 'No header information available in binary data blocks'}
else:
return
return img
self.data_series[i] = self.data_series[i].transpose()[:]
self.progressBar.setValue((float(i + 1) / (total)) * 100.)
self.log.appendPlainText('Applying transposition to data series: image %d' % i)
qt.QCoreApplication.processEvents()
iid = self.imgDict[str(self.images_list.currentText())]
self.select_new_image(None, imgID=iid)
else:
if self.data.any():
self.data = self.data.transpose()[:]
iid = self.imgDict[str(self.images_list.currentText())]
self.data_series[iid] = self.data[:]
self.log.appendPlainText('Applying transposition to current data')
self.on_draw()
else:
message = "Could not transform image if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
self.progressBar.setValue(0)
info = self._getSaveFileNameAndFilter(self, "Save data series as single high density file",
qt.QDir.currentPath(),
filter=self.tr("HDF5 archive (*.h5)"))
if self.data_series or self.sequential_file_list:
if str(info[0]) != '' and str(info[1]) != '':
format_ = self.extract_format_from_string(str(info[1]))
fname = self.add_extention_if_absent(str(info[0]), format_)
if format_ == '*.h5':
self.convert_and_save_to_h5(fname)
else:
qt.QMessageBox.warning(self, 'Warning', "Unknown format: %s" % format_)
return
else:
if str(info[0]) != '' and str(info[1]) != '':
message = "Could not save image as file if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
def vertical_mirror(self):
if self.transform_data_series:
if self.sequential_file_mode:
self.transformation_queue.addItem('vertical_mirror')
self.transform_list += ['vertical_mirror']
self.log.appendPlainText('Add vertical mirror to transformations queue')
qt.QCoreApplication.processEvents()
else:
total = len(self.data_series)
if not total:
message = "Could not transform image if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
return
for i in range(len(self.data_series)):
self.data_series[i] = numpy.fliplr(self.data_series[i])[:]
self.progressBar.setValue((float(i + 1) / (total)) * 100.)
self.log.appendPlainText('Applying vertical mirror to data series: image %d' % i)
qt.QCoreApplication.processEvents()
iid = self.imgDict[str(self.images_list.currentText())]
self.select_new_image(None, imgID=iid)
else:
if self.data.any():
self.data = numpy.fliplr(self.data)[:]
iid = self.imgDict[str(self.images_list.currentText())]
self.data_series[iid] = self.data[:]
self.log.appendPlainText('Applying vertical mirror to current data')
self.on_draw()
else:
def rotation_270(self):
if self.transform_data_series:
if self.sequential_file_mode:
self.transformation_queue.addItem('rotation(-90)')
self.transform_list += ['rotation(-90)']
self.log.appendPlainText('Add - 90 rotation to transformations queue')
qt.QCoreApplication.processEvents()
else:
total = len(self.data_series)
if not total:
message = "Could not transform image if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
return
for i in range(len(self.data_series)):
self.data_series[i] = numpy.rot90(self.data_series[i], 3)[:]
self.progressBar.setValue((float(i + 1) / (total)) * 100.)
self.log.appendPlainText('Applying - 90 rotation to data series: image %d' % i)
qt.QCoreApplication.processEvents()
iid = self.imgDict[str(self.images_list.currentText())]
self.select_new_image(None, imgID=iid)
else:
if self.data.any():
self.data = numpy.rot90(self.data, 3)[:]
iid = self.imgDict[str(self.images_list.currentText())]
self.data_series[iid] = self.data[:]
self.log.appendPlainText('Applying - 90 rotation to current data')
self.on_draw()
else:
def rotation_90(self):
if self.transform_data_series:
if self.sequential_file_mode:
self.transformation_queue.addItem('rotation(+90)')
self.transform_list += ['rotation(+90)']
self.log.appendPlainText('Add + 90 rotation to transformations queue')
qt.QCoreApplication.processEvents()
else:
total = len(self.data_series)
if not total:
message = "Could not transform image if no data have been loaded"
qt.QMessageBox.warning(self, 'Warning', message)
return
for i in range(len(self.data_series)):
self.data_series[i] = numpy.rot90(self.data_series[i])[:]
self.progressBar.setValue((float(i + 1) / (total)) * 100.)
self.log.appendPlainText('Applying + 90 rotation to data series: image %d' % i)
qt.QCoreApplication.processEvents()
iid = self.imgDict[str(self.images_list.currentText())]
self.select_new_image(None, imgID=iid)
else:
if self.data.any():
self.data = numpy.rot90(self.data)[:]
iid = self.imgDict[str(self.images_list.currentText())]
self.data_series[iid] = self.data[:]
self.log.appendPlainText('Applying + 90 rotation to current data')
self.on_draw()
else: