def setUp(self): self.source = None self.exp = None self.flatfield_axis = LinearMotor() self.flatfield_axis.motion_velocity = 10000 * q.mm / q.s self.camera = LoggingCamera(flat_axis=self.flatfield_axis) self._data_dir = tempfile.mkdtemp() self.walker = DirectoryWalker(root=self._data_dir)
def live_on_stream2disk_prepare(self): self.fname, fext = self.QFD.getSaveFileName(self, 'Select directory', self.last_dir, "Image Files (*.tif)") self.lv_dirwalker = DirectoryWalker(root=os.path.dirname(self.fname), dsetname="frames_{:>02}.tif", bytes_per_file=2**37) self.lv_acquisitions = [Acquisition("Radios", self.acq_lv_stream2disk)] self.lv_experiment = Experiment(acquisitions=self.lv_acquisitions, walker=self.lv_dirwalker, separate_scans=True, name_fmt="live_view_seq_{:>03}") self.cons_writer = ImageWriter(self.lv_acquisitions, self.lv_dirwalker, async=True) self.cons_viewer = Consumer(self.lv_acquisitions, self.viewer)
def create_exp(self): self.log.info("creating concert experiment") acquisitions = [] #**********CREATE EXPERIMENT AND ATTACH CONSUMERS # CREATE NEW WALKER if self.file_writer_group.isChecked(): bpf = 0 if self.file_writer_group.bigtiff: bpf = 2**37 self.concert_scan.walker = DirectoryWalker( root=self.file_writer_group.root_dir, dsetname=self.file_writer_group.dsetname, bytes_per_file=bpf) else: # if writer is disabled we do not need walker as well self.concert_scan.walker = None # create experiment self.concert_scan.create_experiment( acquisitions, self.file_writer_group.ctsetname, self.file_writer_group.separate_scans)
def setUp(self): super(TestDirectoryWalker, self).setUp() self.path = tempfile.mkdtemp() self.walker = DirectoryWalker(root=self.path) self.data = np.ones((2, 2))
class TestDirectoryWalker(TestCase): def setUp(self): super(TestDirectoryWalker, self).setUp() self.path = tempfile.mkdtemp() self.walker = DirectoryWalker(root=self.path) self.data = np.ones((2, 2)) def tearDown(self): shutil.rmtree(self.path) def test_directory_creation(self): self.walker.descend('foo') self.walker.descend('bar') self.assertTrue(op.exists(op.join(self.path, 'foo'))) self.assertTrue(op.exists(op.join(self.path, 'foo', 'bar'))) async def test_default_write(self): await self.walker.write(async_generate([self.data, self.data])) self.assertTrue(op.exists(op.join(self.path, 'frame_000000.tif'))) self.assertTrue(op.exists(op.join(self.path, 'frame_000001.tif'))) # Cannot write if directory is not empty with self.assertRaises(StorageError): await self.walker.write(async_generate([self.data])) # Make a new one ... self.walker.descend('foo') await self.walker.write(async_generate([self.data])) self.assertTrue( op.exists(op.join(self.path, 'foo', 'frame_000000.tif'))) async def test_custom_write(self): await self.walker.write(async_generate([self.data]), dsetname='foo-{}.tif') self.assertTrue(op.exists(op.join(self.path, 'foo-0.tif'))) def test_invalid_ascend(self): with self.assertRaises(StorageError): self.walker.ascend() async def test_dset_exists(self): await self.walker.write(async_generate([self.data])) with self.assertRaises(StorageError): await self.walker.write(async_generate([self.data])) async def test_same_directory_different_dset(self): await self.walker.write(async_generate([self.data])) await self.walker.write(async_generate([self.data]), dsetname='bar-{}.tif') async def test_dset_prefix(self): async def test_raises(dsetname): with self.assertRaises(ValueError): await self.walker.write(async_generate([self.data]), dsetname=dsetname) async def test_ok(dsetname): await self.walker.write(async_generate([self.data]), dsetname=dsetname) await test_ok('bar-{}.tif') await test_ok('baz-{:>06}.tif') await test_ok('spam-{0}') await test_raises('bar') await test_raises('bar-{') await test_raises('bar-}') await test_raises('bar-}{') await test_raises('bar-}{{}')
class TestDirectoryWalker(TestCase): def setUp(self): super(TestDirectoryWalker, self).setUp() self.path = tempfile.mkdtemp() self.walker = DirectoryWalker(root=self.path) self.data = np.ones((2, 2)) def tearDown(self): shutil.rmtree(self.path) def test_directory_creation(self): self.walker.descend('foo') self.walker.descend('bar') self.assertTrue(op.exists(op.join(self.path, 'foo'))) self.assertTrue(op.exists(op.join(self.path, 'foo', 'bar'))) def test_default_write(self): self.walker.write([self.data, self.data]) self.assertTrue(op.exists(op.join(self.path, 'frame_000000.tif'))) self.assertTrue(op.exists(op.join(self.path, 'frame_000001.tif'))) # Cannot write if directory is not empty with self.assertRaises(StorageError): self.walker.write([self.data]) # Make a new one ... self.walker.descend('foo') self.walker.write([self.data]) self.assertTrue(op.exists(op.join(self.path, 'foo', 'frame_000000.tif'))) def test_custom_write(self): self.walker.write([self.data], dsetname='foo-{}.tif') self.assertTrue(op.exists(op.join(self.path, 'foo-0.tif'))) def test_invalid_ascend(self): with self.assertRaises(StorageError): self.walker.ascend() def test_dset_exists(self): self.walker.write(data=[self.data]) with self.assertRaises(StorageError): self.walker.write(data=[self.data]) def test_same_directory_different_dset(self): self.walker.write(data=[self.data]) self.walker.write(data=[self.data], dsetname='bar-{}.tif') def test_dset_prefix(self): def test_raises(dsetname): with self.assertRaises(ValueError): self.walker.write(data=[self.data], dsetname=dsetname) def test_ok(dsetname): self.walker.write(data=[self.data], dsetname=dsetname) test_ok('bar-{}.tif') test_ok('baz-{:>06}.tif') test_ok('spam-{0}') test_raises('bar') test_raises('bar-{') test_raises('bar-}') test_raises('bar-}{') test_raises('bar-}{{}')
def setUp(self): super(TestExperimentStates, self).setUp() self.data_dir = tempfile.mkdtemp() self.walker = DirectoryWalker(root=self.data_dir)