def __init__(self, **names_vals): super(OqParam, self).__init__(**names_vals) self.risk_investigation_time = ( self.risk_investigation_time or self.investigation_time) if ('intensity_measure_types_and_levels' in names_vals and 'intensity_measure_types' in names_vals): logging.warn('Ignoring intensity_measure_types since ' 'intensity_measure_types_and_levels is set') if 'intensity_measure_types_and_levels' in names_vals: self.hazard_imtls = self.intensity_measure_types_and_levels delattr(self, 'intensity_measure_types_and_levels') elif 'intensity_measure_types' in names_vals: self.hazard_imtls = dict.fromkeys(self.intensity_measure_types) delattr(self, 'intensity_measure_types') self._file_type, self._risk_files = get_risk_files(self.inputs) # check the IMTs vs the GSIMs if 'gsim_logic_tree' in self.inputs: if self.gsim: raise ValueError('If `gsim_logic_tree_file` is set, there ' 'must be no `gsim` key') path = os.path.join( self.base_path, self.inputs['gsim_logic_tree']) self._gsims_by_trt = logictree.GsimLogicTree(path, []).values for gsims in self._gsims_by_trt.values(): self.check_gsims(gsims) elif self.gsim is not None: self.check_gsims([self.gsim])
def __init__(self, **names_vals): super(OqParam, self).__init__(**names_vals) self.risk_investigation_time = ( self.risk_investigation_time or self.investigation_time) if ('intensity_measure_types_and_levels' in names_vals and 'intensity_measure_types' in names_vals): logging.warn('Ignoring intensity_measure_types since ' 'intensity_measure_types_and_levels is set') if 'intensity_measure_types_and_levels' in names_vals: self.hazard_imtls = self.intensity_measure_types_and_levels delattr(self, 'intensity_measure_types_and_levels') elif 'intensity_measure_types' in names_vals: self.hazard_imtls = dict.fromkeys(self.intensity_measure_types) delattr(self, 'intensity_measure_types') self._file_type, self._risk_files = get_risk_files(self.inputs) # check the IMTs vs the GSIMs if 'gsim_logic_tree' in self.inputs: if self.gsim: raise ValueError('If `gsim_logic_tree_file` is set, there ' 'must be no `gsim` key') path = os.path.join( self.base_path, self.inputs['gsim_logic_tree']) self._gsims_by_trt = logictree.GsimLogicTree(path, ['*']).values for gsims in self._gsims_by_trt.values(): self.check_gsims(gsims) elif self.gsim is not None: self.check_gsims([self.gsim]) # checks for disaggregation if self.calculation_mode == 'disaggregation': if not self.individual_curves: raise ValueError( 'For disaggregation the flag `individual_curves` ' 'must be true') elif not self.poes_disagg and not self.iml_disagg: raise ValueError('poes_disagg or iml_disagg must be set ' 'in the job.ini file') elif self.poes_disagg and self.iml_disagg: logging.warn( 'iml_disagg=%s will not be computed from poes_disagg=%s', str(self.iml_disagg), self.poes_disagg) # checks for event_based_risk if (self.calculation_mode == 'event_based_risk' and self.asset_correlation not in (0, 1)): raise ValueError('asset_correlation != {0, 1} is no longer' ' supported')
def is_valid_intensity_measure_types(self): """ If the IMTs and levels are extracted from the risk models, they must not be set directly. Moreover, if `intensity_measure_types_and_levels` is set directly, `intensity_measure_types` must not be set. """ if self.ground_motion_correlation_model: for imt in self.imtls: if not (imt.startswith('SA') or imt == 'PGA'): raise ValueError( 'Correlation model %s does not accept IMT=%s' % (self.ground_motion_correlation_model, imt)) _, risk_files = get_risk_files(self.inputs) if risk_files: # IMTLs extracted from the risk files return (self.intensity_measure_types is None and self.intensity_measure_types_and_levels is None) elif not hasattr(self, 'hazard_imtls') and not hasattr( self, 'risk_imtls'): return False return True
def is_valid_intensity_measure_types(self): """ If the IMTs and levels are extracted from the risk models, they must not be set directly. Moreover, if `intensity_measure_types_and_levels` is set directly, `intensity_measure_types` must not be set. """ if self.ground_motion_correlation_model: for imt in self.imtls: if not (imt.startswith('SA') or imt == 'PGA'): raise ValueError( 'Correlation model %s does not accept IMT=%s' % ( self.ground_motion_correlation_model, imt)) _, risk_files = get_risk_files(self.inputs) if risk_files: # IMTLs extracted from the risk files return (self.intensity_measure_types is None and self.intensity_measure_types_and_levels is None) elif not hasattr(self, 'hazard_imtls') and not hasattr( self, 'risk_imtls'): return False return True
def __init__(self, **names_vals): super(OqParam, self).__init__(**names_vals) job_ini = self.inputs['job_ini'] if 'calculation_mode' not in names_vals: raise InvalidFile('Missing calculation_mode in %s' % job_ini) self.risk_investigation_time = (self.risk_investigation_time or self.investigation_time) if ('intensity_measure_types_and_levels' in names_vals and 'intensity_measure_types' in names_vals): logging.warn('Ignoring intensity_measure_types since ' 'intensity_measure_types_and_levels is set') if 'iml_disagg' in names_vals: self.hazard_imtls = self.iml_disagg if 'intensity_measure_types_and_levels' in names_vals: raise InvalidFile( 'Please remove the intensity_measure_types_and_levels ' 'from %s: they will be inferred from the iml_disagg ' 'dictionary' % job_ini) elif 'intensity_measure_types_and_levels' in names_vals: self.hazard_imtls = self.intensity_measure_types_and_levels delattr(self, 'intensity_measure_types_and_levels') elif 'intensity_measure_types' in names_vals: self.hazard_imtls = dict.fromkeys(self.intensity_measure_types) delattr(self, 'intensity_measure_types') self._file_type, self._risk_files = get_risk_files(self.inputs) self.check_source_model() if self.hazard_precomputed(): self.check_missing('site_model', 'warn') self.check_missing('gsim_logic_tree', 'warn') self.check_missing('source_model_logic_tree', 'warn') # check the gsim_logic_tree if self.inputs.get('gsim_logic_tree'): if self.gsim: raise InvalidFile('%s: if `gsim_logic_tree_file` is set, there' ' must be no `gsim` key' % job_ini) path = os.path.join(self.base_path, self.inputs['gsim_logic_tree']) gsim_lt = logictree.GsimLogicTree(path, ['*']) # check the number of branchsets branchsets = len(gsim_lt._ltnode) if 'scenario' in self.calculation_mode and branchsets > 1: raise InvalidFile( '%s: %s for a scenario calculation must contain a single ' 'branchset, found %d!' % (job_ini, path, branchsets)) # check the IMTs vs the GSIMs self._gsims_by_trt = gsim_lt.values for gsims in self._gsims_by_trt.values(): self.check_gsims(gsims) elif self.gsim is not None: self.check_gsims([self.gsim]) # checks for hazard outputs if not self.hazard_stats(): if self.uniform_hazard_spectra: raise InvalidFile( '%(job_ini)s: uniform_hazard_spectra=true is inconsistent ' 'with mean_hazard_curves=false' % self.inputs) elif self.hazard_maps: raise InvalidFile( '%(job_ini)s: hazard_maps=true is inconsistent ' 'with mean_hazard_curves=false' % self.inputs) # checks for disaggregation if self.calculation_mode == 'disaggregation': if not self.poes_disagg and not self.iml_disagg: raise InvalidFile('poes_disagg or iml_disagg must be set ' 'in %(job_ini)s' % self.inputs) elif self.poes_disagg and self.iml_disagg: raise InvalidFile( '%s: iml_disagg and poes_disagg cannot be set ' 'at the same time' % job_ini) for k in ('mag_bin_width', 'distance_bin_width', 'coordinate_bin_width', 'num_epsilon_bins'): if k not in vars(self): raise InvalidFile('%s must be set in %s' % (k, job_ini)) # checks for classical_damage if self.calculation_mode == 'classical_damage': if self.conditional_loss_poes: raise InvalidFile('%s: conditional_loss_poes are not defined ' 'for classical_damage calculations' % job_ini) # checks for event_based_risk if (self.calculation_mode == 'event_based_risk' and self.asset_correlation not in (0, 1)): raise ValueError('asset_correlation != {0, 1} is no longer' ' supported') elif (self.calculation_mode == 'event_based_risk' and self.conditional_loss_poes and not self.asset_loss_table): raise InvalidFile( '%s: asset_loss_table is not set, probably you want to remove' ' conditional_loss_poes' % job_ini) # check for GMFs from file if (self.inputs.get('gmfs', '').endswith('.csv') and not self.sites and 'sites' not in self.inputs): raise InvalidFile('%s: You forgot sites|sites_csv' % job_ini) # checks for ucerf if 'ucerf' in self.calculation_mode: if self.ses_per_logic_tree_path >= TWO16: raise ValueError('ses_per_logic_tree_path too big: %d' % self.ses_per_logic_tree_path) if self.number_of_logic_tree_samples >= TWO16: raise ValueError('number_of_logic_tree_samples too big: %d' % self.number_of_logic_tree_samples)
def file_type(self): try: return self._file_type except AttributeError: self._file_type, self._risk_files = get_risk_files(self.inputs) return self._file_type
def __init__(self, **names_vals): super(OqParam, self).__init__(**names_vals) self.risk_investigation_time = (self.risk_investigation_time or self.investigation_time) if ('intensity_measure_types_and_levels' in names_vals and 'intensity_measure_types' in names_vals): logging.warn('Ignoring intensity_measure_types since ' 'intensity_measure_types_and_levels is set') if 'intensity_measure_types_and_levels' in names_vals: self.hazard_imtls = self.intensity_measure_types_and_levels delattr(self, 'intensity_measure_types_and_levels') elif 'intensity_measure_types' in names_vals: self.hazard_imtls = dict.fromkeys(self.intensity_measure_types) delattr(self, 'intensity_measure_types') self._file_type, self._risk_files = get_risk_files(self.inputs) # check the gsim_logic_tree if 'gsim_logic_tree' in self.inputs: if self.gsim: raise ValueError('If `gsim_logic_tree_file` is set, there ' 'must be no `gsim` key') path = os.path.join(self.base_path, self.inputs['gsim_logic_tree']) gsim_lt = logictree.GsimLogicTree(path, ['*']) # check the number of branchsets branchsets = len(gsim_lt._ltnode) if 'scenario' in self.calculation_mode and branchsets > 1: raise InvalidFile( '%s for a scenario calculation must contain a single ' 'branchset, found %d!' % (path, branchsets)) # check the IMTs vs the GSIMs self._gsims_by_trt = gsim_lt.values for gsims in self._gsims_by_trt.values(): self.check_gsims(gsims) elif self.gsim is not None: self.check_gsims([self.gsim]) # checks for disaggregation if self.calculation_mode == 'disaggregation': if not self.poes_disagg and not self.iml_disagg: raise ValueError('poes_disagg or iml_disagg must be set ' 'in the job.ini file') elif self.poes_disagg and self.iml_disagg: logging.warn( 'iml_disagg=%s will not be computed from poes_disagg=%s', str(self.iml_disagg), self.poes_disagg) # checks for classical_damage if self.calculation_mode == 'classical_damage': if self.quantile_loss_curves: raise ValueError('quantile_loss_curves are not defined ' 'for classical_damage calculations: ' 'remove them for the .ini file') if self.conditional_loss_poes: raise ValueError('conditional_loss_poes are not defined ' 'for classical_damage calculations: ' 'remove them for the .ini file') # checks for event_based_risk if (self.calculation_mode == 'event_based_risk' and self.asset_correlation not in (0, 1)): raise ValueError('asset_correlation != {0, 1} is no longer' ' supported') # checks for ucerf if 'ucerf' in self.calculation_mode: if self.ses_per_logic_tree_path >= TWO16: raise ValueError('ses_per_logic_tree_path too big: %d' % self.ses_per_logic_tree_path) if self.number_of_logic_tree_samples >= TWO16: raise ValueError('number_of_logic_tree_samples too big: %d' % self.number_of_logic_tree_samples)
def all_cost_types(self): """ Return the cost types of the computation (including `occupants` if it is there) in order. """ return sorted(get_risk_files(self.inputs)[1])