# conv=path+'initial.conv.sh', # dist=4.52, # distance to cluster in kpc # z=0.0038) #binflag = snap.data['binflag'] #m0 = snap.data['m0_MSUN']; m1 = snap.data['m1_MSUN'] #r0 = snap.data['bin_star_radius0_RSUN']; r1 = snap.data['bin_star_radius1_RSUN'] #k0 = snap.data['bin_startype0']; k1 = snap.data['bin_startype1'] #sma = snap.data['a_AU']; ecc = snap.data['e'] #id0 = snap.data['id0']; id1 = snap.data['id1'] #id_star = snap.data['id'] ##################cmc-3.2#################################### snap = cmct.Snapshot( fname=path + 'initial.snap0651.dat.gz', conv=path + 'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) binflag = snap.data['binflag'] m0 = snap.data['m0[MSUN]'] m1 = snap.data['m1[MSUN]'] r0 = snap.data['bin_star_radius0[RSUN]'] r1 = snap.data['bin_star_radius1[RSUN]'] k0 = snap.data['bin_startype0'] k1 = snap.data['bin_startype1'] sma = snap.data['a[AU]'] ecc = snap.data['e'] id0 = snap.data['id0'] id1 = snap.data['id1'] id_star = snap.data['id']
def velocity_dispersion_old(path, string, thekey, Starinbin=200, mcut=0): snapno = read_keys(thekey)[0] snaptime = float(read_keys(thekey)[1]) units = read_units(path + string) lpc = units[0]['l_pc'] kms = 1e-5 * units[0]['l_cgs'] / units[0]['nbt_cgs'] f4 = open( path + string + '.snap' + snapno + '.vel_dispersion_vr_pm_' + str(Starinbin) + '_' + str(mcut) + '.dat', 'w+') print( '#0)r2D(pc) 1)sigma_v(1D; km/s) 2)sigma_v_err(km/s) 3)sigma_pmr(1D; km/s) 4)sigma_pmr_err(km/s) 5)sigma_pmt(1D; km/s) 6)sigma_pmt_err(km/s) 7)sigma_pm(km/s) 8)sigma_pm_err(km/s) 9)sigma_pm2(km/s) 10)sigma_pm2_err(km/s)', file=f4) #################### snapfile = cmct.Snapshot( fname=path + 'initial.snapshots.h5', snapshot_name=thekey, conv=path + 'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) print('read snap hdf5') ##################### ################### Vr = [] Vpm_r = [] Vpm_t = [] Vpm = [] R = [] count = 0 print(len(snapfile.data['r'])) v_r = snapfile.data['vr'] * kms # converts from code units to km/s v_t = snapfile.data['vt'] * kms r_pc = snapfile.data['r'] * lpc #convert r from code units to pc r_all, v_all = convert_to_3d(r_pc, v_r, v_t) binflag = snapfile.data['binflag'] ktype = snapfile.data['startype'] k0 = snapfile.data['bin_startype0'] k1 = snapfile.data['bin_startype1'] m = snapfile.data['m_MSUN'] m0 = snapfile.data['m0_MSUN'] m1 = snapfile.data['m1_MSUN'] #print(v_all) for i in range(len(r_all[0])): if binflag[i] == 1: if mcut == 0 and (2 <= k0[i] <= 9 or 2 <= k1[i] <= 9): #for k in range(0,70): Vr.append(v_all[0, i]) # Use this if you want 1d vel dispersion Vpm_r.append(v_all[1, i]) Vpm_t.append(v_all[2, i]) Vpm.append(np.sqrt(v_all[1, i]**2 + v_all[2, i]**2)) rd = np.sqrt(r_all[1, i]**2. + r_all[2, i]**2.) R.append(rd) count = count + 1 elif (k0[i] < 10 and m0[i] >= mcut) or (k1[i] < 10 and m1[i] >= mcut): #print(snapfile.data['bin_startype0'][i], snapfile.data['m0_MSUN'][i], snapfile.data['binflag'][i]) Vr.append(v_all[0, i]) # Use this if you want 1d vel dispersion Vpm_r.append(v_all[1, i]) Vpm_t.append(v_all[2, i]) Vpm.append(np.sqrt(v_all[1, i]**2 + v_all[2, i]**2)) rd = np.sqrt(r_all[1, i]**2. + r_all[2, i]**2.) R.append(rd) count = count + 1 else: if mcut == 0 and 2 <= ktype[i] <= 9: Vr.append(v_all[0, i]) # Use this if you want 1d vel dispersion Vpm_r.append(v_all[1, i]) Vpm_t.append(v_all[2, i]) Vpm.append(np.sqrt(v_all[1, i]**2 + v_all[2, i]**2)) rd = np.sqrt(r_all[1, i]**2. + r_all[2, i]**2.) R.append(rd) count = count + 1 elif ktype[i] < 10 and m[i] >= mcut: #print(snapfile.data['startype'][i], snapfile.data['m_MSUN'][i], snapfile.data['binflag'][i]) Vr.append(v_all[0, i]) # Use this if you want 1d vel dispersion Vpm_r.append(v_all[1, i]) Vpm_t.append(v_all[2, i]) Vpm.append(np.sqrt(v_all[1, i]**2 + v_all[2, i]**2)) rd = np.sqrt(r_all[1, i]**2. + r_all[2, i]**2.) R.append(rd) count = count + 1 print(Vr) print('get vr vt done') ################################################ mean_model = np.mean(Vr) #Find global mean of all model RVs mean_model_pmr = np.mean(Vpm_r) mean_model_pmt = np.mean(Vpm_t) mean_model_pm = np.mean(Vpm) print('mean=', mean_model, mean_model_pm) array = np.zeros((len(Vr), 5)) for i in range(0, len(Vr)): array[i, 0] = R[i] array[i, 1] = Vr[i] array[i, 2] = Vpm_r[i] array[i, 3] = Vpm_t[i] array[i, 4] = Vpm[i] array = array[array[:, 0].argsort( )] # sorts each measurement in order of radial position ##################################### sigma_vel_array = [] sigma_pmr_array = [] sigma_pmt_array = [] sigma_pm_array = [] R_array = [] #mean_array = [] #flag = 0 sum_vel = 0 sum_pmr = 0 sum_pmt = 0 sum_pm = 0 vel_array = [ ] # Makes an array with velocites of all stars within each bin pmr_array = [] pmt_array = [] pm_array = [] r_array = [] #bin_count = 0 total_count = 0 for j in range(0, len(array)): if total_count <= Starinbin: vel_array.append(array[j, 1]) pmr_array.append(array[j, 2]) pmt_array.append(array[j, 3]) pm_array.append(array[j, 4]) r_array.append(array[j, 0]) total_count = total_count + 1 else: count = 0. for k in range(0, len(vel_array)): r = np.mean(r_array) sum_vel = sum_vel + (vel_array[k] - mean_model)**2. sum_pmr = sum_pmr + (pmr_array[k] - mean_model_pmr)**2. sum_pmt = sum_pmt + (pmt_array[k] - mean_model_pmt)**2. sum_pm = sum_pm + (pm_array[k] - mean_model_pm)**2. count = count + 1. sigma_vel = np.sqrt(sum_vel / count) error_vel = np.sqrt(sigma_vel**2.0 / (2. * count)) sigma_pmr = np.sqrt(sum_pmr / count) error_pmr = np.sqrt(sigma_pmr**2.0 / (2. * count)) sigma_pmt = np.sqrt(sum_pmt / count) error_pmt = np.sqrt(sigma_pmt**2.0 / (2. * count)) sigma_pm = np.sqrt(sum_pm / count) error_pm = np.sqrt(sigma_pm**2.0 / (2. * count)) print(r, sigma_vel, error_vel, sigma_pmr, error_pmr, sigma_pmt, error_pmt, sigma_pm, error_pm, file=f4) #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_vel_array.append(sigma_vel) sigma_pmr_array.append(sigma_pmr) sigma_pmt_array.append(sigma_pmt) sigma_pm_array.append(sigma_pm) R_array.append(np.mean(r_array)) sum_vel = 0 sum_pmr = 0 sum_pmt = 0 sum_pm = 0 #flag = 0 #bin_count = 0 total_count = 0 vel_array = [] pmr_array = [] pmt_array = [] pm_array = [] r_array = []
def velocity_dispersion_hdf5(modelpath, thekey, Starinbin=200, mcut=0, hdf5flag=0): snapno = read_keys(thekey)[0] snaptime = float(read_keys(thekey)[1]) fvel = open( modelpath + 'initial.snap' + snapno + '.vel_dispersion_vr_pm_' + str(Starinbin) + '_' + str(mcut) + '.dat', 'w+') print( '#0)r2D(pc) 1)sigma_v(1D; km/s) 2)sigma_v_err(km/s) 3)sigma_pmr(1D; km/s) 4)sigma_pmr_err(km/s) 5)sigma_pmt(1D; km/s) 6)sigma_pmt_err(km/s)', file=fvel) if hdf5flag == 1: snap_h5 = modelpath + 'initial.snapshots.h5' snap = cmct.Snapshot( fname=snap_h5, snapshot_name=thekey, conv=modelpath + 'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) snap.make_2d_projection(seed=8675309) VX = snap.data['vx[KM/S]'] VY = snap.data['vy[KM/S]'] VZ = snap.data['vz[KM/S]'] rd = snap.data['d[PC]'] ktype = snap.data['startype'] k0 = snap.data['bin_startype0'] k1 = snap.data['bin_startype1'] m = snap.data['m_MSUN'] m0 = snap.data['m0_MSUN'] m1 = snap.data['m1_MSUN'] binflag = snap.data['binflag'] print('read snap data') if hdf5flag == 0: binflag = [] VX = [] VY = [] VZ = [] rd = [] ktype = [] k0 = [] k1 = [] m = [] m0 = [] m1 = [] snap2d = modelpath + 'initial.snap' + snapno + '.2Dproj.dat.gz' with gzip.open(snap2d, 'r') as f2d: next(f2d) next(f2d) for line in f2d: data = line.split() binflag.append(int(data[2])) VX.append(float(data[18])) VY.append(float(data[19])) VZ.append(float(data[20])) rd.append(float(data[0])) ktype.append(int(data[3])) k0.append(int(data[5])) k1.append(int(data[6])) m.append(float(data[9])) m0.append(float(data[10])) m1.append(float(data[11])) print('read snap data') vel_r = [] vel_pmr = [] vel_pmt = [] rpc = [] for xx in range(len(ktype)): if binflag[xx] == 1: if mcut == 0 and 2 <= k0[xx] <= 9 or 2 <= k1[xx] <= 9: rpc.append(rd[xx]) vel_r.append(VX[xx]) vel_pmr.append(VY[xx]) vel_pmt.append(VZ[xx]) elif (k0[xx] < 10 and m0[xx] >= mcut) or (k1[xx] < 10 and m1[xx] >= mcut): rpc.append(rd[xx]) vel_r.append(VX[xx]) vel_pmr.append(VY[xx]) vel_pmt.append(VZ[xx]) else: if mcut == 0 and 2 <= ktype[xx] <= 9: rpc.append(rd[xx]) vel_r.append(VX[xx]) vel_pmr.append(VY[xx]) vel_pmt.append(VZ[xx]) elif ktype[xx] < 10 and m[xx] >= mcut: rpc.append(rd[xx]) vel_r.append(VX[xx]) vel_pmr.append(VY[xx]) vel_pmt.append(VZ[xx]) array = np.zeros((len(vel_r), 4)) for i in range(0, len(vel_r)): array[i, 0] = rpc[i] array[i, 1] = vel_r[i] array[i, 2] = vel_pmr[i] array[i, 3] = vel_pmt[i] array = array[array[:, 0].argsort( )] # sorts each measurement in order of radial position mean_r = np.mean(vel_r) mean_pmr = np.mean(vel_pmr) mean_pmt = np.mean(vel_pmt) print(mean_r, mean_pmr, mean_pmt) sigma_r_array = [] sigma_pmr_array = [] sigma_pmt_array = [] R_array = [] velr_array = [] velpmr_array = [] velpmt_array = [] r_array = [] sum_r = 0 sum_pmr = 0 sum_pmt = 0 total_count = 0 for ii in range(0, len(array)): if total_count <= Starinbin: velr_array.append(array[ii, 1]) velpmr_array.append(array[ii, 2]) velpmt_array.append(array[ii, 3]) r_array.append(array[ii, 0]) total_count = total_count + 1 else: count = 0. for k in range(0, len(velr_array)): r = np.mean(r_array) sum_r = sum_r + (velr_array[k] - mean_r)**2. sum_pmr = sum_pmr + (velpmr_array[k] - mean_pmr)**2. sum_pmt = sum_pmt + (velpmt_array[k] - mean_pmt)**2. count = count + 1. sigma_r = np.sqrt(sum_r / count) error_r = np.sqrt(sigma_r**2.0 / (2. * count)) sigma_pmr = np.sqrt(sum_pmr / count) error_pmr = np.sqrt(sigma_pmr**2.0 / (2. * count)) sigma_pmt = np.sqrt(sum_pmt / count) error_pmt = np.sqrt(sigma_pmt**2.0 / (2. * count)) print(r, sigma_r, error_r, sigma_pmr, error_pmr, sigma_pmt, error_pmt, file=fvel) sigma_r_array.append(sigma_r) sigma_pmr_array.append(sigma_pmr) sigma_pmt_array.append(sigma_pmt) R_array.append(np.mean(r_array)) sum_r = 0 sum_pmr = 0 sum_pmt = 0 total_count = 0 velr_array = [] velpmr_array = [] velpmt_array = [] r_array = []
def make_2D_projection(modelpath, thekey, units, writefilename, SEEDY=10, PROJ=(0, 1)): #units = scripts.read_units(filestring) snapno = read_keys(thekey)[0] snaptime = float(read_keys(thekey)[1]) print(type(snapno)) lpc = units[0]['l_pc'] kms = 1e-5 * units[0]['l_cgs'] / units[0]['nbt_cgs'] t_myr = snaptime * units[0]['t_myr'] #read the snapfile snapfile = cmct.Snapshot( fname=modelpath + 'initial.snapshots.h5', snapshot_name=thekey, conv=modelpath + 'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) print('read_snapfile') #writefilename=modelpath+'initial.snap'+snapno+'.2Dproj.dat' writefile = open(writefilename, 'w+') writefile.write( "#t=%g\n#1.r2D(pc) 2.Ltot(Lsun) 3.binflag 4.startype 5.L(Lsun) 6.startype0 7.startype1 8.L0(Lsun) 9.L1(Lsun) 10.Mtot(Msun) 11.M0(Msun) 12.M1(Msun) 13.id 14.id0 15.id1 16.rx(pc) 17.ry(pc) 18.rz(pc) 19.vx(km/s) 20.vy(km/s) 21.vz(km/s)\n" % (t_myr)) print('write file') colnos = (2, 7, 14, 15, 17, 18, 19, 20, 1, 8, 9, 3, 4, 0, 10, 11) #0-r, 1-binflag, 2-startype, 3-L, 4-startype0, 5-startype1, 6-L0, 7-L1, 8-Mtot, 9-M0, 10-M1, 11-vr, 12-vt, 13-id, 14-id0, 15-id1 #data = np.genfromtxt(snapfile) r = snapfile.data['r'] * lpc vr = snapfile.data['vr'] * kms vt = snapfile.data['vt'] * kms r3d, v3d = convert_to_3d(r, vr, vt, SEEDY=SEEDY) r2d, ind = project_and_radially_sort(r3d, PROJ=PROJ) print('N:', len(ind)) #valid_line=0 valid_line = 1 for i in range(len(ind)): #try: # for j in range(len(data[ind[i]])): # if str(data[ind[i],j])=='nan' or str(data[ind[i],j])=='inf': # valid_line = 0 # print(data[ind[i],:]) # raise StopIteration() # else: # valid_line = 1 #except StopIteration: # pass if valid_line == 1: if snapfile.data['binflag'][ind[i]] == 1.: Ltot = snapfile.data['bin_star_lum0_LSUN'][ ind[i]] + snapfile.data['bin_star_lum1_LSUN'][ind[i]] Mtot = snapfile.data['m_MSUN'][ind[i]] else: Ltot = snapfile.data['luminosity_LSUN'][ind[i]] Mtot = snapfile.data['m_MSUN'][ind[i]] writefile.write( "%g %g %g %g %g %g %g %g %g %g %g %g %d %d %d %g %g %g %g %g %g\n" % (r2d[ind[i]], Ltot, snapfile.data['binflag'][ind[i]], snapfile.data['startype'][ind[i]], Ltot, snapfile.data['bin_startype0'][ind[i]], snapfile.data['bin_startype1'][ind[i]], snapfile.data['bin_star_lum0_LSUN'][ind[i]], snapfile.data['bin_star_lum1_LSUN'][ind[i]], Mtot, snapfile.data['m0_MSUN'][ind[i]], snapfile.data['m1_MSUN'][ind[i]], snapfile.data['id'][ind[i]], snapfile.data['id0'][ind[i]], snapfile.data['id1'][ind[i]], r3d[0, ind[i]], r3d[1, ind[i]], r3d[2, ind[i]], v3d[0, ind[i]], v3d[1, ind[i]], v3d[2, ind[i]])) writefile.close() return r, vr, vt, r3d, v3d
def make_SBP_VDP_NDP_hdf5_smooth(modelpath, dgc): ##dgc in kpc snap_h5 = modelpath + 'initial.snapshots.h5' t_conv = conv('t', modelpath + 'initial.conv.sh') with pd.HDFStore(snap_h5) as snaps: snap_keys = snaps.keys() snap_no = [] snap_time = [] for ii in range(len(snap_keys)): temp_key = read_keys(snap_keys[ii]) temp_no = int(temp_key[0]) temp_time = float(temp_key[1]) snap_no.append(int(temp_key[0])) snap_time.append(float(temp_key[1])) #if temp_time*t_conv < 10000. or temp_time*t_conv >13000. or temp_no%2!=0: # continue if temp_time * t_conv < 7000. or temp_time * t_conv > 9000. or temp_no % 2 != 0: continue else: temp_snap = cmct.Snapshot( fname=snap_h5, snapshot_name=snap_keys[ii], conv=modelpath + 'initial.conv.sh', dist=dgc, # distance to cluster in kpc z=0.0038) ##Make surface brightness profile temp_snap.add_photometry( '/projects/b1095/syr904/MyCodes/cmctoolkit/filt_index.txt') v_bincenter, v_profile = temp_snap.make_smoothed_brightness_profile( 'V', bins=80, min_mass=None, max_mass=None, max_lum=12, fluxdict=None, startypes=np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), min_logr=-2.0) # Make velocity dispersion profiles star_velbin_center, star_veldisp_profile, star_e_veldisp_profile = temp_snap.make_smoothed_veldisp_profile( bins=80, min_mass=0.85, max_mass=None, dmax=None, fluxdict=None, startypes=np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), min_logr=-1.5) star_velbin_arcsec = uc.pc2arcsec(dgc, star_velbin_center) ##Make number density profile star_numbin_center, star_profile, star_e_profile = temp_snap.make_smoothed_number_profile( bins=80, min_mass=0.85, max_mass=None, fluxdict=None, startypes=np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), min_logr=-2.0) star_numbin_arcsec = uc.pc2arcsec(dgc, star_numbin_center) star_profile_arcsec = star_profile / (uc.pc2arcsec(dgc, 1.)**2) star_e_profile_arcsec = star_e_profile / (uc.pc2arcsec(dgc, 1.)**2) fsbp = modelpath + 'SBP' + str(temp_no) + '_LCUT12.txt' fvdp = modelpath + 'VDP' + str(temp_no) + '_MCUT0d85.txt' fndp = modelpath + 'NDP' + str(temp_no) + '_MCUT0d85.txt' np.savetxt(fsbp, np.c_[v_bincenter, v_profile], fmt='%f %f', header='1.r(arcsec) 2.miu_v(mag/arcsec^2) t=' + str(temp_time), comments='#') np.savetxt( fvdp, np.c_[star_velbin_arcsec, star_veldisp_profile, star_e_veldisp_profile], fmt='%f %f %f', header='1.r(arcsec) 2.sigma_v(km/s) 3.sigma_v_err(km/s) t=' + str(temp_time), comments='#') np.savetxt( fndp, np.c_[star_numbin_arcsec, star_profile_arcsec, star_e_profile_arcsec], fmt='%f %f %f', header='1.r(arcsec) 2.num(1/arcsec^2) 3.num_err(1/arcsec^2) t=' + str(temp_time), comments='#') print(snap_keys[ii]) snap_no_sort, snap_time_sort = (list(t) for t in zip( *sorted(zip(snap_no, snap_time)))) np.savetxt(modelpath + 'snap_keys.txt', np.c_[snap_no_sort, snap_time_sort], fmt='%d %.8f', header='1.snap_no 2.snap_time', comments='#')
def print_Nns_snap(modelpath): all_keys = np.genfromtxt(modelpath+'snap_keys.txt', dtype = str) t_conv = conv('t', modelpath+'initial.conv.sh') try: fh = open(modelpath+'initial.ns.dat', 'r') except: #if True: fhandle=open(modelpath+'initial.ns.dat', 'a+') fhandle.write('#1.Totaltime, 2.Nns,tot, 3.Nns,single, 4.Nns,binary, 5.Nns,mtb, 6.Npulsar, 7.Nmsp, 8.Nns-ns, 9.Nns-bh, 10.Nns-wd, 11.Nns-ms, 12.Nns-postms\n') for xx in range(len(all_keys[:,0])): keys_str = '/'+all_keys[:,0][xx]+'(t='+all_keys[:,1][xx]+')' snap = cmct.Snapshot(fname=modelpath+'initial.snapshots.h5', snapshot_name=keys_str, conv=modelpath+'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) T = float(all_keys[:,1][xx])*t_conv binflag = snap.data['binflag'] ktype = snap.data['startype'] #print(ktype) k0 = snap.data['bin_startype0']; k1 = snap.data['bin_startype1'] ospin = snap.data['ospin'] ospin0 = snap.data['ospin0']; ospin1 = snap.data['ospin1'] B = snap.data['B'] B0 = snap.data['B0']; B1 = snap.data['B1'] rad0 = snap.data['radrol0']; rad1 = snap.data['radrol1'] N_NS=0; N_NS_SIN=0; N_NS_BIN=0; N_NS_MTB=0; N_PULS=0; N_MSP=0; N_NSNS=0; N_NSBH=0; N_NSWD=0; N_NSMS=0; N_NSPOSTMS=0 for kk in range(len(binflag)): if binflag[kk]!=1: #print('yes1') if ktype[kk]==13: #print('yes2') N_NS+=1; N_NS_SIN+=1 spin=twopi*yearsc/ospin[kk] deathcut=(spin**2)*(0.17*10**12) if deathcut<B[kk]: N_PULS+=1 if spin<=0.03: N_MSP+=1 else: if k0[kk]==13: #print('yes3') N_NS+=1; N_NS_BIN+=1 spin0=twopi*yearsc/ospin0[kk] deathcut0=(spin0**2)*(0.17*10**12) if rad1[kk]>=1: N_NS_MTB+=1 if deathcut0<B0[kk]: N_PULS+=1 if spin0<=0.03: N_MSP+=1 if k1[kk]<2: N_NSMS+=1 elif k1[kk]>=10 and k1[kk]<=12: N_NSWD+=1 elif k1[kk]==13: N_NSNS+=1 elif k1[kk]==14: N_NSBH+=1 else: N_NSPOSTMS+=1 if k1[kk]==13: #print('yes4') N_NS+=1; N_NS_BIN+=1 spin1=twopi*yearsc/ospin1[kk] deathcut1=(spin1**2)*(0.17*10**12) if rad0[kk]>=1: N_NS_MTB+=1 if deathcut1<B1[kk]: N_PULS+=1 if spin1<=0.03: N_MSP+=1 if k0[kk]<2: N_NSMS+=1 elif k0[kk]>=10 and k0[kk]<=12: N_NSWD+=1 elif k0[kk]==13: print('already counted') elif k0[kk]==14: N_NSBH+=1 else: N_NSPOSTMS+=1 fhandle.write('%f %d %d %d %d %d %d %d %d %d %d %d\n'%(T, N_NS, N_NS_SIN, N_NS_BIN, N_NS_MTB, N_PULS, N_MSP, N_NSNS, N_NSBH, N_NSWD, N_NSMS, N_NSPOSTMS)) print(xx) fhandle.close()
def get_allpsr_atsnap(modelpath, mspfg, snapno): T=[]; BF=[]; S=[]; F=[]; ID_0=[]; ID_1=[]; M_0=[]; M_1=[]; K_0=[]; K_1=[]; Aaxis=[]; E=[]; DMDT0=[]; DMDT1=[]; RAD0=[]; RAD1=[]; RADIUS=[]; TCFLAG=[] all_keys = np.genfromtxt(modelpath+'snap_keys.txt', dtype = 'str') all_snapno = all_keys[:,0]; all_snaptime = all_keys[:,1] thekey = '/'+str(snapno)+'(t='+all_snaptime[snapno]+')' pref='initial' filestr=modelpath+pref t_conv=conv('t', filestr+'.conv.sh') l_conv=conv('l', filestr+'.conv.sh') snap = cmct.Snapshot(fname=modelpath+'initial.snapshots.h5', snapshot_name=thekey, conv=modelpath+'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) print('read snap') t_age = snap.age Bf, Spin, Id0, Id1, M0, M1, K0, K1, A, Ecc, Fc, Dmdt0, Dmdt1, Radrol0, Radrol1, R=get_allpsr_snapshot(snap, mspfg) print('get psr data') prop_init, prop_finl, prop_des=ntc.find_tc_properties_final(modelpath) tc_id0 = prop_init['id0']; tc_id1 = prop_init['id1']; tc_type = prop_init['type'] tcflag = [] for i in range(len(Id0)): tcflag.append(4) for j in range(len(tc_id0)): if Id1[i]!=-100: if (Id0[i]==tc_id0[j] and Id1[i]==tc_id1[j]) or (Id1[i]==tc_id0[j] and Id0[i]==tc_id1[j]): if tc_type[j]=='SS_COLL_Giant': tcflag[i]=81 break if tc_type[j]=='SS_COLL_TC_P': tcflag[i]=91 break elif Id0[i]==tc_id0[j] or Id0[i]==tc_id1[j]: if tc_type[j]=='SS_COLL_Giant': tcflag[i]=82 break if tc_type[j]=='SS_COLL_TC_P': tcflag[i]=92 break else: if Id0[i]==tc_id0[j] or Id0[i]==tc_id1[j]: if tc_type[j]=='SS_COLL_Giant': tcflag[i]=83 break if tc_type[j]=='SS_COLL_TC_P': tcflag[i]=93 break Time=list(np.full_like(Id0, t_age, dtype=np.double)) #print(Time, Model, Mst) T=T+Time; BF=BF+Bf; S=S+Spin; F=F+Fc; ID_0=ID_0+Id0; ID_1=ID_1+Id1; M_0=M_0+M0; M_1=M_1+M1; K_0=K_0+K0; K_1=K_1+K1; Aaxis=Aaxis+A; E=E+Ecc DMDT0=DMDT0+Dmdt0; DMDT1=DMDT1+Dmdt1; RAD0=RAD0+Radrol0; RAD1=RAD1+Radrol1; RADIUS=RADIUS+R TCFLAG=TCFLAG+tcflag RADIUS=np.array(RADIUS)*l_conv print('done') print(len(T), len(RADIUS), len(BF), len(S), len(DMDT0), len(DMDT1), len(RAD0), len(RAD1), len(M_0), len(M_1), len(ID_0), len(ID_1), len(K_0), len(K_1), len(Aaxis), len(E), len(F), len(TCFLAG)) np.savetxt(modelpath+mspfg+str(snapno)+'.dat', np.c_[T, RADIUS, BF, S, DMDT0, DMDT1, RAD0, RAD1, M_0, M_1, ID_0, ID_1, K_0, K_1, Aaxis, E, F, TCFLAG], fmt ='%f %f %e %f %f %f %f %f %f %f %d %d %d %d %f %f %d %d', delimiter= ' ', header = '1.Time(Myr) 2.r(pc) 3.B(G) 4.P(sec) 5.dmdt0(Msun/yr) 6.dmdt1(Msun/yr) 7.rolrad0 8.rolrad1 9.m0(Msun) 10.m1(Msun) 11.ID0 12.ID1 13.k0 14.k1 15.a(AU) 16.ecc 17.Formation 18.TCflag', comments = '#')
def find_WD_XX_atsnap_hdf5(filepath, lowlim, highlim, snapno, savename): property_init, property_finl, property_des = nhf.find_tc_properties( filepath) ID0 = property_init['id0'] ID1 = property_init['id1'] T = property_init['time'] Types = property_init['type'] all_keys = np.genfromtxt(filepath + 'snap_keys.txt', dtype='str') all_snapno = all_keys[:, 0] all_snaptime = all_keys[:, 1] thekey = '/' + str(snapno) + '(t=' + all_snaptime[snapno] + ')' filestr = filepath + 'initial' snap = cmct.Snapshot( fname=filepath + 'initial.snapshots.h5', snapshot_name=thekey, conv=filepath + 'initial.conv.sh', dist=4.52, # distance to cluster in kpc z=0.0038) t_conv = dyn.conv('t', filestr + '.conv.sh') l_conv = dyn.conv('l', filestr + '.conv.sh') #os.system('rm '+savepath) fmsb = open(filepath + savename + str(snapno) + '.dat', 'w+') fmsb.write( '#1.ID0 2.ID1 3.M0 4.M1 5.K0 6.K1 7.a(AU) 8.ecc 9.radrol0 10.radrol1 11.B(G) 12.P(sec) 13.tcflag 14.SN 15.TC_time(Myr) 16.R(pc)\n' ) binflag = snap.data['binflag'] k0 = snap.data['bin_startype0'] k1 = snap.data['bin_startype1'] id0 = snap.data['id0'] id1 = snap.data['id1'] m0 = snap.data['m0_MSUN'] m1 = snap.data['m1_MSUN'] sma = snap.data['a_AU'] ecc = snap.data['e'] rad0 = snap.data['radrol0'] rad1 = snap.data['radrol1'] B0 = snap.data['B0'] B1 = snap.data['B1'] ospin0 = snap.data['ospin0'] ospin1 = snap.data['ospin1'] SN0 = snap.data['formation0'] SN1 = snap.data['formation1'] Rpc = snap.data['r'] * l_conv for xx in range(len(binflag)): if binflag[xx] == 1: if 10 <= k0[xx] <= 12 and lowlim <= k1[xx] <= highlim: ID0ms = id0[xx] ID1ms = id1[xx] tcflag = 4 tctime = -100 for ii in range(len(ID0)): if (ID0ms == ID0[ii] and ID1ms == ID1[ii]) or (ID1ms == ID0[ii] and ID0ms == ID1[ii]): if Types[ii] == 'SS_COLL_Giant': tcflag = 81 tctime = T[ii] * t_conv break if Types[ii] == 'SS_COLL_TC_P': tcflag = 91 tctime = T[ii] * t_conv break elif ID0ms == ID0[ii] or ID0ms == ID1[ii]: if Types[ii] == 'SS_COLL_Giant': tcflag = 82 tctime = T[ii] * t_conv break if Types[ii] == 'SS_COLL_TC_P': tcflag = 92 tctime = T[ii] * t_conv break fmsb.write( '%d %d %f %f %d %d %f %f %f %f %e %f %d %d %f %f\n' % (id0[xx], id1[xx], m0[xx], m1[xx], k0[xx], k1[xx], sma[xx], ecc[xx], rad0[xx], rad1[xx], B0[xx], twopi * yearsc / ospin0[xx], tcflag, SN0[xx], tctime, Rpc[xx])) if lowlim <= k0[xx] <= highlim and 10 <= k1[xx] <= 12: ID0ms = id1[xx] ID1ms = id0[xx] tcflag = 4 tctime = -100 for ii in range(len(ID0)): if (ID0ms == ID0[ii] and ID1ms == ID1[ii]) or (ID1ms == ID0[ii] and ID0ms == ID1[ii]): if Types[ii] == 'SS_COLL_Giant': tcflag = 81 tctime = T[ii] * t_conv break if Types[ii] == 'SS_COLL_TC_P': tcflag = 91 tctime = T[ii] * t_conv break elif ID0ms == ID0[ii] or ID0ms == ID1[ii]: if Types[ii] == 'SS_COLL_Giant': tcflag = 82 tctime = T[ii] * t_conv break if Types[ii] == 'SS_COLL_TC_P': tcflag = 92 tctime = T[ii] * t_conv break fmsb.write( '%d %d %f %f %d %d %f %f %f %f %e %f %d %d %f %f\n' % (id1[xx], id0[xx], m1[xx], m0[xx], k1[xx], k0[xx], sma[xx], ecc[xx], rad1[xx], rad0[xx], B1[xx], twopi * yearsc / ospin1[xx], tcflag, SN1[xx], tctime, Rpc[xx])) fmsb.close()