def _derive_imls_from_vulnerability(self, upload): """ Generates a new scale of IML values from the a job's vulnerability model (if one exists). The new IML values will be written to the INTENSITY_MEASURE_LEVELS config param in the [HAZARD] section of the config file. This will override the IML values specified for this job in the uiapi.oq_params.imls DB field. :param upload: :py:class:`geonode.mtapi.models.Upload` instance associated with this job """ vuln_input = upload.input_set.get(input_type='vulnerability') lower_bound, upper_bound = \ _get_iml_bounds_from_vuln_file(vuln_input.path) iml_scale = view_utils.log_scale( lower_bound, upper_bound, self.num_of_derived_imls) # format the new IML scale properly for the config file imls_str = _float_list_to_str(iml_scale, ', ') self.cfg_parser.set('HAZARD', 'INTENSITY_MEASURE_LEVELS', imls_str)
def _derive_imls_from_vulnerability(self, upload): """ Generates a new scale of IML values from the a job's vulnerability model (if one exists). The new IML values will be written to the INTENSITY_MEASURE_LEVELS config param in the [HAZARD] section of the config file. This will override the IML values specified for this job in the uiapi.oq_params.imls DB field. :param upload: :py:class:`geonode.mtapi.models.Upload` instance associated with this job """ vuln_input = upload.input_set.get(input_type='vulnerability') lower_bound, upper_bound = \ _get_iml_bounds_from_vuln_file(vuln_input.path) iml_scale = view_utils.log_scale(lower_bound, upper_bound, self.num_of_derived_imls) # format the new IML scale properly for the config file imls_str = _float_list_to_str(iml_scale, ', ') self.cfg_parser.set('HAZARD', 'INTENSITY_MEASURE_LEVELS', imls_str)
def test_log_scale(self): lb = 0.060256 ub = 9.780226 n = 10 expected_scale = [ 0.060255999999999997, 0.1060705, 0.1867192, 0.32868750000000002, 0.57859870000000002, 1.0185251, 1.7929411, 3.1561694999999999, 5.5559022999999996, 9.7802260000000008] scale = log_scale(lb, ub, n) # the first and last values in the scale should be equal to # the lower_bound and upper_bound, respectively self.assertEqual(lb, scale[0]) self.assertEqual(ub, scale[-1]) self.assertEqual(expected_scale, scale)
def test_log_scale(self): lb = 0.060256 ub = 9.780226 n = 10 expected_scale = [ 0.060255999999999997, 0.1060705, 0.1867192, 0.32868750000000002, 0.57859870000000002, 1.0185251, 1.7929411, 3.1561694999999999, 5.5559022999999996, 9.7802260000000008 ] scale = log_scale(lb, ub, n) # the first and last values in the scale should be equal to # the lower_bound and upper_bound, respectively self.assertEqual(lb, scale[0]) self.assertEqual(ub, scale[-1]) self.assertEqual(expected_scale, scale)