def test_multi_evolve_with_dict(self): EvolvedBinaryBPP, EvolvedBinaryBCM, initCond = Evolve.evolve( initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, randomseed=523574, n_per_block=100) pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False, check_less_precise=True) pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False, check_less_precise=True)
def cosmic_sampler(age, Nbin, Z, sigma, random_seed): """Creates and evolves a set of binaries with given age (to evolve to), number of binaries, metallicity, and velocity dispersion. Will later loop through globular and open clusters and apply this for loop""" n_grid = Nbin # Initial (input) binares -- using sampler method from cosmic #1234 - random seed InitialBinaries, sampled_mass, n_sampled = InitialBinaryTable.sampler('multidim',\ [11], [11], random_seed, 1, 'delta_burst', age, Z, Nbin) # Inclination and omega values inc = np.arccos(2. * np.random.uniform(0, 1, Nbin) - 1.) omega = np.random.uniform(0, 2 * np.pi, Nbin) OMEGA = np.random.uniform(0, 2 * np.pi, Nbin) print(InitialBinaries) # Making Input variables global (for plotting later) global p_i, m1_i, m2_i, ecc_i, tphysf_i, Z_i # Input binary params (for plotting later) p_i = InitialBinaries['porb'] m1_i = InitialBinaries['mass1_binary'] m2_i = InitialBinaries['mass2_binary'] ecc_i = InitialBinaries['ecc'] tphysf_i = InitialBinaries['tphysf'] Z_i = InitialBinaries['metallicity'] # Evolving input binaries bpp, bcm, initC = Evolve.evolve(initialbinarytable=InitialBinaries, BSEDict=BSEDict) # Making returned variables global global p_f, m1_f, m2_f, ecc_f, tphysf_f, r1_f, r2_f, lum1_f, lum2_f, Teff1, Teff2 # Evolved Binary Params (made global for plotting later, can ) p_f = bcm['porb'] m1_f = bcm['mass_1'] m2_f = bcm['mass_2'] ecc_f = bcm['ecc'] tphysf_f = bcm['tphys'] r1_f = bcm['rad_1'] r2_f = bcm['rad_2'] lum1_f = bcm['lumin_1'] lum2_f = bcm['lumin_2'] Teff1 = bcm['teff_1'] #Effective temperature - just in case Teff2 = bcm['teff_2'] return bcm
def EvolveBinaries(self): """Takes Initial (hard) binaries from above and evolves them""" #OLD COSMIC (on quest) #bpp, bcm, initC = Evolve.evolve(initialbinarytable = self.InitialBinaries, BSEDict = self.BSEDict) #COSMIC v3.3.0 bpp, bcm, initC, kick_info = Evolve.evolve( initialbinarytable=self.InitialBinaries, BSEDict=self.BSEDict) self.bpp = bpp self.bcm = bcm ################## #we need to grab only the final values at the age of the cluster, and those that are still in binaries ############### self.bcmEvolved = self.bcm.loc[(self.bcm['tphys'] == self.age) & (self.bcm['bin_state'] == 0) & (self.bcm['mass_1'] > 0) & (self.bcm['mass_2'] > 0)] #reset index? self.bcmEvolved.reset_index(drop=True, inplace=True)
def EvolveBinaries(self): """Takes Initial (hard) binaries from above and evolves them""" # BSE dictionary copied from cosmic's documentation (unchanged): https://cosmic-popsynth.github.io BSEDict = {'xi': 0.5, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'wdflag': 0, 'alpha1': 1.0, \ 'pts1': 0.001, 'pts3': 0.02, 'pts2': 0.01, 'epsnov': 0.001, 'hewind': 1.0, 'ck': -1000, 'bwind': 0.0, 'lambdaf': 1.0, \ 'mxns': 3.0, 'beta': -1.0, 'tflag': 1, 'acc2': 1.5, 'nsflag': 3, 'ceflag': 0, 'eddfac': 1.0, 'merger': 0, 'ifflag': 0, \ 'bconst': -3000, 'sigma': 265.0, 'gamma': -2.0, 'ppsn': 1,\ 'natal_kick_array' : [-100.0,-100.0,-100.0,-100.0,-100.0,-100.0], 'bhsigmafrac' : 1.0, 'polar_kick_angle' : 90,\ 'qcrit_array' : [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0], 'cekickflag' : 0, \ 'cehestarflag' : 0, 'cemergeflag' : 0, 'ecsnp' : 2.5, 'ecsn_mlow' : 1.6, 'aic' : 1, 'sigmadiv' :-20.0} bpp, bcm, initC = Evolve.evolve( initialbinarytable=self.InitialBinaries, BSEDict=BSEDict) self.bpp = bpp self.bcm = bcm self.bcmEvolved = self.bcm.loc[self.bcm['tphys'] == self.age] print(self.bcmEvolved)
def cosmic_run(cluster_age, Nbin): n_grid = Nbin m1 = np.random.uniform(0.5, 2, 1000) m2 = np.random.uniform(0.5, 2, 1000) metal = np.ones(n_grid) porb = np.random.uniform(0, 1000, 1000) ecc = np.random.random(1000) k1 = np.ones(n_grid) k2 = np.ones(n_grid) t_p = np.ones(n_grid) * cluster_age # Initial grid of binaries (input parameters) binary_grid = InitialBinaryTable.MultipleBinary(m1=m1, m2=m2, \ porb=porb, ecc=ecc, tphysf=t_p,\ kstar1=k1, kstar2=k2, metallicity=metal) # Setting up variables drawn from initial binary table (binary_grid) p_i = binary_grid['porb'] m1_i = binary_grid['mass1_binary'] m2_i = binary_grid['mass2_binary'] ecc_i = binary_grid['ecc'] tphysf_i = binary_grid['tphysf'] Z_i = binary_grid['metallicity'] # Using this class to evolve the binaries taken from the initial binary grid bpp, bcm, initC = Evolve.evolve(initialbinarytable=binary_grid, BSEDict=BSEDict) # Setting up variables from evolved binaries (bcm - certain times) p_f = bcm['porb'] m1_f = bcm['mass_1'] m2_f = bcm['mass_2'] ecc_f = bcm['ecc'] tphysf_f = bcm['tphys'] r1_f = bcm['rad_1'] r2_f = bcm['rad_2'] return bcm
def test_single_evolve_with_dict_and_table(self): EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve( initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, randomseed=523574) pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False, check_less_precise=True) pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False, check_less_precise=True)
def test_single_evolve_with_inifile(self): EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve( initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, params=PARAMS_INI, randomseed=523574) pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False, check_less_precise=True) pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False, check_less_precise=True)
final_kstar2 = [10] # Sampling initial binaries - pulled from cosmic's documentation InitialBinaries, sampled_mass, n_sampled = InitialBinaryTable.sampler('multidim', [0,14], [0,14], \ 2,1, SFH_model='delta_burst', \ component_age=13000.0, met=0.02, size=60000) # Initial Binary Period Histogram f, ax = plt.subplots(figsize=(8, 5)) ax.hist(np.log10(p_i), bins=50, color='#CF0A2C') ax.set_xlabel('Input Periods (log-days)') ax.grid(None) f.savefig('/projects/p30137/abowen/CEB/cosmic/plots/InputBinaryHist-60k.png') # Evolving the binaries bpp, bcm, initC = Evolve.evolve(initialbinarytable=InitialBinaries, BSEDict=BSEDict) # Defining initial and final periods p_i = InitialBinaries['porb'] p_f = bcm['porb'] # Evolved Binary Histogram - Period f, ax = plt.subplots(figsize=(8, 5)) ax.hist(np.log10(p_f), bins=50, color='black') ax.set_xlabel('Evolved periods (log-days)') ax.grid(None) f.savefig('/projects/p30137/abowen/CEB/cosmic/plots/EvolvedBinaryHist-60k.png') # Making copy of bcm for later EvolvedBinaries = bcm
for bpp_met, initC_met in zip(bpp_mets, initC_mets): ## true/false params for the binary this_BBH = False this_BBHm = False this_HMXB = False sample_bpp = bpps.iloc[np.where(bpps['metallicity'] == bpp_met)[0]] sample_initC = initCs.iloc[np.where( initCs['metallicity'] == initC_met)[0]] if (sample_initC.shape[0] > 1): sample_initC = sample_initC.iloc[:-1] bpp, bcm, initC, kick_info = Evolve.evolve( initialbinarytable=sample_initC, timestep_conditions=timestep_conditions) merger_type = int(bcm['merger_type'].iloc[-1]) bin_state = bcm['bin_state'].iloc[-1] z_f = sample_bpp['redshift'].iloc[-1] d_L = (1 + z_f) * cosmo.comoving_distance(z_f).to( u.cm).value ## luminosity distance, in cm for flux calculation ## "cosmological weight" of the system using comoving volume element dVdz = cosmo.differential_comoving_volume(z_f) p_cosmic = dVdz * (1 + z_f)**-1 ## get ZAMS masses for the binary ZAMS_mass_k1 = bpp['mass_1'].iloc[0]
final_kstar1 = [10, 11, 12] final_kstar2 = [10, 11, 12] prim_mod = 'kroupa01' ecc_mod = 'uniform' porb_mod = 'sana12' SF_st = 13700.0 SF_d = 0.0 Z = 0.017 num = 10000 InitBin, mass_singles, mass_binaries, n_singles, n_binaries = InitialBinaryTable.sampler( 'independent', final_kstar1, final_kstar2, binfrac_model=0.5, primary_model=prim_mod, ecc_model=ecc_mod, porb_model=porb_mod, SF_start=SF_st, SF_duration=SF_d, met=Z, size=num) bpp, bcm, initC, kick = Evolve.evolve(initialbinarytable=InitBin, BSEDict=BSEDict, n=8) bpp.to_hdf('datafile.hdf', key='bpp') bcm.to_hdf('datafile.hdf', key='bcm') initC.to_hdf('datafile.hdf', key='bcm')
B = f.create_group('BSEDict') for key in BSEDict.keys(): f['BSEDict'][key] = BSEDict[key] f.attrs['COSMIC_git_hash'] = commit_cosmic f.attrs['LMXB_git_hash'] = commit_lmxb f.attrs['Nbse'] = run_config.Nbse f.attrs['Mexp'] = run_config.Mexp InitialTable = initialize_binary_table(BSE_input) call('rm ' + BSE_input) bpp, bcm, initC = Evolve.evolve(initialbinarytable=InitialTable, BSEDict=BSEDict, nproc=args.ncores, idx=int(args.i) * run_config.Nbse) iloc = np.where(((( (bpp.evol_type == 15) | (bpp.evol_type == 15.5)) & (bpp.kstar_2 < 13)) | (((bpp.evol_type == 16) | (bpp.evol_type == 16.5)) & (bpp.kstar_1 < 13))) & (bpp.sep > 0))[0] bpp_preSN = bpp.iloc[iloc] bin_num = bpp.iloc[iloc].index initC = initC.set_index('bin_num') initC_preSN = initC.loc[bin_num] initC_preSN.to_hdf(INITC_input, key='initC') preSNbinaries = construct_bse_output(bpp_preSN, initC_preSN)
def EvolveBinaries(cls): bpp, bcm, initC = Evolve.evolve(initialbinarytable=cls.InitialBinaries, BSEDict=BSEDict)
# Can print initial binaries if needed # print('Initial Binaries:') # print(binary_grid) # print(' ') # Setting up variables drawn from initial binary table (binary_grid) p_i = binary_grid['porb'] m1_i = binary_grid['mass1_binary'] m2_i = binary_grid['mass2_binary'] ecc_i = binary_grid['ecc'] tphysf_i = binary_grid['tphysf'] Z_i = binary_grid['metallicity'] # Using this class to evolve the binaries taken from the initial binary grid bpp, bcm, initC = Evolve.evolve(initialbinarytable=binary_grid, BSEDict=BSEDict) # Printing Evolved binaries # print('Evolved Binaries:') # print(bpp, bcm, initC) print(np.size(bcm)) # Setting up variables from evolved binaries (bcm - certain times) p_f = bcm['porb'] m1_f = bcm['mass_1'] m2_f = bcm['mass_2'] ecc_f = bcm['ecc'] tphysf_f = bcm['tphys'] r1_f = bcm['rad_1'] r2_f = bcm['rad_2'] print(bcm['radc_1'])