def _add_model(self,model_df,name,freq='d'): self.selection._add(name) m = ObjectDict(freq=SAMPLE_RATE[freq]) self.models[name] = m m.name = name m.data = ObjectDict() m.obs = ObjectDict() m.data.raw = model_df.loc[self.period] if self.obs.freq != 'y': if freq == 'd' and self.obs.freq == 'd': m.data.daily,m.obs.daily = self._intersect(m.data.raw, self.obs.data) m.data.monthly = resample_to_months_df(m.data.daily, self.aggr_how) m.obs.monthly = resample_to_months_df(m.obs.daily, self.aggr_how) elif freq == 'm' or self.obs.freq == 'm': if freq == 'm': _mod = m.data.raw.resample(rule='m', how=self.aggr_how) else: # assume must be daily _mod = resample_to_months_df(m.data.raw, self.aggr_how) if self.obs.freq == 'm': _obs = self.obs.data.resample(rule='m', how=self.aggr_how) else: _obs = resample_to_months_df(self.obs.data, self.aggr_how) m.data.monthly,m.obs.monthly = self._intersect(_mod,_obs) else: raise Exception('model freq is %s' % repr(freq)) m.data.annual = resample_to_years_df(m.data.monthly, self.aggr_how, min_months=6) m.obs.annual = resample_to_years_df(m.obs.monthly, self.aggr_how, min_months=6) m.data.annual,m.obs.annual = self._intersect(m.data.annual,m.obs.annual) else: #obs are annual (recharge) m.data.annual = m.data.raw.resample(rule='a', how=self.aggr_how) m.obs.annual = self.obs.data m.stats = ObjectDict(freq=freq) m.stats.daily = None m.stats.monthly = None if freq == 'd' and self.obs.freq == 'd': m.stats.daily = build_stats_df(m.obs.daily, m.data.daily, m.obs.daily.keys()) if self.obs.freq != 'y': m.stats.monthly = build_stats_df(m.obs.monthly, m.data.monthly, m.obs.monthly.keys()) if m.obs.annual is not None and m.data.annual is not None: m.stats.annual = build_stats_df(m.obs.annual, m.data.annual, m.obs.annual.keys()) self.build_objfunc_stats(m.stats) self._assign_colours()
def _index_results(results_folder): filenames = _identify_results_files(results_folder) expected_variables = _identify_variables(filenames) result = ObjectDict() result.metadata_from = filenames[0] result.name = None result.extent = _infer_extent(result.metadata_from, results_folder) result.period = _infer_time_period(result.metadata_from, results_folder) result.variables = expected_variables result.model_version = _infer_model_version(result.metadata_from, results_folder) return result