Ejemplo n.º 1
0
    def test_custom_kw_collector_current_fs(self):
        config = self.createTestPath("local/custom_kw/mini_config")

        with ErtTestContext(
                "python/enkf/export/custom_kw_collector_from_current_fs",
                config) as context:
            ert = context.getErt()
            fs = ert.getEnkfFsManager().getFileSystem("test_run")
            ert.getEnkfFsManager().switchFileSystem(fs)
            data = CustomKWCollector.loadAllCustomKWData(ert, "test_run")

            self.assertFloatEqual(data["AGGREGATED:PERLIN_1"][0], -0.167794)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_1"][8], -1.276058)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_1"][9], -0.137903)

            self.assertFloatEqual(data["AGGREGATED:PERLIN_2"][0], 1.00263)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_2"][8], -0.105634)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_2"][9], 1.032522)

            self.assertFloatEqual(data["AGGREGATED:PERLIN_3"][0], 0.190479)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_3"][8], -0.917785)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_3"][9], 0.220371)

            self.assertEqual(data["AGGREGATED:STATE"][0], "Positive")
            self.assertEqual(data["AGGREGATED:STATE"][8], "Negative")
            self.assertEqual(data["AGGREGATED:STATE"][9], "Positive")
Ejemplo n.º 2
0
    def test_custom_kw_collector_non_current_fs(self):
        config = self.createTestPath("local/custom_kw/mini_config")

        with ErtTestContext("python/enkf/export/custom_kw_collector_from_fs", config) as context:
            ert = context.getErt()

            data = CustomKWCollector.loadAllCustomKWData(ert, "test_run")

            self.assertTrue(len(data.columns) == 0)
Ejemplo n.º 3
0
    def test_custom_kw_collector_non_current_fs(self):
        config = self.createTestPath("local/custom_kw/mini_config")

        with ErtTestContext("python/enkf/export/custom_kw_collector_from_fs",
                            config) as context:
            ert = context.getErt()

            data = CustomKWCollector.loadAllCustomKWData(ert, "test_run")

            self.assertTrue(len(data.columns) == 0)
Ejemplo n.º 4
0
    def test_custom_kw_collector_current_fs(self):
        config = self.createTestPath("local/custom_kw/mini_config")

        with ErtTestContext("python/enkf/export/custom_kw_collector_from_current_fs", config) as context:
            ert = context.getErt()
            fs = ert.getEnkfFsManager().getFileSystem("test_run")
            ert.getEnkfFsManager().switchFileSystem(fs)
            data = CustomKWCollector.loadAllCustomKWData(ert, "test_run")

            self.assertFloatEqual(data["AGGREGATED:PERLIN_1"][0], -0.167794)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_1"][8], -1.276058)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_1"][9], -0.137903)

            self.assertFloatEqual(data["AGGREGATED:PERLIN_2"][0], 1.00263)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_2"][8], -0.105634)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_2"][9], 1.032522)

            self.assertFloatEqual(data["AGGREGATED:PERLIN_3"][0], 0.190479)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_3"][8], -0.917785)
            self.assertFloatEqual(data["AGGREGATED:PERLIN_3"][9], 0.220371)

            self.assertEqual(data["AGGREGATED:STATE"][0], "Positive")
            self.assertEqual(data["AGGREGATED:STATE"][8], "Negative")
            self.assertEqual(data["AGGREGATED:STATE"][9], "Positive")
Ejemplo n.º 5
0
    def gatherCustomKwData(ert, case, key):
        """ :rtype: pandas.DataFrame """
        data = CustomKWCollector.loadAllCustomKWData(ert, case, [key])

        return data
Ejemplo n.º 6
0
    def run(self, output_file, case_list=None, design_matrix_path=None, infer_iteration=True):
        cases = []

        if case_list is not None:
            if case_list.strip() == "*":
                cases = self.getAllCaseList()
            else:
                cases = case_list.split(",")

        if case_list is None or len(cases) == 0:
            cases = [self.ert().getEnkfFsManager().getCurrentFileSystem().getCaseName()]

        if design_matrix_path is not None:
            if not os.path.exists(design_matrix_path):
                raise UserWarning("The design matrix file does not exists!")

            if not os.path.isfile(design_matrix_path):
                raise UserWarning("The design matrix is not a file!")

        data = pandas.DataFrame()

        for index, case in enumerate(cases):
            case = case.strip()

            if not self.ert().getEnkfFsManager().caseExists(case):
                raise UserWarning("The case '%s' does not exist!" % case)

            if not self.ert().getEnkfFsManager().caseHasData(case):
                raise UserWarning("The case '%s' does not have any data!" % case)

            if infer_iteration:
                iteration_number = self.inferIterationNumber(case)
            else:
                iteration_number = index

            case_data = GenKwCollector.loadAllGenKwData(self.ert(), case)

            custom_kw_data = CustomKWCollector.loadAllCustomKWData(self.ert(), case)
            if not custom_kw_data.empty:
                case_data = case_data.join(custom_kw_data, how='outer')

            if design_matrix_path is not None:
                design_matrix_data = DesignMatrixReader.loadDesignMatrix(design_matrix_path)
                if not design_matrix_data.empty:
                    case_data = case_data.join(design_matrix_data, how='outer')

            misfit_data = MisfitCollector.loadAllMisfitData(self.ert(), case)
            if not misfit_data.empty:
                case_data = case_data.join(misfit_data, how='outer')

            summary_data = SummaryCollector.loadAllSummaryData(self.ert(), case)
            if not summary_data.empty:
                case_data = case_data.join(summary_data, how='outer')
            else:
                case_data["Date"] = None
                case_data.set_index(["Date"], append=True, inplace=True)

            case_data["Iteration"] = iteration_number
            case_data["Case"] = case
            case_data.set_index(["Case", "Iteration"], append=True, inplace=True)

            data = pandas.concat([data, case_data])

        data = data.reorder_levels(["Realization", "Iteration", "Date", "Case"])
        data.to_csv(output_file)

        export_info = "Exported %d rows and %d columns to %s." % (len(data.index), len(data.columns), output_file)
        return export_info