def pre_execute(self):
        """
        Check if there is a previous calculation ID.
        If yes, read the inputs by retrieving the previous calculation;
        if not, read the inputs directly.
        """
        oq = self.oqparam
        if 'gmfs' in oq.inputs or 'multi_peril' in oq.inputs:
            # read hazard from files
            assert not oq.hazard_calculation_id, (
                'You cannot use --hc together with gmfs_file')
            self.read_inputs()
            if 'gmfs' in oq.inputs:
                save_gmfs(self)
            else:
                self.save_multi_peril()
        elif 'hazard_curves' in oq.inputs:  # read hazard from file
            assert not oq.hazard_calculation_id, (
                'You cannot use --hc together with hazard_curves')
            haz_sitecol = readinput.get_site_collection(oq)
            # NB: horrible: get_site_collection calls get_pmap_from_nrml
            # that sets oq.investigation_time, so it must be called first
            self.load_riskmodel()  # must be after get_site_collection
            self.read_exposure(haz_sitecol)  # define .assets_by_site
            self.datastore['poes/grp-00'] = fix_ones(readinput.pmap)
            self.datastore['sitecol'] = self.sitecol
            self.datastore['assetcol'] = self.assetcol
            self.datastore['csm_info'] = fake = source.CompositionInfo.fake()
            self.rlzs_assoc = fake.get_rlzs_assoc()
        elif oq.hazard_calculation_id:
            parent = util.read(oq.hazard_calculation_id)
            self.check_precalc(parent['oqparam'].calculation_mode)
            self.datastore.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_inputs()
            oqp = parent['oqparam']
            if oqp.investigation_time != oq.investigation_time:
                raise ValueError(
                    'The parent calculation was using investigation_time=%s'
                    ' != %s' % (oqp.investigation_time, oq.investigation_time))
            if oqp.minimum_intensity != oq.minimum_intensity:
                raise ValueError(
                    'The parent calculation was using minimum_intensity=%s'
                    ' != %s' % (oqp.minimum_intensity, oq.minimum_intensity))
            missing_imts = set(oq.risk_imtls) - set(oqp.imtls)
            if missing_imts:
                raise ValueError(
                    'The parent calculation is missing the IMT(s) %s' %
                    ', '.join(missing_imts))
        elif self.__class__.precalc:
            calc = calculators[self.__class__.precalc](
                self.oqparam, self.datastore.calc_id)
            calc.run()
            self.param = calc.param
            self.sitecol = calc.sitecol
            self.assetcol = calc.assetcol
            self.riskmodel = calc.riskmodel
            if hasattr(calc, 'rlzs_assoc'):
                self.rlzs_assoc = calc.rlzs_assoc
            else:
                # this happens for instance for a scenario_damage without
                # rupture, gmfs, multi_peril
                raise InvalidFile(
                    '%(job_ini)s: missing gmfs_csv, multi_peril_csv' %
                    oq.inputs)
            if hasattr(calc, 'csm'):  # no scenario
                self.csm = calc.csm
        else:
            self.read_inputs()
        if self.riskmodel:
            self.save_riskmodel()
def pre_execute ( self ) : oq = self . oqparam if 'gmfs' in oq . inputs or 'multi_peril' in oq . inputs : assert not oq . hazard_calculation_id , ( 'You cannot use --hc together with gmfs_file' ) self . read_inputs ( ) if 'gmfs' in oq . inputs : save_gmfs ( self ) else : self . save_multi_peril ( ) elif 'hazard_curves' in oq . inputs : assert not oq . hazard_calculation_id , ( 'You cannot use --hc together with hazard_curves' ) haz_sitecol = readinput . get_site_collection ( oq ) self . load_riskmodel ( ) self . read_exposure ( haz_sitecol ) self . datastore [ 'poes/grp-00' ] = fix_ones ( readinput . pmap ) self . datastore [ 'sitecol' ] = self . sitecol self . datastore [ 'assetcol' ] = self . assetcol self . datastore [ 'csm_info' ] = fake = source . CompositionInfo . fake ( ) self . rlzs_assoc = fake . get_rlzs_assoc ( ) elif oq . hazard_calculation_id : parent = util . read ( oq . hazard_calculation_id ) self . check_precalc ( parent [ 'oqparam' ] . calculation_mode ) self . datastore . parent = 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_inputs ( ) oqp = parent [ 'oqparam' ] if oqp . investigation_time != oq . investigation_time : raise ValueError ( 'The parent calculation was using investigation_time=%s' ' != %s' % ( oqp . investigation_time , oq . investigation_time ) ) if oqp . minimum_intensity != oq . minimum_intensity : raise ValueError ( 'The parent calculation was using minimum_intensity=%s' ' != %s' % ( oqp . minimum_intensity , oq . minimum_intensity ) ) missing_imts = set ( oq . risk_imtls ) - set ( oqp . imtls ) if missing_imts : raise ValueError ( 'The parent calculation is missing the IMT(s) %s' % ', ' . join ( missing_imts ) ) elif self . __class__ . precalc : calc = calculators [ self . __class__ . precalc ] ( self . oqparam , self . datastore . calc_id ) calc . run ( ) self . param = calc . param self . sitecol = calc . sitecol self . assetcol = calc . assetcol self . riskmodel = calc . riskmodel if hasattr ( calc , 'rlzs_assoc' ) : self . rlzs_assoc = calc . rlzs_assoc else : raise InvalidFile ( '%(job_ini)s: missing gmfs_csv, multi_peril_csv' % oq . inputs ) if hasattr ( calc , 'csm' ) : self . csm = calc . csm else : self . read_inputs ( ) if self . riskmodel : self . save_riskmodel ( )
Check if there is a previous calculation ID.
        If yes, read the inputs by retrieving the previous calculation;
        if not, read the inputs directly.