Skip to content

Commit

Permalink
Merge pull request #78 from migueln/master
Browse files Browse the repository at this point in the history
Small set of workarounds and bugfixes
  • Loading branch information
davidsanchez committed Nov 26, 2015
2 parents 90554e9 + 9acb56d commit 4ccf047
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
24 changes: 14 additions & 10 deletions enrico/RunGTlike.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python
import os
from enrico import utils
from enrico import energybin
from enrico.config import get_config
from enrico.gtfunction import Observation
from enrico.fitmaker import FitMaker


def Analysis(folder, config, tag="" ,verbose = 1):
def Analysis(folder, config, tag="", convtyp='-1', verbose = 1):
from enrico import utils
from enrico.gtfunction import Observation
from enrico.fitmaker import FitMaker

""" run an analysis"""
Obs = Observation(folder, config, tag=tag)
if verbose:
Expand Down Expand Up @@ -47,10 +45,14 @@ def GenAnalysisObjects(config, verbose = 1, xmlfile =""):
return FitRunner,Fit

def run(infile):
from enrico import utils
from enrico import energybin
from enrico.config import get_config

"""Run an entire Fermi analysis (spectrum) by reading a config file"""
config = get_config(infile)
folder = config['out']
os.system('mkdir -p ' + folder)
utils.create_dir(folder)

FitRunner,Fit = GenAnalysisObjects(config)
# create all the fit files and run gtlike
Expand All @@ -62,7 +64,7 @@ def run(infile):
#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+'/')
utils.create_dir("%s/%s/" %(config['out'],SpectrumPath))
if float(config['UpperLimit']['TSlimit']) < Fit.Ts(config['target']['name']):
FitRunner.ComputeSED(Fit)
outXml = utils._dump_xml(config)
Expand All @@ -72,7 +74,9 @@ def run(infile):
# Make energy bins by running a *new* analysis
Nbin = config['Ebin']['NumEnergyBins']
energybin.RunEbin(folder,Nbin,Fit,FitRunner)
del FitRunner

del(Result)
del(FitRunner)

# @todo: Should this be a command line utility in bin?
if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions enrico/energybin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def PrepareEbin(Fit, FitRunner):
mes.info("Submition # "+str(ibin)+" at energy "+str(E))
#Update the model for the bin
NewFitObject = ChangeModel(Fit, ener[ibin], ener[ibin + 1], srcname, Pref[ibin] ,Gamma[ibin])
Xmlname = (config['out'] + "/" + srcname +
"_" + str(ibin) + ".xml")
Xmlname = (config['out'] + "/" + srcname + "_" + str(ibin) + ".xml")
NewFitObject.writeXml(Xmlname)# dump the corresponding xml file
config['file']['xml'] = Xmlname
#update the energy bounds
Expand Down
11 changes: 10 additions & 1 deletion enrico/lightcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ def PrepareLC(self,write = 'no'):


def _MakeLC(self,Path=LightcurvePath) :
import gc
import os
gc.enable()
'''Main function of the Lightcurve script. Read the config file and run the gtlike analysis'''
enricodir = environ.DIRS.get('ENRICO_DIR')
fermidir = environ.DIRS.get('FERMI_DIR')

self.PrepareLC(self.config['LightCurve']['MakeConfFile'])#Get the config file

for i in xrange(self.Nbin):
gc.collect()
if self.submit == 'yes':
cmd = "enrico_sed "+self.configfile[i]
scriptname = self.LCfolder+"LC_Script_"+str(i)+".sh"
Expand All @@ -131,7 +135,12 @@ def _MakeLC(self,Path=LightcurvePath) :

call(cmd,enricodir,fermidir,scriptname,JobLog,JobName)#Submit the job
else :
run(self.configfile[i])#run in command line
cmd = "enrico_sed "+self.configfile[i]
os.system(cmd)

#run(self.configfile[i])#run in command line




def _MakePhasebin(self):
Expand Down
3 changes: 2 additions & 1 deletion enrico/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def PlotNpred(Npred, Flux, FluxErr):
def PlotLC(Time, TimeErr, x, xErr, tag="Flux (photon cm^{-2} s^{-1})"):
"""Scatter plot X(Time)"""
ArrowSize = (max(x) + max(xErr) * 1.3 -
(min(x) - max(xErr) * 1.3)) * 0.1
(min(x) - max(xErr) * 1.3)) * 0.1

arrows = []
for i in xrange(len(Time)):
if xErr[i] == 0:
Expand Down
6 changes: 6 additions & 0 deletions enrico/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ def MJD_to_met(mjd):
def JD_to_met(jd):
return MJD_to_met(mjd)+2400000.5

def create_dir(path):
import os
import os.path

if (not os.path.exists(path)):
os.makedirs(path)

def Checkevtclass(evclass):
classirfs = {1:"P8R2_TRANSIENT100A",2:"P8R2_TRANSIENT100E",4:"P8R2_TRANSIENT100",8:"P8R2_TRANSIENT020E",
Expand Down

0 comments on commit 4ccf047

Please sign in to comment.