def openFile(self): """ Open file to load in. """ if not self.getConfig(gvars.key_batchLoadingMode): directory = self.getLastOpenedDir() filenames, selectedFilter = QFileDialog.getOpenFileNames( self, caption="Open File", filter="Video files (*.tif *fits)", directory=directory, ) if len(filenames) > 0: progressbar = ProgressBar(loop_len=len(filenames), parent=self) for i, full_filename in enumerate(filenames): if progressbar.wasCanceled(): break # Make sure name is unique uniqueName = lib.utils.generate_unique_name( full_filename=full_filename, array=self.data.videos.keys(), ) self.data.load_video_data( path=full_filename, name=uniqueName, alex=self.getConfig(gvars.key_alexEnabled), view_setup=self.getConfig(gvars.key_viewSetup), donor_is_first=self.donor_first, donor_is_left=self.donor_is_left, bg_correction=self.bg_correction, ) item = QStandardItem(uniqueName) item.setCheckable(False) self.currName = uniqueName self.currDir = os.path.dirname(full_filename) self.listModel.appendRow(item) # refresh listView self.listView.repaint() progressbar.increment() # Select first video if loading into an empty listView if self.currRow is None: self.currRow = 0 self.selectListViewTopRow() index = self.listModel.index(self.currRow, 0) name = self.listModel.data(index) self.currName = name # Write most recently opened directory to getConfig file, # but only if a file was selected if self.currDir is not None: self.setConfig(gvars.key_lastOpenedDir, self.currDir) else: self.batchOpen()
def predict_batch(X, model, batch_size=256, progressbar: ProgressBar = None): """ Predicts on batches in a loop """ batches = (X.shape[0] // batch_size) + 1 y_pred = [] for i in range(batches): i1 = i * batch_size i2 = i1 + batch_size print(X[i1:i2].shape) y_pred.append(model.predict_on_batch(X[i1:i2])) if progressbar is not None: progressbar.increment() if progressbar.wasCanceled(): break return np.row_stack(y_pred)
def batchOpen(self): """Loads one video at a time and extracts traces, then clears the video from memory afterwards""" directory = self.getLastOpenedDir() trace_window = self.windows[gvars.TraceWindow] # type: TraceWindow filenames, selectedFilter = QFileDialog.getOpenFileNames( self, caption="Open File", filter="Video files (*.tif *.fits)", directory=directory, ) if len(filenames) > 0: self.processEvents() progressbar = ProgressBar(loop_len=len(filenames), parent=self) for i, full_filename in enumerate(filenames): if progressbar.wasCanceled(): break else: progressbar.increment() self.currName = os.path.basename(full_filename) if self.currName in self.data.videos: continue self.data.load_video_data( path=full_filename, name=os.path.basename(full_filename), donor_is_first=self.donor_first, donor_is_left=self.donor_is_left, bg_correction=self.bg_correction, ) channels = ("green", "red") for c in channels: if self.currentVideo().acc.exists: self.colocalizeSpotsSingleVideo(channel=c, find_npairs="auto") else: self.colocalizeSpotsSingleVideo(channel=c, find_npairs="spinbox") self.getTracesSingleVideo() self.currentVideo().vid = None for c in self.currentVideo().channels + ( self.currentVideo().acc, ): c.raw = None self.listModel.appendRow(QStandardItem(self.currName)) self.listView.repaint() self.currDir = os.path.dirname(full_filename) if self.currDir is not None: self.setConfig(gvars.key_lastOpenedDir, self.currDir) if len(self.data.traces) > 0: currently_loaded = trace_window.returnCurrentListViewNames() # Iterate over all filenames and add to list for name in self.data.traces.keys(): # If name is already in list, skip it if name in currently_loaded: continue item = QStandardItem(name) item.setCheckable(True) trace_window.listModel.appendRow(item) trace_window.selectListViewTopRow() trace_window.getCurrentListObject() trace_window.show() self.batchLoaded = True self.refreshInterface() self.selectListViewTopRow() self.refreshPlot()
def openFile(self, *args): """ Loads ASCII files directly into the TraceWindow. """ directory = self.getLastOpenedDir() filenames, selectedFilter = QFileDialog.getOpenFileNames( self, caption="Open File", filter="Trace files (*.txt *.dat)", directory=directory, ) if len(filenames) != 0: select_top_row = True if len(self.data.traces) == 0 else False update_every_n = int(10) if len(filenames) > 10 else int(2) progressbar = ProgressBar(loop_len=len(filenames) / update_every_n, parent=self) rows = [] for n, full_filename in enumerate(filenames): if progressbar.wasCanceled(): break self.currDir = os.path.dirname(full_filename) try: newTrace = TraceContainer(filename=full_filename, loaded_from_ascii=True) except AttributeError: # if a non-trace file was selected warnings.warn( f"This file could not be read: \n{full_filename}", UserWarning, ) continue if (n % update_every_n) == 0: progressbar.increment() # If file wasn't loaded properly, skip if newTrace.load_successful is False: continue # Don't load duplicates if newTrace.name in self.data.traces.keys(): continue self.data.traces[newTrace.name] = newTrace item = QStandardItem(newTrace.name) rows.append(item) # Don't touch the GUI until loading is done [self.listModel.appendRow(row) for row in rows] [ self.listModel.item(i).setCheckable(True) for i in range(self.listModel.rowCount()) ] self.listView.repaint() progressbar.close() if select_top_row: self.selectListViewTopRow() self.getCurrentListObject() self.setConfig(gvars.key_lastOpenedDir, self.currDir)