def pre_execute(self): """ Check if there is a pre_calculator or a previous calculation ID. If yes, read the inputs by invoking the precalculator or by retrieving the previous calculation; if not, read the inputs directly. """ job_info = hdf5.LiteralAttrs() if self.pre_calculator is not None: # the parameter hazard_calculation_id is only meaningful if # there is a precalculator precalc_id = self.oqparam.hazard_calculation_id if precalc_id is None: # recompute everything self.compute_previous() else: # read previously computed data self.read_previous(precalc_id) self.init() else: # we are in a basic calculator self.basic_pre_execute() if 'source' in self.oqparam.inputs: vars(job_info).update( readinput.get_job_info(self.oqparam, self.csm, self.sitecol)) job_info.hostname = socket.gethostname() if hasattr(self, 'riskmodel'): job_info.require_epsilons = bool(self.riskmodel.covs) self.job_info = job_info self.datastore.flush() try: csm_info = self.datastore['csm_info'] except KeyError: pass else: csm_info.gsim_lt.check_imts(self.oqparam.imtls)
def save(self, key, kw): """ Update the object associated to `key` with the `kw` dictionary; works for LiteralAttrs objects and automatically flushes. """ if key not in self: obj = hdf5.LiteralAttrs() else: obj = self[key] vars(obj).update(kw) self[key] = obj self.flush()
def pre_execute(self): """ Check if there is a pre_calculator or a previous calculation ID. If yes, read the inputs by invoking the precalculator or by retrieving the previous calculation; if not, read the inputs directly. """ job_info = hdf5.LiteralAttrs() if self.pre_calculator is not None: # the parameter hazard_calculation_id is only meaningful if # there is a precalculator precalc_id = self.oqparam.hazard_calculation_id if precalc_id is None: # recompute everything precalc = calculators[self.pre_calculator]( self.oqparam, self.monitor('precalculator'), self.datastore.calc_id) precalc.run() if 'scenario' not in self.oqparam.calculation_mode: self.csm = precalc.csm pre_attrs = vars(precalc) for name in ('riskmodel', 'assets_by_site'): if name in pre_attrs: setattr(self, name, getattr(precalc, name)) else: # read previously computed data parent = datastore.read(precalc_id) self.datastore.set_parent(parent) # copy missing parameters from the parent params = {name: value for name, value in vars(parent['oqparam']).items() if name not in vars(self.oqparam)} self.save_params(**params) self.read_risk_data() else: # we are in a basic calculator self.read_risk_data() if 'source' in self.oqparam.inputs: with self.monitor( 'reading composite source model', autoflush=True): self.csm = readinput.get_composite_source_model( self.oqparam) self.rlzs_assoc = self.csm.info.get_rlzs_assoc() self.datastore['csm_info'] = self.rlzs_assoc.csm_info self.rup_data = {} # we could manage limits here vars(job_info).update(readinput.get_job_info( self.oqparam, self.csm, self.sitecol)) logging.info('Expected output size=%s', job_info.hazard['output_weight']) logging.info('Total weight of the sources=%s', job_info.hazard['input_weight']) self.init() with self.monitor('managing sources', autoflush=True): self.send_sources() self.manager.store_source_info(self.datastore) attrs = self.datastore.hdf5['composite_source_model'].attrs attrs['weight'] = self.csm.weight attrs['filtered_weight'] = self.csm.filtered_weight attrs['maxweight'] = self.csm.maxweight job_info.hostname = socket.gethostname() if hasattr(self, 'riskmodel'): job_info.require_epsilons = bool(self.riskmodel.covs) self.job_info = job_info self.datastore.flush()