def test_resample(self): time_points = TimeVector() start_time = self.ecl_sum.get_data_start_time() end_time = self.ecl_sum.get_end_time() delta = end_time - start_time N = 25 time_points.initRange( CTime(start_time), CTime(end_time), CTime(int(delta.total_seconds() / (N - 1))), ) time_points.append(CTime(end_time)) resampled = self.ecl_sum.resample("OUTPUT_CASE", time_points) for key in self.ecl_sum.keys(): self.assertIn(key, resampled) self.assertEqual( self.ecl_sum.get_data_start_time(), resampled.get_data_start_time() ) delta = self.ecl_sum.get_end_time() - resampled.get_end_time() self.assertTrue(delta.total_seconds() <= 1) keys = ["FOPT", "FOPR", "BPR:15,28,1", "WGOR:OP_1"] for key in keys: for time_index, t in enumerate(time_points): self.assertFloatEqual( resampled.iget(key, time_index), self.ecl_sum.get_interp_direct(key, t), )
def test_resample_extrapolate(self): """ Test resampling of summary with extrapolate option of lower and upper boundaries enabled """ from ecl.util.util import TimeVector, CTime time_points = TimeVector() path = os.path.join(self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3") ecl_sum = EclSum(path, lazy_load=True) start_time = ecl_sum.get_data_start_time() - datetime.timedelta( seconds=86400) end_time = ecl_sum.get_end_time() + datetime.timedelta(seconds=86400) delta = end_time - start_time N = 25 time_points.initRange(CTime(start_time), CTime(end_time), CTime(int(delta.total_seconds() / (N - 1)))) time_points.append(CTime(end_time)) resampled = ecl_sum.resample("OUTPUT_CASE", time_points, lower_extrapolation=True, upper_extrapolation=True) for key in ecl_sum.keys(): self.assertIn(key, resampled) self.assertEqual( ecl_sum.get_data_start_time() - datetime.timedelta(seconds=86400), resampled.get_data_start_time()) key_not_rate = "FOPT" for time_index, t in enumerate(time_points): if t < ecl_sum.get_data_start_time(): self.assertFloatEqual(resampled.iget(key_not_rate, time_index), ecl_sum._get_first_value(key_not_rate)) elif t > ecl_sum.get_end_time(): self.assertFloatEqual(resampled.iget(key_not_rate, time_index), ecl_sum.get_last_value(key_not_rate)) else: self.assertFloatEqual( resampled.iget(key_not_rate, time_index), ecl_sum.get_interp_direct(key_not_rate, t)) key_rate = "FOPR" for time_index, t in enumerate(time_points): if t < ecl_sum.get_data_start_time(): self.assertFloatEqual(resampled.iget(key_rate, time_index), 0) elif t > ecl_sum.get_end_time(): self.assertFloatEqual(resampled.iget(key_rate, time_index), 0) else: self.assertFloatEqual(resampled.iget(key_rate, time_index), ecl_sum.get_interp_direct(key_rate, t))
def test_contains_time(self): start = datetime.datetime(2010, 1, 1, 0, 0, 0) end = datetime.datetime(2010, 2, 1, 0, 0, 0) other = datetime.datetime(2010, 1, 15, 0, 0, 0) tv = TimeVector() tv.append(start) tv.append(end) self.assertTrue(start in tv) self.assertTrue(end in tv) self.assertTrue(other not in tv)
def test_time_vector(self): time_vector = TimeVector() time1 = CTime(datetime.datetime(2013, 8, 13, 0, 0, 0)) time2 = CTime(datetime.datetime(2013, 8, 13, 1, 0, 0)) time_vector.setDefault(time2) time_vector.append(time1) time_vector[2] = time2 self.assertEqual(time_vector[0], time1) self.assertEqual(time_vector[1], time2) self.assertEqual(time_vector[2], time2) tv1 = TimeVector(default_value=datetime.date(2000, 1, 1), initial_size=2) self.assertEqual(tv1[0], datetime.date(2000, 1, 1)) tv2 = TimeVector() tv2.append(time2)
def test_resample(self): time_points = TimeVector() start_time = self.ecl_sum.get_data_start_time() end_time = self.ecl_sum.get_end_time() delta = end_time - start_time N = 25 time_points.initRange( CTime(start_time), CTime(end_time), CTime(int(delta.total_seconds()/(N - 1)))) time_points.append(CTime(end_time)) resampled = self.ecl_sum.resample( "OUTPUT_CASE", time_points ) for key in self.ecl_sum.keys(): self.assertIn( key, resampled ) self.assertEqual(self.ecl_sum.get_data_start_time(), resampled.get_data_start_time()) delta = self.ecl_sum.get_end_time() - resampled.get_end_time() self.assertTrue( delta.total_seconds() <= 1 ) keys = ["FOPT", "FOPR", "BPR:15,28,1", "WGOR:OP_1"] for key in keys: for time_index,t in enumerate(time_points): self.assertFloatEqual(resampled.iget( key, time_index), self.ecl_sum.get_interp_direct( key, t))