Example #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))
Example #2
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': os.path.join(gettempdir(),
                                                          'source-model.xml'),
             'GMPE_LOGIC_TREE_FILE': os.path.join(gettempdir(), 'gmpe.xml'),
             'EXPOSURE': '/absolute/exposure.xml',
             'VULNERABILITY': os.path.join(gettempdir(), 'vulnerability.xml'),
             'CALCULATION_MODE': 'Event Based'},
            params)
        self.assertEqual(['GENERAL', 'HAZARD', 'RISK'], sorted(sections))
Example #3
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.assertEquals(
            {
                "BASE_PATH": gettempdir(),
                "OUTPUT_DIR": "output",
                "SOURCE_MODEL_LOGIC_TREE_FILE": os.path.join(gettempdir(), "source-model.xml"),
                "GMPE_LOGIC_TREE_FILE": os.path.join(gettempdir(), "gmpe.xml"),
                "EXPOSURE": "/absolute/exposure.xml",
                "VULNERABILITY": os.path.join(gettempdir(), "vulnerability.xml"),
                "CALCULATION_MODE": "Event Based",
            },
            params,
        )
        self.assertEquals(["GENERAL", "HAZARD", "RISK"], sorted(sections))
Example #4
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.assertEquals(
            {"BASE_PATH": gettempdir(), "MINIMUM_MAGNITUDE": "5.0", "CALCULATION_MODE": "Event Based"}, params
        )
        self.assertEquals(["GENERAL", "HAZARD"], sorted(sections))
Example #5
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"])
Example #6
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))
Example #7
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"])
Example #8
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))