예제 #1
0
파일: enkf_main.py 프로젝트: jokva/libres
    def _init_res_config(self, config):
        if isinstance(config, ResConfig):
            return config

        # The res_config argument can be None; the only reason to
        # allow that possibility is to be able to test that the
        # site-config loads correctly.
        if config is None or isinstance(config, basestring):
            user_config_file = None

            if isinstance(config, basestring):
                if not isfile(config):
                    raise IOError('No such configuration file "%s".' % res_config)

                warnings.warn("Initializing enkf_main with a config_file is "
                            "deprecated. Please use res_config to load the file "
                            "instead",
                            DeprecationWarning
                            )

                user_config_file = config

            res_config = ResConfig(user_config_file)
            res_config.convertToCReference(self)

            return res_config

        raise TypeError("Expected ResConfig, received: %r" % res_config)
예제 #2
0
def test_exporter_is_not_valid():
    config_file = "snake_oil.ert"
    rc = ResConfig(user_config_file=config_file)
    rc.convertToCReference(None)
    ert = EnKFMain(rc)
    ex = Exporter(ert)
    assert not ex.is_valid()
예제 #3
0
    def __init__(self,
                 test_name,
                 model_config=None,
                 config_dict=None,
                 store_area=False):
        if model_config is None and config_dict is None:
            raise ValueError(
                "Must supply either model_config or config_dict argument")

        work_area = TestArea(test_name)
        work_area.convertToCReference(self)

        if model_config:
            work_area.copy_parent_content(model_config)
            res_config = ResConfig(
                user_config_file=os.path.basename(model_config))
        else:
            work_area.copy_directory_content(work_area.get_original_cwd())
            res_config = ResConfig(config=config_dict)

        res_config.convertToCReference(self)
        c_ptr = self._alloc(work_area, res_config)
        super(ErtTest, self).__init__(c_ptr)
        self.setStore(store_area)

        self.__ert = None
예제 #4
0
    def __init__(self, model_config, res_config=None, strict=True, verbose=True):
        if model_config is not None and not isfile(model_config):
            raise IOError('No such configuration file "%s".' % model_config)

        if res_config is None:
            res_config = ResConfig(model_config)
            res_config.convertToCReference(self)

        if res_config is None or not isinstance(res_config, ResConfig):
            raise TypeError("Failed to construct EnKFMain instance due to invalid res_config.")

        c_ptr = self._alloc(model_config, res_config, strict, verbose)
        if c_ptr:
            super(EnKFMain, self).__init__(c_ptr)
        else:
            raise ValueError('Failed to construct EnKFMain instance from config %s.' % model_config)

        # The model_config argument can be None; the only reason to
        # allow that possibility is to be able to test that the
        # site-config loads correctly.
        if model_config is None:
            self.__simulation_runner = None
            self.__fs_manager = None
            self.__es_update = None
        else:
            self.__simulation_runner = EnkfSimulationRunner(self)
            self.__fs_manager = EnkfFsManager(self)
            self.__es_update = ESUpdate(self)


        self.__key_manager = KeyManager(self)
예제 #5
0
    def facade(self):
        config_file = "snake_oil.ert"

        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        facade = LibresFacade(ert)
        return facade
예제 #6
0
def test_exporter_is_valid():
    with ErtPluginContext():
        config_file = "snake_oil.ert"
        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        ex = Exporter(ert)
        assert ex.is_valid(), "Missing CSV_EXPORT2 or EXPORT_RUNPATH jobs"
예제 #7
0
    def api(self):
        config_file = 'snake_oil.ert'

        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        facade = LibresFacade(ert)
        api = PlotApi(facade)
        return api
예제 #8
0
def test_exporter_is_not_valid():
    config_file = "snake_oil.ert"
    rc = ResConfig(user_config_file=config_file)
    rc.convertToCReference(None)
    ert = EnKFMain(rc)
    notifier = ErtCliNotifier(ert, config_file)
    with ERT.adapt(notifier):
        ex = Exporter()
        assert not ex.is_valid()
예제 #9
0
def test_no_prior(test_data_root):
    """check dataset without prior data"""
    test_data_dir = os.path.join(test_data_root, "snake_oil")
    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))
    res_config = ResConfig("snake_oil.ert")
    res_config.convertToCReference(None)
    ert = EnKFMain(res_config)
    expected_msg = "Empty prior ensemble"
    # check that it fails
    with pytest.raises(ValidationError, match=expected_msg):
        ahmanalysis.AhmAnalysisJob(ert).run(prior_name="default")
예제 #10
0
    def _init_res_config(self, config):
        if isinstance(config, ResConfig):
            return config

        # The res_config argument can be None; the only reason to
        # allow that possibility is to be able to test that the
        # site-config loads correctly.
        if config is None:
            config = ResConfig(None)
            config.convertToCReference(self)
            return config

        raise TypeError("Expected ResConfig, received: %r" % config)
예제 #11
0
def api(tmpdir, source_root):
    with tmpdir.as_cwd():
        test_data_root = source_root / "test-data" / "local"
        test_data_dir = os.path.join(test_data_root, "snake_oil")
        shutil.copytree(test_data_dir, "test_data")
        os.chdir("test_data")
        config_file = "snake_oil.ert"
        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        facade = LibresFacade(ert)
        api = PlotApi(facade)
        yield api
예제 #12
0
    def test_executing_workflow(self):
        with open("test_wf", "w") as wf_file:
            wf_file.write("EXPORT_RUNPATH")

        config_file = "poly.ert"
        with open(config_file, "a") as file:
            file.write("LOAD_WORKFLOW test_wf")

        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        args = Namespace(name="test_wf")
        execute_workflow(ert, args.name)
        assert os.path.isfile(".ert_runpath_list")
예제 #13
0
def test_ahmanalysis_run(test_data_root):
    """test data_set with only scalar parameters"""
    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")
    res_config.convertToCReference(None)
    ert = EnKFMain(res_config)

    ahmanalysis.AhmAnalysisJob(ert).run(prior_name="default_0")

    # assert that this returns/generates a KS csv file
    output_dir = Path("storage/snake_oil/reports/default_0/AhmAnalysisJob")
    group_obs = [
        "FOPR",
        "WOPR_OP1",
        "SNAKE_OIL_WPR_DIFF",
        "All_obs",
        "All_obs-SNAKE_OIL_WPR_DIFF",
        "All_obs-WOPR_OP1",
        "All_obs-FOPR",
    ]
    parameters = [
        "SNAKE_OIL_PARAM:OP1_PERSISTENCE",
        "SNAKE_OIL_PARAM:OP1_OCTAVES",
        "SNAKE_OIL_PARAM:OP1_DIVERGENCE_SCALE",
        "SNAKE_OIL_PARAM:OP1_OFFSET",
        "SNAKE_OIL_PARAM:OP2_PERSISTENCE",
        "SNAKE_OIL_PARAM:OP2_OCTAVES",
        "SNAKE_OIL_PARAM:OP2_DIVERGENCE_SCALE",
        "SNAKE_OIL_PARAM:OP2_OFFSET",
        "SNAKE_OIL_PARAM:BPR_555_PERSISTENCE",
        "SNAKE_OIL_PARAM:BPR_138_PERSISTENCE",
    ]
    assert (output_dir / "ks.csv").is_file()
    ks_df = pd.read_csv(output_dir / "ks.csv")
    for keys in ks_df["Parameters"].tolist():
        assert keys in parameters
    assert ks_df.columns[1:].tolist() == group_obs
    assert ks_df["WOPR_OP1"].max() <= 1
    assert ks_df["WOPR_OP1"].min() >= 0
    assert (output_dir / "active_obs_info.csv").is_file()
    assert (output_dir / "misfit_obs_info.csv").is_file()
    assert (output_dir / "prior.csv").is_file()
    for group in group_obs:
        filename = group + ".csv"
        assert (output_dir / filename).is_file()
예제 #14
0
    def test_executing_workflow(self):
        with open('test_wf', 'w') as wf_file:
            wf_file.write('EXPORT_RUNPATH')

        config_file = 'poly.ert'
        with open(config_file, 'a') as file:
            file.write("LOAD_WORKFLOW test_wf")

        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        notifier = ErtCliNotifier(ert, config_file)
        ERT.adapt(notifier)
        args = Namespace(name="test_wf")
        execute_workflow(args.name)
        assert os.path.isfile(".ert_runpath_list")
예제 #15
0
def test_run_export():
    with ErtPluginContext():
        config_file = "snake_oil.ert"
        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        ex = Exporter(ert)
        parameters = {
            "output_file": "export.csv",
            "time_index": "raw",
            "column_keys": "FOPR",
        }
        ex.run_export(parameters)

        shutil.rmtree("storage")
        with pytest.raises(UserWarning) as warn:
            ex.run_export(parameters)
        assert ex._export_job in str(warn)
예제 #16
0
def test_ahmanalysis_run_field(test_data_root, grid_prop):
    """test data_set with scalar and Field parameters"""
    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))
    os.makedirs("fields")
    grid = EclGridGenerator.createRectangular((10, 12, 5), (1, 1, 1))
    for iens in range(10):
        grid_prop("PERMX", 10, grid.getGlobalSize(), "fields/permx%d.grdecl" % iens)
        grid_prop("PORO", 0.2, grid.getGlobalSize(), "fields/poro%d.grdecl" % iens)

    res_config = ResConfig("snake_oil_field.ert")
    res_config.convertToCReference(None)
    ert = EnKFMain(res_config)

    ahmanalysis.AhmAnalysisJob(ert).run(prior_name="default")

    # assert that this returns/generates the delta field parameter
    gen_obs_list = GenDataObservationCollector.getAllObservationKeys(ert)
    summary_obs_list = SummaryObservationCollector.getAllObservationKeys(ert)
    obs_keys = gen_obs_list + summary_obs_list
    output_deltafield = os.path.join(
        "storage",
        "snake_oil_field",
        "reports",
        "default",
        "AhmAnalysisJob",
        "delta_fieldPERMX.csv",
    )
    assert os.path.isfile(output_deltafield)
    delta_df = pd.read_csv(output_deltafield, index_col=0)
    assert len(delta_df.columns) == 8 + (len(obs_keys) * 2) + 1
    # check field parameter is present and not empty in the final KS matrix
    output_ks = output_deltafield.replace("delta_fieldPERMX.csv", "ks.csv")
    ks_df = pd.read_csv(output_ks, index_col=0)
    assert not ks_df.empty
    assert "FIELD_PERMX" in ks_df.index.tolist()
    check_empty = ks_df.loc[["FIELD_PERMX"], :].isnull().all(axis=1)
    assert not check_empty["FIELD_PERMX"]