コード例 #1
0
ファイル: sit_reader_test.py プロジェクト: cat-cfs/libcbm_py
 def test_error_on_unsupported_config_type(self):
     config = {
         "classifiers": {
             "type": "NOT SUPPORTED",
             "params": {
                 "p1": "classifiers"
             }
         }
     }
     with self.assertRaises(NotImplementedError):
         sit_reader.read(config, ".")
コード例 #2
0
def read_sit_config(config_path):
    """Load SIT data and configuration from the json formatted configuration
    file at specified config_path.

    Args:
        config_path (str): path to SIT configuration

    Returns:
        types.SimpleNamespace: an object with the following properties:

            - config: the dictionary representation of the json configuration
                at the specified config_path
            - sit_data: if the "import_config" key is present in the
                configuration, this is a loaded and parsed sit dataset, and
                otherwise it is None.
    """
    sit = SimpleNamespace()
    with open(config_path, 'r', encoding="utf-8") as config_file:
        sit.config = json.load(config_file)
        config_path = config_path
        if "import_config" in sit.config:
            sit.sit_data = sit_reader.read(sit.config["import_config"],
                                           os.path.dirname(config_path))
        else:
            sit.sit_data = None
        return sit
コード例 #3
0
def load_sit_data():
    sit = SimpleNamespace()
    sit_config = load_config()
    sit.sit_data = sit_reader.read(
        sit_config["import_config"], get_test_data_dir())
    sit.config = sit_config
    return sit
コード例 #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)