예제 #1
0
    def load_csv(activation_file, verbose=False):

        if activation_file is None:
            print("WARNING: No activations loaded since file not specified; i.e. there is no ground truth.")
            return

        # read csv
        with open(activation_file) as csv_file:
            csv_reader = csv.reader(csv_file)
            line_count = 0
            id_frame_xyz_camval = []
            for row in csv_reader:
                if verbose and line_count == 0:
                    print(row)
                elif line_count >= 1:
                    id_frame_xyz_camval.append(torch.tensor(
                        (float(row[0]), float(row[1]), float(row[2]), float(row[3]), float(row[4]), float(row[5]))))
                line_count += 1

        id_frame_xyz_camval = torch.stack(id_frame_xyz_camval, 0)

        gt = em.EmitterSet(xyz=id_frame_xyz_camval[:, 2:5], frame_ix=id_frame_xyz_camval[:, 1].long(),
                           phot=id_frame_xyz_camval[:, -1], id=id_frame_xyz_camval[:, 0].long())
        gt.sort_by_frame_()

        return gt
예제 #2
0
    def test_forward_handcrafted(self, evaluator):
        # if evaluator.mode != 'phot':
        #     return
        """Setup"""
        tp = em.EmitterSet(xyz=torch.zeros((4, 3)),
                           phot=torch.tensor([1050., 1950., 3050., 4050]),
                           frame_ix=torch.tensor([0, 0, 1, 2]),
                           bg=torch.ones((4, )) * 10,
                           xy_unit='px',
                           px_size=(127., 117.))

        ref = tp.clone()
        ref.xyz += 0.5
        ref.phot = torch.tensor([1000., 2000., 3000., 4000.])
        ref.xyz_cr = (torch.tensor([[10., 10., 15], [8., 8., 10], [6., 6., 7],
                                    [4., 4., 5.]]) / 100.)**2
        ref.phot_cr = torch.tensor([10., 12., 14., 16.])**2
        ref.bg_cr = torch.tensor([1., 2., 3., 4])**2
        """Run"""
        _, _, _, dpos, dphot, dbg = evaluator.forward(
            tp, ref)  # test only on non reduced values
        """Assertions"""
        assert (dpos.abs().argsort(0) == torch.arange(4).unsqueeze(1).repeat(1, 3)).all(), "Weighted error for pos." \
                                                                                           "should be monot. increasing"

        assert (dphot.abs().argsort(descending=True) == torch.arange(4)).all(), "Weighted error for photon should be " \
                                                                                "monot. decreasing"

        assert (dbg.abs().argsort(descending=True) == torch.arange(4)).all(), "Weighted error for background should be " \
                                                                                "monot. decreasing"
예제 #3
0
 def em(self):
     """Setup"""
     xyz = torch.rand(100, 3) * torch.Tensor([[100., 100., 1000.]])
     return emitter.EmitterSet(xyz,
                               xyz_sig=xyz * 0.1,
                               phot=torch.ones(100),
                               frame_ix=torch.arange(100),
                               xy_unit='nm')
예제 #4
0
def test_save_load_h5py(em_rand, em_all_attrs, save_fn, load_fn, extension,
                        tmpdir):
    path = str(tmpdir / f'emitter{extension}')

    for em in (em_rand, em_all_attrs):
        save_fn(path, em.data, em.meta)

        data, meta, decode_meta = load_fn(path)
        em_reloaded = emitter.EmitterSet(**data, **meta)

        assert em == em_reloaded  # if equality check is wrong, this is wrong as well
        assert decode_meta['version'][0] == 'v'
예제 #5
0
    def test_weight_hard(self, waiter):
        """
        Tests entire weight unit with hard computed values

        Args:
            waiter: fixture

        """

        """Setup"""
        tar_frames = torch.zeros((1, 6, 5, 5))
        tar_frames[:, 5] = torch.rand_like(tar_frames[:, 5])  # let bg be non-zero

        em = emitter.EmitterSet(xyz=torch.tensor([[1., 1., 0], [3., 3., 0.]]), phot=torch.Tensor([1., 5.]),
                                frame_ix=torch.tensor([0, 0]), xy_unit='px')

        """Run"""
        mask = waiter.forward(em, tar_frames, 0, 0)

        """Assertions"""
        assert (mask[:, 0] == 1.).all(), "p channel must be weight 1"
        # some zero value assertions applicaple for both const and phot weight
        assert (mask[:, 1:-1, 2, 2] == 0.).all(), "intersection must be 0"
        assert (mask[:, 1:-1, 3:, :2] == 0.).all()
        assert (mask[:, 1:-1, :2, 3:] == 0.).all()

        if waiter.weight_mode == 'const':
            assert (mask[:, 5] == 1.).all(), "bg channel must be weight 1"
            assert (mask[:, 1:-1].unique() == torch.tensor([0., 1])).all(), "in const. mode values must be 0 or 1"

        if waiter.weight_mode == 'phot':
            assert (mask[:, 1:-1, :2, :2] == 1.).all(), "CRLB estimate for photon count 1"
            assert mask[:, 1, 3, 3] == pytest.approx(0.02468, abs=0.0001), "Photon CRLB estimate for count of 5"
            assert mask[:, 2, 3, 3] == pytest.approx(40.51641, abs=0.0001), "X CRLB estimate"
            assert mask[:, 3, 3, 3] == pytest.approx(40.51641, abs=0.0001), "Y CRLB estimate"
            assert mask[:, 4, 3, 3] == pytest.approx(40.51641, abs=0.0001), "Y CRLB estimate"
            assert test_utils.tens_almeq(mask[:, 5], 1 / tar_frames[:, 5] ** 2.3, 1e-5), "BG CRLB estimate"