Esempio n. 1
0
    def test_prepare_path_parameters(self):
        content = """
            [GENERAL]
            CALCULATION_MODE = Event Based
            OUTPUT_DIR = output

            [HAZARD]
            SOURCE_MODEL_LOGIC_TREE_FILE = source-model.xml
            GMPE_LOGIC_TREE_FILE = gmpe.xml

            [RISK]
            EXPOSURE = /absolute/exposure.xml
            VULNERABILITY = vulnerability.xml
            """
        config_path = helpers.touch(content=textwrap.dedent(content))

        params, sections = _parse_config_file(config_path)
        params, sections = _prepare_config_parameters(params, sections)

        self.assertEqual(
            {
                "BASE_PATH": gettempdir(),
                "OUTPUT_DIR": "output",
                "SOURCE_MODEL_LOGIC_TREE_FILE": "source-model.xml",
                "GMPE_LOGIC_TREE_FILE": "gmpe.xml",
                "EXPOSURE": "/absolute/exposure.xml",
                "VULNERABILITY": "vulnerability.xml",
                "CALCULATION_MODE": "Event Based",
            },
            params,
        )
        self.assertEqual(["GENERAL", "HAZARD", "RISK"], sorted(sections))
Esempio n. 2
0
    def test_parse_file(self):
        content = """
            [GENERAL]
            CALCULATION_MODE = Event Based

            [HAZARD]
            MINIMUM_MAGNITUDE = 5.0
            """
        config_path = helpers.touch(dir=gettempdir(), content=textwrap.dedent(content))

        params, sections = _parse_config_file(config_path)

        self.assertEqual(
            {"BASE_PATH": gettempdir(), "CALCULATION_MODE": "Event Based", "MINIMUM_MAGNITUDE": "5.0"}, params
        )
        self.assertEqual(["GENERAL", "HAZARD"], sorted(sections))
Esempio n. 3
0
    def test_prepare_parameters(self):
        content = """
            [GENERAL]
            CALCULATION_MODE = Event Based
            # unknown parameter
            FOO = 5

            [HAZARD]
            MINIMUM_MAGNITUDE = 5.0
            # not used for this calc mode
            COMPUTE_MEAN_HAZARD_CURVE = true
            """
        config_path = helpers.touch(dir=gettempdir(), content=textwrap.dedent(content))

        params, sections = _parse_config_file(config_path)
        params, sections = _prepare_config_parameters(params, sections)

        self.assertEqual(
            {"BASE_PATH": gettempdir(), "MINIMUM_MAGNITUDE": "5.0", "CALCULATION_MODE": "Event Based"}, params
        )
        self.assertEqual(["GENERAL", "HAZARD"], sorted(sections))
Esempio n. 4
0
    def test_prepare_parameters_for_uhs_set_imt_to_sa(self):
        # The imt is always set to "sa" for uhs jobs.
        content = """
            [general]

            CALCULATION_MODE = UHS

            SITES = 0.0, 0.0

            DESCRIPTION = Uniform Hazard Spectra Demo

            [HAZARD]

            # parameters for UHS calculations
            UHS_PERIODS = 0.025, 0.45, 2.5
            POES = 0.1, 0.02
            INTENSITY_MEASURE_TYPE = PGA
            """
        config_path = helpers.touch(dir=gettempdir(), content=textwrap.dedent(content))

        params, sections = _parse_config_file(config_path)
        params, sections = _prepare_config_parameters(params, sections)
        self.assertEqual("SA", params["INTENSITY_MEASURE_TYPE"])