Пример #1
0
    def test_gen_data_collector(self):
        config = self.createTestPath("local/mini_ert/mini_config")
        with ErtTestContext(
            "python/enkf/export/gen_data_observation_collector", config
        ) as context:
            ert = context.getErt()

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 1
            )
            self.assertEqual(obs_key, "GEN_PERLIN_1")

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 2
            )
            self.assertEqual(obs_key, "GEN_PERLIN_2")

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 3
            )
            self.assertEqual(obs_key, "GEN_PERLIN_3")

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 4
            )
            self.assertIsNone(obs_key)

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLINk", 1
            )
            self.assertIsNone(obs_key)
def test_gen_data_report_steps():
    with open("config_file.ert", "w") as fout:
        # Write a minimal config file
        fout.write(
            dedent("""
        NUM_REALIZATIONS 1
        OBS_CONFIG observations
        TIME_MAP time_map
        GEN_DATA RESPONSE RESULT_FILE:result_%d.out REPORT_STEPS:0,1 INPUT_FORMAT:ASCII
        """))
    with open("obs_data_0.txt", "w") as fout:
        fout.write("1.0 0.1")
    with open("obs_data_1.txt", "w") as fout:
        fout.write("2.0 0.1")

    with open("time_map", "w") as fout:
        fout.write("2014-09-10\n2017-02-05")

    with open("observations", "w") as fout:
        fout.write(
            dedent("""
        GENERAL_OBSERVATION OBS_0 {
            DATA       = RESPONSE;
            INDEX_LIST = 0;
            RESTART    = 0;
            OBS_FILE   = obs_data_0.txt;
        };

        GENERAL_OBSERVATION OBS_1 {
            DATA       = RESPONSE;
            INDEX_LIST = 0;
            RESTART    = 1;
            OBS_FILE   = obs_data_1.txt;
        };
        """))

    res_config = ResConfig("config_file.ert")
    ert = EnKFMain(res_config)
    obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
        ert, "RESPONSE", 0)
    assert obs_key == "OBS_0"

    obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
        ert, "RESPONSE", 1)
    assert obs_key == "OBS_1"

    obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
        ert, "RESPONSE", 2)
    assert obs_key is None

    obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
        ert, "NOT_A_KEY", 0)
    assert obs_key is None
Пример #3
0
    def observation_keys(self, key):
        if self._enkf_main.getKeyManager().isGenDataKey(key):
            key_parts = key.split("@")
            key = key_parts[0]
            if len(key_parts) > 1:
                report_step = int(key_parts[1])
            else:
                report_step = 0

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                self._enkf_main, key, report_step
            )
            if obs_key is not None:
                return [obs_key]
            else:
                return []
        elif self._enkf_main.getKeyManager().isSummaryKey(key):
            return [
                str(k)
                for k in self._enkf_main.ensembleConfig()
                .getNode(key)
                .getObservationKeys()
            ]
        else:
            return []
    def test_gen_data_collector(self):
        config = self.createTestPath("local/mini_ert/mini_config")
        with ErtTestContext(
            "python/enkf/export/gen_data_observation_collector", config
        ) as context:
            ert = context.getErt()

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 1
            )
            self.assertEqual(obs_key, "GEN_PERLIN_1")

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 2
            )
            self.assertEqual(obs_key, "GEN_PERLIN_2")

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 3
            )
            self.assertEqual(obs_key, "GEN_PERLIN_3")

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLIN", 4
            )
            self.assertIsNone(obs_key)

            obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
                ert, "PERLINk", 1
            )
            self.assertIsNone(obs_key)

            data = GenDataObservationCollector.loadGenDataObservations(
                ert, "default", "GEN_PERLIN_1"
            )

            self.assertFloatEqual(data["GEN_PERLIN_1"][0], -0.616789)
            self.assertFloatEqual(data["STD_GEN_PERLIN_1"][0], 0.2)

            with self.assertRaises(KeyError):
                GenDataObservationCollector.loadGenDataObservations(
                    ert, "default", "GEN_PERLIN_4"
                )
Пример #5
0
    def gatherGenDataObservationData(ert, case, key_with_report_step):
        """ :rtype: pandas.DataFrame """
        key, report_step = key_with_report_step.split("@", 1)
        report_step = int(report_step)

        obs_key = GenDataObservationCollector.getObservationKeyForDataKey(ert, key, report_step)

        if obs_key is not None:
            obs_data = GenDataObservationCollector.loadGenDataObservations(ert, case, obs_key)
            columns = {obs_key: key_with_report_step, "STD_%s" % obs_key: "STD_%s" % key_with_report_step}
            obs_data = obs_data.rename(columns=columns)
        else:
            obs_data = DataFrame()

        return obs_data.dropna()
Пример #6
0
        key, report_step = key.split("@", 1)
        report_step = int(report_step)
        try:
            data = GenDataCollector.loadGenData(ert, case, key, report_step)
        except ValueError:
            data = DataFrame()

        return data.dropna()  # removes all rows that has a NaN

    @staticmethod
    def gatherGenDataObservationData(ert, case, key_with_report_step):
        """ :rtype: pandas.DataFrame """
        key, report_step = key_with_report_step.split("@", 1)
        report_step = int(report_step)

        obs_key = GenDataObservationCollector.getObservationKeyForDataKey(
            ert, key, report_step)

        if obs_key is not None:
            obs_data = GenDataObservationCollector.loadGenDataObservations(
                ert, case, obs_key)
            columns = {
                obs_key: key_with_report_step,
                "STD_%s" % obs_key: "STD_%s" % key_with_report_step
            }
            obs_data = obs_data.rename(columns=columns)
        else:
            obs_data = DataFrame()

        return obs_data.dropna()

    @staticmethod