def _predict_bias(self, obs_set, fc_set): # Return a set of bias_ts per observation geo_point bias_set = api.TemperatureSourceVector() kf = api.KalmanFilter() kbp = api.KalmanBiasPredictor(kf) kta = api.Timeaxis2(self.t0, api.deltahours(3), 8) for obs in obs_set: kbp.update_with_forecast(fc_set, obs.ts, kta) pattern = api.KalmanState.get_x(kbp.state) # a_ts = api.Timeseries(pattern, api.deltahours(3), self.ta) # can do using ct of Timeseries, or: b_ts = api.create_periodic_pattern_ts(pattern, api.deltahours(3), self.ta.time(0), self.ta) # function bias_set.append(api.TemperatureSource(obs.mid_point(), b_ts)) return bias_set
def test_periodic_pattern_ts(self): c = api.Calendar() t0 = c.time(2016, 1, 1) dt = api.deltahours(1) n = 240 ta = api.Timeaxis2(t0, dt, n) pattern_values = api.DoubleVector.from_numpy(np.arange(8)) pattern_dt = api.deltahours(3) pattern_t0 = c.time(2015,6,1) pattern_ts = api.create_periodic_pattern_ts(pattern_values, pattern_dt, pattern_t0, ta) # this is how to create a periodic pattern ts (used in gridpp/kalman bias handling) self.assertAlmostEqual(pattern_ts.value(0), 0.0) self.assertAlmostEqual(pattern_ts.value(1), 0.0) self.assertAlmostEqual(pattern_ts.value(2), 0.0) self.assertAlmostEqual(pattern_ts.value(3), 1.0) # next step in pattern starts here self.assertAlmostEqual(pattern_ts.value(24), 0.0) # next day repeats the pattern
def _predict_bias(self, obs_set, fc_set): # Return a set of bias_ts per observation geo_point bias_set = api.TemperatureSourceVector() kf = api.KalmanFilter() kbp = api.KalmanBiasPredictor(kf) kta = api.TimeAxis(self.t0, api.deltahours(3), 8) for obs in obs_set: kbp.update_with_forecast(fc_set, obs.ts, kta) pattern = api.KalmanState.get_x(kbp.state) # a_ts = api.TimeSeries(pattern, api.deltahours(3), self.ta) # can do using ct of TimeSeries, or: b_ts = api.create_periodic_pattern_ts(pattern, api.deltahours(3), self.ta.time(0), self.ta) # function bias_set.append(api.TemperatureSource(obs.mid_point(), b_ts)) return bias_set