def test_ts_fixed(self): dv=np.arange(self.ta.size()) v=api.DoubleVector.from_numpy(dv) xv=v.to_numpy() tsfixed=api.TsFixed(self.ta, v, api.POINT_AVERAGE_VALUE) self.assertEqual(tsfixed.size(), self.ta.size()) self.assertAlmostEqual(tsfixed.get(0).v, v[0]) vv=tsfixed.values.to_numpy() # introduced .values for compatibility assert_array_almost_equal(dv, vv) tsfixed.values[0]=10.0 dv[0]=10.0 assert_array_almost_equal(dv, tsfixed.v.to_numpy()) ts_ta=tsfixed.time_axis # a TsFixed do have .time_axis and .values self.assertEqual(len(ts_ta), len(self.ta)) # should have same length etc. # verify some simple core-ts to TimeSeries interoperability full_ts=tsfixed.TimeSeries # returns a new TimeSeries as clone from tsfixed self.assertEqual(full_ts.size(), tsfixed.size()) for i in range(tsfixed.size()): self.assertEqual(full_ts.time(i), tsfixed.time(i)) self.assertAlmostEqual(full_ts.value(i), tsfixed.value(i), 5) ns=tsfixed.nash_sutcliffe(full_ts) self.assertAlmostEqual(ns, 1.0, 4) kg=tsfixed.kling_gupta(full_ts, 1.0, 1.0, 1.0) self.assertAlmostEqual(kg, 1.0, 4) # self.assertAlmostEqual(v,vv) # some reference testing: ref_v=tsfixed.v del tsfixed assert_array_almost_equal(dv, ref_v.to_numpy())
def test_operations_on_TsFixed(self): dv = np.arange(self.ta.size()) v = api.DoubleVector.FromNdArray(dv) # test create tsa = api.TsFixed(self.ta, v) # assert its contains time and values as expected. self.assertEqual(self.ta.total_period(), tsa.total_period()) [ self.assertAlmostEqual(tsa.value(i), v[i]) for i in range(self.ta.size()) ] [ self.assertEqual(tsa.time(i), self.ta(i).start) for i in range(self.ta.size()) ] [ self.assertAlmostEqual(tsa.get(i).v, v[i]) for i in range(self.ta.size()) ] # set one value v[0] = 122 tsa.set(0, v[0]) self.assertAlmostEqual(v[0], tsa.value(0)) # test fill with values for i in range(len(v)): v[i] = 123 tsa.fill(v[0]) [ self.assertAlmostEqual(tsa.get(i).v, v[i]) for i in range(self.ta.size()) ]
def test_TsFixed(self): dv = np.arange(self.ta.size()) v = api.DoubleVector.FromNdArray(dv) xv = v.to_numpy() tsfixed = api.TsFixed(self.ta, v) self.assertEqual(tsfixed.size(), self.ta.size()) self.assertAlmostEqual(tsfixed.get(0).v, v[0]) vv = tsfixed.v.to_numpy() assert_array_almost_equal(dv, vv) tsfixed.v[0] = 10.0 dv[0] = 10.0 assert_array_almost_equal(dv, tsfixed.v.to_numpy()) # self.assertAlmostEqual(v,vv) # some reference testing: ref_v = tsfixed.v del tsfixed assert_array_almost_equal(dv, ref_v.to_numpy())
def test_ts_fixed(self): dv = np.arange(self.ta.size()) v = api.DoubleVector.from_numpy(dv) xv = v.to_numpy() tsfixed = api.TsFixed(self.ta, v) self.assertEqual(tsfixed.size(), self.ta.size()) self.assertAlmostEqual(tsfixed.get(0).v, v[0]) vv = tsfixed.values.to_numpy() # introduced .values for compatibility assert_array_almost_equal(dv, vv) tsfixed.values[0] = 10.0 dv[0] = 10.0 assert_array_almost_equal(dv, tsfixed.v.to_numpy()) ts_ta = tsfixed.time_axis # a TsFixed do have .time_axis and .values self.assertEqual(len(ts_ta), len(self.ta)) # should have same length etc. # self.assertAlmostEqual(v,vv) # some reference testing: ref_v = tsfixed.v del tsfixed assert_array_almost_equal(dv, ref_v.to_numpy())
def test_ts_transform(self): dv=np.arange(self.ta.size()) v=api.DoubleVector.from_numpy(dv) t=api.UtcTimeVector(); for i in range(self.ta.size()): t.push_back(self.ta(i).start) # t.push_back(self.ta(self.ta.size()-1).end) #important! needs n+1 points to determine n periods in the timeaxis t_start=self.ta.total_period().start dt=api.deltahours(1) tax=api.TimeAxisFixedDeltaT(t_start + api.deltaminutes(30), dt, self.ta.size()) tsf=api.TsFactory() ts1=tsf.create_point_ts(self.ta.size(), self.t, self.d, v) ts2=tsf.create_time_point_ts(self.ta.total_period(), t, v) ts3=api.TsFixed(tax, v, api.POINT_INSTANT_VALUE) tst=api.TsTransform() tt1=tst.to_average(t_start, dt, tax.size(), ts1) tt2=tst.to_average(t_start, dt, tax.size(), ts2) tt3=tst.to_average(t_start, dt, tax.size(), ts3) self.assertEqual(tt1.size(), tax.size()) self.assertEqual(tt2.size(), tax.size()) self.assertEqual(tt3.size(), tax.size())