Exemplo n.º 1
0
class TestBgPerEmitterFromBgFrame:
    @pytest.fixture(scope='class')
    def extractor(self):
        return background.BgPerEmitterFromBgFrame(17, (-0.5, 63.5),
                                                  (-0.5, 63.5), (64, 64))

    def test_mean_filter(self, extractor):
        """
        Args:
            extractor: fixture as above

        """
        """Some hard coded setups"""
        x_in = []
        x_in.append(torch.randn((1, 1, 64, 64)))
        x_in.append(torch.zeros((1, 1, 64, 64)))
        x_in.append(
            torch.meshgrid(
                torch.arange(64),
                torch.arange(64))[0].unsqueeze(0).unsqueeze(0).float())

        # excpt outcome
        expect = []
        expect.append(torch.zeros_like(x_in[0]))
        expect.append(torch.zeros_like(x_in[0]))
        expect.append(8)
        """Run"""
        out = []
        for x in x_in:
            out.append(extractor._mean_filter(x))
        """Assertions"""
        assert test_utils.tens_almeq(out[0], expect[0], 1)  # 10 sigma
        assert test_utils.tens_almeq(out[1], expect[1])
        assert test_utils.tens_almeq(out[2][0, 0, 8, :],
                                     8 * torch.ones_like(out[2][0, 0, 0, :]),
                                     1e-4)

    test_data = [
        (torch.zeros(
            (1, 1, 64, 64)), emitter.RandomEmitterSet(100), torch.zeros(
                (100, ))),
        (torch.meshgrid(torch.arange(64),
                        torch.arange(64))[0].unsqueeze(0).unsqueeze(0).float(),
         emitter.CoordinateOnlyEmitter(torch.tensor([[8., 0., 0.]])),
         torch.tensor([8.])),
        (torch.rand((1, 1, 64, 64)),
         emitter.CoordinateOnlyEmitter(torch.tensor([[70., 32., 0.]])),
         torch.tensor([float('nan')]))
    ]

    @pytest.mark.parametrize("bg,em,expect_bg", test_data)
    def test_forward(self, extractor, bg, em, expect_bg):
        """Run"""
        out = extractor.forward(em, bg)
        """Assertions"""
        assert test_utils.tens_almeq(out.bg, expect_bg, 1e-4, nan=True)
Exemplo n.º 2
0
    def em(self):
        """Setup"""
        xyz = torch.tensor([[10., 50., 100.]])
        em = emitter.CoordinateOnlyEmitter(xyz, xy_unit='nm')
        em.phot = torch.ones_like(em.phot)

        return em
Exemplo n.º 3
0
    def test_xyz_cr_conversion(self, xyz_scr_input, xy_unit, px_size, expct_px,
                               expct_nm):
        """
        Here we test the cramer rao unit conversion. We can reuse the testdata as for the xyz conversion because it does
        not make a difference for the test candidate.

        """
        """Init and expect warning if specified"""
        em = emitter.CoordinateOnlyEmitter(torch.rand_like(xyz_scr_input),
                                           xy_unit=xy_unit,
                                           px_size=px_size)
        em.xyz_cr = xyz_scr_input**2
        """Test the respective units"""
        if isinstance(expct_px, str) and expct_px == "err":
            with pytest.raises(ValueError):
                _ = em.xyz_cr_px
        else:
            assert test_utils.tens_almeq(em.xyz_scr_px, expct_px)

        if isinstance(expct_nm, str) and expct_nm == "err":
            with pytest.raises(ValueError):
                _ = em.xyz_cr_nm

        else:
            assert test_utils.tens_almeq(em.xyz_scr_nm, expct_nm)
Exemplo n.º 4
0
    def test_plot_frame_render_equality(self, rend):
        """Setup"""
        xyz = torch.tensor([[10., 50., 100.]])
        em = emitter.CoordinateOnlyEmitter(xyz, xy_unit='nm')
        """Run"""
        PlotFrameCoord(torch.zeros((101, 101)), em.xyz_nm).plot()
        plt.show()

        rend.render(em)
        plt.show()
Exemplo n.º 5
0
    def test_forward(self, waiter):

        """Setup"""
        tar_frames = torch.rand((2, 21, 64, 64))
        tar_em = emitter.CoordinateOnlyEmitter(torch.tensor([[0., 0., 0.], [0.49, 0., 0.]]), 'px')

        """Run"""
        weight_out = waiter.forward(tar_em, tar_frames, 0, 1)

        """Assertions"""
        assert weight_out.size(1) == 21
Exemplo n.º 6
0
    def test_xyz_conversion(self, xyz_input, xy_unit, px_size, expct_px,
                            expct_nm):
        """Init and expect warning if specified"""
        em = emitter.CoordinateOnlyEmitter(xyz_input,
                                           xy_unit=xy_unit,
                                           px_size=px_size)
        """Test the respective units"""
        if isinstance(expct_px, str) and expct_px == "err":
            with pytest.raises(ValueError):
                _ = em.xyz_px
        else:
            assert test_utils.tens_almeq(em.xyz_px, expct_px)

        if isinstance(expct_nm, str) and expct_nm == "err":
            with pytest.raises(ValueError):
                _ = em.xyz_nm

        else:
            assert test_utils.tens_almeq(em.xyz_nm, expct_nm)