Ejemplo n.º 1
0
 def get_model_func(self):
     modellist=[]
     ppcross=crss.crossSection(self.ppPath)
     counter=0
     for p in self.processes:
         model=mod.model(self.parentspec[counter],p,self.data,self.source,ppcross)
         modellist.append(model.model_val)
         counter+=1
     return modellist
Ejemplo n.º 2
0
    def fit(self,config=False):
        '''
        performs the fit of all processes and returns the final
        parameter values (list) as well as the model function values
        as a list of  arrays and the
        '''
        
        ppcross=crss.crossSection(self.ppPath)
        print 'Setting up fitting routine using:'
        print 'evaluating processes %s specs %s with initial parmeters %s'%(self.processes,self.parentspec,self.inPara)
        
        modelfit=fitter.fitter(self.parentspec,self.inPara,self.processes,self.data,self.source,self.confDict,ppcross)
        fitFunc=modelfit.fit(config)
        #print 'return from fitter in sedfitter: ',fitFunc
        
        '''
        Produce finer sampled model functions compared to the fit functions,
        these are used for nice plots instead of the data point sampled 
        graphs that are for test purposes and for the fit
        '''
        fineGammaY=[]
        fineGammaX=[]
        counter=0
        for p in self.processes:
            finalmodel=mod.model(self.parentspec[counter],p,self.data,self.source,ppcross)
            finalmodel.set_final_gamma_prec(300)
            if p=='pp':
                '''
                general pp interaction returns secondary emission processes
                (Bremsstrahlung and IC) as separated spectra in addition to the pp spectrum and the total spectrum
                '''
                fineResults=finalmodel.model_val(fitFunc[0][counter])
                fineGammaY.append(fineResults[0][0])#total spec
                fineGammaY.append(fineResults[0][1])# only pp
                fineGammaY.append(fineResults[0][2])# only bremsstrahlung
                fineGammaY.append(fineResults[0][3])# only IC
                fineGammaX.append(fineResults[1])
                fineGammaX.append(fineResults[1])
                fineGammaX.append(fineResults[1])
                fineGammaX.append(fineResults[1])
                counter+=4
            else:
                fineResults=finalmodel.model_val(fitFunc[0][counter])
                fineGammaY.append(fineResults[0])
                fineGammaX.append(fineResults[1])
                counter+=1
            
            print self.print_fit_results(fitFunc)

        return fitFunc+(fineGammaY,fineGammaX)
Ejemplo n.º 3
0
def plot_sec_spec():
    particlePoints=1000
    Eg=np.logspace(7.,13.,100)/1.e9
    Ee=np.logspace(6.,15.,particlePoints)/1.e9
    parameter=[1.,9.,-2.5,10.]
    #Ne=spsh.bplcut(Ee,[49.4,-2.43,-2.7,1.69,5.])
    Ne=spsh.sbplcuty(Ee,[49.4,1.,-1.5,1.176,-1.4,5.])
    
    #Ne2=spsh.plcut()
    ylist=[]
    xlist=[]
    taglist=[]
    elist=[]
    ppcrosspath='/Users/jogler/Physik/Fermi/scripts/pp_data/'
    ppcross=crs.crossSection(ppcrosspath)

    source=sed.source(6000,30.,3.e4)
    source.set_radiation_densities(0.25,0.84,3.0e-3,0.9)#W51C densities Abdo et al 2009
    source.set_radiation_photons(-8.,4.,0.1)
    source.set_am_prop(10.,10.,1.)
    
    fluxScale=Eg/(4.*np.pi*(source.dist*const.PARSEC*const.m2cm)**2.)/const.erg2GeV
    print 'Scale: ',fluxScale
    pp=mod.model(Ne,'pp',[],source,ppcross)
    ppSpec=pp.nucFactor*pp.EdQdE_pp(Ne,Ee,Eg)
    #secEPoints=np.logspace(np.log10(Eg[0]),np.log10(Eg[len(Eg)-1]),particlePoints)
    eSecSpec=pp.nucFactor*(pp.EdQdE_pp(Ne,Ee,Ee,1)+pp.EdQdE_pp(Ne,Ee,Ee,2))*source.age*const.yr2s
    print 'points in secondary spec: ',np.size(eSecSpec)
    
    secBrems=pp.Brems_spec(eSecSpec,Ee,Eg)
    secIC=pp.IC_spec_gamma(source.phTot,source.Eph,eSecSpec,Ee,Eg)

    ylist.append(ppSpec*fluxScale)
    ylist.append(secBrems*fluxScale)
    ylist.append(secIC*fluxScale)
    
    xlist.append(Eg)
    xlist.append(Eg)
    xlist.append(Eg)
    elist.append(0)
    elist.append(0)
    elist.append(0)
    taglist.append('pp')
    taglist.append('brems sec')
    taglist.append('IC sec')
    
    fig=plot(xlist,ylist,[],elist,taglist,r'$\mathrm{E}_{\gamma}\, \mathrm{ [GeV]}$',r'$EF_{\gamma}\, [\mathrm{erg}\, \mathrm{ cm}^{-2} \mathrm{s}^{-1}]$')
    plt.show(fig)
Ejemplo n.º 4
0
def plot_spectrum(typ=['ic','brems','pp']):
    '''plots spectra'''
    Eg=np.logspace(6.,12.,100)
    Ee=np.logspace(6.,15.,1000)
    parameter=[1.,9.,-2.5,10.]
    #Ne2=spsh.bplcut(Ee,[49.4,-1.5,-2.9,10.176,13.])
    Ne2=spsh.sbplcut(Ee,[49.4,9.,-1.5,10.301,2.3,13.])
    #print Ne
    Ne=spsh.sbplcuty(Ee,[49.4,9.,-1.5,10.301,2.3,13.])#W51C values abdo et al 2009
    ENe=Ee*Ne2
    spec=sed.spectrum(spsh.sbplcut,[49.4,9.,-1.5,10.301,2.3,13.],1.e6,1.e15,1000.)
    
    #Ne2=spsh.plcut()
    ylist=[]
    xlist=[]
    taglist=[]
    elist=[]
    source=sed.source()
    source.set_radiation_densities(0.25,0.84,3.0e-3,0.9)#W51C densities Abdo et al 2009
    source.set_radiation_photons(-8.,4.,0.1)
    source.set_am_prop(10.,10.,1.)
    ppcrosspath='/Users/jogler/Physik/Fermi/scripts/pp_data/'
    ppcross=crs.crossSection(ppcrosspath)

    if 'brems' in typ:
        brems=mod.model(spec,'brems',[],source,ppcross)
        En=brems.spec.get_xvals()*brems.spec.value()
        print En-ENe
        ylist.append((Eg/1.e9)*brems.Brems_spec(ENe,Ee/1.e9,Eg/1.e9))
        #ylist.append(brems.Brems_spec(ENe,Ee/10**9,Eg/10**9))
        # ylist.append(brems.Brems_spec_ee(Ne,Ee,Eg))
        xlist.append(Eg)
        #xlist.append(Eg)
        taglist.append('Brems N')
        #taglist.append('Brems ee')
        elist.append(0)
        #elist.append(0)

    if 'ic' in typ:
        for ph in [source.phTot,source.phCMB,source.phDust,source.phStar]:
            ic=mod.model(Ne,'ic',[],source,ppcrosspath)
            ylist.append(Eg/1.e9*ic.IC_spec_gamma(ph/source.Eph,source.Eph,ENe,Ee/10**9,Eg/10**9))
            xlist.append(Eg)
            elist.append(0)
            
        for t in['IC total','IC CMB','IC Dust','IC Star']: 
            taglist.append(t)
    
    if 'pp' in typ:
        pp=mod.model(Ne,'pp',[],source,ppcross)
        ylist.append(pp.EdQdE_pp(Ne,Ee/10**9,Eg/10**9))
        xlist.append(Eg)
        elist.append(0)
        taglist.append(r'$\mathrm{pp}_{\gamma} $')
        ''' plot e+ e- sec spec'''
        ylist.append(pp.EdQdE_pp(Ne,Ee/10**9,Eg/10**9,1))
        xlist.append(Eg)
        elist.append(0)
        taglist.append('pp_e-')
        ylist.append(pp.EdQdE_pp(Ne,Ee/10**9,Eg/10**9,2))
        xlist.append(Eg)
        elist.append(0)
        taglist.append('pp_e+')
    if 'comp' in typ:
        if 'brems' in typ:
            print 'nH: %.2f nHeff: %.2f Zeff: %.2f'%(source.nH,source.nHeff,source.Zeff)
            bremsSp=gs.brems_spectrum(ENe,Ee/10**9,source.nHeff)
            ylist.append(Eg/10**9*bremsSp(Eg/10**9))
            xlist.append(Eg)
            elist.append(0)
            taglist.append('brems dima')
        if 'ic' in typ:
            icSp=gs.IC_spectrum(source.phTot/source.Eph,source.Eph,ENe,Ee/10**9)
            ylist.append(Eg/10**9*icSp(Eg/10**9))
            xlist.append(Eg)
            elist.append(0)
            taglist.append('ic dima')
        if 'pp' in typ:
            ppSp=gs.EdQdE_pp(Ne,Ee/10**9,source.nH,0)
            ylist.append(ppSp(Eg/10**9))
            xlist.append(Eg)
            elist.append(0)
            taglist.append('pp dima')
        
    fig0=plot(xlist,ylist,[],elist,taglist,r'$\mathrm{E}_{\gamma}\, \mathrm{ [eV]}$',r'$E^2F_{\gamma}\, [\mathrm{erg}\,\mathrm{ cm}^{-3} \mathrm{s}^{-1}]$')
    #plt.show(fig0)

    xlist=[]
    ylist=[]
    elist=[]
    taglist=[]
    
    xlist.append(Ee)
    xlist.append(Ee)
    ylist.append(Ne)
    ylist.append(Ne2)
    elist.append(0)
    elist.append(0)
    taglist.append('Ne')
    taglist.append('Ne2')
    fig1=plot(xlist,ylist,[],elist,taglist,r'$\mathrm{E}_{\gamma}\, \mathrm{ [eV]}$',r'$N_e\, [\mathrm{N}_{e}\mathrm{ cm}^{-3} \mathrm{s}^{-1}]$')
    plt.show()