def test_identify_var_type(self): self.assertEnumIsFullyDefined(EclSumVarType, "ecl_smspec_var_type", "lib/include/ert/ecl/smspec_node.h") self.assertEqual(EclSum.varType("WWCT:OP_X"), EclSumVarType.ECL_SMSPEC_WELL_VAR) self.assertEqual(EclSum.varType("RPR"), EclSumVarType.ECL_SMSPEC_REGION_VAR) self.assertEqual(EclSum.varType("WNEWTON"), EclSumVarType.ECL_SMSPEC_MISC_VAR) self.assertEqual(EclSum.varType("AARQ:4"), EclSumVarType.ECL_SMSPEC_AQUIFER_VAR) case = createEclSum("CSV", [("FOPT", None, 0), ("FOPR", None, 0), ("AARQ", None, 10), ("RGPT", None, 1)]) node = case.smspec_node("FOPT") self.assertEqual(node.varType(), EclSumVarType.ECL_SMSPEC_FIELD_VAR) node = case.smspec_node("AARQ:10") self.assertEqual(node.varType(), EclSumVarType.ECL_SMSPEC_AQUIFER_VAR) self.assertEqual(node.getNum(), 10) node = case.smspec_node("RGPT:1") self.assertEqual(node.varType(), EclSumVarType.ECL_SMSPEC_REGION_VAR) self.assertEqual(node.getNum(), 1) self.assertTrue(node.isTotal())
def test_segment(self): sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4")) segment_vars = sum.keys("SOFR:F-8:*") self.assertIn("SOFR:F-8:1", segment_vars) for var in segment_vars: tmp = var.split(":") nr = int(tmp[2]) self.assertTrue(nr >= 0)
def test_restart(self): hist = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1")) base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE")) pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False) self.assertIsNotNone(hist) self.assertIsNotNone(base) self.assertIsNotNone(pred)
def test_create(self): ensemble_config = EnsembleConfig() obs = EnkfObs(ensemble_config) self.assertEqual(len(obs), 0) self.assertFalse(obs.valid) with self.assertRaises(ValueError): obs.load(self.obs_config) self.assertEqual(len(obs), 0) time_map = TimeMap() obs = EnkfObs(ensemble_config, external_time_map=time_map) self.assertEqual(len(obs), 0) grid = EclGrid(self.grid) refcase = EclSum(self.refcase) history = History(refcase, False) obs = EnkfObs(ensemble_config, grid=grid, history=history) self.assertTrue(obs.valid) with self.assertRaises(IOError): obs.load("/does/not/exist") obs.load(self.obs_config) self.assertTrue(obs.valid) self.assertEqual(len(obs), 33) obs.clear() self.assertEqual(len(obs), 0) obs.load(self.obs_config) self.assertEqual(len(obs), 33) self.assertNotIn("RFT2", obs) obs.load(self.obs_config2) self.assertEqual(len(obs), 35) self.assertIn("RFT2", obs)
def test_creation(self): ecl_sum = EclSum.writer("TEST", datetime(2010, 1, 1), 10, 10, 10) ecl_sum.addVariable("FOPT") ecl_sum.addVariable("FOPR") smspec = ecl_sum.cNamespace().get_smspec(ecl_sum) test_data = [(1, 0, 10), (1, 1, 20), (1, 2, 30), (2, 0, 40)] for report_step, mini_step, sim_days in test_data: ecl_sum_tstep = EclSumTStep(report_step, mini_step, sim_days, smspec) self.assertEqual(ecl_sum_tstep.getSimDays(), sim_days) self.assertEqual(ecl_sum_tstep.getReport(), report_step) self.assertEqual(ecl_sum_tstep.getMiniStep(), mini_step) self.assertTrue("FOPT" in ecl_sum_tstep) self.assertTrue("FOPR" in ecl_sum_tstep) self.assertFalse("WWCT" in ecl_sum_tstep) random_float = random.random() ecl_sum_tstep["FOPT"] = random_float ecl_sum_tstep["FOPR"] = random_float + 1 self.assertAlmostEqual(random_float, ecl_sum_tstep["FOPT"], places=5) self.assertAlmostEqual(random_float + 1, ecl_sum_tstep["FOPR"], places=5) with self.assertRaises(KeyError): ecl_sum_tstep["FROPR"] = 2 with self.assertRaises(KeyError): value = ecl_sum_tstep["FROPR"]
def test_rates(self): grid_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") rst_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") sum_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") grid = EclGrid(grid_path) well_info = WellInfo(grid, rst_path) sum = EclSum(sum_path) for wtl in well_info: for well_state in wtl: # print "%03d %g %g " % (R , well_state.oilRate(), sum.get_from_report( "WOPR:%s" % well , R)) if wtl.getName() == "OP_4": pass # print well_state.oilRate(), well_state.waterRate(), well_state.gasRate(), well_state.volumeRate() # print well_state.oilRateSI(), well_state.waterRateSI(), well_state.gasRateSI(), well_state.volumeRateSI() self.assertEqual(well_state.oilRate(), well_state.oilRateSI()) self.assertEqual(well_state.waterRate(), well_state.waterRateSI()) self.assertEqual(well_state.gasRate(), well_state.gasRateSI()) self.assertEqual(well_state.volumeRate(), well_state.volumeRateSI()) # print sum.get_from_report("WOPR:%s" % wtl.getName(), 1) # print sum.get_from_report( "WWPR:%s" % wtl.getName(), 30 ) for conn in well_state.globalConnections(): # print conn.gasRate(), conn.waterRate(), conn.oilRate() # print conn.gasRateSI(), conn.waterRateSI(), conn.oilRateSI() self.assertEqual(conn.gasRate(), conn.gasRateSI()) self.assertEqual(conn.waterRate(), conn.waterRateSI()) self.assertEqual(conn.oilRate(), conn.oilRateSI()) self.assertEqual(conn.volumeRate(), conn.volumeRateSI())
class EclSumVectorTest(ExtendedTestCase): def setUp(self): self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") self.ecl_sum = EclSum(self.test_file) def test_reportOnly_warns(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") vector = EclSumVector(self.ecl_sum, "FOPT", True) assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) def test_basic(self): self.assertEqual(512, len(self.ecl_sum.keys())) pfx = 'EclSum(name' self.assertEqual(pfx, repr(self.ecl_sum)[:len(pfx)]) it = iter(self.ecl_sum) t = self.ecl_sum[it.next()] # EclSumVector self.assertEqual(63, len(t)) self.assertEqual('BARSA', t.unit) pfx = 'EclSumVector(key = ' self.assertEqual(pfx, repr(t)[:len(pfx)])
def test_write(self): with TestAreaContext("my_space") as area: intersect_summary = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0") ) self.assertIsNotNone(intersect_summary) write_location = os.path.join(os.getcwd(), "CASE") intersect_summary.fwrite(ecl_case=write_location) reloaded_summary = EclSum(write_location) self.assertEqual(intersect_summary.keys(), reloaded_summary.keys())
def test_case2( self ): cwd = os.getcwd() os.chdir(self.createTestPath(path)) sum = EclSum(base) self.assertIsNone(sum.path) self.assertTrue(sum.base == base) self.assertTrue(sum.case == base) self.assertTrue(sum.abs_path == self.createTestPath(path)) os.chdir(cwd)
def test_writer(self): writer = EclSum.writer("CASE" , datetime.date( 2000 , 1 , 1) , 10 , 10 , 5) self.assertIsInstance(self.ecl_sum, EclSum) writer.addVariable( "FOPT" ) self.assertTrue( writer.has_key( "FOPT" )) writer.addTStep( 1 , 100 )
def test_restart_mapping(self): history = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0") ) total = EclSum( self.createTestPath( "Statoil/ECLIPSE/SummaryRestart/Prediction/NOR-2013A_R007_PRED-0") , include_restart = True) history_dates = history.get_dates( ) total_dates = total.get_dates( ) for i in range(len(history_dates)): self.assertEqual( history_dates[i] , total_dates[i] ) keys = history.keys( pattern = "W*") for key in keys: if key in total: self.assertEqual( history.iget( key , 5 ) , total.iget( key , 5 )) self.assertFalse( "WGPR:NOT_21_D" in history ) self.assertTrue( "WGPR:NOT_21_D" in total ) self.assertEqual( total.iget( "WGPR:NOT_21_D", 5) , 0) # Default value
def __init__(self, baseCase): sum = EclSum(baseCase) if sum: self.baseCase = sum else: raise Error("Failed to open ECLIPSE sumamry case:%s" % baseCase) self.expression = None self.keyList = {} self.start = None self.end = None self.interval = "1Y"
def test_truncated_data(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) file_size = os.path.getsize("ECLIPSE.UNSMRY") with open("ECLIPSE.UNSMRY", "r+") as f: f.truncate(file_size / 2) with self.assertRaises(IOError): EclSum("ECLIPSE")
def test_Heidrun(self): sum = EclSum( self.createTestPath("Statoil/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS")) self.assertEqual( 452 , len(sum)) self.assertFloatEqual( 1.8533144e+8 , sum.get_last_value("FOPT")) trange = sum.timeRange( start = datetime.date( 2015 , 1 , 1), interval = "1M") self.assertTrue( trange[0] == datetime.date( 2016 , 2 , 1 )) for t in trange: sum.get_interp( "FOPT" , date = t )
def test_run_default(self): with TestAreaContext(""): self.case.fwrite() # Too few arguments with self.assertRaises(CallError): subprocess.check_call([self.script]) # Too few arguments with self.assertRaises(CallError): subprocess.check_call([self.script, "CSV"]) # Invalid first arguments with self.assertRaises(CallError): subprocess.check_call( [self.script, "DOES_NOT_EXIST", "OUTPUT"]) # Should run OK: subprocess.check_call([self.script, "CSV", "OUTPUT"]) output_case = EclSum("OUTPUT") self.assertEqual(output_case.get_data_start_time(), self.case.get_data_start_time()) self.assertEqual(output_case.get_end_time(), self.case.get_end_time())
def test_ix_case(self): intersect_summary = EclSum(self.createTestPath("Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well")) self.assertIsNotNone(intersect_summary) self.assertTrue( "HWELL_PROD" in [intersect_summary.smspec_node(key).wgname for key in intersect_summary.keys()] ) eclipse_summary = EclSum(self.createTestPath("Statoil/ECLIPSE/ix/summary/ECL100/E100_CREATE_REGION_AROUND_WELL")) self.assertIsNotNone(eclipse_summary) hwell_padder = lambda key : key if key.split(":")[-1] != "HWELL_PR" else key + "OD" self.assertEqual( intersect_summary.keys("WWCT*"), map(hwell_padder, eclipse_summary.keys("WWCT*")) )
def test_different_names(self): length = 100 case = createEclSum("CSV", [("FOPT", None, 0), ("FOPR", None, 0), ("FGPT", None, 0)], sim_length_days=length, num_report_step=10, num_mini_step=10, func_table={ "FOPT": fopt, "FOPR": fopr, "FGPT": fgpt }) with TestAreaContext("sum_different"): case.fwrite() shutil.move("CSV.SMSPEC", "CSVX.SMSPEC") with self.assertRaises(IOError): case2 = EclSum.load("Does/not/exist", "CSV.UNSMRY") with self.assertRaises(IOError): case2 = EclSum.load("CSVX.SMSPEC", "CSVX.UNSMRY") case2 = EclSum.load("CSVX.SMSPEC", "CSV.UNSMRY") self.assert_solve(case2)
def create(self, smspec_file, unsmry_file): ecl_sum = EclSum.load(smspec_file, unsmry_file) smspec_name = os.path.basename(smspec_file) unsmry_name = os.path.basename(unsmry_file) smspec = BaseFile(input_name=smspec_name) with open(smspec_file, "r") as f: smspec.content.save(smspec_name, File(f)) unsmry = BaseFile(input_name=unsmry_name) with open(unsmry_file, "r") as f: unsmry.content.save(unsmry_name, File(f)) summary = Summary.objects.create(unsmry_file=unsmry, smspec_file=smspec) return summary
def test_ix_write(self): for data_set in [ "Statoil/ECLIPSE/ix/summary/Create_Region_Around_Well", "Statoil/ECLIPSE/ix/troll/IX_NOPH3_R04_75X75X1_grid2.SMSPEC" ]: with TestAreaContext("my_space" + data_set.split("/")[-1]) as area: intersect_summary = EclSum(self.createTestPath(data_set)) self.assertIsNotNone(intersect_summary) write_location = os.path.join(os.getcwd(), "CASE") intersect_summary.fwrite(ecl_case=write_location) reloaded_summary = EclSum(write_location) self.assertEqual( list(intersect_summary.keys()), list(reloaded_summary.keys()) )
def test_missing_smspec_keyword(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) with openEclFile("ECLIPSE.SMSPEC") as f: kw_list = [] for kw in f: kw_list.append(EclKW.copy(kw)) with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f: for kw in kw_list: if kw.getName() == "KEYWORDS": continue kw.fwrite(f) with self.assertRaises(IOError): EclSum("ECLIPSE")
def runSimulator(simulator, history_simulator, time_step_count): """ @rtype: EclSum """ ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10, 10) ecl_sum.addVariable('FOPT', unit="SM3") ecl_sum.addVariable('FOPR', unit="SM3/DAY") ecl_sum.addVariable('FGPT', unit="SM3") ecl_sum.addVariable('FGPR', unit="SM3/DAY") ecl_sum.addVariable('FWPT', unit="SM3") ecl_sum.addVariable('FWPR', unit="SM3/DAY") ecl_sum.addVariable('FGOR', unit="SM3/SM3") ecl_sum.addVariable('FWCT', unit="SM3/SM3") ecl_sum.addVariable('FOIP', unit="SM3") ecl_sum.addVariable('FGIP', unit="SM3") ecl_sum.addVariable('FWIP', unit="SM3") ecl_sum.addVariable('FOPTH', unit="SM3") ecl_sum.addVariable('FOPRH', unit="SM3/DAY") ecl_sum.addVariable('FGPTH', unit="SM3") ecl_sum.addVariable('FGPRH', unit="SM3/DAY") ecl_sum.addVariable('FWPTH', unit="SM3") ecl_sum.addVariable('FWPRH', unit="SM3/DAY") ecl_sum.addVariable('FGORH', unit="SM3/SM3") ecl_sum.addVariable('FWCTH', unit="SM3/SM3") ecl_sum.addVariable('FOIPH', unit="SM3") ecl_sum.addVariable('FGIPH', unit="SM3") ecl_sum.addVariable('FWIPH', unit="SM3") ecl_sum.addVariable('WOPR', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WOPR', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WWPR', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WWPR', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGPR', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WGPR', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGOR', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WGOR', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('WWCT', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WWCT', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('WOPRH', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WOPRH', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WWPRH', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WWPRH', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGPRH', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WGPRH', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGORH', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WGORH', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('WWCTH', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WWCTH', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('BPR', num=globalIndex(5, 5, 5), unit="BARSA") ecl_sum.addVariable('BPR', num=globalIndex(1, 3, 8), unit="BARSA") time_map = [] mini_step_count = 10 total_step_count = time_step_count * mini_step_count for report_step in range(time_step_count): for mini_step in range(mini_step_count): t_step = ecl_sum.addTStep(report_step + 1, sim_days=report_step * mini_step_count + mini_step) time_map.append(t_step.getSimTime().datetime().strftime("%d/%m/%Y")) simulator.step(scale=1.0 / total_step_count) history_simulator.step(scale=1.0 / total_step_count) t_step['FOPR'] = simulator.fopr() t_step['FOPT'] = simulator.fopt() t_step['FGPR'] = simulator.fgpr() t_step['FGPT'] = simulator.fgpt() t_step['FWPR'] = simulator.fwpr() t_step['FWPT'] = simulator.fwpt() t_step['FGOR'] = simulator.fgor() t_step['FWCT'] = simulator.fwct() t_step['FOIP'] = simulator.foip() t_step['FGIP'] = simulator.fgip() t_step['FWIP'] = simulator.fwip() t_step['WOPR:OP1'] = simulator.opr('OP1') t_step['WOPR:OP2'] = simulator.opr('OP2') t_step['WGPR:OP1'] = simulator.gpr('OP1') t_step['WGPR:OP2'] = simulator.gpr('OP2') t_step['WWPR:OP1'] = simulator.wpr('OP1') t_step['WWPR:OP2'] = simulator.wpr('OP2') t_step['WGOR:OP1'] = simulator.gor('OP1') t_step['WGOR:OP2'] = simulator.gor('OP2') t_step['WWCT:OP1'] = simulator.wct('OP1') t_step['WWCT:OP2'] = simulator.wct('OP2') t_step['BPR:5,5,5'] = simulator.bpr('5,5,5') t_step['BPR:1,3,8'] = simulator.bpr('1,3,8') t_step['FOPRH'] = history_simulator.fopr() t_step['FOPTH'] = history_simulator.fopt() t_step['FGPRH'] = history_simulator.fgpr() t_step['FGPTH'] = history_simulator.fgpt() t_step['FWPRH'] = history_simulator.fwpr() t_step['FWPTH'] = history_simulator.fwpt() t_step['FGORH'] = history_simulator.fgor() t_step['FWCTH'] = history_simulator.fwct() t_step['FOIPH'] = history_simulator.foip() t_step['FGIPH'] = history_simulator.fgip() t_step['FWIPH'] = history_simulator.fwip() t_step['WOPRH:OP1'] = history_simulator.opr('OP1') t_step['WOPRH:OP2'] = history_simulator.opr('OP2') t_step['WGPRH:OP1'] = history_simulator.gpr('OP1') t_step['WGPRH:OP2'] = history_simulator.gpr('OP2') t_step['WWPRH:OP1'] = history_simulator.wpr('OP1') t_step['WWPRH:OP2'] = history_simulator.wpr('OP2') t_step['WGORH:OP1'] = history_simulator.gor('OP1') t_step['WGORH:OP2'] = history_simulator.gor('OP2') t_step['WWCTH:OP1'] = history_simulator.wct('OP1') t_step['WWCTH:OP2'] = history_simulator.wct('OP2') return ecl_sum, time_map
def setUp(self): self.test_file = self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") self.ecl_sum = EclSum(self.test_file)
def test_ix_caseII(self): troll_summary = EclSum( self.createTestPath("Statoil/ECLIPSE/ix/troll/IX_NOPH3_R04_75X75X1_grid2.SMSPEC")) self.assertIsNotNone(troll_summary) self.assertTrue("WMCTL:Q21BH1" in list(troll_summary.keys()))
def test_invalid(self): with self.assertRaises(IOError): sum = EclSum("Does/not/exist")
class EclSumTest(ExtendedTestCase): def setUp(self): self.test_file = self.createTestPath( "Statoil/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") self.ecl_sum = EclSum(self.test_file) def test_time_range_year(self): real_range = self.ecl_sum.timeRange(interval="1y", extend_end=False) extended_range = self.ecl_sum.timeRange(interval="1y", extend_end=True) assert real_range[-1] < extended_range[-1] def test_time_range_day(self): real_range = self.ecl_sum.timeRange(interval="1d", extend_end=False) extended_range = self.ecl_sum.timeRange(interval="1d", extend_end=True) assert real_range[-1] == extended_range[-1] def test_time_range_month(self): real_range = self.ecl_sum.timeRange(interval="1m", extend_end=False) extended_range = self.ecl_sum.timeRange(interval="1m", extend_end=True) assert real_range[-1] < extended_range[-1] def test_dump_csv_line(self): ecl_sum_vector = EclSumKeyWordVector(self.ecl_sum) ecl_sum_vector.addKeywords("F*") with self.assertRaises(KeyError): ecl_sum_vector.addKeyword("MISSING") dtime = datetime.datetime(2002, 1, 1, 0, 0, 0) with TestAreaContext("EclSum/csv_dump"): test_file_name = self.createTestPath("dump.csv") outputH = open(test_file_name, "w") self.ecl_sum.dumpCSVLine(dtime, ecl_sum_vector, outputH) assert os.path.isfile(test_file_name) def test_truncated_smspec(self): with TestAreaContext("EclSum/truncated_smspec") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) file_size = os.path.getsize("ECLIPSE.SMSPEC") with open("ECLIPSE.SMSPEC", "r+") as f: f.truncate(file_size / 2) with self.assertRaises(IOError): EclSum("ECLIPSE") def test_truncated_data(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) file_size = os.path.getsize("ECLIPSE.UNSMRY") with open("ECLIPSE.UNSMRY", "r+") as f: f.truncate(file_size / 2) with self.assertRaises(IOError): EclSum("ECLIPSE") def test_missing_smspec_keyword(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) with openEclFile("ECLIPSE.SMSPEC") as f: kw_list = [] for kw in f: kw_list.append(EclKW.copy(kw)) with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f: for kw in kw_list: if kw.getName() == "KEYWORDS": continue kw.fwrite(f) with self.assertRaises(IOError): EclSum("ECLIPSE") def test_missing_unsmry_keyword(self): with TestAreaContext("EclSum/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file( self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) with openEclFile("ECLIPSE.UNSMRY") as f: kw_list = [] for kw in f: kw_list.append(EclKW.copy(kw)) with openFortIO("ECLIPSE.UNSMRY", mode=FortIO.WRITE_MODE) as f: c = 0 for kw in kw_list: if kw.getName() == "PARAMS": if c % 5 == 0: continue c += 1 kw.fwrite(f) with self.assertRaises(IOError): EclSum("ECLIPSE") def test_labscale(self): case = self.createTestPath("Statoil/ECLIPSE/LabScale/HDMODEL") sum = EclSum(case) self.assertEqual(sum.getStartTime(), datetime.datetime(2013, 1, 1, 0, 0, 0)) self.assertEqual(sum.getEndTime(), datetime.datetime(2013, 1, 1, 19, 30, 0)) self.assertFloatEqual(sum.getSimulationLength(), 0.8125)
"2014-09-01": 93.21, "2014-10-01": 84.40, "2014-11-01": 75.79, "2014-12-01": 59.29, "2015-01-01": 47.22, "2015-02-01": 50.58, "2015-03-01": 47.82, "2015-04-01": 54.45, "2015-05-01": 59.27, "2015-06-01": 59.82, "2015-07-01": 50.90, "2015-08-01": 42.87, "2015-09-01": 45.48} if __name__ == '__main__': ecl_sum = EclSum("SNAKE_OIL_FIELD") start_time = ecl_sum.getStartTime() date_ranges = ecl_sum.timeRange(start_time, interval="1M") production_sums = ecl_sum.blockedProduction("FOPT", date_ranges) npv = 0.0 for index in range(0, len(date_ranges) - 1): date = date_ranges[index + 1] # end of period production_sum = production_sums[index] oil_price = OIL_PRICES[date.date().strftime("%Y-%m-%d")] production_value = oil_price * production_sum npv += production_value with open("snake_oil_npv.txt", "w") as output_file:
def runSimulator(simulator, history_simulator, time_step_count): """ @rtype: EclSum """ ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10, 10) ecl_sum.addVariable("FOPT") ecl_sum.addVariable("FOPR") ecl_sum.addVariable("FGPT") ecl_sum.addVariable("FGPR") ecl_sum.addVariable("FWPT") ecl_sum.addVariable("FWPR") ecl_sum.addVariable("FGOR") ecl_sum.addVariable("FWCT") ecl_sum.addVariable("FOPTH") ecl_sum.addVariable("FOPRH") ecl_sum.addVariable("FGPTH") ecl_sum.addVariable("FGPRH") ecl_sum.addVariable("FWPTH") ecl_sum.addVariable("FWPRH") ecl_sum.addVariable("FGORH") ecl_sum.addVariable("FWCTH") ecl_sum.addVariable("WOPR", wgname="OP1") ecl_sum.addVariable("WOPR", wgname="OP2") ecl_sum.addVariable("WWPR", wgname="OP1") ecl_sum.addVariable("WWPR", wgname="OP2") ecl_sum.addVariable("WGPR", wgname="OP1") ecl_sum.addVariable("WGPR", wgname="OP2") ecl_sum.addVariable("WGOR", wgname="OP1") ecl_sum.addVariable("WGOR", wgname="OP2") ecl_sum.addVariable("WWCT", wgname="OP1") ecl_sum.addVariable("WWCT", wgname="OP2") ecl_sum.addVariable("WOPRH", wgname="OP1") ecl_sum.addVariable("WOPRH", wgname="OP2") ecl_sum.addVariable("WWPRH", wgname="OP1") ecl_sum.addVariable("WWPRH", wgname="OP2") ecl_sum.addVariable("WGPRH", wgname="OP1") ecl_sum.addVariable("WGPRH", wgname="OP2") ecl_sum.addVariable("WGORH", wgname="OP1") ecl_sum.addVariable("WGORH", wgname="OP2") ecl_sum.addVariable("WWCTH", wgname="OP1") ecl_sum.addVariable("WWCTH", wgname="OP2") ecl_sum.addVariable("BPR", num=globalIndex(5, 5, 5)) ecl_sum.addVariable("BPR", num=globalIndex(1, 3, 8)) time_map = [] mini_step_count = 10 total_step_count = time_step_count * mini_step_count for report_step in range(time_step_count): for mini_step in range(mini_step_count): t_step = ecl_sum.addTStep(report_step + 1, sim_days=report_step * mini_step_count + mini_step) time_map.append(t_step.getSimTime().datetime().strftime("%d/%m/%Y")) simulator.step(scale=1.0 / total_step_count) history_simulator.step(scale=1.0 / total_step_count) t_step["FOPR"] = simulator.fopr() t_step["FOPT"] = simulator.fopt() t_step["FGPR"] = simulator.fgpr() t_step["FGPT"] = simulator.fgpt() t_step["FWPR"] = simulator.fwpr() t_step["FWPT"] = simulator.fwpt() t_step["FGOR"] = simulator.fgor() t_step["FWCT"] = simulator.fwct() t_step["WOPR:OP1"] = simulator.opr("OP1") t_step["WOPR:OP2"] = simulator.opr("OP2") t_step["WGPR:OP1"] = simulator.gpr("OP1") t_step["WGPR:OP2"] = simulator.gpr("OP2") t_step["WWPR:OP1"] = simulator.wpr("OP1") t_step["WWPR:OP2"] = simulator.wpr("OP2") t_step["WGOR:OP1"] = simulator.gor("OP1") t_step["WGOR:OP2"] = simulator.gor("OP2") t_step["WWCT:OP1"] = simulator.wct("OP1") t_step["WWCT:OP2"] = simulator.wct("OP2") t_step["BPR:5,5,5"] = simulator.bpr("5,5,5") t_step["BPR:1,3,8"] = simulator.bpr("1,3,8") t_step["FOPRH"] = history_simulator.fopr() t_step["FOPTH"] = history_simulator.fopt() t_step["FGPRH"] = history_simulator.fgpr() t_step["FGPTH"] = history_simulator.fgpt() t_step["FWPRH"] = history_simulator.fwpr() t_step["FWPTH"] = history_simulator.fwpt() t_step["FGORH"] = history_simulator.fgor() t_step["FWCTH"] = history_simulator.fwct() t_step["WOPRH:OP1"] = history_simulator.opr("OP1") t_step["WOPRH:OP2"] = history_simulator.opr("OP2") t_step["WGPRH:OP1"] = history_simulator.gpr("OP1") t_step["WGPRH:OP2"] = history_simulator.gpr("OP2") t_step["WWPRH:OP1"] = history_simulator.wpr("OP1") t_step["WWPRH:OP2"] = history_simulator.wpr("OP2") t_step["WGORH:OP1"] = history_simulator.gor("OP1") t_step["WGORH:OP2"] = history_simulator.gor("OP2") t_step["WWCTH:OP1"] = history_simulator.wct("OP1") t_step["WWCTH:OP2"] = history_simulator.wct("OP2") return ecl_sum, time_map
def load_smry(fname): """Returns (smry,list of keywords).""" smry = EclSum(fname) return smry, list(smry.keys())
def getReportStepTimeFromRefcase(self, refcase, report_step): if not report_step in self.report_times: self.report_times[report_step] = EclSum.cNamespace( ).get_report_time(refcase, report_step).ctime() return self.report_times[report_step]
def runSimulator(simulator, history_simulator, time_step_count): """ @rtype: EclSum """ ecl_sum = EclSum.writer("SNAKE_OIL_FIELD", datetime(2010, 1, 1), 10, 10, 10) ecl_sum.addVariable('FOPT', unit="SM3") ecl_sum.addVariable('FOPR', unit="SM3/DAY") ecl_sum.addVariable('FGPT', unit="SM3") ecl_sum.addVariable('FGPR', unit="SM3/DAY") ecl_sum.addVariable('FWPT', unit="SM3") ecl_sum.addVariable('FWPR', unit="SM3/DAY") ecl_sum.addVariable('FGOR', unit="SM3/SM3") ecl_sum.addVariable('FWCT', unit="SM3/SM3") ecl_sum.addVariable('FOIP', unit="SM3") ecl_sum.addVariable('FGIP', unit="SM3") ecl_sum.addVariable('FWIP', unit="SM3") ecl_sum.addVariable('FOPTH', unit="SM3") ecl_sum.addVariable('FOPRH', unit="SM3/DAY") ecl_sum.addVariable('FGPTH', unit="SM3") ecl_sum.addVariable('FGPRH', unit="SM3/DAY") ecl_sum.addVariable('FWPTH', unit="SM3") ecl_sum.addVariable('FWPRH', unit="SM3/DAY") ecl_sum.addVariable('FGORH', unit="SM3/SM3") ecl_sum.addVariable('FWCTH', unit="SM3/SM3") ecl_sum.addVariable('FOIPH', unit="SM3") ecl_sum.addVariable('FGIPH', unit="SM3") ecl_sum.addVariable('FWIPH', unit="SM3") ecl_sum.addVariable('WOPR', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WOPR', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WWPR', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WWPR', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGPR', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WGPR', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGOR', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WGOR', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('WWCT', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WWCT', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('WOPRH', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WOPRH', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WWPRH', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WWPRH', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGPRH', wgname='OP1', unit="SM3/DAY") ecl_sum.addVariable('WGPRH', wgname='OP2', unit="SM3/DAY") ecl_sum.addVariable('WGORH', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WGORH', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('WWCTH', wgname='OP1', unit="SM3/SM3") ecl_sum.addVariable('WWCTH', wgname='OP2', unit="SM3/SM3") ecl_sum.addVariable('BPR', num=globalIndex(5, 5, 5), unit="BARSA") ecl_sum.addVariable('BPR', num=globalIndex(1, 3, 8), unit="BARSA") time_map = [] mini_step_count = 10 total_step_count = time_step_count * mini_step_count for report_step in range(time_step_count): for mini_step in range(mini_step_count): t_step = ecl_sum.addTStep(report_step + 1, sim_days=report_step * mini_step_count + mini_step) time_map.append( t_step.getSimTime().datetime().strftime("%d/%m/%Y")) simulator.step(scale=1.0 / total_step_count) history_simulator.step(scale=1.0 / total_step_count) t_step['FOPR'] = simulator.fopr() t_step['FOPT'] = simulator.fopt() t_step['FGPR'] = simulator.fgpr() t_step['FGPT'] = simulator.fgpt() t_step['FWPR'] = simulator.fwpr() t_step['FWPT'] = simulator.fwpt() t_step['FGOR'] = simulator.fgor() t_step['FWCT'] = simulator.fwct() t_step['FOIP'] = simulator.foip() t_step['FGIP'] = simulator.fgip() t_step['FWIP'] = simulator.fwip() t_step['WOPR:OP1'] = simulator.opr('OP1') t_step['WOPR:OP2'] = simulator.opr('OP2') t_step['WGPR:OP1'] = simulator.gpr('OP1') t_step['WGPR:OP2'] = simulator.gpr('OP2') t_step['WWPR:OP1'] = simulator.wpr('OP1') t_step['WWPR:OP2'] = simulator.wpr('OP2') t_step['WGOR:OP1'] = simulator.gor('OP1') t_step['WGOR:OP2'] = simulator.gor('OP2') t_step['WWCT:OP1'] = simulator.wct('OP1') t_step['WWCT:OP2'] = simulator.wct('OP2') t_step['BPR:5,5,5'] = simulator.bpr('5,5,5') t_step['BPR:1,3,8'] = simulator.bpr('1,3,8') t_step['FOPRH'] = history_simulator.fopr() t_step['FOPTH'] = history_simulator.fopt() t_step['FGPRH'] = history_simulator.fgpr() t_step['FGPTH'] = history_simulator.fgpt() t_step['FWPRH'] = history_simulator.fwpr() t_step['FWPTH'] = history_simulator.fwpt() t_step['FGORH'] = history_simulator.fgor() t_step['FWCTH'] = history_simulator.fwct() t_step['FOIPH'] = history_simulator.foip() t_step['FGIPH'] = history_simulator.fgip() t_step['FWIPH'] = history_simulator.fwip() t_step['WOPRH:OP1'] = history_simulator.opr('OP1') t_step['WOPRH:OP2'] = history_simulator.opr('OP2') t_step['WGPRH:OP1'] = history_simulator.gpr('OP1') t_step['WGPRH:OP2'] = history_simulator.gpr('OP2') t_step['WWPRH:OP1'] = history_simulator.wpr('OP1') t_step['WWPRH:OP2'] = history_simulator.wpr('OP2') t_step['WGORH:OP1'] = history_simulator.gor('OP1') t_step['WGORH:OP2'] = history_simulator.gor('OP2') t_step['WWCTH:OP1'] = history_simulator.wct('OP1') t_step['WWCTH:OP2'] = history_simulator.wct('OP2') return ecl_sum, time_map
sim_length_days=100, num_report_step=10, num_mini_step=10, func_table={ "FOPT": fopt, "FOPR": fopr, "FGPT": fgpt }) with TestAreaContext("sum_invalid"): case.fwrite() with open("CASE.txt", "w") as f: f.write("No - this is not EclKW file ....") with self.assertRaises(IOError): case2 = EclSum.load("CSV.SMSPEC", "CASE.txt") with self.assertRaises(IOError): case2 = EclSum.load("CASE.txt", "CSV.UNSMRY") kw1 = EclKW("TEST1", 30, EclDataType.ECL_INT) kw2 = EclKW("TEST2", 30, EclDataType.ECL_INT) with openFortIO("CASE.KW", FortIO.WRITE_MODE) as f: kw1.fwrite(f) kw2.fwrite(f) with self.assertRaises(IOError): case2 = EclSum.load("CSV.SMSPEC", "CASE.KW") with self.assertRaises(IOError):