def get_oqparam(job_ini, pkg=None, calculators=None, hc_id=None, validate=1): """ Parse a dictionary of parameters from an INI-style config file. :param job_ini: Path to configuration file/archive or dictionary of parameters :param pkg: Python package where to find the configuration file (optional) :param calculators: Sequence of calculator names (optional) used to restrict the valid choices for `calculation_mode` :param hc_id: Not None only when called from a post calculation :param validate: Flag. By default it is true and the parameters are validated :returns: An :class:`openquake.commonlib.oqvalidation.OqParam` instance containing the validate and casted parameters/values parsed from the job.ini file as well as a subdictionary 'inputs' containing absolute paths to all of the files referenced in the job.ini, keyed by the parameter name. """ # UGLY: this is here to avoid circular imports from openquake.calculators import base OqParam.calculation_mode.validator.choices = tuple(calculators or base.calculators) if not isinstance(job_ini, dict): basedir = os.path.dirname(pkg.__file__) if pkg else '' job_ini = get_params(os.path.join(basedir, job_ini)) if hc_id: job_ini.update(hazard_calculation_id=str(hc_id)) re = os.environ.get('OQ_REDUCE') # debugging facility if re: # reduce the imtls to the first imt # reduce the logic tree to one random realization # reduce the sites by a factor of `re` # reduce the ses by a factor of `re` # set save_disk_space = true os.environ['OQ_SAMPLE_SITES'] = str(1 / float(re)) job_ini['number_of_logic_tree_samples'] = 1 ses = job_ini.get('ses_per_logic_tree_path') if ses: ses = str(int(numpy.ceil(int(ses) / float(re)))) job_ini['ses_per_logic_tree_path'] = ses imtls = job_ini.get('intensity_measure_types_and_levels') if imtls: imtls = valid.intensity_measure_types_and_levels(imtls) imt = next(iter(imtls)) job_ini['intensity_measure_types_and_levels'] = repr( {imt: imtls[imt]}) job_ini['save_disk_space'] = True oqparam = OqParam(**job_ini) if validate and '_job_id' not in job_ini: oqparam.check_source_model() oqparam.validate() return oqparam
def get_oqparam(job_ini, pkg=None, calculators=None, hc_id=None, validate=1, **kw): """ Parse a dictionary of parameters from an INI-style config file. :param job_ini: Path to configuration file/archive or dictionary of parameters :param pkg: Python package where to find the configuration file (optional) :param calculators: Sequence of calculator names (optional) used to restrict the valid choices for `calculation_mode` :param hc_id: Not None only when called from a post calculation :param validate: Flag. By default it is true and the parameters are validated :param kw: String-valued keyword arguments used to override the job.ini parameters :returns: An :class:`openquake.commonlib.oqvalidation.OqParam` instance containing the validate and casted parameters/values parsed from the job.ini file as well as a subdictionary 'inputs' containing absolute paths to all of the files referenced in the job.ini, keyed by the parameter name. """ # UGLY: this is here to avoid circular imports from openquake.calculators import base OqParam.calculation_mode.validator.choices = tuple(calculators or base.calculators) if not isinstance(job_ini, dict): basedir = os.path.dirname(pkg.__file__) if pkg else '' job_ini = get_params(os.path.join(basedir, job_ini)) if hc_id: job_ini.update(hazard_calculation_id=str(hc_id)) job_ini.update(kw) oqparam = OqParam(**job_ini) if validate and '_job_id' not in job_ini: oqparam.check_source_model() oqparam.validate() return oqparam