def test_forward_fill_old(self):
        result = masked_array(self.data, mask=self.mask)
        result[2] = 1

        assert_equal(forward_fill(self.test_array, maxgap=1), result)

        result[5] = 4
        result[6] = 4

        assert_equal(forward_fill(self.test_array), result)
    def test_forward_fill_old(self):
        result = masked_array(self.data, mask=self.mask)
        result[2] = 1

        assert_equal(forward_fill(self.test_array, maxgap=1), result)

        result[5] = 4
        result[6] = 4

        assert_equal(forward_fill(self.test_array), result)
Exemplo n.º 3
0
    def _set_annual_indices(self, minimum_size=None, reference_season=None):
        """
    Sets the ENSO indices per periods of 12 months, starting at the first 
    month of the reference season if any, otherwise at October.

    The same steps are followed as for :meth:`set_monthly_indices`.

    Parameters
    ----------
    minimum_size : {None, int}, optional
        Minimum size for the groups of consecutive values.
        If None, defaults to :attr:`minimum_size`.
    reference_season : {None, string or sequence}, optional
        Reference season.
        If None, defaults to :attr:`reference_season`.

    See Also
    --------
    :meth:`set_monthly_indices`
        Sets the ENSO indices for each month.

    """
        # Get the monthly indices .....
        _monthly = self.set_monthly_indices(minimum_size=minimum_size,
                                            reference_season=reference_season)
        # Make sure we reset the full_year flag to True (we lost it w/ set_monthly
        self.full_year = True
        # Get the annual indices
        refseason = self.refseason
        if refseason:
            _annual = _monthly[self.months == refseason[0]]
            refseason = months2code(refseason)
        else:
            _annual = _monthly[self.months == 10]
        _annual = adjust_endpoints(forward_fill(fill_missing_dates(_annual)),
                                   self._dates[0], self._dates[-1])
        # Cache the results ...........
        self._cachedmonthly['indices_annual'] = _annual
        return _annual
Exemplo n.º 4
0
    def _set_annual_indices(self, minimum_size=None, reference_season=None):
        """
    Sets the ENSO indices per periods of 12 months, starting at the first 
    month of the reference season if any, otherwise at October.

    The same steps are followed as for :meth:`set_monthly_indices`.

    Parameters
    ----------
    minimum_size : {None, int}, optional
        Minimum size for the groups of consecutive values.
        If None, defaults to :attr:`minimum_size`.
    reference_season : {None, string or sequence}, optional
        Reference season.
        If None, defaults to :attr:`reference_season`.

    See Also
    --------
    :meth:`set_monthly_indices`
        Sets the ENSO indices for each month.

    """
        # Get the monthly indices .....
        _monthly = self.set_monthly_indices(minimum_size=minimum_size, reference_season=reference_season)
        # Make sure we reset the full_year flag to True (we lost it w/ set_monthly
        self.full_year = True
        # Get the annual indices
        refseason = self.refseason
        if refseason:
            _annual = _monthly[self.months == refseason[0]]
            refseason = months2code(refseason)
        else:
            _annual = _monthly[self.months == 10]
        _annual = adjust_endpoints(forward_fill(fill_missing_dates(_annual)), self._dates[0], self._dates[-1])
        # Cache the results ...........
        self._cachedmonthly["indices_annual"] = _annual
        return _annual
    def test_forward_fill(self):
        x = ma.arange(20)
        x[(x%5 != 0)] = masked
        # Test forward_fill w/o gaps, starting unmasked
        test = forward_fill(x)
        assert_equal(test, [ 0, 0, 0, 0, 0, 5, 5, 5, 5, 5,
                            10,10,10,10,10,15,15,15,15,15])
        # Test forward_fill w/ gaps, starting unmasked
        test = forward_fill(x, 3)
        assert_equal(test, x)
        assert_equal(test._mask, x._mask)
        # Test forward_fill w/ gaps, starting unmasked
        x[[3,4]] = (3,4)
        test = forward_fill(x, 3)
        assert_equal(test, [ 0, 0, 0, 3, 4, 5, 5, 5, 5, 5,
                            10,10,10,10,10,15,15,15,15,15,])
        assert_equal(test._mask,[0,0,0,0,0,0,1,1,1,1,
                                 0,1,1,1,1,0,1,1,1,1,])
        # Test forward_fill w/o gaps, starting masked
        x[[0,3,4]] = masked
        test = forward_fill(x)
        assert_equal(test, [ 0, 0, 0, 0, 0, 5, 5, 5, 5, 5,
                            10,10,10,10,10,15,15,15,15,15])
        assert_equal(test._mask, [1,1,1,1,1,0,0,0,0,0,
                                  0,0,0,0,0,0,0,0,0,0,])
        # Test forward_fill w/ gaps, starting masked
        test = forward_fill(x,3)
        assert_equal(test, [ 0, 0, 0, 0, 0, 5, 5, 5, 5, 5,
                            10,10,10,10,10,15,15,15,15,15])
        assert_equal(test._mask, [1,1,1,1,1,0,1,1,1,1,
                                  0,1,1,1,1,0,1,1,1,1,])

        # Test forward_fill w/o gaps, starting masked, ending unmasked
        x[:].mask = False
        x[0] = masked
        test = forward_fill(x)
        assert_equal(test, ma.arange(20))
        assert_equal(test._mask, [1,0,0,0,0,0,0,0,0,0,
                                  0,0,0,0,0,0,0,0,0,0,])
    def test_forward_fill(self):
        x = ma.arange(20)
        x[(x % 5 != 0)] = masked
        # Test forward_fill w/o gaps, starting unmasked
        test = forward_fill(x)
        assert_equal(test, [
            0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 15, 15, 15, 15,
            15
        ])
        # Test forward_fill w/ gaps, starting unmasked
        test = forward_fill(x, 3)
        assert_equal(test, x)
        assert_equal(test._mask, x._mask)
        # Test forward_fill w/ gaps, starting unmasked
        x[[3, 4]] = (3, 4)
        test = forward_fill(x, 3)
        assert_equal(test, [
            0,
            0,
            0,
            3,
            4,
            5,
            5,
            5,
            5,
            5,
            10,
            10,
            10,
            10,
            10,
            15,
            15,
            15,
            15,
            15,
        ])
        assert_equal(test._mask, [
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            1,
            1,
            0,
            1,
            1,
            1,
            1,
            0,
            1,
            1,
            1,
            1,
        ])
        # Test forward_fill w/o gaps, starting masked
        x[[0, 3, 4]] = masked
        test = forward_fill(x)
        assert_equal(test, [
            0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 15, 15, 15, 15,
            15
        ])
        assert_equal(test._mask, [
            1,
            1,
            1,
            1,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
        ])
        # Test forward_fill w/ gaps, starting masked
        test = forward_fill(x, 3)
        assert_equal(test, [
            0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 15, 15, 15, 15,
            15
        ])
        assert_equal(test._mask, [
            1,
            1,
            1,
            1,
            1,
            0,
            1,
            1,
            1,
            1,
            0,
            1,
            1,
            1,
            1,
            0,
            1,
            1,
            1,
            1,
        ])

        # Test forward_fill w/o gaps, starting masked, ending unmasked
        x[:].mask = False
        x[0] = masked
        test = forward_fill(x)
        assert_equal(test, ma.arange(20))
        assert_equal(test._mask, [
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
        ])
Exemplo n.º 7
0
 def ffill(self,tsl,*args,**kw):
     _ts = tsl._data
     _tsF = tsi.forward_fill(_ts,**kw)
     tsl._data = _tsF
     return tsl