Example #1
0
 def set_spectra(self):
     funclist=[]
     counter=0
     print self.specName
     for name in self.specName:
         if len(self.eranges)!=0 and len(self.inPara)!=0:
             print self.eranges[counter][0],self.eranges[counter][1]
             print self.inPara[counter]
             sp=spectrum(specsh.func(name)[0],self.inPara[counter],self.eranges[counter][0],self.eranges[counter][1])
             sp.set_func_name(name)
             funclist.append(sp)
             counter+=1
         elif len(self.eranges)!=0 and  len(self.inPara)==0:
             sp=spectrum(specsh.func(name)[0],np.zeros(specsh.func(name)[1]),self.eranges[counter][0],self.eranges[counter][1])
             sp.set_func_name(name)
             funclist.append(sp)
             counter+=1 
         elif len(self.eranges)==0 and  len(self.inPara)==0:
             sp=spectrum(specsh.func(name)[0],np.zeros(specsh.func(name)[1]),100,1e15)
             sp.set_func_name(name)
             funclist.append(sp)
             counter+=1 
         else:
             print "ERROR: setting spectrum %i for process %s"%(counter,name)
             print "ERROR: check energy ranges and intial parameters"
     self.parentspec=funclist
Example #2
0
 def get_parameter_def(self):
     '''
     returns a list containing a list of the paramerters as first entry
     and a second list explaining if the parameter is linear (0) or 10**p (1)
     '''
     pardef=[]
     pardef.append(self.par)
     pardef.append(specsh.func(self.funcName)[2])
     return pardef
def plot_spectrum(ispec,ipara,iprocess,erange,distance,size,shape,shellth,age,crosspath):
    #print ipara,type(ipara)
    if ipara!=[]:
        ipara=ut.argparse_list_of_list_conv(ipara)[0]
    specfunc=spsh.func(ispec[0])[0]
    #print specfunc(np.linspace(erange[0],erange[1],10),ipara)
    '''SNR specific setting of source parameters'''
    '''W51C'''
    Source=sed.source(distance,size,age,shape,shellth)
    Source.set_radiation_photons(-7.,2.,0.05)#energy range and binning for target photons
    Source.set_am_prop(nH=10.,nIH=0.,Z=1.) # inter stellar medium parameters
    Source.set_radiation_densities(0.25,0.84,3.0e-3,0.9) # radiation field desities and temperatures for IR and UV photonfields (CMB is fixed and cannot be changed)

    spec=sed.spectrum(specfunc,ipara,erange[0],erange[1],precision=100)
    #print spec
    gammaEmission=model.model(spec,iprocess[0],Source,crosspath)
    gammaEmission.set_final_gamma_prec(1000)
    fineGamma,xFineGamma=gammaEmission.model_val(ipara)
    
    #print 'type func: ',type(func),func
    
    
    '''
    Prepare the plotting of the functions
    in a pretty way
    '''

    xvals=[]
    yvals=[]
    yerrors=[]
    yerrflaq=[]
    tags=['bla','blub']
    counter=0
    Fscale=const.MeV2erg
    for p in iprocess:
       tags.append('%s'%(p))
       counter+=1
        
    counter=0
    for f in fineGamma:
        if type(f)==list:# required for secondaries in pp process
            for ff in f:
                yvals.append(ff*Fscale)
                yerrflaq.append(0)
        else:    
            yvals.append(f*Fscale)
            yerrflaq.append(0)
        
    for xf in xFineGamma:
        if type(xf)==list:# required for secondaries in pp process
            for xxf in xf:
                xvals.append(xxf)
        else:    
            xvals.append(xf)

    if len(xvals)!= len(yvals):
        print 'ERROR: number of x arrays not equal to y arrays'
        exit()

    
    #print 'x: %s'%xvals
    #print 'y: %s'%yvals
        
    fig=ut.plot([xvals],[yvals],error_flaq=yerrflaq,marker_array=tags,res=False,onlybands=False,forceLog=False,ytitle=r'E$^{2}$ dN/dE [erg $\mathrm{cm}^{-2} \mathrm{ s}^{-1}$]')
    fig.show()


    #plt.figure()
  
    var=raw_input("Press enter to exit")