diff --git a/config_example.yml b/config_example.yml index 42fd5ef1f596ce8ff3f25e940a236215a82e90a5..b814bd00d7c482e4ced517150fac9f524f01daae 100644 --- a/config_example.yml +++ b/config_example.yml @@ -7,3 +7,4 @@ database_gde_tiles: # Database where info on the GDE tiles is stored password: password_of_username exposure_entities_to_run: all # Either "all", a comma-space-separated list of entity names, or a name of a .txt or .csv file exposure_entities_code: ISO3 # Either "ISO3" in this or a nested structure with exposure entities names and 3-character codes +occupancies_to_run: residential, commercial, industrial # Need to exist for the indicated `model_name` diff --git a/gdecore/configuration.py b/gdecore/configuration.py index 07fed20b985b327c5413983f35ed829137395939..cd678c31770af47277f3e35bb362afebe976fc2a 100644 --- a/gdecore/configuration.py +++ b/gdecore/configuration.py @@ -65,6 +65,7 @@ class Configuration: "database_gde_tiles", "exposure_entities_to_run", "exposure_entities_code", + "occupancies_to_run", ] def __init__(self, filepath, force_config_over_hierarchies=False): @@ -111,6 +112,10 @@ class Configuration: logger.critical(error_message) sys.exit(1) + self.occupancies_to_run = ConfigurationMethods.assign_listed_parameters( + config, "occupancies_to_run" + ) + # Terminate if critical parameters are missing (not all parameters are critical) for key_parameter in self.REQUIRES: if getattr(self, key_parameter) is None: diff --git a/gdecore/gdecore.py b/gdecore/gdecore.py index 511cefdc015f835d82889056af4e6ac5221f74c6..c7cf04799485fdd5b3ee2ec390e1021e859af02c 100644 --- a/gdecore/gdecore.py +++ b/gdecore/gdecore.py @@ -67,6 +67,14 @@ def main(): ) ) + # Run by exposure entity and occupancy case + for exposure_entity_name in config.exposure_entities_to_run: + for occupancy_case in config.occupancies_to_run: + logger.info( + "Running exposure entity '%s', occupancy case '%s'." + % (exposure_entity_name, occupancy_case) + ) + # Leave the program logger.info("gde-core has finished") sys.exit() diff --git a/tests/data/config_for_testing_good.yml b/tests/data/config_for_testing_good.yml index 3fcfe497e9de14f2a1d0d73ec6e242f3a86b581b..9d5af692e85aa37e91323d12ea808b717ec0e954 100644 --- a/tests/data/config_for_testing_good.yml +++ b/tests/data/config_for_testing_good.yml @@ -6,3 +6,4 @@ database_gde_tiles: password: some_password exposure_entities_to_run: Italy exposure_entities_code: ISO3 +occupancies_to_run: residential, commercial diff --git a/tests/data/config_for_testing_missing.yml b/tests/data/config_for_testing_missing.yml new file mode 100644 index 0000000000000000000000000000000000000000..3fcfe497e9de14f2a1d0d73ec6e242f3a86b581b --- /dev/null +++ b/tests/data/config_for_testing_missing.yml @@ -0,0 +1,8 @@ +model_name: esrm20 +database_gde_tiles: + host: host.somewhere.xx + dbname: some_database_name + username: some_username + password: some_password +exposure_entities_to_run: Italy +exposure_entities_code: ISO3 diff --git a/tests/test_configuration.py b/tests/test_configuration.py index a91bd4f441ab001ff1989a63ed9cf4227965b47b..8d767c1481c79de0c72d10f4d2b583223c59d6e8 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -36,6 +36,9 @@ def test_Configuration(): assert len(returned_config.exposure_entities_to_run) == 1 assert returned_config.exposure_entities_to_run[0] == "Italy" assert returned_config.exposure_entities_code == "ISO3" + assert len(returned_config.occupancies_to_run) == 2 + assert returned_config.occupancies_to_run[0] == "residential" + assert returned_config.occupancies_to_run[1] == "commercial" # Test case in which the file is not found with pytest.raises(OSError) as excinfo: @@ -45,6 +48,14 @@ def test_Configuration(): ) assert "OSError" in str(excinfo.type) + # Test case in which a parameter is missing + with pytest.raises(OSError) as excinfo: + returned_config = Configuration( + os.path.join(os.path.dirname(__file__), "data", "config_for_testing_missing.yml"), + force_config_over_hierarchies=True, + ) + assert "OSError" in str(excinfo.type) + def test_Configuration_interpret_exposure_entities_to_run(test_db): returned_config = Configuration(