Exemplo n.º 1
0
 def test__idvalid(self):
     data = np.array(
         [np.inf, np.nan, -99., 99, -9999., -9999, -10., -5., 0., 5., 10.])
     self.assertTrue(
         np.allclose(util._idvalid(data), np.array([6, 7, 8, 9, 10])))
     self.assertTrue(np.allclose(util._idvalid(data, minval=-5., maxval=5.),
                                 np.array([7, 8, 9])))
     self.assertTrue(
         np.allclose(util._idvalid(data, isinvalid=[-9999], maxval=5.),
                     np.array([2, 6, 7, 8, 9])))
Exemplo n.º 2
0
 def _get_valid_pairs(self, obs, raw):
     """INTERNAL: Helper method to identify valid obs-raw pairs
     """
     # checking input shape consistency
     self._check_shape(obs, raw)
     # radar values at gage locations
     rawatobs = self.get_raw_at_obs(raw, obs)
     # check where both gage and radar observations are valid
     ix = np.intersect1d(util._idvalid(obs, minval=self.minval), util._idvalid(rawatobs, minval=self.minval))
     return rawatobs, ix
Exemplo n.º 3
0
 def test__idvalid(self):
     data = np.array(
         [np.inf, np.nan, -99., 99, -9999., -9999, -10., -5., 0., 5., 10.])
     self.assertTrue(
         np.allclose(util._idvalid(data), np.array([6, 7, 8, 9, 10])))
     self.assertTrue(np.allclose(util._idvalid(data, minval=-5., maxval=5.),
                                 np.array([7, 8, 9])))
     self.assertTrue(
         np.allclose(util._idvalid(data, isinvalid=[-9999], maxval=5.),
                     np.array([2, 6, 7, 8, 9])))
Exemplo n.º 4
0
 def _get_valid_pairs(self, obs, raw):
     """INTERNAL: Helper method to identify valid obs-raw pairs
     """
     # checking input shape consistency
     self._check_shape(obs, raw)
     # radar values at gage locations
     rawatobs = self.get_raw_at_obs(raw, obs)
     # check where both gage and radar observations are valid
     ix = np.intersect1d(util._idvalid(obs, minval=self.minval),
                         util._idvalid(rawatobs, minval=self.minval))
     return rawatobs, ix
Exemplo n.º 5
0
 def test__idvalid(self):
     data = np.array([
         np.inf, np.nan, -99.0, 99, -9999.0, -9999, -10.0, -5.0, 0.0, 5.0,
         10.0
     ])
     assert np.allclose(util._idvalid(data), np.array([6, 7, 8, 9, 10]))
     assert np.allclose(util._idvalid(data, minval=-5.0, maxval=5.0),
                        np.array([7, 8, 9]))
     assert np.allclose(
         util._idvalid(data, isinvalid=[-9999], maxval=5.0),
         np.array([2, 6, 7, 8, 9]),
     )
Exemplo n.º 6
0
 def __init__(self, obs, est, minval=None):
     # Check input
     if len(obs) != len(est):
         raise ValueError("WRADLIB: obs and est need to have the "
                          "same length. len(obs)={}, "
                          "len(est)={}".format(len(obs), len(est)))
     self.est = est
     self.obs = obs
     # remember those pairs which both have valid obs and est
     self.ix = np.intersect1d(util._idvalid(obs, minval=minval),
                              util._idvalid(est, minval=minval))
     self.n = len(self.ix)
     if self.n == 0:
         warnings.warn("WRADLIB: No valid pairs of observed and "
                       "estimated available for ErrorMetrics!")
     self.resids = self.est[self.ix] - self.obs[self.ix]
Exemplo n.º 7
0
    def xvalidate(self, obs, raw):
        """Leave-One-Out Cross Validation, applicable to all gage adjustment
        classes.

        This method will be inherited to other Adjust classes. It should thus
        be applicable to all adjustment procedures without any modification.
        This way, the actual adjustment procedure has only to be defined *once*
        in the :meth:`~wradlib.adjust.AdjustBase.__call__` method.

        The output of this method can be evaluated by using the
        `verify.ErrorMetrics` class.

        Parameters
        ----------
        obs : array of floats
        raw : array of floats

        Returns
        -------
        obs : array of floats
            valid observations at those locations which have a valid radar
            observation
        estatobs : array of floats
            estimated values at the valid observation locations

        """
        rawatobs, ix = self._get_valid_pairs(obs, raw)
        self.get_raws_directly_at_obs = RawAtObs(self.obs_coords,
                                                 self.raw_coords,
                                                 nnear=1)
        raws_directly_at_obs = self.get_raws_directly_at_obs(raw)
        ix = np.intersect1d(
            ix, util._idvalid(raws_directly_at_obs, minval=self.minval))
        # Container for estimation results at the observation location
        estatobs = np.zeros(obs.shape) * np.nan
        # check whether enough gages remain for adjustment
        if len(ix) <= (self.mingages - 1):
            # not enough gages for cross validation: return empty arrays
            return obs, estatobs
        # Now iterate over valid pairs
        for i in ix:
            # Pass all valid pairs except ONE which you pass as target
            ix_adjust = np.setdiff1d(ix, [i])
            estatobs[i] = self.__call__(
                obs,
                raws_directly_at_obs[i],
                self.obs_coords[i].reshape((1, -1)),
                rawatobs,
                ix_adjust,
            )
        return obs, estatobs
Exemplo n.º 8
0
    def xvalidate(self, obs, raw):
        """Leave-One-Out Cross Validation, applicable to all gage adjustment
        classes.

        This method will be inherited to other Adjust classes. It should thus
        be applicable to all adjustment procedures without any modification.
        This way, the actual adjustment procedure has only to be defined *once*
        in the __call__ method.

        The output of this method can be evaluated by using the
        `verify.ErrorMetrics` class.

        Parameters
        ----------
        obs : array of floats
        raw : array of floats

        Returns
        -------
        obs : array of floats
            valid observations at those locations which have a valid radar
            observation
        estatobs : array of floats
            estimated values at the valid observation locations

        """
        rawatobs, ix = self._get_valid_pairs(obs, raw)
        self.get_raws_directly_at_obs = Raw_at_obs(self.obs_coords,
                                                   self.raw_coords, nnear=1)
        raws_directly_at_obs = self.get_raws_directly_at_obs(raw)
        ix = np.intersect1d(ix, util._idvalid(raws_directly_at_obs,
                                              minval=self.minval))
        # Container for estimation results at the observation location
        estatobs = np.zeros(obs.shape) * np.nan
        # check whether enough gages remain for adjustment
        if len(ix) <= (self.mingages - 1):
            # not enough gages for cross validation: return empty arrays
            return obs, estatobs
        # Now iterate over valid pairs
        for i in ix:
            # Pass all valid pairs except ONE which you pass as target
            ix_adjust = np.setdiff1d(ix, [i])
            estatobs[i] = self.__call__(obs, raws_directly_at_obs[i],
                                        self.obs_coords[i].reshape((1, -1)),
                                        rawatobs, ix_adjust)
        return obs, estatobs