Exemple #1
0
    def test_background_subtract(self):
        # create some test data
        xvals = np.linspace(-10, 10, 201)
        yvals = np.ceil(gauss(xvals, 0, 100, 0, 1) + 2 * xvals + 30)

        # add some reproducible random noise
        np.random.seed(1)
        yvals += np.sqrt(yvals) * np.random.randn(yvals.size)
        yvals_sd = np.sqrt(yvals)

        # now make an (N, T, Y) detector image
        n_tbins = 10
        detector = np.repeat(yvals, n_tbins).reshape(xvals.size, n_tbins).T
        detector_sd = np.repeat(yvals_sd, n_tbins).reshape(xvals.size, n_tbins).T
        detector = detector.reshape(1, n_tbins, xvals.size)
        detector_sd = detector_sd.reshape(1, n_tbins, xvals.size)

        mask = np.zeros((1, n_tbins, 201), np.bool)
        mask[:, :, 30:70] = True
        mask[:, :, 130:160] = True

        det_bkg, detSD_bkg = plp.background_subtract(detector, detector_sd, mask)

        # each of the (N, T) entries should have the same background subtracted
        # entries
        verified_data = np.load(os.path.join(self.path, "background_subtract.npy"))

        it = np.nditer(detector, flags=["multi_index"])
        it.remove_axis(2)
        while not it.finished:
            profile = det_bkg[it.multi_index]
            profile_sd = detSD_bkg[it.multi_index]
            assert_almost_equal(verified_data, np.c_[profile, profile_sd])
            it.iternext()
Exemple #2
0
    def test_background_subtract_line(self):
        # checked each step of the background subtraction with IGOR
        # so this test background correction should be correct.

        # create some test data
        xvals = np.linspace(-10, 10, 201)
        yvals = np.ceil(gauss(xvals, 0, 100, 0, 1) + 2 * xvals + 30)

        # add some reproducible random noise
        np.random.seed(1)
        yvals += np.sqrt(yvals) * np.random.randn(yvals.size)
        yvals_sd = np.sqrt(yvals)

        mask = np.zeros(201, np.bool)
        mask[30:70] = True
        mask[130:160] = True

        profile, profile_sd = plp.background_subtract_line(yvals,
                                                           yvals_sd,
                                                           mask)

        verified_data = np.load(os.path.join(self.path,
                                             'background_subtract.npy'))

        assert_almost_equal(verified_data, np.c_[profile, profile_sd])
Exemple #3
0
 def test_find_specular_ridge(self):
     xvals = np.linspace(-10, 10, 201)
     yvals = np.ceil(gauss(xvals, 0, 1000, 0, 1))
     detector = np.repeat(yvals[:, np.newaxis], 1000, axis=1).T
     detector_sd = np.sqrt(detector)
     output = plp.find_specular_ridge(detector[np.newaxis, :], detector_sd[np.newaxis, :])
     assert_(len(output) == 2)
     assert_almost_equal(output[0][0], 100)
Exemple #4
0
 def test_peak_finder(self):
     mean = 10.1234
     sd = 5.55
     x = np.linspace(-100, 100.5, 101)
     y = peak_utils.gauss(x, 0, 10, mean, sd)
     res = peak_utils.peak_finder(y, x=x)
     assert_almost_equal(res[1][0], mean)
     assert_almost_equal(res[1][1], sd)
Exemple #5
0
 def test_peak_finder(self):
     mean = 10.1234
     sd = 5.55
     x = np.linspace(-100, 100.5, 101)
     y = peak_utils.gauss(x, 0, 10, mean, sd)
     res = peak_utils.peak_finder(y, x=x)
     assert_almost_equal(res[1][0], mean)
     assert_almost_equal(res[1][1], sd)
Exemple #6
0
 def test_find_specular_ridge(self):
     xvals = np.linspace(-10, 10, 201)
     yvals = np.ceil(gauss(xvals, 0, 1000, 0, 1))
     detector = np.repeat(yvals[:, np.newaxis], 1000, axis=1).T
     detector_sd = np.sqrt(detector)
     output = plp.find_specular_ridge(detector[np.newaxis, :],
                                      detector_sd[np.newaxis, :])
     assert_(len(output) == 5)
     assert_almost_equal(output[0][0], 100)
Exemple #7
0
    def test_background_subtract_line(self):
        # checked each step of the background subtraction with IGOR
        # so this test background correction should be correct.

        # create some test data
        xvals = np.linspace(-10, 10, 201)
        yvals = np.ceil(gauss(xvals, 0, 100, 0, 1) + 2 * xvals + 30)

        # add some reproducible random noise
        np.random.seed(1)
        yvals += np.sqrt(yvals) * np.random.randn(yvals.size)
        yvals_sd = np.sqrt(yvals)

        mask = np.zeros(201, bool)
        mask[30:70] = True
        mask[130:160] = True

        profile, profile_sd = plp.background_subtract_line(
            yvals, yvals_sd, mask)

        verified_data = np.load(pjoin(self.pth, "background_subtract.npy"))

        assert_almost_equal(verified_data, np.c_[profile, profile_sd])
Exemple #8
0
    def test_background_subtract(self):
        # create some test data
        xvals = np.linspace(-10, 10, 201)
        yvals = np.ceil(gauss(xvals, 0, 100, 0, 1) + 2 * xvals + 30)

        # add some reproducible random noise
        np.random.seed(1)
        yvals += np.sqrt(yvals) * np.random.randn(yvals.size)
        yvals_sd = np.sqrt(yvals)

        # now make an (N, T, Y) detector image
        n_tbins = 10
        detector = np.repeat(yvals, n_tbins).reshape(xvals.size, n_tbins).T
        detector_sd = np.repeat(yvals_sd,
                                n_tbins).reshape(xvals.size, n_tbins).T
        detector = detector.reshape(1, n_tbins, xvals.size)
        detector_sd = detector_sd.reshape(1, n_tbins, xvals.size)

        mask = np.zeros((1, n_tbins, 201), np.bool)
        mask[:, :, 30:70] = True
        mask[:, :, 130:160] = True

        det_bkg, detSD_bkg = plp.background_subtract(detector, detector_sd,
                                                     mask)

        # each of the (N, T) entries should have the same background subtracted
        # entries
        verified_data = np.load(
            os.path.join(self.pth, 'background_subtract.npy'))

        it = np.nditer(detector, flags=['multi_index'])
        it.remove_axis(2)
        while not it.finished:
            profile = det_bkg[it.multi_index]
            profile_sd = detSD_bkg[it.multi_index]
            assert_almost_equal(verified_data, np.c_[profile, profile_sd])
            it.iternext()