コード例 #1
0
    def stageData(self, m):
        r"""Extracts model data which is comparable to the observations.

        The observational data measure the anomaly in terrestrial
        water storage, 'twsa' in terms of [kg m-2]. We convert this
        unit to [cm] using the density of water. The models are
        expected to provide the terrestrial water storage variable,
        'tws', and we need to find the anomaly. First, the model
        result is trimmed to match the temporal extents of the
        observational data. Then, to get the anomaly, we subtract off
        the temporal mean,

        .. math:: \mathit{twsa}(t,\mathbf{x}) = tws(t,\mathbf{x}) - \frac{1}{t_f-t_0}\int_{t_0}^{t_f} tws(t,\mathbf{x})\ dt 

        We do this for the model 'tws' variable, and optionally for
        the observation, treating its 'twsa' variable as 'tws' in the
        above expression. This is because the observational data can
        have a small mean even though it represents only the anomaly.

        Parameters
        ----------
        m : ILAMB.ModelResult.ModelResult
            the model result context

        Returns
        -------
        obs : ILAMB.Variable.Variable
            the variable context associated with the observational dataset
        mod : ILAMB.Variable.Variable
            the variable context associated with the model result

        """
        # get the observational data
        obs = Variable(filename=self.source,
                       variable_name=self.variable,
                       alternate_vars=self.alternate_vars).convert("cm")

        # get the model data, in the units of the obseravtions
        mod = m.extractTimeSeries(
            self.variable, alt_vars=self.alternate_vars).convert(obs.unit)
        obs, mod = il.MakeComparable(obs, mod, clip_ref=True)

        # subtract off the mean
        mean = obs.integrateInTime(mean=True)
        obs.data -= mean.data
        mean = mod.integrateInTime(mean=True)
        mod.data -= mean.data

        return obs, mod
コード例 #2
0
ファイル: ConfTWSA.py プロジェクト: dvalters/ILAMB
    def stageData(self,m):
        r"""Extracts model data which is comparable to the observations.

        The observational data measure the anomaly in terrestrial
        water storage, 'twsa' in terms of [kg m-2]. We convert this
        unit to [cm] using the density of water. The models are
        expected to provide the terrestrial water storage variable,
        'tws', and we need to find the anomaly. First, the model
        result is trimmed to match the temporal extents of the
        observational data. Then, to get the anomaly, we subtract off
        the temporal mean,

        .. math:: \mathit{twsa}(t,\mathbf{x}) = tws(t,\mathbf{x}) - \frac{1}{t_f-t_0}\int_{t_0}^{t_f} tws(t,\mathbf{x})\ dt 

        We do this for the model 'tws' variable, and optionally for
        the observation, treating its 'twsa' variable as 'tws' in the
        above expression. This is because the observational data can
        have a small mean even though it represents only the anomaly.

        Parameters
        ----------
        m : ILAMB.ModelResult.ModelResult
            the model result context

        Returns
        -------
        obs : ILAMB.Variable.Variable
            the variable context associated with the observational dataset
        mod : ILAMB.Variable.Variable
            the variable context associated with the model result

        """
        # get the observational data
        obs = Variable(filename       = self.source,
                       variable_name  = self.variable,
                       alternate_vars = self.alternate_vars).convert("cm")

        # get the model data, in the units of the obseravtions
        mod = m.extractTimeSeries(self.variable,
                                  alt_vars     = self.alternate_vars,
                                  expression   = self.derived,
                                  initial_time = obs.time_bnds[ 0,0],
                                  final_time   = obs.time_bnds[-1,1])

        # if the derived expression is used, then we get a mass flux
        # rate and need to accumulate
        try:
            mod.convert(obs.unit)
        except:
            mod = mod.accumulateInTime()
            mod.name = obs.name
        obs,mod = il.MakeComparable(obs,mod,clip_ref=True)

        # subtract off the mean
        mean      = obs.integrateInTime(mean=True)
        obs.data -= mean.data
        mean      = mod.integrateInTime(mean=True)
        mod.data -= mean.data

        # compute mean values over each basin
        odata = np.ma.zeros((obs.time.size,len(self.basins)))
        mdata = np.ma.zeros((mod.time.size,len(self.basins)))
        for i,basin in enumerate(self.basins):
            odata[:,i] = obs.integrateInSpace(region=basin,mean=True).data
            mdata[:,i] = mod.integrateInSpace(region=basin,mean=True).data
        obs.data = odata; obs.ndata = odata.shape[1]; obs.spatial = False
        mod.data = mdata; mod.ndata = mdata.shape[1]; mod.spatial = False
        mod.data.mask = obs.data.mask
        
        return obs,mod