class TestLocalSingle:

    input_schema = input_group(['qtot'])
    output_schema = ['qtot_nse']

    def __init__(self, obs, eval_period, min_valid=15):

        self.valid_idx = {}
        self.nse = {}
        self.flow_variable = 'qtot'
        for k in [self.flow_variable]:

            data = obs[k]

            if np.isnan(data).any():
                nan_mask = np.isnan(data)
                self.valid_idx[k] = np.where(nan_mask == False)
            else:
                self.valid_idx[k] = slice(0, len(eval_period))

            self.nse[k] = NSE(data[self.valid_idx[k]])

    def evaluate(self, modelled):
        qtot_nse = self.nse[self.flow_variable](
            modelled[self.flow_variable][self.valid_idx[self.flow_variable]])
        return np.array(qtot_nse)
Exemple #2
0
class LocalQTotal:
    '''
    Simple sum of run
    '''

    input_schema = input_group(['qtot', 'etot', 'dd'], 'volume')
    output_schema = ['qtot_vol', 'etot_vol', 'dd_vol']

    def __init__(self, obs, eval_period):
        pass

    def evaluate(self, modelled):
        return np.array((np.sum(modelled['qtot']), np.sum(modelled['etot']),
                         np.sum(modelled['dd'])))
Exemple #3
0
class LocalEval:

    input_schema = input_group(['qtot'])
    output_schema = ['nse_daily','nse_monthly','bias']

    def __init__(self,obs,eval_period,min_valid=15,flow_variable='qtot'):
        '''
        obs : timeseries of observations
        obj_period : the period over which we will evaluate

        assume that observations and modelled data are
        already constrained to eval_period
        '''
        self.flow_variable = flow_variable
        
        # Create filters for any missing data
        qtot = obs[flow_variable]

        if np.isnan(qtot).any():
            nan_mask = np.isnan(qtot)
            self.valid_idx = np.where(nan_mask == False)
            self.to_monthly = FilteredMonthlyResampler(eval_period,qtot,min_valid)
        else:
            self.to_monthly = MonthlyResampler(eval_period)
            self.valid_idx = slice(0,len(eval_period))


        # Build the fast monthly resampler
        #self.to_monthly = MonthlyResampler(eval_period)

        # Build our caching evaluators

        self.bias = Bias(qtot[self.valid_idx])
        self.nse_d = NSE(qtot[self.valid_idx])
        self.nse_m = NSE(self.to_monthly(qtot))

    def evaluate(self,modelled):
        qtot = modelled[self.flow_variable][self.valid_idx]
        qtot_m = self.to_monthly(modelled[self.flow_variable])
        #return dict(nse_daily=self.nse_d((qtot)),nse_monthly=self.nse_m(qtot_m),bias=self.bias(qtot))
        return np.array((self.nse_d((qtot)),self.nse_m(qtot_m),self.bias(qtot)))
class LocalQtotRouting:

    input_schema = input_group(['qtot'], 'flat')
    output_schema = ['qtot_nse']

    def __init__(self, obs, eval_period, routing_spec, min_valid=15):

        self.valid_idx = {}
        self.nse = {}
        self.flow_variable = 'qtot'
        for k in [self.flow_variable]:

            data = obs[k]

            if np.isnan(data).any():
                nan_mask = np.isnan(data)
                self.valid_idx[k] = np.where(nan_mask == False)
            else:
                self.valid_idx[k] = slice(0, len(eval_period))

            self.nse[k] = NSE(data[self.valid_idx[k]])

        run_period = routing_spec['run_period']
        self.eval_index = np.s_[(
            eval_period[0] -
            run_period[0]).days:(eval_period[-1] - run_period[0]).days + 1]
        self.gauge_idx = routing_spec['gauge_idx']

        from awrams.models.awralrouting.routing_support import RoutingRunner
        self.routing_runner = RoutingRunner(**routing_spec)

    def evaluate(self, modelled):
        out_loss = self.routing_runner.do_routing(modelled['qtot'],
                                                  modelled['params']['k_rout'])
        qtot = out_loss[self.eval_index, self.gauge_idx]
        qtot_nse = self.nse[self.flow_variable](
            qtot[self.valid_idx[self.flow_variable]])
        return np.array(qtot_nse)
class TestLocalMulti:

    input_schema = input_group(['qtot', 'etot'])
    output_schema = ['qtot_nse', 'etot_nse']

    def __init__(self,
                 obs,
                 eval_period,
                 min_valid=15,
                 flow_variable='qtot_avg',
                 et_variable='etot_avg'):

        self.valid_idx = {}
        self.nse = {}

        self.flow_variable = flow_variable
        self.et_variable = et_variable

        for k in [flow_variable, et_variable]:

            data = obs[k]

            if np.isnan(data).any():
                nan_mask = np.isnan(data)
                self.valid_idx[k] = np.where(nan_mask == False)
            else:
                self.valid_idx[k] = slice(0, len(eval_period))

            self.nse[k] = NSE(data[self.valid_idx[k]])

    def evaluate(self, modelled):
        qtot_nse = self.nse[self.flow_variable](
            modelled[self.flow_variable][self.valid_idx[self.flow_variable]])
        etot_nse = self.nse[self.et_variable](
            modelled[self.et_variable][self.valid_idx[self.et_variable]])
        return dict(qtot_nse=qtot_nse, etot_nse=etot_nse)