def test_simple(self): dcalib = numpy.array([1, 1.3, 2, 3.5, 4, 5, 0.1, 6, 9.1], dtype=numpy.float) wl_calib = (400 + numpy.array(range(len(dcalib)))) coef = numpy.vstack([wl_calib, dcalib]).T self.assertEqual(coef.shape[1], 2) da = spectrum.coefficients_to_dataarray(coef) self.assertEqual(da.shape, (dcalib.shape[0], 1, 1, 1, 1)) numpy.testing.assert_equal(da[:, 0, 0, 0, 0], dcalib) numpy.testing.assert_equal(da.metadata[model.MD_WL_LIST], wl_calib * 1e-9)
def open_ec(fn): """ Read a csv file of format "wavelength in nm{TAB}coefficient" into a standard odemis spectrum efficiency DataArray return (list of one DataArray) """ try: coef = numpy.loadtxt(fn) # check that the values are probably correct (in particular not in m) except IOError: # file not openable raise except Exception: raise ValueError("File is not in the format wavelength {TAB} coefficient") wl = coef[:, 0] if not (all(1000e-9 < wl) and all(wl <= 10000)): raise ValueError("Wavelength must be between 1 and 10000 (nm)") da = spectrum.coefficients_to_dataarray(coef) return [da]
def open_ec(fn): """ Read a csv file of format "wavelength(nm)\tcoefficient" into a standard odemis spectrum efficiency DataArray return (list of one DataArray) """ try: coef = numpy.loadtxt(fn) except IOError: # file not openable raise except Exception: raise ValueError("File is not in the format wavelength (nm) {TAB} coefficient") # check that the values are probably correct (in particular not in m) wl = coef[:, 0] if not (all(1000e-9 < wl) and all(wl <= 10000)): raise ValueError("Wavelength must be between 1 and 10000 (nm)") da = spectrum.coefficients_to_dataarray(coef) da.metadata[model.MD_DESCRIPTION] = "Spectrum efficiency compensation" return [da]