Commit c149a4b2 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[dataset] Dataset inherits from qObject to emit signal

parent 94f5d0a9
......@@ -34,11 +34,12 @@ import fabio
from silx.io import utils
from silx.io.url import DataUrl
from silx.gui import qt
from linkdick06.io import utils as link_utils
class Dataset():
class Dataset(qt.QObject):
"""Class to define a dataset from a series of raw data and dark data.
:param raw_filename: first filename of raw data to iterate from.
......@@ -50,13 +51,17 @@ class Dataset():
:param Union[List,numpy.ndarray] dark_data: list or numpy array of the
dataset dark data.
"""
signalProgress = qt.Signal(int)
def __init__(self, raw_filename=None, dark_filename=None, filenames=None,
data=None, dark_data=None, thread=False):
qt.QObject.__init__(self)
self._data = None
self.dark_frames = []
self.raw_filename = raw_filename
self.filenames = filenames
self.progress = 0
if data is not None:
if raw_filename is not None:
......@@ -73,6 +78,7 @@ class Dataset():
self._data = data
self._data_has_changed = False
self.dark_frames = dark_data
elif not thread:
self.startDataset()
......@@ -94,6 +100,7 @@ class Dataset():
self.motors_mne = series.getframe(0).header["motor_mne"].split(" ")
count = 0
link_utils.advancement_display(count, series.nframes, "Creating database")
for frame in series.frames():
self.data_urls.append(DataUrl(file_path=frame.file_container.filename,
......@@ -101,6 +108,7 @@ class Dataset():
self.motors_positions.append(frame.header['motor_pos'].split(" "))
count += 1
self.signalProgress.emit(int(count / series.nframes * 100))
link_utils.advancement_display(count, series.nframes, "Creating database")
......
......@@ -69,12 +69,14 @@ class BackgroundSubstractionWidget(qt.QWidget):
self._thread.setArgs(self.dataset.data, self.dataset.dark_frames)
self._thread.finished.connect(self._updateData)
self._thread.start()
self._computeB.setEnabled(False)
def _updateData(self):
"""
Updates the stack with the data computed in the thread
"""
self._thread.finished.disconnect(self._updateData)
self._computeB.setEnabled(True)
self.dataset.data = self._thread.data
assert self.dataset.data is not None
self.setStack(self.dataset.data)
......@@ -87,8 +89,7 @@ class BackgroundSubstractionWidget(qt.QWidget):
:param Dataset dataset: dataset
"""
self.dataset = dataset
if len(dataset.data.shape) != 3:
self.setStack(dataset.data)
self.setStack(dataset.data)
def setStack(self, *arg, **kwargs):
"""
......
......@@ -42,6 +42,8 @@ class DatasetSelectionWidget(qt.QTabWidget):
If both options are filled up, only the files in the list of filenames
are read.
"""
signalProgress = qt.Signal(int)
def __init__(self, parent=None):
qt.QTabWidget.__init__(self, parent)
......@@ -58,15 +60,25 @@ class DatasetSelectionWidget(qt.QTabWidget):
self._darkFilenameData = FilenameSelectionWidget(parent=self)
self.addTab(self._darkFilenameData, 'dark data')
def getDataset(self):
self.dataset = None
def startDataset(self):
# Data files win over filename
if not self._rawFilesData.getFiles():
return Dataset(raw_filename=self._rawFilenameData.getFilename(),
dark_filename=self._darkFilenameData.getFilename(), thread=True)
self.dataset = Dataset(raw_filename=self._rawFilenameData.getFilename(),
dark_filename=self._darkFilenameData.getFilename(),
thread=True)
else:
return Dataset(filenames=self._rawFilesData.getFiles(),
dark_filename=self._darkFilenameData.getFilename(), thread=True)
self.dataset = Dataset(filenames=self._rawFilesData.getFiles(),
dark_filename=self._darkFilenameData.getFilename(),
thread=True)
self.dataset.signalProgress.connect(self.updateProgress)
self.dataset.startDataset()
def updateProgress(self, progress):
self.signalProgress.emit(progress)
class FilesSelectionWidget(qt.QWidget):
......
......@@ -43,6 +43,7 @@ class ShiftCorrectionWidget(qt.QWidget):
"""
A widget to apply shift correction to a stack of images
"""
signalProgress = qt.Signal()
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment