Example #1
0
    def test_hydro(self):
        fn = Path(TESTS_DATA, "Raven", "q_sim.nc")
        ds = xr.open_dataset(fn)
        miss = checks.missing_any(ds.q_sim, freq="YS")
        np.testing.assert_array_equal(miss[:-1], False)
        np.testing.assert_array_equal(miss[-1], True)

        miss = checks.missing_any(ds.q_sim, freq="YS", season="JJA")
        np.testing.assert_array_equal(miss, False)
Example #2
0
    def test_season(self, tasmin_series):
        ts = tasmin_series(np.zeros(360))
        miss = checks.missing_any(ts, freq="YS", season="MAM")
        np.testing.assert_equal(miss, [False])

        miss = checks.missing_any(ts, freq="YS", season="JJA")
        np.testing.assert_array_equal(miss, [True, True])

        miss = checks.missing_any(ts, freq="YS", season="SON")
        np.testing.assert_equal(miss, [False])
Example #3
0
 def test_missing_days(self, tas_series):
     a = np.arange(360.0)
     a[5:10] = np.nan
     ts = tas_series(a)
     out = checks.missing_any(ts, freq="MS")
     assert out[0]
     assert not out[1]
Example #4
0
    def missing(self, *args, **kwds):
        """Return whether an output is considered missing or not."""
        from functools import reduce

        indexer = kwds["indexer"]
        freq = kwds["freq"] or generic.default_freq(**indexer)

        miss = (checks.missing_any(da, freq, **indexer) for da in args)
        return reduce(np.logical_or, miss)
Example #5
0
    def missing(*args, **kwds):
        """Return whether an output is considered missing or not."""
        from functools import reduce

        freq = kwds.get("freq")
        if freq is not None:
            # We flag any period with missing data
            miss = (checks.missing_any(da, freq) for da in args)
        else:
            # There is no resampling, we flag where one of the input is missing
            miss = (da.isnull() for da in args)
        return reduce(np.logical_or, miss)
Example #6
0
    def test_month(self, tasmin_series):
        ts = tasmin_series(np.zeros(36))
        miss = checks.missing_any(ts, freq="YS", month=7)
        np.testing.assert_equal(miss, [False])

        miss = checks.missing_any(ts, freq="YS", month=8)
        np.testing.assert_equal(miss, [True])

        with pytest.raises(ValueError, match=r"No data for selected period."):
            checks.missing_any(ts, freq="YS", month=1)

        miss = checks.missing_any(ts, freq="YS", month=[7, 8])
        np.testing.assert_equal(miss, [True])

        ts = tasmin_series(np.zeros(76))
        miss = checks.missing_any(ts, freq="YS", month=[7, 8])
        np.testing.assert_equal(miss, [False])
Example #7
0
 def test_to_period_end(self, tasmin_series):
     a = np.zeros(365) + K2C + 5.0
     a[2] -= 20
     ts = tasmin_series(a)
     miss = checks.missing_any(ts, freq="A-JUN")
     np.testing.assert_equal(miss, [False])
Example #8
0
 def test_missing_season(self):
     n = 378
     times = pd.date_range("2001-12-31", freq="1D", periods=n)
     da = xr.DataArray(np.arange(n), [("time", times)])
     miss = checks.missing_any(da, "Q-NOV")
     np.testing.assert_array_equal(miss, [True, False, False, False, True])