def test_settings_observer_metadata_with_zstack(self): settings_observer = SettingsObserver(model.getComponents()) vas = {"exposureTime"} s1 = stream.FluoStream("FM", self.ccd, self.ccd.data, self.light, self.light_filter, detvas=vas, focuser=self.fm_focuser) s1.detExposureTime.value = 0.023 # 23 ms zlevels_list = generate_zlevels(self.fm_focuser, [-2e-6, 2e-6], 1e-6) zlevels = {s1: list(zlevels_list)} f = acquireZStack([s1], zlevels, settings_observer) # get the data data, exp = f.result() self.assertIsNone(exp) for d in data: self.assertTrue(model.MD_EXTRA_SETTINGS in d.metadata) # if zstack, so the center has 3 components self.assertEqual(len(d.metadata[model.MD_POS]), 3) # if zstack, so the pixel size has 3 components self.assertEqual(len(d.metadata[model.MD_PIXEL_SIZE]), 3) self.assertEqual( data[0].metadata[model.MD_EXTRA_SETTINGS]["Camera"] ["exposureTime"], [0.023, "s"])
def test_compressed_stack(self): """ Test the whole procedure (acquire compressed zstack + stitch) of acquireTiledArea function """ # With fm streams settings_obs = SettingsObserver([self.stage]) fm_fov = compute_camera_fov(self.ccd) # Using "songbird-sim-ccd.h5" in simcam with tile max_res: (260, 348) area = (0, 0, fm_fov[0] * 2, fm_fov[1] * 2) # left, top, right, bottom overlap = 0.2 focus_value = self.focus.position.value['z'] zsteps = 3 # Create focus zlevels from the given zsteps number zlevels = numpy.linspace(focus_value - (zsteps / 2 * 1e-6), focus_value + (zsteps / 2 * 1e-6), zsteps).tolist() future = acquireTiledArea(self.fm_streams, self.stage, area=area, overlap=overlap, settings_obs=settings_obs, zlevels=zlevels) data = future.result() self.assertTrue(future.done()) self.assertEqual(len(data), 2) self.assertIsInstance(data[0], model.DataArray) self.assertEqual(len(data[0].shape), 2)
def test_metadata(self): """ Check if extra metadata are saved """ settings_obs = SettingsObserver(model.getComponents()) self.ccd.binning.value = ( 1, 1) # make sure we don't save the right metadata by accident detvas = {'exposureTime', 'binning', 'gain'} s1 = stream.FluoStream("fluo2", self.ccd, self.ccd.data, self.light, self.light_filter, detvas=detvas) s2 = stream.BrightfieldStream("bf", self.ccd, self.ccd.data, self.light, detvas=detvas) # Set different binning values for each stream s1.detBinning.value = (2, 2) s2.detBinning.value = (4, 4) st = stream.StreamTree(streams=[s1, s2]) f = acqmng.acquire(st.getProjections(), settings_obs=settings_obs) data, e = f.result() for s in data: self.assertTrue(model.MD_EXTRA_SETTINGS in s.metadata, "Stream %s didn't save extra metadata." % s) self.assertEqual( data[0].metadata[model.MD_EXTRA_SETTINGS][self.ccd.name] ['binning'], [(2, 2), 'px']) self.assertEqual( data[1].metadata[model.MD_EXTRA_SETTINGS][self.ccd.name] ['binning'], [(4, 4), 'px'])
def test_whole_procedure(self): """ Test the whole procedure (acquire + stitch) of acquireTiledArea function """ # With fm streams settings_obs = SettingsObserver([self.stage]) fm_fov = compute_camera_fov(self.ccd) # Using "songbird-sim-ccd.h5" in simcam with tile max_res: (260, 348) area = (0, 0, fm_fov[0] * 4, fm_fov[1] * 4) # left, top, right, bottom overlap = 0.2 self.stage.moveAbs({'x': 0, 'y': 0}).result() future = acquireTiledArea(self.fm_streams, self.stage, area=area, overlap=overlap, settings_obs=settings_obs) data = future.result() self.assertEqual(future._state, FINISHED) self.assertEqual(len(data), 2) self.assertIsInstance(data[0], odemis.model.DataArray) self.assertEqual(len(data[0].shape), 2) # With sem stream area = (0, 0, 0.00001, 0.00001) self.stage.moveAbs({'x': 0, 'y': 0}).result() future = acquireTiledArea(self.sem_streams, self.stage, area=area, overlap=overlap) data = future.result() self.assertEqual(future._state, FINISHED) self.assertEqual(len(data), 1) self.assertIsInstance(data[0], model.DataArray) self.assertEqual(len(data[0].shape), 2)
def test_metadata(self): """ Check if extra metadata are saved """ settings_obs = SettingsObserver(model.getComponents()) detvas = {"binning", "exposureTime"} sems = stream.SEMStream("test sem", self.sed, self.sed.data, self.ebeam) specs = stream.SpectrumSettingsStream("test spec", self.spec, self.spec.data, self.ebeam, detvas=detvas) sps = stream.SEMSpectrumMDStream("test sem-spec", [sems, specs]) specs.roi.value = (0, 0, 1, 1) specs.repetition.value = (2, 3) specs.detBinning.value = (2, specs.detBinning.value[1]) specs.detExposureTime.value = 0.1 specs2 = stream.SpectrumSettingsStream("test spec2", self.spec, self.spec.data, self.ebeam, detvas=detvas) sps2 = stream.SEMSpectrumMDStream("test sem-spec2", [sems, specs2]) specs2.roi.value = (0, 0, 1, 1) specs2.repetition.value = (2, 3) specs2.detBinning.value = (4, specs2.detBinning.value[1]) specs2.detExposureTime.value = 0.05 f = acqmng.acquire([sps, sps2], settings_obs) data = f.result() spec1_data = data[0][1] spec2_data = data[0][3] self.assertEqual( spec1_data.metadata[model.MD_EXTRA_SETTINGS][self.spec.name] ['binning'], [(2, specs.detBinning.value[1]), 'px']) self.assertEqual( spec2_data.metadata[model.MD_EXTRA_SETTINGS][self.spec.name] ['binning'], [(4, specs2.detBinning.value[1]), 'px']) self.assertEqual( spec1_data.metadata[model.MD_EXTRA_SETTINGS][self.spec.name] ['exposureTime'], [0.1, 's']) self.assertEqual( spec2_data.metadata[model.MD_EXTRA_SETTINGS][self.spec.name] ['exposureTime'], [0.05, 's'])