gdeimporter.py 2.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3

# Copyright (C) 2021:
#   Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

import logging
import sys
21
22
from gdeimporter.configuration import Configuration
from gdeimporter.aggregatedexposuremodel import ExposureModelESRM20
23
24
25
26
27
28

# Add a logger printing error, warning, info and debug messages to the screen
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))

29
30
EXPOSURE_MODELS = {"esrm20": ExposureModelESRM20}

31
32
33

def main():

34
    # Log the start of the run
35
36
    logger.info("gde-importer has started")

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    # Read configuration parameters
    config = Configuration("config.yml")

    # Retrieve list of exposure entities covered by the input aggregated model and the types of
    # data units for which their exposure models are defined for different occupancy cases
    if config.exposure_format.lower() not in EXPOSURE_MODELS:
        raise IOError("ERROR: exposure_format NOT SUPPORTED")

    aem = EXPOSURE_MODELS[config.exposure_format.lower()](config)

    print("Name of the model: %s" % (aem.model_name))
    print("Format: %s" % (aem.exposure_format))
    if aem.occupancy_cases is not None:
        print("Occupancy cases: %s" % (", ".join(aem.occupancy_cases)))

    if len(aem.exposure_entities.keys()) > 0:
        print("Data retrieved:")
        for exposure_entity in aem.exposure_entities.keys():
            print("   %s:" % exposure_entity)
            for case in aem.exposure_entities[exposure_entity].occupancy_cases.keys():
                print("      %s:" % case)
                for attr in ["data_units_type", "data_units_level", "data_units_definition"]:
                    print(
                        "         %s: %s"
                        % (
                            attr,
                            aem.exposure_entities[exposure_entity].occupancy_cases[case][attr],
                        )
                    )

67
    # Leave the program
68
    logger.info("gde-importer has finished")
69
70
71
72
73
    sys.exit()


if __name__ == "__main__":
    main()