def run(infile): """Run an entire Fermi analysis (spectrum) by reading a config file""" config = get_config(infile) folder = config['out'] os.system('mkdir -p ' + folder) FitRunner, Fit = GenAnalysisObjects(config) # create all the fit files and run gtlike FitRunner.PerformFit(Fit) Result = FitRunner.GetAndPrintResults( Fit) #Get and dump the target specific results if config['verbose'] == 'yes': utils.GetFluxes(Fit, FitRunner.obs.Emin, FitRunner.obs.Emax) #print the flux of all the sources utils.DumpResult(Result, config) #plot the SED and model map if possible and asked if config['Spectrum']['ResultPlots'] == 'yes': from enrico.constants import SpectrumPath os.system("mkdir -p " + config['out'] + '/' + SpectrumPath + '/') if float(config['UpperLimit']['TSlimit']) < Fit.Ts( config['target']['name']): FitRunner.ComputeSED(Fit) outXml = utils._dump_xml(config) if config['Spectrum'][ 'SummedLike'] != 'yes': # the possiblity of making the model map is checked inside the function FitRunner.ModelMap(outXml) # Make energy bins by running a *new* analysis Nbin = config['Ebin']['NumEnergyBins'] energybin.RunEbin(folder, Nbin, Fit, FitRunner)
def run(infile): from enrico import utils from enrico import energybin from enrico.config import get_config from enrico import Loggin mes = Loggin.Message() """Run an entire Fermi analysis (spectrum) by reading a config file""" config = get_config(infile) folder = config['out'] utils.mkdir_p(folder) FitRunner, Fit = GenAnalysisObjects(config) # create all the fit files and run gtlike FitRunner.PerformFit(Fit) sedresult = None #plot the SED and model map if possible and asked if float(config['UpperLimit']['TSlimit']) < Fit.Ts( config['target']['name']): if config['Spectrum']['ResultPlots'] == 'yes': from enrico.constants import SpectrumPath utils.mkdir_p("%s/%s/" % (config['out'], SpectrumPath)) sedresult = FitRunner.ComputeSED(Fit, dump=True) else: sedresult = FitRunner.ComputeSED(Fit, dump=False) if (config['energy']['decorrelation_energy'] == 'yes'): #Update the energy scale to decorrelation energy mes.info( 'Setting the decorrelation energy as new Scale for the spectral parameters' ) spectrum = Fit[FitRunner.obs.srcname].funcs['Spectrum'] modeltype = spectrum.genericName() genericName = Fit.model.srcs[ FitRunner.obs.srcname].spectrum().genericName() varscale = None if genericName == "PowerLaw2": varscale = None elif genericName in [ "PowerLaw", "PLSuperExpCutoff", "EblAtten::PLSuperExpCutoff" ]: varscale = "Scale" elif genericName in ["LogParabola","EblAtten::LogParabola", \ "BrokenPowerLaw", "EblAtten::BrokenPowerLaw"]: varscale = "Eb" if varscale is not None: spectrum.getParam(varscale).setValue(sedresult.decE) FitRunner.PerformFit(Fit) #Get and dump the target specific results Result = FitRunner.GetAndPrintResults(Fit) utils.DumpResult(Result, config) # Make energy bins by running a *new* analysis Nbin = config['Ebin']['NumEnergyBins'] FitRunner.config['file']['parent_config'] = infile if config['Spectrum']['ResultParentPlots'] == "yes": plot_sed_fromconfig(get_config(config['file']['parent_config']), ignore_missing_bins=True) if config['Spectrum']['ResultPlots'] == 'yes': outXml = utils._dump_xml(config) # the possibility of making the model map is checked inside the function FitRunner.ModelMap(outXml) if Nbin > 0: FitRunner.config['Spectrum']['ResultParentPlots'] = "yes" plot_sed_fromconfig(get_config(infile), ignore_missing_bins=True) energybin.RunEbin(folder, Nbin, Fit, FitRunner, sedresult) del (sedresult) del (Result) del (FitRunner)