Ejemplo n.º 1
0
def hard_soft(cluster, filestring, snapno):
    import scripts
    units = scripts.read_units(
        '/projects/b1011/kyle/cmc/branches/cmc-mpi/m22_project/rundir/' +
        cluster + '/' + filestring + '/initial')
    data2 = np.loadtxt('RV_model_sigma_' + filestring + '.dat')
    km = units[0]['l_cgs'] * 1.0e-5
    pc = units[0]['l_pc']
    time = units[0]['nbt_cgs']

    ########## make array with velocity dispersions for each bin for the particular snapshot you're interested in
    sigma = []
    s = int(snapno)
    for i in range(0, len(data2)):
        if data2[i, 0] == s:
            for j in range(2, 19, 3):
                sigma.append(data2[i, j])

#######################

    data = np.loadtxt(
        '/projects/b1011/kyle/cmc/branches/cmc-mpi/m22_project/rundir/' +
        cluster + '/' + filestring + '/initial.snap' + snapno +
        '.hrdiag_modified.dat')
    data2 = np.loadtxt(
        '/projects/b1011/kyle/cmc/branches/cmc-mpi/m22_project/rundir/' +
        cluster + '/' + filestring + '/initial.snap' + snapno + '.dat.gz')
    data[:, 0] = data[:, 0] * pc  # converts from code units to pc
    data[:, 0] = conversions.pc_to_arcsec(
        data[:, 0], 4.4)  # converts radius from pc to arcsec

    M_G_array = []
    M_MS_array = []
    m_array = []
    count_G = 0
    count_MS = 0
    count = 0
    for j in range(0, 6):
        M_G = 0
        M_MS = 0
        m = 0
        count_G = 0
        count_MS = 0
        count = 0
        if j == 0:
            r_min = 26.67
            r_max = 79.85
        if j == 1:
            r_min = 80.173
            r_max = 123.844
        if j == 2:
            r_min = 127.816
            r_max = 168.111
        if j == 3:
            r_min = 169.443
            r_max = 234.509
        if j == 4:
            r_min = 237.539
            r_max = 326.939
        if j == 5:
            r_min = 335.386
            r_max = 611.081
        for i in range(0, len(data)):
            if data[i, 0] > r_min and data[i, 0] <= r_max:
                m = m + data[i, 8]  # If any object (single or binary)
                count = count + 1  # counts all objects
                if data[i, 1] == 0:  # if a single star
                    if data[i, 2] >= 3 and data[i, 2] <= 6:  # If a giant star
                        M_G = M_G + data[i, 8]
                        count_G = count_G + 1
                    if data[i, 2] <= 1:  # If a MS star
                        M_MS = M_MS + data[i, 8]
                        count_MS = count_MS + 1
                else:  # If a binary
                    if data[i, 4] >= 3 and data[
                            i, 4] <= 6:  # If component 0 is a giant
                        M_G = M_G + data[i, 9]
                        count_G = count_G + 1
                    if data[i, 5] >= 3 and data[
                            i, 5] <= 6:  # If component 1 is a giant
                        M_G = M_G + data[i, 10]
                        count_G = count_G + 1
                    if data[i, 4] <= 1:  # If component 0 is a MS
                        M_MS = M_MS + data[i, 9]
                        count_MS = count_MS + 1
                    if data[i, 5] <= 1:  # If component 1 is a MS
                        M_MS = M_MS + data[i, 10]
                        count_MS = count_MS + 1

        M_G_array.append(M_G / count_G)
        M_MS_array.append(M_MS / count_MS)
        m_array.append(m / count)
        print M_G / count_G, M_MS / count_MS, m / count, count_G, count_MS, count

    for i in range(0, len(m_array)):
        # Convert the arrays from Msun to kg
        M_G_array[i] = M_G_array[i] * 1.99e30
        M_MS_array[i] = M_MS_array[i] * 1.99e30
        m_array[i] = m_array[i] * 1.99e30
        sigma[i] = sigma[i] * 1000.  # convert sigma to m/s
    G = 6.67e-11
    a = []
    for i in range(0, len(m_array)):
        a.append(G * M_G_array[i] * M_MS_array[i] /
                 (2.0 * m_array[i] * sigma[i]**2.) / 1.496e11)
    print a
    print sigma

    # find mean giant radius for entire cluster
    R = 0
    count = 0
    for i in range(0, len(data2)):
        if data2[i, 7] == 0:
            if data2[i, 14] >= 3 and data2[i, 14] <= 6:
                R = R + data2[i, 16]
                print data2[i, 16], data2[i, 14], data2[i, 1]
                count = count + 1
        else:
            if data2[i, 17] >= 3 and data2[i, 17] <= 6:
                R = R + data2[i, 21]
                count = count + 1
            if data2[i, 18] >= 3 and data2[i, 18] <= 6:
                R = R + data2[i, 22]
                count = count + 1
    print R / count * 1.0, count
Ejemplo n.º 2
0
    rc_obs = 1.85  # pc
    rh_obs = 4.42

#simulation = 'm10_400000e5_5.0_1.0_0.05_FULL'
#path = '/projects/b1011/sourav/new_runs/kick_grid/rv2/kickscale_0.1/'
path = '/projects/b1011/sourav/new_runs/kick_grid/rv1/kickscale_0.05/'
snapno = '0894'
#snapno = '0731'
#path = '/projects/b1011/sourav/new_runs/kick_grid/rv1/kickscale_0.1/'
#snapno = '1056'

########  MAKE SBP ##############

data = np.genfromtxt(path + 'initial.snap' + snapno + '.2D_SBPLcut15.dat')
data2 = np.genfromtxt(cluster + '_data_2.dat')
arcsec = conversions.pc_to_arcsec(data[:, 1], d_helio)
SB = conversions.SB_converter_tot(data[:, 3])
SB_err = data[:, 6] / data[:, 5] * SB

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

rc_obs = conversions.pc_to_arcsec(rc_obs, d_helio)
rh_obs = conversions.pc_to_arcsec(rh_obs, d_helio)

##### get observed properties #####
props = np.genfromtxt(path + 'initial.snap' + snapno + '.obs_params.dat')
rc_model = conversions.pc_to_arcsec(props[0, 7], d_helio)
rh_model = conversions.pc_to_arcsec(props[0, 8], d_helio)
M_total = np.str(props[0, 12])
time = np.str(props[0, 10])
Ejemplo n.º 3
0
            SB_t[:],
            facecolor='gold',
            edgecolor='black',
            s=20,
            label=r'$\rm{Trager\,et\,al.\,1995}$')
ax2.scatter([10000, 10000], [-5, -5],
            c='gold',
            s=30,
            edgecolor='black',
            label=r'$\rm{Baumgardt\,&\,Hilker\,(2018)}$')

for i in range(0, len(paths)):
    path = paths[i]
    snapno = snap2d[i]
    data5 = np.genfromtxt(path + 'initial.snap' + snapno + '.2D_SBPLcut15.dat')
    arcsec = conversions.pc_to_arcsec(data5[:, 1], R_sun_obs)
    SB = conversions.SB_converter(data5[:, 3])
    SBerr = data5[:, 6] / data5[:, 5] * SB

    arcsec_cut = []
    SB_cut = []
    SBerr_cut = []
    for k in range(len(SB)):
        if arcsec[k] < 10 and SB[k] > 20:
            Nothing = 0
        else:
            arcsec_cut.append(arcsec[k])
            SB_cut.append(SB[k])
            #SBerr_cut.append(SBerr[k])

    dataG = np.genfromtxt(path + 'initial.snap' + snapno +
Ejemplo n.º 4
0
def velocity_dispersion(path,string, snapno,ALL=1):
	import scripts
	import random
	units=scripts.read_units(path+string)
	km = units[0]['l_cgs']*1.0e-5
	time = units[0]['nbt_cgs']
	f = open('RV_model.dat','w')
	f1 = open('RV_model_sigma.dat','a')
	if ALL == 1:
		f4 = open(path+string+'.snap'+snapno+'.vel_dispersion_tight.dat','w')
	if ALL == 0:
		f4 = open(path+string+'.snap'+snapno+'.vel_dispersion_giants_25.dat','w')
	f2 = open('RV_obs_sigma.dat','w')
	f3 = open('giants.dat','w')
	print>>f4,'#0)r2D(pc) 1)sigma_v(1D; km/s) 2) sigma_err (km/s)'
####################
	data = np.genfromtxt(path+string+'.snap'+snapno+'.dat.gz')
#####################
###################
	Vr = []
	R = []
	bin_count = 0
	count = 0
	bin_array = []
	for i in range(0,len(data)):
		bin = 0
		if ALL == 1:
                        v_r = data[i,3]*km/time # converts from code units to km/s
                        v_t = data[i,4]*km/time
                        r_km = data[i,2]*km  #convert r from code units to km
			if data[i,7] != 1:	# Looks at singles only
                                if data[i,14] <= 9 and data[i,1] >= 0.4:
                                        for k in range(0,1):
                                        #for k in range(0,25):
                                                r,v = convert_to_3d(r_km, v_r, v_t)
                                                Vr.append(v[0])    # Use this if you want 1d vel dispersion
                                                r = np.sqrt(r[1]**2. + r[2]**2.)/3.086e13  # convert r from km to pc
                                                R.append(r)
                                                count = count + 1
		if ALL == 0:
			v_r = data[i,3]*km/time # converts from code units to km/s
			v_t = data[i,4]*km/time
			r_km = data[i,2]*km  #convert r from code units to km
			if data[i,7] != 1:
				if data[i,14] >= 2 and data[i,14] <= 9:
                                        for k in range(0,1):
					#for k in range(0,25):
                                                r,v = convert_to_3d(r_km, v_r, v_t)
                                                Vr.append(v[0])    # Use this if you want 1d vel dispersion
                                                r = np.sqrt(r[1]**2. + r[2]**2.)/3.086e13  # convert r from km to pc
                                                R.append(r)
                                                count = count + 1
################################################
	mean_model = np.mean(Vr[:]) #Find global mean of all model RVs
	print 'mean=',mean_model
	array = np.zeros((len(Vr),2))
	for i in range(0,len(Vr)):
		array[i,0] = R[i]
		array[i,1] = Vr[i]
	array = array[array[:,0].argsort()]  # sorts each measurement in order of radial position
	for i in range(0,len(Vr)):
		print>>f, array[i,0], array[i,1] #Print each radius/LOS velocity pair in order of radial position	

#####################################	
	sigma_array = []	
	R_array = []
	R_array2 = []
	mean_array = []
	mean_array2 = []
	sigma_array2 = []
	flag = 0
	sum = 0
	print>>f1, snapno,
        ## Define each bin as having 2000 stars. Every 2000 stars, start new bin

	vel_array = []  # Makes an array with velocites of all stars within each bin
	r_array = []
	bin_count = 0
	total_count = 0
	r_min = conversions.pc_to_arcsec(array[0,0],5.0)
	r_min_bin = r_min
	for j in range(0,len(array)):
		RRR = conversions.pc_to_arcsec(array[j,0],5.0) 
		#print j, r_min_bin, RRR, RRR - r_min_bin, total_count  
		if total_count <= 2000:# or RRR - r_min_bin <= 1.58:
		#if total_count <= 500:
			vel_array.append(array[j,1])
			r_array.append(array[j,0])
			total_count = total_count + 1
		else:
		#if total_count > 100 and RRR - r_min_bin > 1.58:
			count = 0.
			r_min_bin = conversions.pc_to_arcsec(array[j,0],5.0)
			for k in range(0,len(vel_array)):
				r = np.mean(r_array)
				sum = sum + (vel_array[k]-mean_model)**2.
				count = count + 1.
			sigma = np.sqrt(sum/count)
			error = np.sqrt(sigma**2.0/(2.*count))
			print>>f1, r, sigma, error,
			print>>f4, r, sigma, error
			#print r, 'sigma=',sigma, 'error=',error, 'count=',count, 'N_binaries=',bin_count,'N_stars=',total_count,'binary fraction=',float(bin_count)/float(total_count)
			sigma_array.append(sigma)
			R_array.append(np.mean(r_array))
			sum = 0
			flag = 0
			bin_count = 0
			total_count = 0
			vel_array = []
			r_array = []
	print>>f1,' '