Ejemplo n.º 1
0
    def test_is_valid_warns(self):
        # `is_valid` should warn if we specify a `vulnerability_file` as well
        # as `intensity_measure_types` and `intensity_measure_types_and_levels`
        subset_iml_imt = VALID_IML_IMT.copy()
        subset_iml_imt.pop('PGA')

        # intensity_measure_types_and_levels just needs to be a subset of
        # intensity_measure_types
        self.hc.intensity_measure_types_and_levels = subset_iml_imt

        form = validation.EventBasedHazardForm(
            instance=self.hc, files=dict(structural_vulnerability=object()))

        with warnings.catch_warnings(record=True) as w:
            form.is_valid()

        expected_warnings = [
            '`intensity_measure_types_and_levels` is ignored when a '
            '`vulnerability_file` is specified',
            '`intensity_measure_types` is ignored when a `vulnerability_file` '
            'is specified',
        ]

        actual_warnings = [m.message.message for m in w]
        self.assertEqual(sorted(expected_warnings), sorted(actual_warnings))
Ejemplo n.º 2
0
    def test_ses_per_logic_tree_path_is_not_valid(self):
        expected_errors = {
            'ses_per_logic_tree_path': [
                '`Stochastic Event Sets Per Sample` (ses_per_logic_tree_path) '
                'must be > 0'
            ],
        }

        self.hc.ses_per_logic_tree_path = -1

        form = validation.EventBasedHazardForm(instance=self.hc, files=None)
        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
Ejemplo n.º 3
0
    def test_gmfs_false_hazard_curves_true(self):
        # An error should be raised if `hazard_curves_from_gmfs` is `True`, but
        # `ground_motion_fields` is `False`.
        # GMFs are needed to compute hazard curves.
        expected_errors = {
            'hazard_curves_from_gmfs': [
                '`hazard_curves_from_gmfs` requires '
                '`ground_motion_fields` to be `true`'
            ],
        }
        self.hc.ground_motion_fields = False
        self.hc.hazard_curves_from_gmfs = True

        form = validation.EventBasedHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
Ejemplo n.º 4
0
    def test_invalid_params_complet_lt_gmf_with_eb_enum(self):
        # When the `complete_logic_tree_gmf` is requested with end-branch
        # enumeration, this is not allowed. (The complete LT GMF is not a
        # useful artifact in this case.)
        expected_errors = {
            'complete_logic_tree_gmf': [
                '`complete_logic_tree_gmf` is not available with end branch '
                'enumeration'
            ],
        }

        self.hc.number_of_logic_tree_samples = 0
        self.hc.complete_logic_tree_gmf = True

        form = validation.EventBasedHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
Ejemplo n.º 5
0
    def test_hazard_curves_from_gmf_no_iml_imt(self):
        # Test a configuration where the user has requested to post-process
        # GMFs into hazard curves.
        # In this case, the configuration is missing the required
        # `intensity_measure_types_and_levels`.
        expected_errors = {
            'intensity_measure_types_and_levels': [
                '`hazard_curves_from_gmfs` requires '
                '`intensity_measure_types_and_levels`'
            ],
        }

        self.hc.intensity_measure_types_and_levels = None

        form = validation.EventBasedHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
Ejemplo n.º 6
0
    def test_invalid_imts(self):
        expected_errors = {
            'intensity_measure_types': [
                'SA(-0.1): SA period values must be >= 0',
                ('SA<2.5>: SA must be specified with a period value, in the '
                 'form `SA(N)`, where N is a value >= 0'),
                'SA(2x): SA period value should be a float >= 0',
                'PGZ: Invalid intensity measure type',
            ],
        }

        self.hc.intensity_measure_types = INVALID_IML_IMT.keys()
        self.hc.intensity_measure_types_and_levels = None
        self.hc.hazard_curves_from_gmfs = False

        form = validation.EventBasedHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
Ejemplo n.º 7
0
    def test_hazard_curves_from_gmf_invalid_iml_imt(self):
        # Test a configuration where the user has requested to post-process
        # GMFs into hazard curves.
        # In this case, the configuration has the required
        # `intensity_measure_types_and_levels`, but the IMTs are not a subset
        # of `intensity_measure_types`.
        expected_errors = {
            'intensity_measure_types_and_levels':
            ['Unknown IMT(s) [SA(0)] in `intensity_measure_types`'],
        }
        iml_imt = VALID_IML_IMT.keys()
        iml_imt.pop()

        self.hc.intensity_measure_types = iml_imt
        self.hc.intensity_measure_types_and_levels = VALID_IML_IMT

        form = validation.EventBasedHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
Ejemplo n.º 8
0
    def test_valid_event_based_params(self):
        form = validation.EventBasedHazardForm(instance=self.hc, files=None)

        self.assertTrue(form.is_valid(), dict(form.errors))