<commit_before>import os
from math import sqrt
import numpy as np
import ROOT
from enrico import utils
from enrico import root_style
from enrico import plotting
from enrico import environ
from enrico.config import get_config
from enrico.constants import LightcurvePath,FoldedLCPath
from enrico.submit import call
from enrico.RunGTlike import run, GenAnalysisObjects
from enrico import Loggin

class LightCurve(Loggin.Message):
    """Class to calculate light curves and variability indexes."""
    def __init__(self, config):
        super(LightCurve,self).__init__()
        Loggin.Message.__init__(self)
        ROOT.gROOT.SetBatch(ROOT.kTRUE) #Batch mode
        self.config        = get_config(config)
        self.generalconfig = get_config(config)
        print(self.generalconfig)
        #Read the config
        self.srcname = self.config['target']['name'] #src name
        self.Tag = self.config['file']['tag']
        self.tmin = self.config['time']['tmin']
        self.tmax = self.config['time']['tmax']

        self.submit = self.config['Submit']
        # One point of the LC will be computed as a spectrum plot.
        # enrico_sed will be used
        # Do fits files will be generated
        self.config['Spectrum']['FitsGeneration'] = self.config['LightCurve']['FitsGeneration']
        #Froze the Spectral index at a value of self.config['LightCurve']['SpectralIndex'] (no effect if 0)
        self.config['Spectrum']['FrozenSpectralIndex'] = self.config['LightCurve']['SpectralIndex']
        #TS limit. Compute an UL if the TS is below TSLightCurve
        self.config['UpperLimit']['TSlimit'] = self.config['LightCurve']['TSLightCurve']

        self.folder = self.config['out']

        #No plot, no bin in energy, no decE optimization, Normal UL
        self.config['Spectrum']['ResultPlots'] = 'no'
        self.config['Ebin']['NumEnergyBins'] = 0
        self.config['energy']['decorrelation_energy'] = 'no'
        self.config['UpperLimit']['envelope'] = 'no'
        #No submition. Submission will be directly handle by this soft
        self.config['Submit'] = 'no'
#        self.config['verbose'] ='no' #Be quiet
        
        # Try to speed-up the analysis by reusing the evt file from the main analysis
        self._RecycleEvtCoarse()

        self.configfile = []#All the config file in the disk are stored in a list
    
    def _RecycleEvtCoarse(self):
        ''' Try to guess if there's an EvtCoarse file with the events extracted, reuse it '''
        import os.path
        evtcoarsefile = str("%s/%s_%s_EvtCoarse.fits"%(self.folder,self.srcname,self.Tag))
        if os.path.isfile(evtcoarsefile):
            print("reusing %s as event file to speed-up the analysis" %evtcoarsefile)
            self.config['file']['event'] = evtcoarsefile

    def _MakeTimeBins(self):
        self.time_array = np.zeros(0)
        self.Nbin = 0
        self.gtifile = []
        if self.config['time']['file'] != '':
            print "use ",self.config['time']['file'] 
            self.gtifile.append(self.config['time']['file'])
            times = np.genfromtxt(self.gtifile[0],dtype="float",unpack=True)
            self.Nbin = times.size/2
            self.time_array=np.reshape(times,times.size,'F')
            if self.config['time']['type']=='MJD':
                 self.time_array = utils.MJD_to_met(self.time_array)
            elif self.config['time']['type']=='JD':
                 self.time_array = utils.JD_to_met(self.time_array)
        else:
            self.Nbin = self.config['LightCurve']['NLCbin']
            self.time_array = np.zeros(self.Nbin*2)
#            self.dt = (self.tmax - self.tmin) / self.Nbin
            t = np.arange(self.tmin,self.tmax+0.000001,(self.tmax - self.tmin) / self.Nbin)
            for i in xrange(self.Nbin):
                self.time_array[2*i] = t[i]
                self.time_array[2*i+1]= t[i+1]

        self.info("Running LC with "+str(self.Nbin)+" bins")
        for i in xrange(self.Nbin):
            print "Bin ",i," Start=",self.time_array[2*i]," Stop=",self.time_array[2*i+1]
        print 

    def _errorReading(self,message,i):
        self.warning(message+" : "+self.configfile[i])
        print "Job Number : ",i
        self.warning("Please have a look at this job log file")


    def _ManageFolder(self,path):
        """   All files will be stored in a subfolder name path + NLCbin
        Create a subfolder"""
        self.LCfolder =  self.folder+"/LightCurve_"+str(self.Nbin)+"bins/"
        os.system("mkdir -p "+self.LCfolder)
        self.config['out'] = self.LCfolder


    def PrepareLC(self,write = 'no'):
        """Simple function to prepare the LC generation : generate and write the config files"""
        for i in xrange(self.Nbin):
            self.config['time']['tmin'] = self.time_array[2*i]
            self.config['time']['tmax'] = self.time_array[2*i+1]
            self.config['file']['tag'] = self.Tag + '_LC_' + str(i)
            filename = (self.config['out'] + "Config_" + str(i) + "_" +
                    str(self.config['time']['tmin']) + "_" +
                    str(self.config['time']['tmax']))#Name of the config file

            if len(self.gtifile)==1:
                self.config['time']['file']=self.gtifile[0]
            elif len(self.gtifile)>1:
                print 'Time selection file for bin {0} = {1}'.format(i,self.gtifile[i])
                self.config['time']['file']=self.gtifile[i]

            if write == 'yes':
                self.config.write(open(filename, 'w'))

            self.configfile.append(filename)

    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"
                JobLog = self.LCfolder+"LC_Job_"+str(i)+".log"
                JobName = (self.config['target']['name'] + "_" +
                       self.config['analysis']['likelihood'] +
                       "_LC_" + self.config['file']['tag'])+"_"+str(i)+".log"

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

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




    def _MakePhasebin(self):
        """document me """
        self.time_array = np.zeros(self.Nbin*2)
        self.config['time']['type'] = 'MJD'
        T0 = self.config['FoldedLC']['epoch']
        Period = self.config['FoldedLC']['Period']
        t1 = utils.met_to_MJD(self.config['time']['tmin'])
        t2 = utils.met_to_MJD(self.config['time']['tmax'])

        if T0==0:
            T0=t1
        elif t1 < T0:
           T0 -= np.ceil((T0-t1)/Period)*Period
           # find orbit numbers covered by range (t1,t2)
        norbt1 = int(np.floor((t1-T0)/Period))
        norbt2 = int(np.ceil((t2-T0)/Period))

        phase = np.linspace(0,1,self.Nbin+1)

        self.gtifile=[] #reset gtifiles
        for i in range(self.Nbin):
            self.time_array[2*i] = self.config['time']['tmin']
            self.time_array[2*i+1] = self.config['time']['tmax']
            gtifn = os.path.join(self.LCfolder,"TimeSelection_{0:02.0f}.dat".format(i))
            ints=[]

            for norb in range(norbt1,norbt2+1):
                ints.append(((T0+(norb+phase[i])*Period),(T0+(norb+phase[i+1])*Period)))
            tsel = np.array(ints)
            np.savetxt(gtifn,tsel)
            self.gtifile.append(gtifn)


    def MakeLC(self) :
        """Run a std lc """
        self._MakeTimeBins()
        self._ManageFolder(LightcurvePath)
        self._MakeLC()

    def MakeFoldedLC(self):
        """run a folded lc """
        self.Nbin = self.config['FoldedLC']['NLCbin']
        self._ManageFolder(FoldedLCPath)
        self._MakePhasebin()
        self._MakeLC()

    def PlotLC(self):
        '''Plot a lightcurve which have been generated previously'''
        self._MakeTimeBins()
        self._ManageFolder(LightcurvePath)
        self.PrepareLC()#Get the config file
        self._PlotLC()

    def PlotFoldedLC(self):
        '''Plot a lightcurve which have been generated previously'''
        self.Nbin = self.config['FoldedLC']['NLCbin']
        self._ManageFolder(FoldedLCPath)
        self._MakePhasebin()
        self.PrepareLC()#Get the config file
        self._PlotLC(True)

    def _PlotLC(self,folded=False):
        root_style.RootStyle()#Nice plot style

        self.info("Reading files produced by enrico")
        LcOutPath = self.LCfolder + self.config['target']['name']

        #Result are stored into list. This allow to get rid of the bin which failled
        Time = []
        TimeErr = []
        Flux = []
        FluxErr = []
        Index = []
        IndexErr = []
        Cutoff = []
        CutoffErr = []
        FluxForNpred = []
        FluxErrForNpred = []
        Npred = []
        Npred_detected_indices = []
        TS = []

        # Find name used for index parameter
        if (self.config['target']['spectrum'] == 'PowerLaw' or
                self.config['target']['spectrum'] == 'PowerLaw2'):
                IndexName = 'Index'
                CutoffName = None
        elif (self.config['target']['spectrum'] == 'PLExpCutoff' or
                self.config['target']['spectrum'] == 'PLSuperExpCutoff'):
            IndexName = 'Index1'
            CutoffName = 'Cutoff'
            CutoffErrName = 'dCutoff'
        else:
            IndexName = 'alpha'
            CutoffName = None
        IndexErrName = 'd' + IndexName

        Nfail = 0
        for i in xrange(self.Nbin):
            CurConfig = get_config(self.configfile[i])
            #Read the result. If it fails, it means that the bins has not bin computed. A warning message is printed
            try :
                ResultDic = utils.ReadResult(CurConfig)
            except :
                self._errorReading("Fail reading config file",i)
                Nfail+=1
                continue

            #Update the time and time error array
            Time.append((ResultDic.get("tmax")+ResultDic.get("tmin"))/2.)
            TimeErr.append((ResultDic.get("tmax")-ResultDic.get("tmin"))/2.)
            #Check is an ul have been computed. The error is set to zero for the TGraph.
            if ResultDic.has_key('Ulvalue') :
                Flux.append(ResultDic.get("Ulvalue"))
                FluxErr.append(0)
                Index.append(ResultDic.get(IndexName))
                IndexErr.append(0)
            else :
                Flux.append(ResultDic.get("Flux"))
                FluxErr.append(ResultDic.get("dFlux"))
                Index.append(ResultDic.get(IndexName))
                IndexErr.append(ResultDic.get(IndexErrName))
                if CutoffName is not None:
                    Cutoff.append(ResultDic.get(CutoffName))
                    CutoffErr.append(ResultDic.get(CutoffErrName))
            FluxErrForNpred.append(ResultDic.get("dFlux"))
            FluxForNpred.append(ResultDic.get("Flux"))
            #Get the Npred and TS values
            Npred.append(ResultDic.get("Npred"))
            TS.append(ResultDic.get("TS"))
            if (CurConfig['LightCurve']['TSLightCurve']<float(ResultDic.get("TS"))):
                Npred_detected_indices.append(i-Nfail)

        #change the list into np array
        TS = np.array(TS)
        Npred = np.array(Npred)
        Npred_detected = Npred[Npred_detected_indices]
        Time = np.array(Time)
        TimeErr = np.array(TimeErr)
        Flux = np.array(Flux)
        FluxErr = np.array(FluxErr)
        Index = np.array(Index)
        IndexErr = np.array(IndexErr)
        Cutoff = np.array(Cutoff)
        CutoffErr = np.array(CutoffErr)
        FluxForNpred = np.array(FluxForNpred)
        FluxErrForNpred = np.array(FluxErrForNpred)

        #Plots the diagnostic plots is asked
        # Plots are : Npred vs flux
        #             TS vs Time
        if self.config['LightCurve']['DiagnosticPlots'] == 'yes':
            fittedFunc = self.CheckNpred(Npred,FluxForNpred,FluxErrForNpred,Npred_detected_indices)#check the errors calculation
            gTHNpred,TgrNpred = plotting.PlotNpred(Npred,FluxForNpred,FluxErrForNpred)
            CanvNpred = _GetCanvas()
            gTHNpred.Draw()
            TgrNpred.Draw('zP')
	    if len(Npred_detected)>0:
	    	TgrNpred_detected = plotting.PlotNpred(Npred_detected,Flux[Npred_detected_indices],FluxErrForNpred[Npred_detected_indices])
	    	TgrNpred_detected.SetLineColor(2)<commit_msg>fix small lc bug issue 103<commit_after>import os
from math import sqrt
import numpy as np
import ROOT
from enrico import utils
from enrico import root_style
from enrico import plotting
from enrico import environ
from enrico.config import get_config
from enrico.constants import LightcurvePath,FoldedLCPath
from enrico.submit import call
from enrico.RunGTlike import run, GenAnalysisObjects
from enrico import Loggin

class LightCurve(Loggin.Message):
    """Class to calculate light curves and variability indexes."""
    def __init__(self, config):
        super(LightCurve,self).__init__()
        Loggin.Message.__init__(self)
        ROOT.gROOT.SetBatch(ROOT.kTRUE) #Batch mode
        self.config        = get_config(config)
        self.generalconfig = get_config(config)
        print(self.generalconfig)
        #Read the config
        self.srcname = self.config['target']['name'] #src name
        self.Tag = self.config['file']['tag']
        self.tmin = self.config['time']['tmin']
        self.tmax = self.config['time']['tmax']

        self.submit = self.config['Submit']
        # One point of the LC will be computed as a spectrum plot.
        # enrico_sed will be used
        # Do fits files will be generated
        self.config['Spectrum']['FitsGeneration'] = self.config['LightCurve']['FitsGeneration']
        #Froze the Spectral index at a value of self.config['LightCurve']['SpectralIndex'] (no effect if 0)
        self.config['Spectrum']['FrozenSpectralIndex'] = self.config['LightCurve']['SpectralIndex']
        #TS limit. Compute an UL if the TS is below TSLightCurve
        self.config['UpperLimit']['TSlimit'] = self.config['LightCurve']['TSLightCurve']

        self.folder = self.config['out']

        #No plot, no bin in energy, no decE optimization, Normal UL
        self.config['Spectrum']['ResultPlots'] = 'no'
        self.config['Ebin']['NumEnergyBins'] = 0
        self.config['energy']['decorrelation_energy'] = 'no'
        self.config['UpperLimit']['envelope'] = 'no'
        #No submition. Submission will be directly handle by this soft
        self.config['Submit'] = 'no'
#        self.config['verbose'] ='no' #Be quiet
        
        # Try to speed-up the analysis by reusing the evt file from the main analysis
        self._RecycleEvtCoarse()

        self.configfile = []#All the config file in the disk are stored in a list
    
    def _RecycleEvtCoarse(self):
        ''' Try to guess if there's an EvtCoarse file with the events extracted, reuse it '''
        import os.path
        evtcoarsefile = str("%s/%s_%s_EvtCoarse.fits"%(self.folder,self.srcname,self.Tag))
        if os.path.isfile(evtcoarsefile):
            print("reusing %s as event file to speed-up the analysis" %evtcoarsefile)
            self.config['file']['event'] = evtcoarsefile

    def _MakeTimeBins(self):
        self.time_array = np.zeros(0)
        self.Nbin = 0
        self.gtifile = []
        if self.config['time']['file'] != '':
            print "use ",self.config['time']['file'] 
            self.gtifile.append(self.config['time']['file'])
            times = np.genfromtxt(self.gtifile[0],dtype="float",unpack=True)
            self.Nbin = times.size/2
            self.time_array=np.reshape(times,times.size,'F')
            if self.config['time']['type']=='MJD':
                 self.time_array = utils.MJD_to_met(self.time_array)
            elif self.config['time']['type']=='JD':
                 self.time_array = utils.JD_to_met(self.time_array)
        else:
            self.Nbin = self.config['LightCurve']['NLCbin']
            self.time_array = np.zeros(self.Nbin*2)
#            self.dt = (self.tmax - self.tmin) / self.Nbin
            t = np.arange(self.tmin,self.tmax+0.000001,(self.tmax - self.tmin) / self.Nbin)
            for i in xrange(self.Nbin):
                self.time_array[2*i] = t[i]
                self.time_array[2*i+1]= t[i+1]

        self.info("Running LC with "+str(self.Nbin)+" bins")
        for i in xrange(self.Nbin):
            print "Bin ",i," Start=",self.time_array[2*i]," Stop=",self.time_array[2*i+1]
        print 

    def _errorReading(self,message,i):
        self.warning(message+" : "+self.configfile[i])
        print "Job Number : ",i
        self.warning("Please have a look at this job log file")


    def _ManageFolder(self,path):
        """   All files will be stored in a subfolder name path + NLCbin
        Create a subfolder"""
        self.LCfolder =  self.folder+"/LightCurve_"+str(self.Nbin)+"bins/"
        os.system("mkdir -p "+self.LCfolder)
        self.config['out'] = self.LCfolder


    def PrepareLC(self,write = 'no'):
        """Simple function to prepare the LC generation : generate and write the config files"""
        for i in xrange(self.Nbin):
            self.config['time']['tmin'] = self.time_array[2*i]
            self.config['time']['tmax'] = self.time_array[2*i+1]
            self.config['file']['tag'] = self.Tag + '_LC_' + str(i)
            filename = (self.config['out'] + "Config_" + str(i) + "_" +
                    str(self.config['time']['tmin']) + "_" +
                    str(self.config['time']['tmax']))#Name of the config file

            if len(self.gtifile)==1:
                self.config['time']['file']=self.gtifile[0]
            elif len(self.gtifile)>1:
                print 'Time selection file for bin {0} = {1}'.format(i,self.gtifile[i])
                self.config['time']['file']=self.gtifile[i]

            if write == 'yes':
                self.config.write(open(filename, 'w'))

            self.configfile.append(filename)

    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"
                JobLog = self.LCfolder+"LC_Job_"+str(i)+".log"
                JobName = (self.config['target']['name'] + "_" +
                       self.config['analysis']['likelihood'] +
                       "_LC_" + self.config['file']['tag'])+"_"+str(i)+".log"

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

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




    def _MakePhasebin(self):
        """document me """
        self.time_array = np.zeros(self.Nbin*2)
        self.config['time']['type'] = 'MJD'
        T0 = self.config['FoldedLC']['epoch']
        Period = self.config['FoldedLC']['Period']
        t1 = utils.met_to_MJD(self.config['time']['tmin'])
        t2 = utils.met_to_MJD(self.config['time']['tmax'])

        if T0==0:
            T0=t1
        elif t1 < T0:
           T0 -= np.ceil((T0-t1)/Period)*Period
           # find orbit numbers covered by range (t1,t2)
        norbt1 = int(np.floor((t1-T0)/Period))
        norbt2 = int(np.ceil((t2-T0)/Period))

        phase = np.linspace(0,1,self.Nbin+1)

        self.gtifile=[] #reset gtifiles
        for i in range(self.Nbin):
            self.time_array[2*i] = self.config['time']['tmin']
            self.time_array[2*i+1] = self.config['time']['tmax']
            gtifn = os.path.join(self.LCfolder,"TimeSelection_{0:02.0f}.dat".format(i))
            ints=[]

            for norb in range(norbt1,norbt2+1):
                ints.append(((T0+(norb+phase[i])*Period),(T0+(norb+phase[i+1])*Period)))
            tsel = np.array(ints)
            np.savetxt(gtifn,tsel)
            self.gtifile.append(gtifn)


    def MakeLC(self) :
        """Run a std lc """
        self._MakeTimeBins()
        self._ManageFolder(LightcurvePath)
        self._MakeLC()

    def MakeFoldedLC(self):
        """run a folded lc """
        self.Nbin = self.config['FoldedLC']['NLCbin']
        self._ManageFolder(FoldedLCPath)
        self._MakePhasebin()
        self._MakeLC()

    def PlotLC(self):
        '''Plot a lightcurve which have been generated previously'''
        self._MakeTimeBins()
        self._ManageFolder(LightcurvePath)
        self.PrepareLC()#Get the config file
        self._PlotLC()

    def PlotFoldedLC(self):
        '''Plot a lightcurve which have been generated previously'''
        self.Nbin = self.config['FoldedLC']['NLCbin']
        self._ManageFolder(FoldedLCPath)
        self._MakePhasebin()
        self.PrepareLC()#Get the config file
        self._PlotLC(True)

    def _PlotLC(self,folded=False):
        root_style.RootStyle()#Nice plot style

        self.info("Reading files produced by enrico")
        LcOutPath = self.LCfolder + self.config['target']['name']

        #Result are stored into list. This allow to get rid of the bin which failled
        Time = []
        TimeErr = []
        Flux = []
        FluxErr = []
        Index = []
        IndexErr = []
        Cutoff = []
        CutoffErr = []
        FluxForNpred = []
        FluxErrForNpred = []
        Npred = []
        Npred_detected_indices = []
        TS = []

        # Find name used for index parameter
        if (self.config['target']['spectrum'] == 'PowerLaw' or
                self.config['target']['spectrum'] == 'PowerLaw2'):
                IndexName = 'Index'
                CutoffName = None
        elif (self.config['target']['spectrum'] == 'PLExpCutoff' or
                self.config['target']['spectrum'] == 'PLSuperExpCutoff'):
            IndexName = 'Index1'
            CutoffName = 'Cutoff'
            CutoffErrName = 'dCutoff'
        else:
            IndexName = 'alpha'
            CutoffName = None
        IndexErrName = 'd' + IndexName

        Nfail = 0
        for i in xrange(self.Nbin):
            CurConfig = get_config(self.configfile[i])
            #Read the result. If it fails, it means that the bins has not bin computed. A warning message is printed
            try :
                ResultDic = utils.ReadResult(CurConfig)
            except :
                self._errorReading("Fail reading config file",i)
                Nfail+=1
                continue

            #Update the time and time error array
            Time.append((ResultDic.get("tmax")+ResultDic.get("tmin"))/2.)
            TimeErr.append((ResultDic.get("tmax")-ResultDic.get("tmin"))/2.)
            #Check is an ul have been computed. The error is set to zero for the TGraph.
            if ResultDic.has_key('Ulvalue') :
                Flux.append(ResultDic.get("Ulvalue"))
                FluxErr.append(0)
                Index.append(ResultDic.get(IndexName))
                IndexErr.append(0)
            else :
                Flux.append(ResultDic.get("Flux"))
                FluxErr.append(ResultDic.get("dFlux"))
                Index.append(ResultDic.get(IndexName))
                IndexErr.append(ResultDic.get(IndexErrName))
                if CutoffName is not None:
                    Cutoff.append(ResultDic.get(CutoffName))
                    CutoffErr.append(ResultDic.get(CutoffErrName))
            FluxErrForNpred.append(ResultDic.get("dFlux"))
            FluxForNpred.append(ResultDic.get("Flux"))
            #Get the Npred and TS values
            Npred.append(ResultDic.get("Npred"))
            TS.append(ResultDic.get("TS"))
            if (CurConfig['LightCurve']['TSLightCurve']<float(ResultDic.get("TS"))):
                Npred_detected_indices.append(i-Nfail)

        #change the list into np array
        TS = np.array(TS)
        Npred = np.array(Npred)
        Npred_detected = Npred[Npred_detected_indices]
        Time = np.array(Time)
        TimeErr = np.array(TimeErr)
        Flux = np.array(Flux)
        FluxErr = np.array(FluxErr)
        Index = np.array(Index)
        IndexErr = np.array(IndexErr)
        Cutoff = np.array(Cutoff)
        CutoffErr = np.array(CutoffErr)
        FluxForNpred = np.array(FluxForNpred)
        FluxErrForNpred = np.array(FluxErrForNpred)

        #Plots the diagnostic plots is asked
        # Plots are : Npred vs flux
        #             TS vs Time
        if self.config['LightCurve']['DiagnosticPlots'] == 'yes':
            fittedFunc = self.CheckNpred(Npred,FluxForNpred,FluxErrForNpred,Npred_detected_indices)#check the errors calculation
            gTHNpred,TgrNpred = plotting.PlotNpred(Npred,FluxForNpred,FluxErrForNpred)
            CanvNpred = _GetCanvas()
            gTHNpred.Draw()
            TgrNpred.Draw('zP')
	    if len(Npred_detected)>0:
	    	_,TgrNpred_detected = plotting.PlotNpred(Npred_detected,Flux[Npred_detected_indices],FluxErrForNpred[Npred_detected_indices])
	    	TgrNpred_detected.SetLineColor(2)
{'fraction_non_alphanumeric': 0.13257735921583702, 'fraction_numerical': 0.005958101095521814, 'mean_word_length': 2.2617853560682044, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1263771', 'n_tokens_mistral': 8319, 'n_tokens_neox': 8020, 'n_words': 1628}