示例#1
0
    def _calculate_(self, tas=None, pr=None, tas_percentile_dict=None, pr_percentile_dict=None):
        """
        Allows subclasses to overload parameter definitions for `calculate`.
        """

        assert (tas.ndim == 3)
        assert (pr.ndim == 3)

        try:
            dt_arr = self.field.temporal.value_datetime[self._curr_group]
        except AttributeError:
            if not hasattr(self, '_curr_group'):
                dt_arr = self.field.temporal.value_datetime
            else:
                raise

        if tas_percentile_dict is None:
            try:
                tas_percentile_dict = self._storage_percentile_dict['tas']
                pr_percentile_dict = self._storage_percentile_dict['pr']
            except KeyError:
                dt_arr_perc = self.field.temporal.value_datetime
                alias_tas = self.parms['tas']
                alias_pr = self.parms['pr']
                t_arr_perc = self.field.variables[alias_tas].value.squeeze()
                p_arr_perc = self.field.variables[alias_pr].value.squeeze()
                tas_percentile_dict = get_percentile_dict(t_arr_perc, dt_arr_perc, self.percentile_tas,
                                                          self.window_width)
                pr_percentile_dict = get_percentile_dict(p_arr_perc, dt_arr_perc, self.percentile_pr, self.window_width)
                self._storage_percentile_dict['tas'] = tas_percentile_dict
                self._storage_percentile_dict['pr'] = pr_percentile_dict

        ret = _icclim_function_map[self.key]['func'](tas, tas_percentile_dict, pr, pr_percentile_dict, dt_arr,
                                                     fill_val1=tas.fill_value, fill_val2=pr.fill_value)
        # convert output to a masked array
        ret_mask = ret == tas.fill_value
        ret = np.ma.array(ret, mask=ret_mask, fill_value=tas.fill_value)
        return ret
示例#2
0
    def calculate(self, values, percentile_dict=None):

        # if the percentile dictionary is not provided compute it
        if percentile_dict is None:
            try:
                percentile_dict = self._storage_percentile_dict[self._curr_variable.alias]
            except KeyError:
                variable = self.field.variables[self._curr_variable.alias]
                value = variable.value[0, :, 0, :, :]
                assert (value.ndim == 3)
                percentile_dict = get_percentile_dict(value, self.field.temporal.value_datetime, self.percentile,
                                                      self.window_width, only_leap_years=self.only_leap_years)
                self._storage_percentile_dict[self._curr_variable.alias] = percentile_dict

        dt_arr = self.field.temporal.value_datetime[self._curr_group]
        ret = _icclim_function_map[self.key]['func'](values, dt_arr, percentile_dict, fill_val=values.fill_value)
        return ret
示例#3
0
    def get_percentile_dict(*args, **kwargs):
        """See :func:`icclim.percentile_dict.get_percentile_dict` documentation."""

        return get_percentile_dict(*args, **kwargs)