splat/model.py
def _modelFitPlotComparison(spec,model,display=True,**kwargs):
    '''
    Routine to compare spectrum to a model or models
    '''

# set up model spectrum or spectra
    if isinstance(model,list) == False:
        model = [model]
    scale = kwargs.get('scale',[1.0]*len(model))
    if isinstance(scale,list) == False:
        scale = [scale]
    stat = kwargs.get('stat',[False]*len(model))
    if isinstance(stat,list) == False:
        stat = [stat]
    if kwargs.get('compare',False) == True:
        scale = []
        stat = []
        for i,m in enumerate(model):
            st,sc = compareSpectra(spec,m,stat='chisqr',**kwargs)      # note: assumed to be chi-square
            scale.append(sc)
            stat.append(st)
    for i,m in enumerate(model):
        m.scale(scale[i])

# plotting
    olegend = kwargs.get('name',spec.name)

# plot one model on top of one spectrum in one plot
    if kwargs.get('overplot',True) == True and len(model) == 1:
        sps = [spec,model[0]]
#        model[0].info()
        colors = ['k','b']
        mlegend = r'{} '.format(SPECTRAL_MODELS[getattr(model[0],'model')]['name'])
        mlegend+='{:s}={:.0f} '.format(SPECTRAL_MODEL_PARAMETERS['teff']['title'],getattr(model[0],'teff'))
        mlegend+='{:s}={:.2f} '.format(SPECTRAL_MODEL_PARAMETERS['logg']['title'],getattr(model[0],'logg'))
        mlegend+='{:s}={:.1f} '.format(SPECTRAL_MODEL_PARAMETERS['z']['title'],getattr(model[0],'z'))
        legend = [olegend,mlegend]
        if kwargs.get('showdifference',True) == True: 
            sps.append(spec-model[0])
            colors.append('grey')
            legend.append(r'Difference ($\chi^2$ = {:.0f})'.format(stat[i]))
        sps = tuple(sps)
        return splot.plotSpectrum(*sps,colors=kwargs.get('colors',colors),file=kwargs.get('file',False),\
            uncertainty=kwargs.get('uncertainty',True),telluric=kwargs.get('telluric',True),legend=legend)

# plot several models on top of spectrum in one plot
    elif kwargs.get('overplot',True) == True and len(model) > 1:
        sps = [spec]
        colors = ['k']
        legend = [olegend]
        for i,m in enumerate(model):
            sps.append(m)
            colors.append('grey')
            mlegend = r'{:s}={:.0f} '.format(SPECTRAL_MODEL_PARAMETERS['teff']['title'],getattr(m,'teff'))
            mlegend+='{:s}={:.2f} '.format(SPECTRAL_MODEL_PARAMETERS['logg']['title'],getattr(m,'logg'))
            mlegend+='{:s}={:.1f} '.format(SPECTRAL_MODEL_PARAMETERS['z']['title'],getattr(m,'z'))
            legend.append(mlegend)
        sps = tuple(sps)
        return splot.plotSpectrum(*sps,colors=kwargs.get('colors',colors),file=kwargs.get('file',False),\
            uncertainty=kwargs.get('uncertainty',True),telluric=kwargs.get('telluric',True),legend=legend)

# plot individual panels of spectra - there must be a filename given
    else: 
        if kwargs.get('file',False) == False:
            kwargs['file'] = 'modelFitComparison.pdf'
        plotlist = []
        legends = []
        colors = []
        for i,m in enumerate(model): 
            sps = [spec,m]
            c = ['k','b']
            mlegend = r'{}\n'.format(SPECTRAL_MODELS[getattr(m,'model')]['citation'])
            mlegend+='{:s}={:.0f} '.format(SPECTRAL_MODEL_PARAMETERS['teff']['title'],getattr(m,'teff'))
            mlegend+='{:s}={:.2f} '.format(SPECTRAL_MODEL_PARAMETERS['logg']['title'],getattr(m,'logg'))
            mlegend+='{:s}={:.1f} '.format(SPECTRAL_MODEL_PARAMETERS['z']['title'],getattr(m,'z'))
            leg = [olegend,mlegend]
            if kwargs.get('showdifference',True): 
                plotlist.append(spec-m)
                c.append('grey')
                leg.append(r'Difference ($\chi^2$ = {:.0f})'.format(stat[i]))
            plotlist.append(sps)
            colors.append(kwargs.get('colors',c))
            legends.append(leg)

        return splot.plotSpectrum(plotlist,multiplot=True,multipage=True,legends=legends,colors=colors,\
            file=kwargs.get('file',False),uncertainty=kwargs.get('uncertainty',True),telluric=kwargs.get('telluric',True))

    Routine to compare spectrum to a model or models
    
Routine to compare spectrum to a model or models
Routine to compare spectrum to a model or models
def _modelFitPlotComparison(spec,model,display=True,**kwargs):
    if isinstance(model,list) == False:
        model = [model]
    scale = kwargs.get('scale',[1.0]*len(model))
    if isinstance(scale,list) == False:
        scale = [scale]
    stat = kwargs.get('stat',[False]*len(model))
    if isinstance(stat,list) == False:
        stat = [stat]
    if kwargs.get('compare',False) == True:
        scale = []
        stat = []
        for i,m in enumerate(model):
            st,sc = compareSpectra(spec,m,stat='chisqr',**kwargs)      
            scale.append(sc)
            stat.append(st)
    for i,m in enumerate(model):
        m.scale(scale[i])
    olegend = kwargs.get('name',spec.name)
    if kwargs.get('overplot',True) == True and len(model) == 1:
        sps = [spec,model[0]]
        colors = ['k','b']
        mlegend = r'{} '.format(SPECTRAL_MODELS[getattr(model[0],'model')]['name'])
        mlegend+='{:s}={:.0f} '.format(SPECTRAL_MODEL_PARAMETERS['teff']['title'],getattr(model[0],'teff'))
        mlegend+='{:s}={:.2f} '.format(SPECTRAL_MODEL_PARAMETERS['logg']['title'],getattr(model[0],'logg'))
        mlegend+='{:s}={:.1f} '.format(SPECTRAL_MODEL_PARAMETERS['z']['title'],getattr(model[0],'z'))
        legend = [olegend,mlegend]
        if kwargs.get('showdifference',True) == True: 
            sps.append(spec-model[0])
            colors.append('grey')
            legend.append(r'Difference ($\chi^2$ = {:.0f})'.format(stat[i]))
        sps = tuple(sps)
        return splot.plotSpectrum(*sps,colors=kwargs.get('colors',colors),file=kwargs.get('file',False),\
            uncertainty=kwargs.get('uncertainty',True),telluric=kwargs.get('telluric',True),legend=legend)
    elif kwargs.get('overplot',True) == True and len(model) > 1:
        sps = [spec]
        colors = ['k']
        legend = [olegend]
        for i,m in enumerate(model):
            sps.append(m)
            colors.append('grey')
            mlegend = r'{:s}={:.0f} '.format(SPECTRAL_MODEL_PARAMETERS['teff']['title'],getattr(m,'teff'))
            mlegend+='{:s}={:.2f} '.format(SPECTRAL_MODEL_PARAMETERS['logg']['title'],getattr(m,'logg'))
            mlegend+='{:s}={:.1f} '.format(SPECTRAL_MODEL_PARAMETERS['z']['title'],getattr(m,'z'))
            legend.append(mlegend)
        sps = tuple(sps)
        return splot.plotSpectrum(*sps,colors=kwargs.get('colors',colors),file=kwargs.get('file',False),\
            uncertainty=kwargs.get('uncertainty',True),telluric=kwargs.get('telluric',True),legend=legend)
    else: 
        if kwargs.get('file',False) == False:
            kwargs['file'] = 'modelFitComparison.pdf'
        plotlist = []
        legends = []
        colors = []
        for i,m in enumerate(model): 
            sps = [spec,m]
            c = ['k','b']
            mlegend = r'{}\n'.format(SPECTRAL_MODELS[getattr(m,'model')]['citation'])
            mlegend+='{:s}={:.0f} '.format(SPECTRAL_MODEL_PARAMETERS['teff']['title'],getattr(m,'teff'))
            mlegend+='{:s}={:.2f} '.format(SPECTRAL_MODEL_PARAMETERS['logg']['title'],getattr(m,'logg'))
            mlegend+='{:s}={:.1f} '.format(SPECTRAL_MODEL_PARAMETERS['z']['title'],getattr(m,'z'))
            leg = [olegend,mlegend]
            if kwargs.get('showdifference',True): 
                plotlist.append(spec-m)
                c.append('grey')
                leg.append(r'Difference ($\chi^2$ = {:.0f})'.format(stat[i]))
            plotlist.append(sps)
            colors.append(kwargs.get('colors',c))
            legends.append(leg)
        return splot.plotSpectrum(plotlist,multiplot=True,multipage=True,legends=legends,colors=colors,\
            file=kwargs.get('file',False),uncertainty=kwargs.get('uncertainty',True),telluric=kwargs.get('telluric',True))
def _modelFitPlotComparison ( spec , model , display = True , ** kwargs ) : if isinstance ( model , list ) == False : model = [ model ] scale = kwargs . get ( 'scale' , [ 1.0 ] * len ( model ) ) if isinstance ( scale , list ) == False : scale = [ scale ] stat = kwargs . get ( 'stat' , [ False ] * len ( model ) ) if isinstance ( stat , list ) == False : stat = [ stat ] if kwargs . get ( 'compare' , False ) == True : scale = [ ] stat = [ ] for i , m in enumerate ( model ) : st , sc = compareSpectra ( spec , m , stat = 'chisqr' , ** kwargs ) scale . append ( sc ) stat . append ( st ) for i , m in enumerate ( model ) : m . scale ( scale [ i ] ) olegend = kwargs . get ( 'name' , spec . name ) if kwargs . get ( 'overplot' , True ) == True and len ( model ) == 1 : sps = [ spec , model [ 0 ] ] colors = [ 'k' , 'b' ] mlegend = r'{} ' . format ( SPECTRAL_MODELS [ getattr ( model [ 0 ] , 'model' ) ] [ 'name' ] ) mlegend += '{:s}={:.0f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'teff' ] [ 'title' ] , getattr ( model [ 0 ] , 'teff' ) ) mlegend += '{:s}={:.2f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'logg' ] [ 'title' ] , getattr ( model [ 0 ] , 'logg' ) ) mlegend += '{:s}={:.1f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'z' ] [ 'title' ] , getattr ( model [ 0 ] , 'z' ) ) legend = [ olegend , mlegend ] if kwargs . get ( 'showdifference' , True ) == True : sps . append ( spec - model [ 0 ] ) colors . append ( 'grey' ) legend . append ( r'Difference ($\chi^2$ = {:.0f})' . format ( stat [ i ] ) ) sps = tuple ( sps ) return splot . plotSpectrum ( * sps , colors = kwargs . get ( 'colors' , colors ) , file = kwargs . get ( 'file' , False ) , uncertainty = kwargs . get ( 'uncertainty' , True ) , telluric = kwargs . get ( 'telluric' , True ) , legend = legend ) elif kwargs . get ( 'overplot' , True ) == True and len ( model ) > 1 : sps = [ spec ] colors = [ 'k' ] legend = [ olegend ] for i , m in enumerate ( model ) : sps . append ( m ) colors . append ( 'grey' ) mlegend = r'{:s}={:.0f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'teff' ] [ 'title' ] , getattr ( m , 'teff' ) ) mlegend += '{:s}={:.2f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'logg' ] [ 'title' ] , getattr ( m , 'logg' ) ) mlegend += '{:s}={:.1f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'z' ] [ 'title' ] , getattr ( m , 'z' ) ) legend . append ( mlegend ) sps = tuple ( sps ) return splot . plotSpectrum ( * sps , colors = kwargs . get ( 'colors' , colors ) , file = kwargs . get ( 'file' , False ) , uncertainty = kwargs . get ( 'uncertainty' , True ) , telluric = kwargs . get ( 'telluric' , True ) , legend = legend ) else : if kwargs . get ( 'file' , False ) == False : kwargs [ 'file' ] = 'modelFitComparison.pdf' plotlist = [ ] legends = [ ] colors = [ ] for i , m in enumerate ( model ) : sps = [ spec , m ] c = [ 'k' , 'b' ] mlegend = r'{}\n' . format ( SPECTRAL_MODELS [ getattr ( m , 'model' ) ] [ 'citation' ] ) mlegend += '{:s}={:.0f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'teff' ] [ 'title' ] , getattr ( m , 'teff' ) ) mlegend += '{:s}={:.2f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'logg' ] [ 'title' ] , getattr ( m , 'logg' ) ) mlegend += '{:s}={:.1f} ' . format ( SPECTRAL_MODEL_PARAMETERS [ 'z' ] [ 'title' ] , getattr ( m , 'z' ) ) leg = [ olegend , mlegend ] if kwargs . get ( 'showdifference' , True ) : plotlist . append ( spec - m ) c . append ( 'grey' ) leg . append ( r'Difference ($\chi^2$ = {:.0f})' . format ( stat [ i ] ) ) plotlist . append ( sps ) colors . append ( kwargs . get ( 'colors' , c ) ) legends . append ( leg ) return splot . plotSpectrum ( plotlist , multiplot = True , multipage = True , legends = legends , colors = colors , file = kwargs . get ( 'file' , False ) , uncertainty = kwargs . get ( 'uncertainty' , True ) , telluric = kwargs . get ( 'telluric' , True ) )
Routine to compare spectrum to a model or models
Routine to compare spectrum to a model or models
'''
    Routine to compare spectrum to a model or models
    ''' # set up model spectrum or spectra # note: assumed to be chi-square # plotting # plot one model on top of one spectrum in one plot #        model[0].info() # plot several models on top of spectrum in one plot # plot individual panels of spectra - there must be a filename given
spec
model
display