def test_timestream_create(self): ts = TimeStream() ts.version = 1 ts.create(self.tmp_path) self.assertEqual(ts.path, self.tmp_path) self.assertDictEqual(ts.image_data, {}) self.assertDictEqual(ts.data, {})
def test_timestream_create_bad(self): ts = TimeStream() with self.assertRaises(ValueError): ts.create(self.tmp_path, version=3) with self.assertRaises(ValueError): ts.create("/not_a/valid/path") with self.assertRaises(TypeError): ts.create("relative/path") with self.assertRaises(TypeError): ts.create(123)
def test_timestream_write(self): ts = TimeStream() ts.version = 1 ts.create(self.tmp_path, ext="jpg") self.assertEqual(ts.path, self.tmp_path) self.assertDictEqual(ts.image_data, {}) self.assertDictEqual(ts.data, {}) for _ in range(10): img = TimeStreamImage() arr = np.arange(300, dtype="uint8") arr = arr.reshape((10, 10, 3)) date = dt.datetime.now() str_date = ts_format_date(date) img.pixels = arr img.datetime = date img.data["fake"] = True ts.write_image(img) self.assertIn(str_date, ts.image_data) self.assertDictEqual(img.data, ts.image_data[str_date]) self.assertTrue(path.exists, img.path)
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)