コード例 #1
0
    def test_integration(self):
        test_data_dir = os.path.join(resources.get_test_resources_dir(),
                                     "moss_c_test_case")

        expected_output = pd.read_csv(
            os.path.join(test_data_dir, "expected_output.csv"))
        ctx = model_context.create_from_csv(test_data_dir)
        pool_results = pd.DataFrame()
        flux_results = pd.DataFrame()

        for i in range(0, 125):

            model.step(ctx)

            pools = ctx.get_pools_df()
            pools.insert(0, "t", i)
            pool_results = pd.concat([pool_results, pools])

            flux = ctx.flux.copy()
            flux.insert(0, "t", i)
            flux_results = pd.concat([flux_results, flux])

        for p in ECOSYSTEM_POOLS:
            self.assertTrue(
                np.allclose(pool_results[p.name], expected_output[p.name]))
コード例 #2
0
    def test_integration_with_tutorial2_eligbilities(self):
        """tests full CBM integration with rule based disturbances and
        disturbance event eligibility expressions
        """
        config_path = os.path.join(
            resources.get_test_resources_dir(),
            "cbm3_tutorial2_eligibilities", "sit_config.json")
        sit = sit_cbm_factory.load_sit(config_path)
        classifiers, inventory = \
            sit_cbm_factory.initialize_inventory(sit)
        with sit_cbm_factory.initialize_cbm(sit) as cbm:
            results, reporting_func = \
                cbm_simulator.create_in_memory_reporting_func()
            rule_based_processor = \
                sit_cbm_factory.create_sit_rule_based_processor(sit, cbm)

            cbm_simulator.simulate(
                cbm,
                n_steps=1,
                classifiers=classifiers,
                inventory=inventory,
                pre_dynamics_func=rule_based_processor.pre_dynamics_func,
                reporting_func=reporting_func)
            self.assertTrue(
                results.pools[results.pools.timestep == 0].shape[0] ==
                inventory.shape[0])
            self.assertTrue(
                len(rule_based_processor.sit_event_stats_by_timestep) > 0)
コード例 #3
0
    def test_integration_spinup(self):
        test_data_dir = os.path.join(resources.get_test_resources_dir(),
                                     "moss_c_test_case")

        ctx = model_context.create_from_csv(test_data_dir)
        spinup_debug = model.spinup(ctx, enable_debugging=True)
        self.assertTrue(spinup_debug is not None)

        self.assertTrue(model.spinup(ctx, enable_debugging=False) is None)
コード例 #4
0
ファイル: sit_reader_test.py プロジェクト: cat-cfs/libcbm_py
 def test_read_csv_integration(self):
     data_dir = os.path.join(resources.get_test_resources_dir(),
                             "cbm3_tutorial2")
     config_path = os.path.join(data_dir, "sit_config.json")
     with open(config_path) as config_file:
         config = json.load(config_file)["import_config"]
     result = sit_reader.read(config, data_dir)
     expected_tables = [
         "classifiers", "classifier_values", "classifier_aggregates",
         "disturbance_types", "age_classes", "inventory", "yield_table",
         "disturbance_events", "transition_rules"
     ]
     for table in expected_tables:
         self.assertTrue(result.__dict__[table] is not None)
コード例 #5
0
    def test_integration_with_different_event_sort_modes(self):
        """tests full CBM integration with rule based disturbances and
        disturbance event eligibility expressions
        """
        config_path = os.path.join(
            resources.get_test_resources_dir(),
            "cbm3_tutorial2_eligibilities", "sit_config.json")
        sit = sit_cbm_factory.load_sit(config_path)
        with sit_cbm_factory.initialize_cbm(sit) as cbm:

            rule_based_processor1 = \
                sit_cbm_factory.create_sit_rule_based_processor(
                    sit, cbm, event_sort=EventSort.disturbance_type)

            self.assertTrue(
                list(rule_based_processor1.sit_events["sort_field"])
                == list(sit.sit_mapping.get_sit_disturbance_type_id(
                    sit.sit_data.disturbance_events["disturbance_type"]))
            )

            rule_based_processor2 = \
                sit_cbm_factory.create_sit_rule_based_processor(
                    sit, cbm, event_sort=EventSort.default_disturbance_type_id)

            expected_default_types = list(
                sit.sit_mapping.get_default_disturbance_type_id(
                    sit.sit_data.disturbance_events[
                        ["disturbance_type"]
                    ].merge(
                        sit.sit_data.disturbance_types,
                        how="left",
                        left_on="disturbance_type",
                        right_on="id"
                    )["name"]
                    )
                )
            assert (
                list(rule_based_processor2.sit_events["sort_field"])
                == expected_default_types)

            rule_based_processor3 = \
                sit_cbm_factory.create_sit_rule_based_processor(
                    sit, cbm, event_sort=EventSort.natural_order)

            self.assertTrue(
                list(rule_based_processor3.sit_events["sort_field"])
                == list(range(len(sit.sit_data.disturbance_events.index)))
            )
コード例 #6
0
def get_test_data_dir():
    return os.path.join(
        resources.get_test_resources_dir(), "sit_rule_based_events")
コード例 #7
0
 def test_get_test_resources_dir(self):
     self.assertTrue(os.path.exists(resources.get_test_resources_dir()))