コード例 #1
0
def fit_rotcur(galaxy, vmode):
    try:

        data = fits.getdata("./fits/%s.%s_model.fits" % (galaxy, vmode))

        R = data[0]
        V = data[1]
        mask = V > 5
        R = R[mask]
        V = V[mask]
        min_vel, max_vel = int(np.nanmin(V)), int(np.nanmax(V))
        temp = []
        v_max_temp = []
        R_turn_temp = []
        for i in model:
            best_params = fit_RC(R, V, i)
            data = best_params[:-1]
            Vmax, Rturn = data[0], data[1]
            if Vmax > 340: Vmax = 0
            if Vmax == 0: Vmax = np.nan
            temp.append(Vmax)
            temp.append(Rturn)
            v_max_temp.append(Vmax)
            R_turn_temp.append(Rturn)

            ax.plot(R, V, "k-")
            ax.plot(R, V, "ks")
            ax.plot(R, best_params[-1], label=i)

        mean_V, median_V, std_V = np.nanmedian(v_max_temp), np.nanmean(
            v_max_temp), np.nanstd(v_max_temp)
        mean_R, median_R, std_R = np.nanmedian(R_turn_temp), np.nanmean(
            R_turn_temp), np.nanstd(R_turn_temp)
        table = [
            galaxy, temp[0], temp[1], temp[2], temp[3], temp[4], temp[5],
            temp[6], temp[7], temp[8], temp[9], temp[10], temp[11], mean_V,
            median_V, std_V, mean_R, median_R, std_R
        ]
        write(table, "manga_vmax_velfit_1.5.%s.csv" % vmode, column=False)

        plt.legend(fontsize="xx-small")
        ax.set_xlabel("r (arcsec)", fontsize=12, labelpad=0)
        ax.set_ylabel('V$_\mathrm{ROT}$ (km/s)', fontsize=12, labelpad=0)
        ax.set_ylim(-50, max_vel + 50)
        AXIS(ax)
        plt.savefig("./vmax_rturn/%s.fit_rotcur.%s.png" % (galaxy, vmode),
                    dpi=300)
        #plt.show()
        plt.cla()
        return median_V, median_R

    except (IOError, OSError):
        table = [galaxy, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        write(table, "manga_vmax_velfit_1.5.%s.csv" % vmode, column=False)
        return 1, 1
        pass
コード例 #2
0
def plot_kin_models(galaxy,
                    vmode,
                    vel_ha,
                    R,
                    Vrot,
                    eVrot,
                    Vrad,
                    eVrad,
                    Vtan,
                    eVtan,
                    VSYS,
                    MODEL,
                    ext,
                    plot=0,
                    save=1):
    e1, e2, e3 = len(eVrot[0]), len(eVrad[0]), len(eVtan[0])

    mask_MODEL = np.divide(MODEL, MODEL)
    MODEL_copy = np.copy(MODEL - VSYS)
    MODEL = MODEL * np.divide(vel_ha, vel_ha)
    MODEL = MODEL - VSYS
    vel_ha = vel_ha - VSYS
    fig = plt.figure(figsize=(6, 2))
    gs2 = GridSpec(1, 3)
    gs2.update(left=0.045,
               right=0.62,
               top=0.815,
               hspace=0.01,
               bottom=0.135,
               wspace=0.)

    ax = plt.subplot(gs2[0, 0])
    ax1 = plt.subplot(gs2[0, 1])
    ax2 = plt.subplot(gs2[0, 2])

    #cmap = plt.cm.get_cmap('bwr')
    #cmap = c_map.reversed()

    vmin = abs(np.nanmin(MODEL))
    vmax = abs(np.nanmax(MODEL))
    max_vel = np.nanmax([vmin, vmax])

    vmin = -(max_vel // 50 + 1) * 50
    vmax = (max_vel // 50 + 1) * 50

    im0 = ax.imshow(vel_ha,
                    cmap=cmap,
                    origin="lower",
                    vmin=vmin,
                    vmax=vmax,
                    aspect="auto",
                    extent=ext,
                    interpolation="nearest")
    im1 = ax1.imshow(MODEL_copy,
                     cmap=cmap,
                     origin="lower",
                     aspect="auto",
                     vmin=vmin,
                     vmax=vmax,
                     extent=ext,
                     interpolation="nearest")

    residual = (vel_ha - MODEL)
    im2 = ax2.imshow(residual,
                     cmap=cmap,
                     origin="lower",
                     aspect="auto",
                     vmin=-50,
                     vmax=50,
                     extent=ext,
                     interpolation="nearest")

    AXIS(ax, tickscolor="k")
    AXIS(ax1, tickscolor="k", remove_yticks=True)
    AXIS(ax2, tickscolor="k", remove_yticks=True)

    ax.set_ylabel('$\mathrm{ \Delta Dec~(pix)}$', fontsize=8, labelpad=0)
    ax.set_xlabel('$\mathrm{ \Delta RA~(pix)}$', fontsize=8, labelpad=0)
    ax1.set_xlabel('$\mathrm{ \Delta RA~(pix)}$', fontsize=8, labelpad=0)
    ax2.set_xlabel('$\mathrm{ \Delta RA~(pix)}$', fontsize=8, labelpad=0)

    ax.text(0.05, 1.01, "$\mathrm{vlos}$", fontsize=7, transform=ax.transAxes)
    ax1.text(0.05,
             1.01,
             "$\mathrm{model}$",
             fontsize=7,
             transform=ax1.transAxes)
    ax2.text(0.05,
             1.01,
             "$\mathrm{residual}$",
             fontsize=7,
             transform=ax2.transAxes)

    #ax.set_facecolor('#e8ebf2')
    #ax1.set_facecolor('#e8ebf2')
    #ax2.set_facecolor('#e8ebf2')

    gs2 = GridSpec(1, 1)
    gs2.update(left=0.68, right=0.995, top=0.815, bottom=0.135)
    ax3 = plt.subplot(gs2[0, 0])

    #from plot_simulated_model import plot_true
    #plot_true(galaxy,vmode,ax3)

    if vmode == "circular":
        ax3.plot(R,
                 Vrot,
                 color="k",
                 linestyle='-',
                 alpha=0.6,
                 linewidth=0.8,
                 label="$\mathrm{V_{t}}$")

        if e1 > 0:
            ax3.errorbar(R,
                         Vrot,
                         yerr=[eVrot[0], eVrot[1]],
                         fmt='o',
                         color="k",
                         markersize=1,
                         elinewidth=0.6,
                         capsize=1.5)
            ax3.fill_between(R,
                             Vrot - eVrot[0],
                             Vrot + eVrot[1],
                             color="darkgray",
                             alpha=0.4)
            #error_bar(ax3,R,Vrot, eVrot[0],eVrot[1],color = "y")

    if vmode == "radial":

        ax3.plot(R,
                 Vrot,
                 color="k",
                 linestyle='-',
                 alpha=0.6,
                 linewidth=0.8,
                 label="$\mathrm{V_{t}}$")

        if e1 > 0:
            ax3.errorbar(R,
                         Vrot,
                         yerr=[eVrot[0], eVrot[1]],
                         fmt='o',
                         color="k",
                         markersize=1.5,
                         elinewidth=0.6,
                         capsize=1.5)
            ax3.fill_between(R,
                             Vrot - eVrot[0],
                             Vrot + eVrot[1],
                             color="darkgray",
                             alpha=0.4)
            #error_bar(ax3,R,Vrot, eVrot[0],eVrot[1],color = "darkgray")

        ax3.plot(R,
                 Vrad,
                 color="orange",
                 linestyle='-',
                 alpha=0.6,
                 linewidth=0.8,
                 label="$\mathrm{V_{r}}$")
        if e2 > 0:
            ax3.errorbar(R,
                         Vrad,
                         yerr=[eVrad[0], eVrad[1]],
                         fmt='o',
                         color="k",
                         markersize=1.5,
                         elinewidth=0.6,
                         capsize=1.5)
            ax3.fill_between(R,
                             Vrad - eVrad[0],
                             Vrad + eVrad[1],
                             color="orange",
                             alpha=0.4)
            #error_bar(ax3,R,Vrad, eVrad[0],eVrad[1],color = "darkorange")

    if vmode == "bisymmetric":
        ax3.plot(R,
                 Vrot,
                 color="k",
                 linestyle='-',
                 alpha=0.6,
                 linewidth=0.8,
                 label="$\mathrm{V_{t}}$")

        if e1 > 0:
            ax3.errorbar(R,
                         Vrot,
                         yerr=[eVrot[0], eVrot[1]],
                         fmt='o',
                         color="k",
                         markersize=1.5,
                         elinewidth=0.6,
                         capsize=1.5)
            ax3.fill_between(R,
                             Vrot - eVrot[0],
                             Vrot + eVrot[1],
                             color="darkgray",
                             alpha=0.4)

        ax3.plot(R,
                 Vrad,
                 color="orange",
                 linestyle='-',
                 alpha=0.6,
                 linewidth=0.8,
                 label="$\mathrm{V_{2,r}}$")

        if e2 > 0:
            ax3.errorbar(R,
                         Vrad,
                         yerr=[eVrad[0], eVrad[1]],
                         fmt='o',
                         color="orange",
                         markersize=1.5,
                         elinewidth=0.6,
                         capsize=1.5)
            ax3.fill_between(R,
                             Vrad - eVrad[0],
                             Vrad + eVrad[1],
                             color="orange",
                             alpha=0.4)

        ax3.plot(R,
                 Vtan,
                 color="skyblue",
                 linestyle='-',
                 alpha=0.6,
                 linewidth=0.8,
                 label="$\mathrm{V_{2,t}}$")

        if e3 > 0:
            ax3.errorbar(R,
                         Vtan,
                         yerr=[eVtan[0], eVtan[1]],
                         fmt='o',
                         color="dodgerblue",
                         markersize=1.5,
                         elinewidth=0.6,
                         capsize=1.5)
            ax3.fill_between(R,
                             Vtan - eVtan[0],
                             Vtan + eVtan[1],
                             color="dodgerblue",
                             alpha=0.4)

    ax3.legend(loc="center",
               fontsize=6.5,
               bbox_to_anchor=(0, 1, 1, 0.1),
               ncol=3,
               frameon=False)

    vels = [Vrot, Vrad, Vtan]
    max_vel, min_vel = int(np.nanmax(vels)), int(np.nanmin(vels))
    min_vel = abs(min_vel)

    #ax3.set_ylim(min_vel-50,max_vel+50)
    ax3.set_ylim(-50 * (min_vel // 50) - 50, 50 * (max_vel // 50) + 80)
    ax3.plot([0, np.nanmax(R)], [0, 0],
             color="k",
             linestyle='-',
             alpha=0.6,
             linewidth=0.5)
    ax3.set_xlabel('$\mathrm{r~(arcsec)}$', fontsize=8, labelpad=0)
    ax3.set_ylabel('$\mathrm{V_{rot}~(km~s^{-1})}$', fontsize=8, labelpad=0)
    ax3.set_facecolor('#e8ebf2')

    AXIS(ax3, tickscolor="k")

    # Make a plot with major ticks that are multiples of 10 and minor ticks that
    # are multiples of 5.  Label major ticks with '%d' formatting but don't label
    # minor ticks.
    if np.nanmax(R) // 10 > 1:
        ax3.xaxis.set_major_locator(MultipleLocator(10))
        ax3.xaxis.set_major_formatter(FormatStrFormatter('%d'))
        # For the minor ticks, use no labels; default NullFormatter.
        ax3.xaxis.set_minor_locator(MultipleLocator(2))
    else:
        ax3.xaxis.set_major_locator(MultipleLocator(2))
        ax3.xaxis.set_major_formatter(FormatStrFormatter('%d'))
        # For the minor ticks, use no labels; default NullFormatter.
        ax3.xaxis.set_minor_locator(MultipleLocator(1))

    if np.nanmax(R) // 100 > 1:
        ax3.xaxis.set_major_locator(MultipleLocator(200))
        ax3.xaxis.set_major_formatter(FormatStrFormatter('%d'))
        # For the minor ticks, use no labels; default NullFormatter.
        ax3.xaxis.set_minor_locator(MultipleLocator(100))

    if np.nanmax(Vrot) // 100 > 1:
        ax3.yaxis.set_major_locator(MultipleLocator(100))
        ax3.yaxis.set_major_formatter(FormatStrFormatter('%d'))
        # For the minor ticks, use no labels; default NullFormatter.
        ax3.yaxis.set_minor_locator(MultipleLocator(20))
    else:
        ax3.yaxis.set_major_locator(MultipleLocator(50))
        ax3.yaxis.set_major_formatter(FormatStrFormatter('%d'))
        # For the minor ticks, use no labels; default NullFormatter.
        ax3.yaxis.set_minor_locator(MultipleLocator(25))

    cb(im1,
       ax,
       orientation="horizontal",
       colormap=cmap,
       bbox=(0.5, 1.135, 1, 1),
       width="100%",
       height="5%",
       label_pad=-17,
       label="$\mathrm{(km~s^{-1})}$",
       font_size=6)
    cb(im2,
       ax2,
       orientation="horizontal",
       colormap=cmap,
       bbox=(0, 1.135, 1, 1),
       width="100%",
       height="5%",
       label_pad=-17,
       label="$\mathrm{(km~s^{-1})}$",
       font_size=6)

    if save == 1 and plot == 1:
        plt.savefig("./plots/kin_%s_model_%s.png" % (vmode, galaxy), dpi=300)
        plt.show()
        plt.clf()
    else:

        if plot == 1:
            plt.show()
            plt.clf()
        if save == 1:
            plt.savefig("./plots/kin_%s_model_%s.png" % (vmode, galaxy),
                        dpi=300)
            plt.clf()
コード例 #3
0
def fit_rotcur(galaxy,vmode,e_Vrot,survey):
	try:

		data = fits.getdata("./fits/%s.%s_model.fits"%(galaxy,vmode))

		R = data[0]
		V = data[1]
		R_plot = np.linspace(0.1,np.nanmax(R),100)

		min_vel,max_vel = int(np.nanmin(V)),int(np.nanmax(V))
		temp = []
		v_max_temp = []
		R_turn_temp = []
		
		for_table = [galaxy]

		for i in model:
			best_params = fit_RC(R,V,i)
			data = best_params[:-1]
			Vmax,Rturn = data[0],data[1]
			if Vmax > 340: Vmax = 0 
			if Vmax == 0: Vmax = np.nan 
			temp.append(Vmax)
			temp.append(Rturn)

			for_table.append(Vmax)
			for_table.append(Rturn)
			v_max_temp.append(Vmax)
			R_turn_temp.append(Rturn)

			ax.plot(R,V,"k-",alpha = 0.6, linewidth=0.8,zorder = 100)
			ax.scatter(R,V, marker='s', c = "k",s = 5,zorder = 100)
			ax.fill_between(R, V-e_Vrot[0], V+e_Vrot[1], color = "deepskyblue", alpha = 0.4)
			ax.plot(R_plot,best_params[-1],label = i,linewidth=0.5)


		#The average values for Vmax and Rturn
		mean_Vmax,median_Vmax,std_Vmax = np.nanmedian(v_max_temp),np.nanmean(v_max_temp),np.nanstd(v_max_temp)
		mean_Rt,median_Rt,std_Rt = np.nanmedian(R_turn_temp),np.nanmean(R_turn_temp),np.nanstd(R_turn_temp)

		for_table.extend([mean_Vmax,median_Vmax,std_Vmax,mean_Rt,median_Rt,std_Rt])
		table = for_table



		if survey != "":
			table_name = "vmax_out_params.%s_model.%s.csv"%(vmode,survey) 
			#write(table,table_name,column = False)
		else:
			table_name = "vmax_out_params.%s_model.%s.csv"%(vmode,galaxy) 




		# write header of table
		if path.exists(table_name) == True:
			pass
		else:
			hdr = ["object"]
			for i in model: hdr.extend(["Vmax_%s_model"%(i), "Rturn_%s_model"%(i)])
			hdr.extend(["mean_Vmax","median_Vmax","std_Vmax","mean_Rt","median_Rt","std_Rt"])
			write(hdr,table_name,column = False)


		write(table,table_name,column = False)

		plt.legend( fontsize = "xx-small")
		ax.set_xlabel("$\mathrm{r~(arcsec)}$", fontsize = 8,labelpad = 0)
		ax.set_ylabel("$\mathrm{V_{rot}~(km~s^{-1})}$",fontsize=8,labelpad = 0)
		ax.set_ylim(-50,max_vel+50)
		AXIS(ax)
		plt.savefig("./vmax_rturn/%s.fit_rotcur.%s.png"%(galaxy,vmode),dpi = 300)
		#plt.show()
		plt.cla()
		return median_Vmax,median_Rt

	except(IOError, OSError):
		table = [galaxy, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
		if survey != "":
			write(table,"vmax_out_params.%s_model.%s.csv"%(vmode,survey),column = False)
		else:
			write(table,"vmax_out_params.%s_model.%s.csv"%(vmode,galaxy),column = False)

		return 1,1	
		pass
コード例 #4
0
def rotcur(galaxy, z_star, PA, INC, X0, Y0):

    p1, p2 = [pos for pos, char in enumerate(galaxy) if char == "-"]
    direc = galaxy[p1 + 1:p2]

    hdu0 = fits.open("%s/%s/%s.Pipe3D.cube.fits.gz" % (path, direc, galaxy))
    #data_extensions = hdu0[2].data
    data = hdu0[3].data
    hdr = hdu0[0].header
    pixel_size = abs(hdr["CD2_2"] * 3600)

    [nz, ny, nx] = data.shape
    ext = [nx / 2., -nx / 2, -ny / 2., ny / 2.]

    ha_flux = data[45]
    e_ha = data[249]

    mask_SN = SN(ha_flux, e_ha, 5)
    M_ones = np.ones((ny, nx)) * mask_SN
    mask_good = np.ones((ny, nx)) * mask_SN

    for i in range(nx):
        for j in range(ny):
            check_ones = M_ones[j - 1:j + 2, i - 1:i + 2]
            not_ones = np.nansum(check_ones)
            if not_ones >= 7:
                mask_good[j][i] = 1
            else:
                mask_good[j][i] = np.nan

    if vel == "gas":
        vel_ha = data[102]
        e_vel_ha = data[330]

        #hdu = fits.open("%s/%s.ELINES.cube.fits.gz"%(path,galaxy))
        #data = hdu[0].data
        #vel_ha =data[0]
        #e_vel_ha =data[0]

    if vel == "stars":
        e_vel_ha = data[300]
        hdu = fits.open("%s/%s.SSP.cube.fits.gz" % (path, galaxy))
        ssp = hdu[0].data
        #ssp = pyfits.getdata("./CALIFA/dataproducts/%s.SSP.cube.fits.gz"%galaxy)
        vel_ha = ssp[13]
        #e_vel_ha= ssp[14]

    e_vel_ha[e_vel_ha > 10] = np.nan
    mask_vel = np.divide(e_vel_ha, e_vel_ha)

    vel_ha = vel_ha * mask_vel
    vel_ha[vel_ha == 0] = np.nan

    XK, YK, VSYS, e_vsys = KC(vel_ha, X0, Y0)
    VSYS = z_star * c
    """
	print ("...................................................................................................")
	print ("..............................%s............................................................"%galaxy)
	print ("........................Examine initial values: ...................................................")
	print ("Guess : PA,INC,X0,Y0:", PA,INC,XK,YK,VSYS)
	print ("...................................................................................................")

	print ("...................................................................................................")
	print ("................... step 1: All free parameters: estiamate X0,Y0, Vsys ..........................." )
	print ("...................................................................................................")
	"""

    nrings = int(36)
    guess = [50, 10, PA, INC, XK, YK, VSYS]
    vary = [True, True, True, True, False, False, True]
    mode_ring = ["pixel", "arcsec", "broad"]
    mode_ring = ["pixel"]

    def first():
        pa, r, x0, y0, vsys = [], [], [], [], []
        pa2, inc2, x02, y02, vsys2 = [], [], [], [], []

        delta_arcsec = int(2 / 1)
        median_pa, median_inc, median_vsys, sigma_pa, sigma_inc, sigma_vsys, R, vrot, vrad, model = RC_sigma(
            vel_ha,
            e_vel_ha,
            nrings,
            guess,
            vary,
            delta=delta_arcsec,
            ring="pixel",
            mode="bisymetric",
            iter=1,
            model=True,
            pixel_scale=pixel_size)

        return median_pa, median_inc, median_vsys, sigma_pa, sigma_inc, sigma_vsys, R, vrot, vrad, model

    median_pa, median_inc, median_vsys, sigma_pa, sigma_inc, sigma_vsys, R, vrot, vr2, model = first(
    )

    def sec():
        vary = [True, True, True, True, False, False, True]
        guess = [60, 0, median_pa, median_inc, XK, YK, median_vsys]
        sigma = [0, 0, 2 * sigma_pa, 2 * sigma_inc, 0, 0, 2 * sigma_vsys]
        delta_arcsec = int(2 / 1)

        vr_e, vr20_e, pa_e, inc_e, vsys_e = RC_sigma_rnd2(
            vel_ha,
            e_vel_ha,
            nrings,
            guess,
            vary,
            sigma,
            mode="bisymetric",
            delta=delta_arcsec,
            ring="pixel",
            iter=10,
            ring_position=R,
            pixel_scale=pixel_size)
        return vr_e, vr20_e, pa_e, inc_e, vsys_e

    def emcee():
        vary = [True, True, True, True, False, False, True]
        guess = [60, 0, pa_med, inc_med, XK, YK, vsys_med]
        sigma = [0, 0, 5 * e_pa, 5 * e_inc, 0, 0, 5 * e_vsys]
        delta_arcsec = int(2 / 1)

        print("sigma:", sigma)

        a = RC_emcee(vel_ha,
                     e_vel_ha,
                     nrings,
                     guess,
                     vary,
                     sigma,
                     mode="bisymetric",
                     delta=delta_arcsec,
                     ring="pixel",
                     iter=5,
                     pixel_scale=pixel_size)
        return a

    #c = emcee()

    e_vr, e_vr2, e_pa, e_inc, e_vsys = sec()

    mask_model = np.divide(model, model)
    fig = plt.figure(figsize=(6, 2))
    gs2 = GridSpec(1, 3)
    gs2.update(left=0.06,
               right=0.62,
               top=0.83,
               hspace=0.01,
               bottom=0.15,
               wspace=0.)

    ax = plt.subplot(gs2[0, 0])
    ax1 = plt.subplot(gs2[0, 1])
    ax2 = plt.subplot(gs2[0, 2])

    im0 = ax.imshow(vel_ha - median_vsys,
                    cmap=califa,
                    origin="l",
                    vmin=-250,
                    vmax=250,
                    aspect="auto",
                    extent=ext,
                    interpolation="nearest")
    im2 = ax1.imshow(model,
                     cmap=califa,
                     origin="l",
                     aspect="auto",
                     vmin=-250,
                     vmax=250,
                     extent=ext,
                     interpolation="nearest")

    residual = (vel_ha * mask_model - median_vsys) - model
    im2 = ax2.imshow(residual,
                     cmap=califa,
                     origin="l",
                     aspect="auto",
                     vmin=-50,
                     vmax=50,
                     extent=ext,
                     interpolation="nearest")

    AXIS(ax, tickscolor="k")
    AXIS(ax1, tickscolor="k", remove_yticks=True)
    AXIS(ax2, tickscolor="k", remove_yticks=True)

    ax.set_ylabel(r'$\Delta$ Dec (pix)', fontsize=8, labelpad=0)
    ax.set_xlabel(r'$\Delta$ RA (pix)', fontsize=8, labelpad=0)
    ax1.set_xlabel(r'$\Delta$ RA (pix)', fontsize=8, labelpad=0)
    ax2.set_xlabel(r'$\Delta$ RA (pix)', fontsize=8, labelpad=0)

    ax.text(0.05, 0.9, "VLOS", fontsize=7, transform=ax.transAxes)
    ax1.text(0.05, 0.9, "MODEL", fontsize=7, transform=ax1.transAxes)
    ax2.text(0.05, 0.9, "RESIDUAL", fontsize=7, transform=ax2.transAxes)

    ax.set_facecolor('#e8ebf2')
    ax1.set_facecolor('#e8ebf2')
    ax2.set_facecolor('#e8ebf2')

    gs2 = GridSpec(1, 1)
    gs2.update(left=0.68, right=0.995, top=0.83, bottom=0.15)
    ax3 = plt.subplot(gs2[0, 0])

    ax3.errorbar(R, vrot, yerr=e_vr, fmt='s', color="k", markersize=3)
    ax3.plot(R, vrot, color="k", linestyle='-', alpha=0.6)

    ax3.plot(R, vr2, color="skyblue", linestyle='-', alpha=0.6)
    ax3.errorbar(R, vr2, yerr=e_vr2, fmt='s', color="skyblue", markersize=3)

    #ax3.set_ylim(-50,300)
    ax3.set_ylim(int(np.nanmin(vr2)) - 20, int(np.nanmax(vrot)) + 20)
    ax3.plot([0, np.nanmax(R)], [0, 0], color="k", linestyle='-', alpha=0.6)
    ax3.set_xlabel('r (arcsec)', fontsize=8, labelpad=0)
    ax3.set_ylabel('V$_\mathrm{ROT}$ (km/s)', fontsize=8, labelpad=0)
    ax3.set_facecolor('#e8ebf2')

    AXIS(ax3, tickscolor="k")

    cb(im0,
       ax,
       orientation="horizontal",
       colormap=califa,
       bbox=(0, 1.12, 1, 1),
       width="100%",
       height="5%",
       label_pad=-23,
       label="(km/s)",
       font_size=7)
    cb(im2,
       ax2,
       orientation="horizontal",
       colormap=califa,
       bbox=(0, 1.12, 1, 1),
       width="100%",
       height="5%",
       label_pad=-23,
       label="(km/s)",
       font_size=7)
    plt.savefig("./plots/kin_model_%s.png" % galaxy, dpi=300)
    #plt.savefig("./kin_model_%s.pdf"%galaxy)
    plt.clf()
    #plt.show()

    try:
        from fit_rotcurve import Rturn_Vmax
        vmax, r_turn, beta, gamma = Rturn_Vmax(R, vrot)

        def vrot_fit(r_sky, v_max, R_turn, beta, gamma):

            x = R_turn / r_sky
            A = (1 + x)**beta
            B = (1 + x**gamma)**(1. / gamma)
            v = v_max * A / B

            return v

        fig = plt.figure(figsize=(2.5, 2.5))
        ax = plt.subplot(111)
        ax.scatter(R, vrot, s=10, marker="o", c="k")
        ax.plot(R, vrot_fit(R, vmax, r_turn, beta, gamma), "b-", alpha=0.3)
        AXIS(ax, tickscolor="k")
        ax.set_xlabel('r (arcsec)', fontsize=8, labelpad=0)
        ax.set_ylabel('V$_\mathrm{ROT}$ (km/s)', fontsize=8, labelpad=0)
        ax.set_ylim(-5, int(np.nanmax(vrot)) + 20)
        ax.set_facecolor('#e8ebf2')
        plt.savefig("./vflat/vflat_r_turn_%s.png" % galaxy, dpi=300)
        #plt.savefig("./vflat_rotcur_%s.pdf"%galaxy)
        plt.clf()
        #plt.show()
        return galaxy, XK, YK, median_pa, sigma_pa, median_inc, sigma_inc, median_vsys, sigma_vsys, vmax, r_turn, beta, gamma
    except (1):
        return galaxy, XK, YK, median_pa, sigma_pa, median_inc, sigma_inc, median_vsys, sigma_vsys, 0, 0, 0, 0
コード例 #5
0
ファイル: plot_models.py プロジェクト: CarlosCoba/pyVELFIT
def plot_kin_models(galaxy,
                    vmode,
                    vel_ha,
                    R,
                    Vrot,
                    Vrad,
                    Vtan,
                    VSYS,
                    MODEL,
                    ext,
                    plot=0,
                    save=1):

    mask_MODEL = np.divide(MODEL, MODEL)
    fig = plt.figure(figsize=(6, 2))
    gs2 = GridSpec(1, 3)
    gs2.update(left=0.06,
               right=0.62,
               top=0.83,
               hspace=0.01,
               bottom=0.15,
               wspace=0.)

    ax = plt.subplot(gs2[0, 0])
    ax1 = plt.subplot(gs2[0, 1])
    ax2 = plt.subplot(gs2[0, 2])

    im0 = ax.imshow(vel_ha - VSYS,
                    cmap=califa,
                    origin="lower",
                    vmin=-250,
                    vmax=250,
                    aspect="auto",
                    extent=ext,
                    interpolation="nearest")
    im2 = ax1.imshow(MODEL,
                     cmap=califa,
                     origin="lower",
                     aspect="auto",
                     vmin=-250,
                     vmax=250,
                     extent=ext,
                     interpolation="nearest")

    residual = (vel_ha * mask_MODEL - VSYS) - MODEL
    im2 = ax2.imshow(residual,
                     cmap=califa,
                     origin="lower",
                     aspect="auto",
                     vmin=-50,
                     vmax=50,
                     extent=ext,
                     interpolation="nearest")

    AXIS(ax, tickscolor="k")
    AXIS(ax1, tickscolor="k", remove_yticks=True)
    AXIS(ax2, tickscolor="k", remove_yticks=True)

    ax.set_ylabel(r'$\Delta$ Dec (pix)', fontsize=8, labelpad=0)
    ax.set_xlabel(r'$\Delta$ RA (pix)', fontsize=8, labelpad=0)
    ax1.set_xlabel(r'$\Delta$ RA (pix)', fontsize=8, labelpad=0)
    ax2.set_xlabel(r'$\Delta$ RA (pix)', fontsize=8, labelpad=0)

    ax.text(0.05, 0.9, "VLOS", fontsize=7, transform=ax.transAxes)
    ax1.text(0.05, 0.9, "MODEL", fontsize=7, transform=ax1.transAxes)
    ax2.text(0.05, 0.9, "RESIDUAL", fontsize=7, transform=ax2.transAxes)

    ax.set_facecolor('#e8ebf2')
    ax1.set_facecolor('#e8ebf2')
    ax2.set_facecolor('#e8ebf2')

    gs2 = GridSpec(1, 1)
    gs2.update(left=0.68, right=0.995, top=0.83, bottom=0.15)
    ax3 = plt.subplot(gs2[0, 0])

    ax3.plot(R,
             Vrot,
             color="k",
             linestyle='-',
             alpha=0.6,
             label="V$_\mathrm{circ}$")
    ax3.scatter(R, Vrot, color="k", s=5, marker="s")
    #ax3.errorbar(R,Vrot, yerr=e_vr, fmt='s', color = "k",markersize = 3, label = "V_\mathrm{circ}")

    ax3.plot(R,
             Vrad,
             color="orange",
             linestyle='-',
             alpha=0.6,
             label="V$_\mathrm{rad}$")
    ax3.scatter(R, Vrad, color="orange", s=5, marker="s")
    #ax3.errorbar(R,Vrad, yerr=e_Vrad, fmt='s', color = "orange",markersize = 3)

    ax3.plot(R,
             Vtan,
             color="skyblue",
             linestyle='-',
             alpha=0.6,
             label="V$_\mathrm{tan}$")
    ax3.scatter(R, Vtan, color="skyblue", s=5, marker="s")
    #ax3.errorbar(R,Vtan, yerr=e_Vtan, fmt='s', color = "skyblue",markersize = 3)

    ax3.legend(loc="center",
               fontsize=6.5,
               bbox_to_anchor=(0, 1, 1, 0.1),
               ncol=3,
               frameon=False)

    vels = [Vrot, Vrad, Vtan]
    max_vel, min_vel = int(np.nanmax(vels)), int(np.nanmin(vels))

    ax3.set_ylim(min_vel - 50, max_vel + 50)
    ax3.plot([0, np.nanmax(R)], [0, 0], color="k", linestyle='-', alpha=0.6)
    ax3.set_xlabel('r (arcsec)', fontsize=8, labelpad=0)
    ax3.set_ylabel('V$_\mathrm{ROT}$ (km/s)', fontsize=8, labelpad=0)
    ax3.set_facecolor('#e8ebf2')

    AXIS(ax3, tickscolor="k")

    cb(im0,
       ax,
       orientation="horizontal",
       colormap=califa,
       bbox=(0, 1.12, 1, 1),
       width="100%",
       height="5%",
       label_pad=-23,
       label="(km/s)",
       font_size=7)
    cb(im2,
       ax2,
       orientation="horizontal",
       colormap=califa,
       bbox=(0, 1.12, 1, 1),
       width="100%",
       height="5%",
       label_pad=-23,
       label="(km/s)",
       font_size=7)

    if save == 1 and plot == 1:
        plt.savefig("./plots/kin_%s_model_%s.png" % (vmode, galaxy), dpi=300)
        plt.show()
        plt.clf()
    else:

        if plot == 1:
            plt.show()
            plt.clf()
        if save == 1:
            plt.savefig("./plots/kin_%s_model_%s.png" % (vmode, galaxy),
                        dpi=300)
            plt.clf()