Ejemplo n.º 1
0
def Laurent_data(ra, dec, vstar, vHI, vCO, vHa, age, galaxy):
    xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i = deprojection_geo(
        ra, dec, galaxy)  #dist0 and theta0 for Laurent but using the

    np.savetxt(
        '/Users/amandaquirk/Desktop/{}_data_original.ascii'.format(age),
        np.c_[ra, dec, dist, theta, vstar, vHI, vCO, vHa],
        header=
        'ra, dec, r (kpc), theta (rad), vLOS_star (km/s), vLOS_HI (km/s), vLOS_CO (km/s), vLOS_Ha (km/s)',
        fmt='%s',
        delimiter='\t')
Ejemplo n.º 2
0
def Laurent_data(vstar, vHI, vCO, vHa, ra, dec, age, galaxy):
	xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i = deprojection_geo(ra, dec, galaxy) #dist0 and theta0 for Laurent but using the iterative values for my rotaiton curves
	# plt.scatter(alpha, beta, c=dist, vmin=0, vmax=15)
	# plt.colorbar()
	# plt.savefig('/Users/amandaquirk/Desktop/r_{}.png'.format(age))
	# plt.close()

	# plt.scatter(alpha, beta, c=theta, vmin=-3.2, vmax=3.2)
	# plt.colorbar()
	# plt.savefig('/Users/amandaquirk/Desktop/theta_{}.png'.format(age))
	# plt.close()

	np.savetxt('/Users/amandaquirk/Desktop/{}_data_smoothed.ascii'.format(age), np.c_[ra, dec, dist, theta, vstar, vHI, vCO, vHa], header='ra, dec, r (kpc), theta (rad), vLOS_star (km/s), vLOS_HI (km/s), vLOS_CO (km/s), vLOS_Ha (km/s)', fmt='%s', delimiter='\t',)
Ejemplo n.º 3
0
def RC(vstar, vHI, vCO, vHa, ra, dec, galaxy
       ):  #will return a file of vrots and AD values, 1 RC, and 1 AD hist
    #use the titled ring function to get dist, vrots
    xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i, assigned_vrot = deprojection_geo(
        ra, dec, galaxy, return_vrot=True)

    #theta/PA check -- should be 0
    #print(np.median(np.tan(PA) - np.tan(theta) * np.cos(np.deg2rad(assigned_i))))

    vrot_star = vrot_tr(vstar, ra, dec, galaxy)
    vrot_HI = vrot_tr(vHI, ra, dec, galaxy)
    vrot_Ha = vrot_tr(vHa, ra, dec, galaxy)
    vrot_CO = vrot_tr(vCO, ra, dec, galaxy)

    #calculate AD
    AD_HI = vrot_HI - vrot_star
    AD_CO = vrot_CO - vrot_star
    AD_Ha = vrot_Ha - vrot_star

    return dist, vrot_star, vrot_HI, vrot_Ha, vrot_CO, AD_HI, AD_Ha, AD_CO
Ejemplo n.º 4
0
def assign_loc(ra, dec, galaxy):
    #use the titled ring function to get dist, vrots
    xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i, assign_vrot = deprojection_geo(
        ra, dec, galaxy,
        return_vrot=True)  #deg, deg, deg, deg, kpc, rad, rad, deg, deg, km/s

    #find model HI vel at LOS
    vHI = HI_LOS(assign_vrot, theta, assigned_i)
    vsys = -180  #km/s

    #assign radial bins
    radial_bins = np.zeros(len(ra), dtype=object)
    #c = np.zeros(len(ra))
    for i in range(len(ra)):
        if dist[i] * 4 < 15:  #arcmin
            radial_bins[i] = 'inner'
            #c[i] = 10
        elif (dist[i] * 4 >= 15) & (dist[i] * 4 < 30):  #arcmin
            radial_bins[i] = 'middle'
            #c[i] = 50
        else:
            radial_bins[i] = 'outer'

    #assign spatial bin
    spatial_bins = np.zeros(len(ra), dtype=object)
    #c = np.zeros(len(ra))
    for i in range(len(ra)):
        if vHI[i] < vsys:
            spatial_bins[i] = 'NE'
            #c[i] = 50
        else:
            spatial_bins[i] = 'SW'

    #checking
    # plt.scatter(alpha * 60, beta * 60, c=c, vmin=0, vmax=55)
    # plt.colorbar()
    # plt.show()

    return radial_bins, spatial_bins, assign_vrot, theta, assigned_i
Ejemplo n.º 5
0
sdss_g = 3.303
sdss_i = 1.698

emap = sfdmap.SFDMap('../Data/sfddata-master/', scaling=1.0)
coords = SkyCoord(ra=ra, dec=dec, unit=(u.deg, u.deg))
extinct_map = emap.ebv(coords)

g_ext = g_mag - extinct_map * sdss_g
i_ext = i_mag - extinct_map * sdss_i
print('Did the extinction corrections')

#calcualte deprojected geo ==========================================================================================================
star = (flag1 == -1) & (
    flag2 == -1)  #let's look at things that are most likely to be stars
isolated = isolation_tag == 0
xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i = deprojection_geo(
    ra, dec, 'M33', unit='deg')

#calculate color and minimum brightnesses
color = g_ext - i_ext
bright = i_mag < 22  #what we'll target for spectroscopy
minimum_bright = i_mag < 24

# #calculate bins and make CMD =======================================================================================================
# MS = (color < -0.5) & (i_ext > 20)
# HeB = (color > 0.75) & (color < 1.3) & (i_ext < 21.5)
# AGB = (i_ext < 20.75) & (i_ext > 20) & (color > 1.6)
# RGB = (color > 0.5) & (i_ext > 21)
# # RGB_poly = Polygon([(1.4, 21), (2.4, 21.25), (3.55, 21.9), (3, 21.89), (2.6, 21.95), (1.9, 22.5), (1.8, 22.8), (1.5, 23.4), (1.2, 24.9), (.43, 23.25), (1.1, 22)])
# # HeB_poly = Polygon([(.8, 22), (1.1, 19.5), (1.4, 18), (1.8, 19), (1.6, 20), (1.1, 22)])
# # AGB_poly = Polygon([(1.4, 21), (2.4, 21.25), (3.55, 21.9), (3.55, 20), (1.8, 20)])
# # RGB_flag = np.zeros(len(i_ext))
Ejemplo n.º 6
0
def outputs(vstar, vHI, vCO, vHa, ra, dec, age, IDs, galaxy, region): #will return a file of vrots and AD values, 1 RC, and 1 AD hist 
	#use the titled ring function to get dist, vrots
	xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i = deprojection_geo(ra, dec, galaxy)

	#theta/PA check -- should be 0
	#print(np.median(np.tan(PA) - np.tan(theta) * np.cos(np.deg2rad(assigned_i)))) 

	vrot0_star = vrot_0(vstar, ra, dec, galaxy)
	vrot_star = vrot_tr(vstar, ra, dec, galaxy)
	#vrot0_HI = vrot_0(vHI, ra, dec, galaxy)
	vrot_HI = vrot_tr(vHI, ra, dec, galaxy)
	#vrot0_Ha = vrot_0(vHa, ra, dec, galaxy)
	vrot_Ha = vrot_tr(vHa, ra, dec, galaxy)
	#vrot0_CO = vrot_0(vCO, ra, dec, galaxy)
	vrot_CO = vrot_tr(vCO, ra, dec, galaxy)

	#calculate AD
	if region == 'inner':
		cut = dist <= 4
	elif region == 'outer':
		print('yes')
		cut = dist > 4
	else:
		cut = dist > 0 #no cut

	AD_HI = vrot_HI[cut] - vrot_star[cut]
	AD_CO = vrot_CO[cut] - vrot_star[cut]
	AD_Ha = vrot_Ha[cut] - vrot_star[cut]

	#save the data here
	np.savetxt('/Volumes/Titan/M33/Data/{}_vrot_ad_data.txt'.format(age), np.c_[IDs, dist, vrot_star, vrot_HI, vrot_CO, vrot_Ha, AD_HI, AD_CO, AD_Ha], fmt='%s', delimiter='\t', header='ID, dist (kpc), star vrot (km/s), HI vrot, CO vrot, Ha vrot, AD wrt HI, AD wrt CO, AD wrt Ha')

	#rotation curve
	# single_plot()
	# plt.scatter(dist, vrot_star, c='r', label='{}'.format(age))
	# #plt.scatter(dist, vrot0_star, c='b') #comp for sanity check of the rotation velocities
	# plt.scatter(dist, vrot_HI, c='darkgrey', label='HI', s=3, alpha=.8)
	# #plt.scatter(dist, vrot_CO, c='teal', label='CO', alpha=.8)
	# #plt.scatter(dist, vrot_Ha, c='b', label='Ha', alpha=.8)
	# plt.xlabel('Deprojected R [kpc]')
	# plt.ylabel('V rot titled ring [kpc]')
	# plt.ylim(0, 300)
	# plt.legend()
	# plt.show()
	# plt.savefig('/Volumes/Titan/M33/Plots/{}_rc.png'.format(age))
	# plt.close()

	#ad hist
	#get rid of nans in the AD list
	AD_HI = AD_HI[~np.isnan(AD_HI)]
	AD_CO = AD_CO[~np.isnan(AD_CO)]
	AD_Ha = AD_Ha[~np.isnan(AD_Ha)]

	print(np.nanmedian(AD_HI))

	# single_plot()
	# plt.hist(AD_HI, bins=range(-100, 200, 10), label='HI' + r'$={}$'.format(round(np.median(AD_HI),2)) + r'$\rm \ km \ s^{-1}$', density=True, histtype='step', linewidth=1.6, linestyle='--', stacked=True, fill=False, color='darkgrey')
	# plt.hist(AD_CO, bins=range(-100, 200, 10), label='CO' + r'$={}$'.format(round(np.median(AD_CO),2)) + r'$\rm \ km \ s^{-1}$', density=True, histtype='step', linewidth=1.6, linestyle='--', stacked=True, fill=True, hatch='//', color='teal')
	# plt.hist(AD_Ha, bins=range(-100, 200, 10), label='Ha' + r'$={}$'.format(round(np.median(AD_Ha),2)) + r'$\rm \ km \ s^{-1}$', density=True, histtype='step', linewidth=1.6, stacked=True, fill=False, color='blue')
	# plt.legend()
	# plt.savefig('/Volumes/Titan/M33/Plots/{}_ad_{}.png'.format(age, region))
	# plt.close()

	return AD_HI
Ejemplo n.º 7
0
def projected_AD(age_label, name, two_comps=False, observed=False):
    if observed == False:
        xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i, assigned_vrot = deprojection_geo(
            ra[age_label * good_qual],
            dec[age_label * good_qual],
            'M33',
            return_vrot=True)

        data_offset = offset(assigned_vrot, theta, assigned_i,
                             vel[age_label * good_qual])

        data = data_offset.reshape(-1, 1)
        gmm = GMM(n_components=1).fit(data)

        #check how our model did
        x = np.linspace(-200, 200, len(data_offset))
        logprob = gmm.score_samples(x.reshape(-1, 1))
        pdf = np.exp(logprob)

        init_vals = [max(pdf), gmm.means_[0][0], 20]  #a, mu, sigma
        best_vals_gmm, covar = curve_fit(gaussian, x, pdf, p0=init_vals)

        plt.hist(data_offset,
                 bins=range(-200, 200, 15),
                 density=True,
                 alpha=.5,
                 histtype='stepfilled',
                 label='data')
        plt.plot(x,
                 pdf,
                 '-k',
                 label=r'$\mu\ \rm =\ {}\ km\ s^-1$'.format(
                     round(best_vals_gmm[1])))
        #plt.plot(x, pdf, '-k', label=r'$\rm \mu=  {}, \sigma= {}$'.format(round(best_vals_gmm[1]), round(best_vals_gmm[2])))
        plt.legend()
        plt.xlabel('LOS offset: vHI - vstar (km/s)')
        plt.title(name)
        #plt.title('BIC = {}, AIC = {}'.format(round(gmm.bic(data)), round(gmm.aic(data))))
        plt.savefig(
            '/Users/amandaquirk/Desktop/{}_mixture_model.png'.format(name))
        plt.close()

        if two_comps == True:
            gmm2 = GMM(n_components=2).fit(data)
            x = np.linspace(-200, 200, 1000)
            responsibilities = gmm2.predict_proba(x.reshape(-1, 1))
            logprob = gmm2.score_samples(x.reshape(-1, 1))
            pdf = np.exp(logprob)
            pdf_individual = responsibilities * pdf[:, np.newaxis]

            mus, sigmas, halo_label, disk_label = do_fit_labels(
                gmm2, x, pdf_individual, 1)

            plt.hist(data_offset,
                     bins=range(-200, 200, 15),
                     density=True,
                     alpha=.5,
                     histtype='stepfilled',
                     label='data')
            plt.plot(x, pdf, '-k', label='mixture model')
            plt.plot(x,
                     pdf_individual[:, halo_label],
                     '--r',
                     label=r'$\rm halo, \mu=  {}, \sigma= {}$'.format(
                         round(mus[halo_label]), round(sigmas[halo_label])))
            plt.plot(x,
                     pdf_individual[:, disk_label],
                     ':r',
                     label=r'$\rm disk, \mu=  {}, \sigma= {}$'.format(
                         round(mus[disk_label]), round(sigmas[disk_label])))
            plt.legend()
            plt.xlabel('LOS offset: vHI - vstar (km/s)')
            plt.title('BIC = {}, AIC = {}'.format(round(gmm2.bic(data)),
                                                  round(gmm2.aic(data))))
            plt.savefig(
                '/Users/amandaquirk/Desktop/{}_mixture_model2.png'.format(
                    name))
            plt.close()

            probs = gmm2.predict_proba(data_offset.reshape(-1, 1))
            halo_prob = probs[:, halo_label]
            disk_prob = probs[:, disk_label]

            np.savetxt(
                '/Volumes/Titan/M33/Data/{}_disk_halo_probs_offset.txt'.format(
                    name),
                np.c_[ID[age_label * good_qual], halo_prob, disk_prob],
                header='ID, halo offset prob, disk offset prob',
                fmt='%s')
    else:
        data_offset1 = HI[age_label * good_qual] - vel[age_label * good_qual]
        data_offset = data_offset1[~np.isnan(data_offset1)]

        data = data_offset.reshape(-1, 1)
        gmm = GMM(n_components=1).fit(data)

        #check how our model did
        x = np.linspace(-200, 200, len(data_offset))
        logprob = gmm.score_samples(x.reshape(-1, 1))
        pdf = np.exp(logprob)

        init_vals = [max(pdf), gmm.means_[0][0], 20]  #a, mu, sigma
        best_vals_gmm, covar = curve_fit(gaussian, x, pdf, p0=init_vals)

        plt.hist(data_offset,
                 bins=range(-200, 200, 15),
                 density=True,
                 alpha=.5,
                 histtype='stepfilled',
                 label='data')
        plt.plot(x,
                 pdf,
                 '-k',
                 label=r'$\mu\ \rm =\ {}\ km\ s^-1$'.format(
                     round(best_vals_gmm[1])))
        #plt.plot(x, pdf, '-k', label=r'$\rm \mu=  {}, \sigma= {}$'.format(round(best_vals_gmm[1]), round(best_vals_gmm[2])))
        plt.legend()
        plt.xlabel('LOS offset: vHI - vstar (km/s)')
        plt.title(name)
        #plt.title('BIC = {}, AIC = {}'.format(round(gmm.bic(data)), round(gmm.aic(data))))
        plt.savefig(
            '/Users/amandaquirk/Desktop/{}_mixture_model_observed.png'.format(
                name))
        plt.close()

        if two_comps == True:
            gmm2 = GMM(n_components=2).fit(data)
            x = np.linspace(-200, 200, 1000)
            responsibilities = gmm2.predict_proba(x.reshape(-1, 1))
            logprob = gmm2.score_samples(x.reshape(-1, 1))
            pdf = np.exp(logprob)
            pdf_individual = responsibilities * pdf[:, np.newaxis]

            mus, sigmas, halo_label, disk_label = do_fit_labels(
                gmm2, x, pdf_individual, 1)

            plt.hist(data_offset,
                     bins=range(-200, 200, 15),
                     density=True,
                     alpha=.5,
                     histtype='stepfilled',
                     label='data')
            plt.plot(x, pdf, '-k', label='mixture model')
            plt.plot(x,
                     pdf_individual[:, halo_label],
                     '--r',
                     label=r'$\rm halo, \mu=  {}, \sigma= {}$'.format(
                         round(mus[halo_label]), round(sigmas[halo_label])))
            plt.plot(x,
                     pdf_individual[:, disk_label],
                     ':r',
                     label=r'$\rm disk, \mu=  {}, \sigma= {}$'.format(
                         round(mus[disk_label]), round(sigmas[disk_label])))
            plt.legend()
            plt.xlabel('LOS offset: vHI - vstar (km/s)')
            plt.title('BIC = {}, AIC = {}'.format(round(gmm2.bic(data)),
                                                  round(gmm2.aic(data))))
            plt.savefig(
                '/Users/amandaquirk/Desktop/{}_mixture_model2_observed.png'.
                format(name))
            plt.close()

            probs = gmm2.predict_proba(data_offset.reshape(-1, 1))
            halo_prob = probs[:, halo_label]
            disk_prob = probs[:, disk_label]

            np.savetxt(
                '/Volumes/Titan/M33/Data/{}_disk_halo_probs_offset_observed.txt'
                .format(name),
                np.c_[ID[age_label * good_qual][~np.isnan(data_offset1)],
                      halo_prob, disk_prob],
                header='ID, halo offset prob, disk offset prob',
                fmt='%s')
Ejemplo n.º 8
0
    80) & (aband * const.c.to(u.km / u.s).value > -80) & (err > -1)
in_m33 = np.invert(np.in1d(ID, fg_id))
good_qual = qual * in_m33

#pull RGB data
RGB = age == 'RGB'
RGB = RGB * not_weak_CN * not_C  #remove stars misclassified

# #calculate the offset from the HI as caluclated via the equation in Kam 2017 ===========================================

# '''
# Karrie interpolates this table; it might be best to do that step later. Skipping for now. (If I do that step here, I should do that step in main deprojection geo function)
# '''

# #pull the deprojected geometry, including the vrot of the TR
xi, eta, alpha, beta, dist, PA, theta, assigned_PA, assigned_i, assigned_vrot = deprojection_geo(
    ra[RGB * good_qual], dec[RGB * good_qual], 'M33', return_vrot=True)


#calculate LOS HI velocity according to Kam 2017
def HI_LOS(vrot, theta, i):  #km/s, rad, deg
    vsys = -180  #km/s
    return vsys + vrot * np.cos(theta) * np.sin(np.deg2rad(i))  #km/s


#calculate LOS offset
def offset(vrot, theta, i, vel):  #km/s, rad, deg, km/s
    vHI = HI_LOS(vrot, theta, i)
    return vHI - vel  #km/s


RGB_offset = offset(assigned_vrot, theta, assigned_i, vel[RGB * good_qual])