示例#1
0
文件: sed.py 项目: buchbend/astrolyze
    def plot_sed(self, axes=plt.gca(), nu_or_lambda='nu', color='black',
                 linewidth=0.5, x_range='normal'):
        '''Plot a multi component greybody model.

        Parameters
        ----------

        nu_or_lambda :
           plot against frequency ``'nu'`` or wavelenght ``'lambda'``
        kappa :
            The kappa to use. ``'easy'`` or ``'Kruegel'``. Please refer
            to :py:func:`functions.astroFunctions.greyBody` for more
            information.
        xRange : PLEASE ADD DESCRIPTION
        linewidth : float
            The linewidth of the plotted lines. Default to 0.5.
        color : matplotlib conform color
            the color of the plotted lines. Default to ``'black'``.
        '''
        if not self.fit_done:
            raise ValueError('Could not plot the data. The data has not been '
                             'fitted yet.')
            sys.exit()
        if self.p2 ==  None:
            pass
        if x_range == 'LTIR':
        # Plot the SED in the range of the determination
            # of the L_TIR: 3-1100 micron
            xmin =  3e-6# micron
            xmax =  1100e-6 # micron
            # conversion to frequency in GHz
            xmin = const.c/xmax/1e9
            xmax = const.c/xmin/1e9
            step = 0.1

        if x_range == 'normal':
            # arbitrary range definition
            xmin = 1e-2
            xmax = 3e5
            step = 0.5
        if type(x_range) == list:
            xmin = x_range[0]
            xmax = x_range[1]
            if len(x_range) < 3:
                step = 0.1
            else:
                step = x_range[2]
        x = np.arange(xmin,xmax,step)
        # multi_component_grey_body gives the summed 'model' and the components
        # grey'. 'grey' is a List
        if nu_or_lambda == 'nu':
            model,grey = astro_functions.multi_component_grey_body(self.p2, x,
                                                                   'nu',
                                                                   self.kappa)
        if nu_or_lambda=='lambda':
            model,grey = astro_functions.multi_component_grey_body(self.p2, x,
                                                                   'nu',
                                                                   self.kappa)
            y=x.copy()
            modelLambda =model.copy()
            greyLambda = []
            for i in range(len(grey)):
                greyLambda += [grey[i].copy()]
            for i in range(len(x)):
                y[i]=(const.c/(x[len(x)-i-1]*1e9))/1e-6
            for i in range(len(model)):
                modelLambda[i]=model[len(model)-i-1]
                for j in range(len(greyLambda)):
                    greyLambda[j][i] = grey[j][len(grey[j])-i-1]
            x=y
            model =modelLambda
            grey = greyLambda
        plt.loglog(x, model, ls='-', color=color, label='_nolegend_', lw=0.5,
                   marker='')
        linestyles = [':','-.','-']
        j=0
        for i in grey:
            plt.loglog(x, i, color=color, ls=linestyles[j], lw=0.5, marker='')
            j+=1
示例#2
0
def plot_sed(p2, nu_or_lambda='nu', color='black', kappa='easy',
            linewidth=0.5, xRange='normal'):
    '''
    Plot a multi component greybody model.

    :param p2:  formatted: p2 = [[t1,t2,t3,...], [N1,N2,N3,...], [beta]]
    :param nu_or_lambda: plot against frequency ``'nu'`` or wavelenght
        ``'lambda'``
    :param kappa: The kappa to use. ``'easy'`` or ``'Kruegel'``. Please refer
       to :py:func:`functions.astroFunctions.greyBody` for more information.
    :param xRange: PLEASE ADD DESCRIPTION
    :param linewidth: The linewidth of the plotted lines. Default to 0.5.
    :param linewidth: float
    :param color: the color of the plotted lines. Default to ``'black'``
    :type color: matplotlib conform color.
    '''

    if xRange == 'LTIR':
    # Plot the SED in the range of the determination
        # of the L_TIR: 3-1100 micron
        xmin =  3e-6# micron
        xmax =  4000e-6 # micron
        # conversion to frequency in GHz
        xmin = const.c/xmax/1e9
        xmax = const.c/xmin/1e9
        step = 0.1

    if xRange == 'normal':
        # arbitrary range definition
        xmin = 1e-2
        xmax = 3e5
        step = 0.5
    if type(xRange) == list:
        xmin = xRange[0]
        xmax = xRange[1]
        if len(xRange) < 3:
            step = 0.1
        else:
            step = xRange[2]
    x = np.arange(xmin,xmax,step)
    # multiComponent gives the summed 'model' and the components 'grey'.
    # 'grey' is a List
    if nu_or_lambda == 'nu':
        model,grey = astFunc.multi_component_grey_body(p2,x,'nu',kappa)
    if nu_or_lambda=='lambda':
        model,grey = astFunc.multi_component_grey_body(p2,x,'nu',kappa)
        y=copy(x)
        modelLambda =copy(model)
        greyLambda = []
        for i in range(len(grey)):
            greyLambda += [copy(grey[i])]
        for i in range(len(x)):
            y[i]=(const.c/(x[len(x)-i-1]*1e9))/1e-6
        for i in range(len(model)):
            modelLambda[i]=model[len(model)-i-1]
            for j in range(len(greyLambda)):
                greyLambda[j][i] = grey[j][len(grey[j])-i-1]
        x=y
        model =modelLambda
        grey = greyLambda
    plt.loglog(x,model,ls='-',color=color,label='_nolegend_',lw=0.5,marker='')
    linestyles = [':','-.','-']
    j=0
    for i in grey:
        plt.loglog(x,i,color=color,ls=linestyles[j],lw=0.5,marker='')
        j+=1