Ejemplo n.º 1
0
def hydrogen(nu,nl, vacuum=True):
    """
    Compute the rest wavelength of Hydrogen recombination lines in angstroms
    """
    rydberg = 10973731.6 # m^-1
    protontoelectron = 1836.15266 # ratio

    lvac = 1.0/rydberg * 1./(1/float(nl)**2 - 1/float(nu)**2) * 1e10 * (1.0+1.0/protontoelectron)

    if not vacuum:
        import ref_index
        return ref_index.vac2air(lvac/10)*10
    else:
        return lvac
Ejemplo n.º 2
0
def get_telluric_lines(wavelength_array, telluric_linelist_file, vacuum=True):
	""" This will load the telluric line list
	
	Reading the telluric line list using astropy Table function
	
	Inputs
	------
	wavelength_array: array
		This is the wavelength array that you want checked against the 
		given telluric line list
		
	telluric_linelist_file: string
		This is the location of the telluric line list file you would like to use.
	
	vacuum: Boolean (default is True)
		Is the telleric line list given in vacuum. Most line lists I've
		seen are provided in vacuum, but it might not always be the case.
	
	Returns
	------
	telluric_lines_centres: array
		The array containing the telluric lines
	
	Examples
	------
	
	"""
	
	import ref_index
	
	line_list_file = telluric_linelist_file
	
	data = Table.read(line_list_file)
	Telluric_Line_List_Wavelength_centre = data['wavelength']

	# Trim the telluric line list to only be within the same
	# wavelength range as the input waveleangth array
	# This saves a lot of time when trying to fit Gaussians
	Above_Min_Wavelength = (Telluric_Line_List_Wavelength_centre > np.min(wavelength_array))
	Below_Max_Wavelength = (Telluric_Line_List_Wavelength_centre < np.max(wavelength_array))

	telluric_lines_centres = Telluric_Line_List_Wavelength_centre[np.where((Below_Max_Wavelength*Above_Min_Wavelength) == True)]
	
	if vacuum:
		telluric_lines_centres = ref_index.vac2air(telluric_lines_centres)
	else:
		pass
	
	return telluric_lines_centres
def vac_to_air(wavelengths):
    """
    convert wavelengths in air to vacuum using ref_index
    
    INPUT: wavelengths - in angstroms
    
    OUTPUT: wavelengths - in angstroms
    
    """
    print('wavelengths.min: ', wavelengths.min())
    new_wavelengths = wavelengths / 10.
    new_wavelengths = ref_index.vac2air(
        new_wavelengths) * 10.  #back to angstroms
    print('new_wavelengths.min():', new_wavelengths.min())
    return new_wavelengths
Ejemplo n.º 4
0
def hydrogen(nu, nl, vacuum=True):
    """
    Compute the rest wavelength of Hydrogen recombination lines in angstroms
    """
    rydberg = 10973731.6  # m^-1
    protontoelectron = 1836.15266  # ratio

    lvac = 1.0 / rydberg * 1. / (1 / float(nl)**2 - 1 / float(nu)**2
                                 ) * 1e10 * (1.0 + 1.0 / protontoelectron)

    if not vacuum:
        import ref_index
        return ref_index.vac2air(lvac / 10) * 10
    else:
        return lvac
Ejemplo n.º 5
0
def fit_hdelta(
        sp,
        date,
        xmin=3900,
        xmax=4300,
        ymin=0.8,
        ymax=1.405,
        #exclude=[3601,3846,3869.37,3913,3956,3984.59,4013.4,4045.81,4081.81,4117.82,4230,4396,4460,4482],
        exclude=[3600, 4035, 4089, 4114, 4150, 4600],
        guesses=[
            0.1,
            ref_index.vac2air(
                pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerd'] * 1e3)
            * 10, 5, 2
        ],
        fittype='voigt'):

    sp.plotter(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
    sp.baseline(xmin=xmin,
                xmax=xmax,
                exclude=exclude,
                subtract=False,
                reset_selection=True,
                highlight_fitregion=True,
                order=1)
    sp.specfit(guesses=guesses, fittype=fittype)
    sp.specfit.xmin, sp.specfit.xmax = sp.specfit.get_model_xlimits()
    sp.specfit.parinfo.tableprint()
    sp.baseline.highlight_fitregion()
    sp.specfit.plot_components(add_baseline=True, component_yoffset=-0.1)
    sp.specfit.plotresiduals(axis=sp.plotter.axis,
                             clear=False,
                             yoffset=ymin + 0.1,
                             label=False)
    sp.plotter.savefig("SN2009ip_UT" + str(date) + "_hdelta.png")
    print " ".join([
        "%15s" % x for x in ('Center Wavelength', 'Peak', 'Integral', 'FWHM')
    ])
    print " ".join([
        "%15g" % x
        for x in (sp.specfit.parinfo.SHIFT0.value,
                  (sp.data - sp.baseline.basespec)[sp.specfit.get_full_model(
                      add_baseline=False) > sp.error].max(),
                  sp.specfit.integral(direct=True),
                  sp.specfit.measure_approximate_fwhm(plot=True,
                                                      interpolate_factor=100))
    ])
Ejemplo n.º 6
0
def fit_hdelta(sp, date, xmin=3900,xmax=4300,ymin=0.8,ymax=1.405,
        #exclude=[3601,3846,3869.37,3913,3956,3984.59,4013.4,4045.81,4081.81,4117.82,4230,4396,4460,4482],
        exclude=[3600,4035,4089,4114,4150,4600],
        guesses=[0.1,ref_index.vac2air(pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerd']*1e3)*10,5,2],
        fittype='voigt'):

    sp.plotter(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax)
    sp.baseline(xmin=xmin, xmax=xmax, exclude=exclude, subtract=False,
        reset_selection=True, highlight_fitregion=True, order=1)
    sp.specfit(guesses=guesses,
            fittype=fittype)
    sp.specfit.xmin, sp.specfit.xmax = sp.specfit.get_model_xlimits()
    sp.specfit.parinfo.tableprint()
    sp.baseline.highlight_fitregion()
    sp.specfit.plot_components(add_baseline=True,component_yoffset=-0.1)
    sp.specfit.plotresiduals(axis=sp.plotter.axis,clear=False,yoffset=ymin+0.1,label=False)
    sp.plotter.savefig("SN2009ip_UT"+str(date)+"_hdelta.png")
    print " ".join(["%15s" % x for x in ('Center Wavelength','Peak','Integral','FWHM')])
    print " ".join(["%15g" % x for x in (sp.specfit.parinfo.SHIFT0.value, (sp.data-sp.baseline.basespec)[sp.specfit.get_full_model(add_baseline=False) > sp.error].max(),sp.specfit.integral(direct=True),sp.specfit.measure_approximate_fwhm(plot=True,interpolate_factor=100)) ])
Ejemplo n.º 7
0
def halpha(sp):
    #return pyspeckitmodels.hydrogen.hydrogen.wavelength['balmera'] * 1e4
    HA = ref_index.vac2air(pyspeckitmodels.hydrogen.hydrogen.wavelength['balmera']*1e3)
    return line(sp, 6562.7715) # NIST
    return line(sp, HA)
Ejemplo n.º 8
0
def brgamma(sp):
    #return pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerg'] * 1e4
    HG = ref_index.vac2air(pyspeckitmodels.hydrogen.hydrogen.wavelength['brackettg']*1e3)
    #return line(sp, 4340.471)
    return line(sp, HG)
Ejemplo n.º 9
0
def padelta(sp):
    #return pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerg'] * 1e4
    HG = ref_index.vac2air(pyspeckitmodels.hydrogen.hydrogen.wavelength['paschend']*1e3)
    #return line(sp, 4340.471)
    return line(sp, HG)
Ejemplo n.º 10
0
def hbeta(sp):
    #return pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerb'] * 1e4
    HB = ref_index.vac2air(pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerb']*1e3)
    return line(sp, 4861.128) # NIST
    return line(sp, HB)
Ejemplo n.º 11
0
def hgamma(sp):
    HG = ref_index.vac2air(
        pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerg'] * 1e3)
    return line(sp, 4340.471)
    return line(sp, HG)
Ejemplo n.º 12
0
def hbeta(sp):
    HB = ref_index.vac2air(
        pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerb'] * 1e3)
    return line(sp, 4861.128)  # NIST
    return line(sp, HB)
Ejemplo n.º 13
0
def halpha(sp):
    HA = ref_index.vac2air(
        pyspeckitmodels.hydrogen.hydrogen.wavelength['balmera'] * 1e3)
    return line(sp, 6562.7715)  # NIST
    return line(sp, HA)
Ejemplo n.º 14
0
def makemyplots(errstyle=None,units=None,xRange=200):
    spectra = ['UT120830_DIS.final.txt','UT120830_DIS.final.txt','UT121002_DIS.final.txt','UT121009_DIS.final.txt']

    eng_to_grk = {'g':'gamma',
            'a':'alpha',
            'b':'beta',
            'd':'delta'}

    figure(0); clf();

    rcParams['font.size']=18

    nx = len(spectra)
    ny = len(eng_to_grk)

    for ii,spname in enumerate(spectra):
        sp = pyspeckit.Spectrum(spname,skiplines=1,xarrkwargs={'xtype':'wavelength','unit':'angstroms'})
        if ii == 1:
            sp.data *= 10
            sp.error *= 10

        sp.baseline(order=5,highlight_fitregion=False, 
                exclude=[a  for x in [4101,4340,4863,5879,6562.8,6850,7067,7575] 
                    for a in [x-50,x+50]])

        sp.specname=spname[:8]
        if ii==1: sp.specname+="$\\times$10"
        sp.xarr.units='angstroms'
        sp.xarr.xtype='wavelength'
        sp.units = '10$^{-14}$ erg s$^{-1}$ cm$^{-2}$ $\\AA^{-1}$'

        for jj,line in enumerate(['a','b','g','d']):
            name = 'balmer'+line
            wavelength = pyspeckitmodels.hydrogen.wavelength[name]
            airwave = ref_index.vac2air(wavelength*1e3)*10

            sp.xarr.refX = airwave
            sp.xarr.refX_units = 'angstroms'
            if units is not None:
                sp.xarr.convert_to_unit(units)

            ax = subplot(ny,nx,ii+jj*ny+1)
            sp.plotter.axis=ax
            if units is None:
                sp.plotter(axis=ax,xmin=airwave-xRange/2, xmax=airwave+xRange/2,
                        offset=0.1*(jj==0), ymin=-0.1, errstyle=errstyle)
            elif units == 'Mm/s':
                sp.plotter(axis=ax,xmin=-xRange/2, xmax=+xRange/2,
                        offset=0.1*(jj==0), ymin=-0.1, errstyle=errstyle)

            print name,"y limits: ",sp.plotter.ymin,sp.plotter.ymax

            ax.set_ylabel('')
            ax.set_xlabel('')
            ax.yaxis.set_major_locator(MaxNLocator(5))
            ax.yaxis.set_tick_params(labelsize=14)
            ax.xaxis.set_major_locator(MaxNLocator(5))
            ax.xaxis.set_tick_params(labelsize=14)
            if ii != 0:
                ax.set_yticklabels([])
            else:
                ax.set_ylabel('H$\\'+eng_to_grk[line]+"$")
            if jj == 0:
                pass
                #sp.plotter.axis.set_ylabel('H$\\'+eng_to_grk[line]+"$\\n"+sp.units)
            else:
                sp.plotter.axis.set_title("")
            #if ii != 2:
            #    sp.plotter.axis.set_xticklabels([])

            if units is not None:
                sp.xarr.convert_to_unit('angstroms')
            
    for ii,spname in enumerate(spectra):
        for jj,line in enumerate(['a','b','g','d']):
            ax = subplot(ny,nx,ii+jj*nx+1)
            yl = subplot(ny,nx,(nx-1)+jj*nx+1).get_ylim()
            ax.set_ylim(-0.1,yl[1])

    tight_layout(pad=2.2,h_pad=0.175,w_pad=0)
    #subplots_adjust(hspace=0.175,wspace=0)
    figtext(0.03,0.5,sp.units,rotation='vertical',va='center',ha='center')
    if units is None:
        figtext(0.5,0.03,"Wavelength ($\\AA$)")
    elif units == 'Mm/s':
        figtext(0.5,0.03,"Velocity (1000 km s$^{-1}$)")


    if errstyle is not None:
        if units is not None:
            savefig('SN2009ip_hlines_grid_errbar_velocity.png')
            savefig('SN2009ip_hlines_grid_errbar_velocity.eps')
        else:
            savefig('SN2009ip_hlines_grid_errbar.png')
            savefig('SN2009ip_hlines_grid_errbar.eps')
    elif units is not None:
        savefig('SN2009ip_hlines_grid_velocity.png')
        savefig('SN2009ip_hlines_grid_velocity.eps')
    else:
        savefig('SN2009ip_hlines_grid.png')
        savefig('SN2009ip_hlines_grid.eps')
    show()
Ejemplo n.º 15
0
def brgamma(sp):
    #return pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerg'] * 1e4
    HG = ref_index.vac2air(
        pyspeckitmodels.hydrogen.hydrogen.wavelength['brackettg'] * 1e3)
    #return line(sp, 4340.471)
    return line(sp, HG)
Ejemplo n.º 16
0
def padelta(sp):
    #return pyspeckitmodels.hydrogen.hydrogen.wavelength['balmerg'] * 1e4
    HG = ref_index.vac2air(
        pyspeckitmodels.hydrogen.hydrogen.wavelength['paschend'] * 1e3)
    #return line(sp, 4340.471)
    return line(sp, HG)