Beispiel #1
0
    def test_no_data_error(self):
        # to raise no data error, there must be no data for a whole window
        spec = np.ones(500)
        spec[50:150] = np.nan

        flags, info = xrfi.xrfi_model_sweep(spec)
        assert flags.shape == (500, )
Beispiel #2
0
    def test_all_flagged(self):
        spec = np.ones(500)
        flags = np.ones(500, dtype=bool)
        weights = np.zeros(500)

        flags_, info = xrfi.xrfi_model_sweep(spectrum=spec, flags=flags)
        assert np.all(flags_)
        assert not info

        flags_, info = xrfi.xrfi_model_sweep(spectrum=spec, weights=weights)
        assert np.all(flags_)
        assert not info

        flags_, info = xrfi.xrfi_model_sweep(spectrum=spec * np.nan)
        assert np.all(flags_)
        assert not info
Beispiel #3
0
    def test_giving_weights(self, sky_flat_1d):
        sky, std, noise, rfi = make_sky(sky_flat_1d)

        flags, info = xrfi.xrfi_model_sweep(
            sky,
            weights=np.ones_like(sky),
            max_iter=10,
            which_bin="all",
            threshold=5,
            use_median=True,
        )

        flags2, info2 = xrfi.xrfi_model_sweep(sky,
                                              max_iter=10,
                                              which_bin="all",
                                              threshold=5,
                                              use_median=True)

        assert np.all(flags == flags2)
Beispiel #4
0
    def test_too_many_flags(self):
        spec = np.ones(500)
        flags = np.ones(500, dtype=bool)
        weights = np.zeros(500)

        # We're testing where not *all* are flagged, just enough to be more than the
        # number of terms...
        flags[::100] = False
        weights[::100] = 1

        flags_, info = xrfi.xrfi_model_sweep(
            spectrum=np.where(flags, np.nan, spec))
        assert np.all(flags_)
        assert not info

        flags_, info = xrfi.xrfi_model_sweep(spectrum=spec, flags=flags)
        assert np.all(flags_)
        assert not info

        flags_, info = xrfi.xrfi_model_sweep(spectrum=spec, weights=weights)
        assert np.all(flags_)
        assert not info
Beispiel #5
0
    def test_xrfi_model_sweep_all(self, sky_model, rfi_model, scale):
        sky, std, noise, rfi = make_sky(sky_model, rfi_model, scale)

        true_flags = rfi_model > 0
        flags, info = xrfi.xrfi_model_sweep(sky,
                                            max_iter=10,
                                            which_bin="all",
                                            threshold=5,
                                            use_median=True)

        # Only consider flags after bin 100 (since that's the bin width)
        wrong = np.where(true_flags[100:] != flags[100:])[0]

        print_wrongness(wrong, std, info, noise, true_flags, sky, rfi)
        assert len(wrong) == 0
Beispiel #6
0
 def test_watershed_last(self, sky_flat_1d):
     with pytest.raises(ValueError):
         xrfi.xrfi_model_sweep(sky_flat_1d, which_bin="last", watershed=4)