def derandomize(tsoutpath, derandStruct, timestamps): plc = pipeconf.PCFGSection("--") plc.setVal("pipeline._0.name", "derandomize") plc.setVal("pipeline._0.derandStruct", derandStruct) plc.setVal("pipeline._1.name", "imagewrite") plc.setVal("pipeline._1.outstream", "outts") outts = TimeStream() outts.name = "derandomized" outts.create(tsoutpath) ctx = pipeconf.PCFGSection("--") ctx.setVal("outts.outts", outts) pl = pipeline.ImagePipeline(plc.pipeline, ctx) # 4. Execute pipeline for i in range(len(timestamps)): ts = timestamps[i] try: result = pl.process(ctx, [ts], True) except Exception as e: print("Skipped {}".format(ts)) continue
def _derandomize(self): # 0. Get the output directory tsoutpath = QtGui.QFileDialog.getExistingDirectory(self, \ "Select Output Derandomization Directory", self._currDir, \ QtGui.QFileDialog.ShowDirsOnly \ | QtGui.QFileDialog.DontResolveSymlinks) tsoutpath = str(tsoutpath) if tsoutpath == "": # Handle the cancel return self._currDir = os.path.dirname(str(tsoutpath)) # 1. Gather all timestamps timestamps = [] for r in range(self._ui.tslist.rowCount()-1): i = self._ui.tslist.item(r,1) tst = i.data(QtCore.Qt.UserRole).toPyObject() timestamps = timestamps + tst.timestamps timestamps = sorted(set(timestamps)) # 2. Get derandStruct derandStruct = self._createDerandStruct() # 3. Create pipeline components plc = pipeconf.PCFGSection("--") plc.setVal("pipeline._0.name", "derandomize") plc.setVal("pipeline._0.derandStruct", derandStruct) plc.setVal("pipeline._1.name", "imagewrite") plc.setVal("pipeline._1.outstream", "outts") outts = TimeStream() outts.name = "derandomized" outts.create(tsoutpath) ctx = pipeconf.PCFGSection("--") ctx.setVal("outts.outts", outts) pl = pipeline.ImagePipeline(plc.pipeline, ctx) # 4. Execute pipeline self._ui.bCancelClicked = False self._ui.pbts.setVisible(True) self._ui.bCancel.setVisible(True) self._ui.pbts.setMinimum(0) self._ui.pbts.setMaximum(len(timestamps)) self._ui.pbts.reset() for i in range(len(timestamps)): self._ui.pbts.setValue(i) QtGui.qApp.processEvents() ts = timestamps[i] try: result = pl.process(ctx, [ts], True) except Exception as e: errmsg = QtGui.QErrorMessage(self) errmsg.setWindowTitle("Error Derandomizing to ". \ format(tsoutpath)) errmsg.showMessage(str(e)) break if self._ui.bCancelClicked: break self._ui.pbts.setValue(self._ui.pbts.maximum()) self._ui.pbts.setVisible(False) self._ui.bCancel.setVisible(False)