示例#1
0
    def test_process_raw_phidp_vulpiani(self, derivation_method, window, copy):
        if derivation_method == "lstsq" and sys.platform.startswith("win"):
            pytest.skip("fails on windows due to MKL issue")
        # Todo: move data setup into fixture
        np.random.seed(42000)
        # Synthetic truth
        dr = 0.5
        r = np.arange(0, 500, dr)

        kdp_true0 = np.sin(0.3 * r)
        kdp_true0[kdp_true0 < 0] = 0.0
        phidp_true0 = 2 * integrate.cumtrapz(kdp_true0, axis=-1, initial=0, dx=dr)
        fillval = phidp_true0[200]
        phidp_true0 = np.concatenate(
            (phidp_true0[:200], np.ones(20) * fillval, phidp_true0[200:])
        )
        phidp_true0 = np.stack([phidp_true0, phidp_true0], axis=0)

        # first, no noise, no folding, no gaps, offset
        phidp_raw0 = phidp_true0.copy() + 30.0

        # second, noise, no folding, no gaps
        phidp_raw1 = phidp_raw0.copy()
        phidp_raw1 += np.random.uniform(-2, 2, phidp_raw1.shape[-1])

        # third, noise, folding, no gaps
        phidp_raw2 = phidp_raw1.copy()
        phidp_raw2[phidp_raw2 > 180] -= 360

        # fourth, noise, folding, large gap
        phidp_raw3 = phidp_raw2.copy()
        phidp_raw3[:, 200:220] = np.nan

        # fifth, noise, folding, large gap, small gaps
        phidp_raw4 = phidp_raw3.copy()
        gaps = np.random.uniform(0, phidp_raw4.shape[-1], 50).astype("int")
        phidp_raw4[:, gaps] = np.nan

        in0 = phidp_raw0.copy()
        out0 = dp.process_raw_phidp_vulpiani(
            in0,
            dr=dr,
            copy=copy,
            winlen=window,
            method=derivation_method,
            pad_mode="reflect",
            pad_kwargs={"reflect_type": "odd"},
            niter=1,
        )
        np.testing.assert_array_equal(in0, phidp_raw0)
        np.testing.assert_allclose(out0[0], phidp_true0, atol=0.6, rtol=0.02)

        out1 = dp.process_raw_phidp_vulpiani(
            phidp_raw1.copy(),
            dr=dr,
            copy=copy,
            winlen=window,
            method=derivation_method,
            pad_mode="reflect",
            pad_kwargs={"reflect_type": "even"},
            niter=1,
        )
        np.testing.assert_allclose(out1[0], phidp_true0, atol=0.8, rtol=0.02)

        out2 = dp.process_raw_phidp_vulpiani(
            phidp_raw1.copy(),
            dr=dr,
            copy=copy,
            winlen=window,
            method=derivation_method,
            pad_mode="reflect",
            pad_kwargs={"reflect_type": "even"},
            niter=1,
        )
        np.testing.assert_allclose(out2[0], phidp_true0, atol=0.8, rtol=0.02)

        out3 = dp.process_raw_phidp_vulpiani(
            phidp_raw1.copy(),
            dr=dr,
            copy=copy,
            winlen=window,
            method=derivation_method,
            pad_mode="reflect",
            pad_kwargs={"reflect_type": "even"},
            niter=1,
        )
        np.testing.assert_allclose(out3[0], phidp_true0, atol=0.8, rtol=0.02)

        in4 = phidp_raw4.copy()
        out4 = dp.process_raw_phidp_vulpiani(
            in4,
            dr=dr,
            copy=copy,
            winlen=window,
            method=derivation_method,
            pad_mode="reflect",
            pad_kwargs={"reflect_type": "even"},
            niter=1,
        )
        np.testing.assert_allclose(out4[0], phidp_true0, atol=1.0, rtol=0.02)

        # check copy
        if copy:
            np.testing.assert_array_equal(in4, phidp_raw4)
        else:
            assert not np.array_equal(in4, phidp_raw4)
示例#2
0
 def test_process_raw_phidp_vulpiani(self):
     dp.process_raw_phidp_vulpiani(self.phidp_raw, dr=self.dr, copy=True)
     dp.process_raw_phidp_vulpiani(self.phidp_raw, dr=self.dr)
示例#3
0
 def test_process_raw_phidp_vulpiani(self):
     dp.process_raw_phidp_vulpiani(self.phidp_raw, dr=self.dr,
                                   copy=True)
     dp.process_raw_phidp_vulpiani(self.phidp_raw, dr=self.dr)