def test_find_best_hard(self): # tests with 2-bands bands = {(490e-9, 510e-9), (400e-9, 413e-9), ((650e-9, 680e-9), (780e-6, 812e-9), (1034e-9, 1500e-9)) } # try with "hard" values: the border for b in bands: # pick a good wl, and check the function finds it if isinstance(b[0], collections.Iterable): sb = b[-1] else: sb = b wl = sb[1] out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual(b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b)) # tests with 5-float bands bands = {(490e-9, 497e-9, 500e-9, 503e-9, 510e-9), (400e-9, 405e-9, 407e-9, 409e-9, 413e-9), ((650e-9, 660e-9, 675e-9, 678e-9, 680e-9), (780e-9, 785e-9, 790e-9, 800e-9, 812e-9), (1034e-9, 1080e-9, 1100e-9, 1200e-9, 1500e-9) ) } # try with "hard" values: the border for b in bands: # pick a good wl, and check the function finds it if isinstance(b[0], collections.Iterable): sb = b[1] else: sb = b wl = sb[0] out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual(b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b))
def test_find_best_easy(self): # tests with 2-float bands bands = {(490e-9, 510e-9), (400e-9, 413e-9), ((650e-9, 680e-9), (780e-9, 812e-9), (1034e-9, 1500e-9))} # try with "easy" values: the center for b in bands: # pick a good wl, and check the function finds it if isinstance(b[0], collections.Iterable): sb = b[-1] else: sb = b wl = sum(sb) / len(sb) out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual( b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b)) # tests with 5-float bands bands = {(490e-9, 497e-9, 500e-9, 503e-9, 510e-9), (400e-9, 405e-9, 407e-9, 409e-9, 413e-9), ((650e-9, 660e-9, 675e-9, 678e-9, 680e-9), (780e-9, 785e-9, 790e-9, 800e-9, 812e-9), (1034e-9, 1080e-9, 1100e-9, 1200e-9, 1500e-9))} # try with "easy" values: the center for b in bands: # pick a good wl, and check the function finds it if isinstance(b[0], collections.Iterable): sb = b[0] else: sb = b wl = sum(sb) / len(sb) out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual( b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b))
def test_find_best_hard(self): # tests with 2-bands bands = {(490e-9, 510e-9), (400e-9, 413e-9), ((650e-9, 680e-9), (780e-6, 812e-9), (1034e-9, 1500e-9))} # try with "hard" values: the border for b in bands: # pick a good wl, and check the function finds it if isinstance(b[0], collections.Iterable): sb = b[-1] else: sb = b wl = sb[1] out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual( b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b)) # tests with 5-float bands bands = ((490e-9, 497e-9, 500e-9, 503e-9, 510e-9), (400e-9, 405e-9, 407e-9, 409e-9, 413e-9), ((650e-9, 660e-9, 675e-9, 678e-9, 680e-9), (780e-9, 785e-9, 790e-9, 800e-9, 812e-9), (1034e-9, 1080e-9, 1100e-9, 1200e-9, 1500e-9))) # try with "hard" values: the border for b in bands: # pick a good wl, and check the function finds it if isinstance(b[0], collections.Iterable): sb = b[1] else: sb = b wl = sb[0] out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual( b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b)) # Try completely out: at least it should pick the closest from the wl for i, wl in ((0, 540e-9), (1, 360e-9)): exb = bands[i] out = fluo.find_best_band_for_dye(wl, bands) self.assertEqual( exb, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, exb))
def test_find_best_overlap(self): # tests with overlapping 2-bands bands = {(490e-9, 510e-9), # 500/10 nm (400e-9, 413e-9), (4000e-9, 600e-9), # 500/100 nm ((650e-9, 680e-9), (780e-9, 812e-9), (1034e-9, 1500e-9)) } wl = 500e-9 out = fluo.find_best_band_for_dye(wl, bands) b = (490e-9, 510e-9) self.assertEqual(b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b))
def test_find_best_overlap(self): # tests with overlapping 2-bands bands = { (490e-9, 510e-9), # 500/10 nm (400e-9, 413e-9), (4000e-9, 600e-9), # 500/100 nm ((650e-9, 680e-9), (780e-9, 812e-9), (1034e-9, 1500e-9)) } wl = 500e-9 out = fluo.find_best_band_for_dye(wl, bands) b = (490e-9, 510e-9) self.assertEqual( b, out, "find_best(%f, %s) returned %s while expected %s" % (wl, bands, out, b))
def set_hardware_settings(self, wavelength, power=None): """ Setup the hardware to the defined settings """ if power is None: power = self.light.power.range[-1] self.power = power # find the fitting wavelength for the light spectra = self.light.spectra.value band = fluo.find_best_band_for_dye(wavelength, spectra) wli = spectra.index(band) self._full_intensity = [0] * len(spectra) self._full_intensity[wli] = 1 # Special CCD settings self.ccd.countConvert.value = 2 # photons self.ccd.countConvertWavelength.value = wavelength
def set_hardware_settings(self, wavelength, power=None): """ Setup the hardware to the defined settings """ if power is None: power = self.light.power.range[-1] elif isinstance(power, numbers.Number): # Convert the power commandline argument float value into a list (to match light power type) power = [power] self.power = power # find the fitting wavelength for the light spectra = self.light.spectra.value band = fluo.find_best_band_for_dye(wavelength, spectra) wli = spectra.index(band) self._full_intensity = [0] * len(spectra) self._full_intensity[wli] = 1 # Special CCD settings self.ccd.countConvert.value = 2 # photons self.ccd.countConvertWavelength.value = wavelength