コード例 #1
0
    def test_spec_calib(self):
        """Test StaticSpectrumStream calibration"""
        spec = self._create_spec_data()
        specs = stream.StaticSpectrumStream("test", spec)

        # Check efficiency compensation
        prev_im2d = specs.image.value

        dbckg = numpy.ones(spec.shape, dtype=numpy.uint16)
        wl_bckg = 400e-9 + numpy.array(range(dbckg.shape[0])) * 10e-9
        obckg = model.DataArray(dbckg, metadata={model.MD_WL_LIST: wl_bckg})
        bckg = calibration.get_spectrum_data([obckg])

        dcalib = numpy.array([1, 1.3, 2, 3.5, 4, 5, 1.3, 6, 9.1],
                             dtype=numpy.float)
        dcalib.shape = (dcalib.shape[0], 1, 1, 1, 1)
        wl_calib = 400e-9 + numpy.array(range(dcalib.shape[0])) * 10e-9
        calib = model.DataArray(dcalib, metadata={model.MD_WL_LIST: wl_calib})

        specs.efficiencyCompensation.value = calib

        specs.background.value = bckg

        # Control spatial spectrum
        im2d = specs.image.value
        # Check it's a RGB DataArray
        self.assertEqual(im2d.shape, spec.shape[-2:] + (3, ))
        self.assertTrue(numpy.any(im2d != prev_im2d))
コード例 #2
0
 def setUp(self):
     data = numpy.ones((251, 1, 1, 200, 300), dtype="uint16")
     data[:, 0, 0, :, 3] = range(200)
     data[:, 0, 0, :, 3] *= 3
     data[:, 0, 0, 1, 3] = range(251)
     data[2, :, :, :, :] = range(300)
     data[200, 0, 0, 2] = range(300)
     wld = 433e-9 + numpy.array(range(data.shape[0])) * 0.1e-9
     md = {
         model.MD_SW_VERSION: "1.0-test",
         model.MD_HW_NAME: "fake ccd",
         model.MD_DESCRIPTION: "Spectrum",
         model.MD_ACQ_DATE: time.time(),
         model.MD_BPP: 12,
         model.MD_PIXEL_SIZE: (2e-6, 2e-6),  # m/px
         model.MD_POS: (-0.001203511795256, -0.000295338300158),  # m
         model.MD_EXP_TIME: 0.2,  # s
         model.MD_LENS_MAG: 60,  # ratio
         model.MD_WL_LIST: wld,
     }
     self.spec_data = model.DataArray(data, md)
     self.spec_stream = stream.StaticSpectrumStream("test spec",
                                                    self.spec_data)
     self.spec_stream.selected_line.value = ((3, 1), (235, 65))
     self.app = wx.App()  # needed for the gui font name
コード例 #3
0
ファイル: img_test.py プロジェクト: thomasaarholt/odemis
    def setUp(self):
        self.app = wx.App()
        data = numpy.zeros((2160, 2560), dtype=numpy.uint16)
        dataRGB = numpy.zeros((2160, 2560, 4))
        metadata = {'Hardware name': 'Andor ZYLA-5.5-USB3 (s/n: VSC-01959)',
                    'Exposure time': 0.3, 'Pixel size': (1.59604600574173e-07, 1.59604600574173e-07),
                    'Acquisition date': 1441361559.258568, 'Hardware version': "firmware: '14.9.16.0' (driver 3.10.30003.5)",
                    'Centre position': (-0.001203511795256, -0.000295338300158), 'Lens magnification': 40.0,
                    'Input wavelength range': (6.15e-07, 6.350000000000001e-07), 'Shear':-4.358492733391727e-16,
                    'Description': 'Filtered colour 1', 'Bits per pixel': 16, 'Binning': (1, 1), 'Pixel readout time': 1e-08,
                    'Gain': 1.1, 'Rotation': 6.279302551026012, 'Light power': 0.0, 'Display tint': (255, 0, 0),
                    'Output wavelength range': (6.990000000000001e-07, 7.01e-07)}
        image = model.DataArray(data, metadata)
        fluo_stream = stream.StaticFluoStream(metadata['Description'], image)
        #fluo_stream.image.value = model.DataArray(dataRGB, metadata)

        data = numpy.zeros((1024, 1024), dtype=numpy.uint16)
        dataRGB = numpy.zeros((1024, 1024, 4))
        metadata = {'Hardware name': 'pcie-6251', 'Description': 'Secondary electrons',
                    'Exposure time': 3e-06, 'Pixel size': (5.9910982493639e-08, 6.0604642506361e-08),
                    'Acquisition date': 1441361562.0, 'Hardware version': 'Unknown (driver 2.1-160-g17a59fb (driver ni_pcimio v0.7.76))',
                    'Centre position': (-0.001203511795256, -0.000295338300158), 'Lens magnification': 5000.0, 'Rotation': 0.0,
                    'Shear': 0.003274715695854}
        image = model.DataArray(data, metadata)
        sem_stream = stream.StaticSEMStream(metadata['Description'], image)
        #sem_stream.image.value = model.DataArray(dataRGB, metadata)
        # create DataProjections for the streams
        fluo_stream_pj = stream.RGBSpatialProjection(fluo_stream)
        sem_stream_pj = stream.RGBSpatialProjection(sem_stream)
        self.streams = [fluo_stream_pj, sem_stream_pj]
        self.min_res = (623, 432)

        # Spectrum stream
        data = numpy.ones((251, 1, 1, 200, 300), dtype="uint16")
        data[:, 0, 0, :, 3] = range(200)
        data[:, 0, 0, :, 3] *= 3
        data[:, 0, 0, 1, 3] = range(251)
        data[2, :, :, :, :] = range(300)
        data[200, 0, 0, 2] = range(300)
        wld = 433e-9 + numpy.array(range(data.shape[0])) * 0.1e-9
        md = {model.MD_SW_VERSION: "1.0-test",
             model.MD_HW_NAME: "fake ccd",
             model.MD_DESCRIPTION: "Spectrum",
             model.MD_ACQ_DATE: time.time(),
             model.MD_BPP: 12,
             model.MD_PIXEL_SIZE: (2e-6, 2e-6), # m/px
             model.MD_POS: (-0.001203511795256, -0.000295338300158), # m
             model.MD_EXP_TIME: 0.2, # s
             model.MD_LENS_MAG: 60, # ratio
             model.MD_WL_LIST: wld,
            }
        spec_data = model.DataArray(data, md)
        self.spec_stream = stream.StaticSpectrumStream("test spec", spec_data)

        # Wait for all the streams to get an RGB image
        time.sleep(0.5)
コード例 #4
0
    def test_spec_0d(self):
        """Test StaticSpectrumStream 0D"""
        spec = self._create_spec_data()
        specs = stream.StaticSpectrumStream("test", spec)

        # Check 0D spectrum
        specs.selected_pixel.value = (1, 1)
        sp0d = specs.get_pixel_spectrum()
        wl0d = specs.get_spectrum_range()
        self.assertEqual(sp0d.shape, (spec.shape[0], ))
        self.assertEqual(wl0d.shape, (spec.shape[0], ))
        self.assertEqual(sp0d.dtype, spec.dtype)
        self.assertTrue(numpy.all(sp0d <= spec.max()))
コード例 #5
0
    def test_spec_2d(self):
        """Test StaticSpectrumStream 2D"""
        spec = self._create_spec_data()
        specs = stream.StaticSpectrumStream("test", spec)

        # Control spatial spectrum
        im2d = specs.image.value
        # Check it's a RGB DataArray
        self.assertEqual(im2d.shape, spec.shape[-2:] + (3, ))
        # Check it's at the right position
        md2d = im2d.metadata
        self.assertEqual(md2d[model.MD_POS], spec.metadata[model.MD_POS])

        # change bandwidth to max
        specs.spectrumBandwidth.value = (specs.spectrumBandwidth.range[0][0],
                                         specs.spectrumBandwidth.range[1][1])
        im2d = specs.image.value
        self.assertEqual(im2d.shape, spec.shape[-2:] + (3, ))

        # Check RGB spatial projection
        time.sleep(0.2)
        specs.fitToRGB.value = True
        im2d = specs.image.value
        self.assertEqual(im2d.shape, spec.shape[-2:] + (3, ))
コード例 #6
0
    def test_spec_1d(self):
        """Test StaticSpectrumStream 1D"""
        spec = self._create_spec_data()
        specs = stream.StaticSpectrumStream("test", spec)

        # Check 1d spectrum on corner-case: parallel to the X axis
        specs.selected_line.value = [(3, 7), (3, 65)]
        sp1d = specs.get_line_spectrum()
        wl1d = specs.get_spectrum_range()
        self.assertEqual(sp1d.ndim, 3)
        self.assertEqual(sp1d.shape, (65 - 7 + 1, spec.shape[0], 3))
        self.assertEqual(sp1d.dtype, numpy.uint8)
        self.assertEqual(wl1d.shape, (spec.shape[0], ))
        self.assertEqual(sp1d.metadata[model.MD_PIXEL_SIZE][1],
                         spec.metadata[model.MD_PIXEL_SIZE][0])

        # compare to doing it manually, by cutting the band at 3
        sp1d_raw_ex = spec[:, 0, 0, 65:6:-1, 3]
        # make it contiguous to be sure to get the fast conversion, because
        # there are (still) some minor differences with the slow conversion
        sp1d_raw_ex = numpy.ascontiguousarray(sp1d_raw_ex.swapaxes(0, 1))

        # Need to convert to RGB to compare
        hist, edges = img.histogram(sp1d_raw_ex)
        irange = img.findOptimalRange(hist, edges, 1 / 256)
        sp1d_rgb_ex = img.DataArray2RGB(sp1d_raw_ex, irange)
        numpy.testing.assert_equal(sp1d, sp1d_rgb_ex)

        # Check 1d spectrum in diagonal
        specs.selected_line.value = [(30, 65), (1, 1)]
        sp1d = specs.get_line_spectrum()
        wl1d = specs.get_spectrum_range()
        self.assertEqual(sp1d.ndim, 3)
        # There is not too much expectations on the size of the spatial axis
        self.assertTrue(29 <= sp1d.shape[0] <= (64 * 1.41))
        self.assertEqual(sp1d.shape[1], spec.shape[0])
        self.assertEqual(sp1d.shape[2], 3)
        self.assertEqual(sp1d.dtype, numpy.uint8)
        self.assertEqual(wl1d.shape, (spec.shape[0], ))
        self.assertGreaterEqual(sp1d.metadata[model.MD_PIXEL_SIZE][1],
                                spec.metadata[model.MD_PIXEL_SIZE][0])

        # Check 1d with larger width
        specs.selected_line.value = [(30, 65), (5, 1)]
        specs.width.value = 12
        sp1d = specs.get_line_spectrum()
        wl1d = specs.get_spectrum_range()
        self.assertEqual(sp1d.ndim, 3)
        # There is not too much expectations on the size of the spatial axis
        self.assertTrue(29 <= sp1d.shape[0] <= (64 * 1.41))
        self.assertEqual(sp1d.shape[1], spec.shape[0])
        self.assertEqual(sp1d.shape[2], 3)
        self.assertEqual(sp1d.dtype, numpy.uint8)
        self.assertEqual(wl1d.shape, (spec.shape[0], ))

        specs.selected_line.value = [(30, 65), (5, 12)]
        specs.width.value = 13  # brings bad luck?
        sp1d = specs.get_line_spectrum()
        wl1d = specs.get_spectrum_range()
        self.assertEqual(sp1d.ndim, 3)
        # There is not too much expectations on the size of the spatial axis
        self.assertTrue(29 <= sp1d.shape[0] <= (53 * 1.41))
        self.assertEqual(sp1d.shape[1], spec.shape[0])
        self.assertEqual(sp1d.shape[2], 3)
        self.assertEqual(sp1d.dtype, numpy.uint8)
        self.assertEqual(wl1d.shape, (spec.shape[0], ))
コード例 #7
0
    def test_spec(self):
        """Test StaticSpectrumStream"""
        # Spectrum
        data = numpy.ones((251, 1, 1, 200, 300), dtype="uint16")
        data[2, :, :, :, :] = range(300)
        data[200, 0, 0, 2] = range(300)
        wld = 433e-9 + numpy.array(range(data.shape[0])) * 0.1e-9
        md = {
            model.MD_SW_VERSION: "1.0-test",
            model.MD_HW_NAME: "fake ccd",
            model.MD_DESCRIPTION: "Spectrum",
            model.MD_ACQ_DATE: time.time(),
            model.MD_BPP: 12,
            model.MD_PIXEL_SIZE: (2e-5, 2e-5),  # m/px
            model.MD_POS: (1.2e-3, -30e-3),  # m
            model.MD_EXP_TIME: 0.2,  # s
            model.MD_LENS_MAG: 60,  # ratio
            model.MD_WL_LIST: wld,
        }
        spec = model.DataArray(data, md)

        specs = stream.StaticSpectrumStream("test", spec)

        # Control spatial spectrum
        im2d = specs.image.value
        # Check it's a RGB DataArray
        self.assertEqual(im2d.shape, data.shape[-2:] + (3, ))
        # Check it's at the right position
        md2d = im2d.metadata
        self.assertEqual(md2d[model.MD_POS], md[model.MD_POS])

        # change bandwidth to max
        specs.spectrumBandwidth.value = (specs.spectrumBandwidth.range[0][0],
                                         specs.spectrumBandwidth.range[1][1])
        im2d = specs.image.value
        self.assertEqual(im2d.shape, data.shape[-2:] + (3, ))

        # Check RGB spatial projection
        time.sleep(0.2)
        specs.fitToRGB.value = True
        im2d = specs.image.value
        self.assertEqual(im2d.shape, data.shape[-2:] + (3, ))

        # Check 0D spectrum
        specs.selected_pixel.value = (1, 1)
        sp0d = specs.get_pixel_spectrum()
        wl0d = specs.get_spectrum_range()
        self.assertEqual(sp0d.shape, (data.shape[0], ))
        self.assertEqual(wl0d.shape, (data.shape[0], ))

        # Check efficiency compensation
        prev_im2d = specs.image.value
        dcalib = numpy.array([1, 1.3, 2, 3.5, 4, 5, 1.3, 6, 9.1],
                             dtype=numpy.float)
        dcalib.shape = (dcalib.shape[0], 1, 1, 1, 1)
        wl_calib = 400e-9 + numpy.array(range(dcalib.shape[0])) * 10e-9
        calib = model.DataArray(dcalib, metadata={model.MD_WL_LIST: wl_calib})

        specs.efficiencyCompensation.value = calib

        # Control spatial spectrum
        im2d = specs.image.value
        # Check it's a RGB DataArray
        self.assertEqual(im2d.shape, data.shape[-2:] + (3, ))
        self.assertTrue(numpy.any(im2d != prev_im2d))