示例#1
0
def BALnicity ( w, f, wline, norm_method = "SP", point=None):

	'''
	calculate the BALnicity index of a line
	
	:INPUT
		nu_line		float
					The frequency of the line at line centre
		
		nu_array		float
					array of frequencies
		
		spec_array	float
					array of intensities/fluxes
		
	:OUTPUT
		BALnicity index		float
		
	'''
	
	# we integrate over positive velocities as looking for blueshifted BALs

	# first we need to normalise to the continuum
	if norm_method == "fit":
		return -999
	elif norm_method == "SP":
		if point == None: 
			point = wline + 100.0
		norm = util.get_flux_at_wavelength( w, f, point)

	elif norm_method == "mean":
		p1 = util.get_flux_at_wavelength( w, f, point[0])
		p2 = util.get_flux_at_wavelength( w, f, point[0])
		norm = np.mean([p1, p2])
	

	fnorm = f / norm

	fv = 1 - (fnorm / 0.9)

	vel = C * (wline - w) / wline * 1e-5 	# velocity in KM/S

	constant = np.zeros(len(vel))
	for i, v in enumerate(vel):

		if v > 2000.0:
			if fnorm[i] < 0.9:
				select = (vel >= (v - 2000.0)) * (vel <= v)
				if fnorm[select].all() <= 0.9:
					constant[i] = 1.0

	integration_limits = (vel < 25000.) * (vel > 3000.)

	if np.sum(constant) == 0:
		return 0.0, norm

	BI = trapz(constant*fv[integration_limits], vel[integration_limits])	
	return BI, norm
示例#2
0
				for iedd in range(len(edd_frac)):

					mdot = mdot_from_edd(edd_frac[iedd], masses[im])

					

					pretty.set_pretty()

					for ispin in range(len(spin)):
						f2000 = []
						for ii in range(len(incs)):
							fname = "sp%i_inc%2i_mbh%i_edd%itminus2" % (int(spin[ispin]+0.5),incs[ii], np.log10(masses[im]), edd_frac[iedd]/0.01)

							w,f=read_agnspec(fname)

							ff = util.get_flux_at_wavelength(w,f,flambda_look)
							f2000.append(ff)
							#plot(w,f,label=incs[ii])
						if sys.argv[1] == "rel":
							plot(incs, f2000, linestyle=lstyles[ispin], c=set2[iedd], label="$\epsilon=%.2f$" % edd_frac[iedd])

						if spin[ispin] == 0 and edd_frac[iedd] == .2:
							fnorm = np.array(f2000)
				
				if masses[im] == 1e9 and flambda_look > 200 and flambda_look < 30000:
					s = r.read_spectrum('disk_only')
					f2000 = []

					for ii in range(len(incs)):
						f = s["A%iP0.50" % incs[ii]]
示例#3
0
def make_spec_plot(s,
                   fname,
                   smooth_factor=10,
                   angles=True,
                   components=False,
                   with_composite=False):
    '''
    make a spectrum plot from astropy.table.table.Table object 

    Parameters
    ----------
    s: astropy.table.table.Table
        table containing spectrum data outputted from Python 

    fname: str 
        filename to save as e.g. sv

    smooth_factor: int 
        factor you would like to smooth by, default 10

    angles: Bool 
        Would you like to plot the viewing angle spectra? 

    components: Bool 
        would you like to plot the individual components e.g. Disk Wind 
    
    Returns
    ----------
    Success returns 0
    Failure returns 1

    Saves output as "spectrum_%s.png" % (fname)
    '''

    if type(s) != astropy.table.table.Table:
        raise TypeError(
            "make_spec_plot takes astropy.table.table.Table object as first arg"
        )
        return 1

    if s.colnames[8] != "Scattered":
        print("Warning- colnames are not in expected order! {} != Scattered".
              format(s.colnames[8]))

    ncomponents = 9

    if angles:

        # first make viewing angle plot
        p.figure(figsize=(8, 12))

        nspecs = len(s.dtype.names) - ncomponents

        nx = 1
        ny = nspecs
        if nspecs > 4:
            nx = 2
            ny = (1 + nspecs) / nx

        print("Making a {} by {} plot, {} spectra".format(nx, ny, nspecs))

        if with_composite:
            lambda_composite, f_composite, errors = np.loadtxt(
                "%s/examples/telfer_qso_composite_hst.asc" %
                (os.environ["PYTHON"]),
                unpack=True,
                comments="#")

        for i in range(nspecs):

            p.subplot(ny, nx, i + 1)

            if with_composite:
                f_1100 = util.get_flux_at_wavelength(
                    s["Lambda"], s[s.dtype.names[ncomponents + i]], 1100.0)
                p.plot(s["Lambda"],
                       util.smooth(s[s.dtype.names[ncomponents + i]] / f_1100,
                                   window_len=smooth_factor),
                       label="Model")
                p.plot(lambda_composite, f_composite, label="HST composite")
                p.legend()

            else:
                p.plot(
                    s["Lambda"],
                    util.smooth(s[s.dtype.names[ncomponents + i]],
                                window_len=smooth_factor))

            p.title(s.dtype.names[ncomponents + i])
            p.xlabel("Wavelength")
            p.ylabel("Flux")

        p.savefig("spectrum_%s.png" % (fname), dpi=300)
        p.clf()

    if components:

        p.figure(figsize=(8, 12))
        p.subplot(211)
        p.plot(s["Lambda"],
               util.smooth(s["Created"], window_len=smooth_factor),
               label="Created")
        p.plot(s["Lambda"],
               util.smooth(s["Emitted"], window_len=smooth_factor),
               label="Emitted")
        p.legend()

        p.subplot(212)

        for i in range(4, 9):
            p.plot(s["Lambda"],
                   util.smooth(s[s.dtype.names[i]], window_len=smooth_factor),
                   label=s.dtype.names[i])

        p.xlabel("Wavelength")
        p.ylabel("Flux")
        p.legend()

        p.savefig("spec_components_%s.png" % (fname), dpi=300)
        p.clf()

    return 0
示例#4
0
labels = ["LINER", "Quasar", "Sy 1", "Sy 2"]

fnames = ["liner_template.ascii",
           "qso_template.ascii","seyfert1_template.ascii",
           "seyfert2_template.ascii"]

figure(figsize=(10,14))
big_tick_labels(18)

for i, f in enumerate(fnames):

	subplot(4,1,i+1)

	w,flux = np.loadtxt(f, unpack=True)

	fnorm = util.get_flux_at_wavelength(w,flux,2000)

	plot(w,flux/fnorm, label=labels[i], linewidth=3, c='k')
	xlim(1000,7000)
	ylim(0.05,100.0)
	semilogy()

	#float_legend()
	text(6000,10,labels[i], fontsize=24)

	if i < 3:
		gca().set_xticklabels([])

	if i == 2:
		text(400,100,"$F / F_{2000}$", fontsize=24, rotation="vertical")