def Initial_Single_Sample(self): """ Creates and evolves a set of "single" = wide binaries with 0Msun comparions with given age (to evolve to), number of stars, and metallicity. """ # Initial (input) binares -- using sampler method from cosmic #1234 - random seed print("initial single input:", self.age, self.Z, self.Nsing) # InitialSingles, sampled_mass, n_sampled = InitialBinaryTable.sampler('multidim',\ # [0,12], [0,12],self.random_seed,1, 'delta_burst', self.age, self.Z, self.Nsing) #OLD COSMIC (on quest) # InitialSingles, sampled_mass, mass_binaries, n_singles, n_binaries = InitialBinaryTable.sampler('independent', \ # [0,12], [0,12], primary_model='kroupa93', ecc_model='uniform', SFH_model='delta_burst', \ # binfrac_model=1.0, component_age=self.age, met=self.Z, size=self.Nsing) #COSMIC v3.3.0 InitialSingles, sampled_mass, mass_binaries, n_singles, n_binaries = InitialBinaryTable.sampler('independent', \ final_kstar1=np.arange(0,13), final_kstar2=np.arange(0,13), primary_model='kroupa93', ecc_model='uniform', SF_start=self.age, SF_duration=0,\ binfrac_model=1.0, met=self.Z, size=self.Nsing, porb_model='log_uniform') #change the periods and secondary masses for i, row in InitialSingles.iterrows(): InitialSingles.at[i, 'mass2_binary'] = 0 InitialSingles.at[i, 'porb'] = 1e10 #print(InitialSingles) if (len(InitialSingles) > self.Nsing): InitialSingles = InitialSingles[0:self.Nsing] if (len(InitialSingles) < self.Nsing): print('!!!!WARNING: to few singles', len(InitialSingles), self.Nsing) self.InitialSingles = InitialSingles
def cluster_bin_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)#, porb_hi = [3]) # 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 (InitialBinaries, bcm)
def Initial_Binary_Sample(self): """ Creates and evolves a set of binaries with given age (to evolve to), number of binaries, metallicity, and velocity dispersion. """ self.porb_hi = min(self.surveyTime, self.period_hardsoft) print("initial binary input:", self.random_seed, self.age, self.Z, self.Nbin, self.sigma, self.period_hardsoft) #OLD Cosmic (currently on Quest) # InitialBinaries, mass_singles, mass_binaries, n_singles, n_binaries = InitialBinaryTable.sampler('multidim',\ # [0,12], [0,12],self.random_seed,1, 'delta_burst', self.age, self.Z, self.Nbin, porb_lo = self.porb_lo, porb_hi = self.porb_hi) #COSMIC v3.3.0 InitialBinaries, mass_singles, mass_binaries, n_singles, n_binaries = InitialBinaryTable.sampler('multidim',\ final_kstar1=np.arange(0,13), final_kstar2=np.arange(0,13),rand_seed=self.random_seed, nproc=1, SF_start=self.age, SF_duration=0, met=self.Z, size=self.Nbin, porb_lo = self.porb_lo, porb_hi = self.porb_hi) self.InitialBinaries = InitialBinaries
def Initial_Binary_Sample(cls, age, Nbin, Z, random_seed): # """Creates and evolves a set of binaries with given # age (to evolve to), number of binaries, metallicity, and velocity dispersion. """ # 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)# porb_hi = [3]) # 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) # Input binary params p_i = InitialBinaries['porb'] m1_i = InitialBinaries['mass1_binary'] #In Msun units m2_i = InitialBinaries['mass2_binary'] ecc_i = InitialBinaries['ecc'] tphysf_i = InitialBinaries['tphysf'] #Time to evolve to (Myr) Z_i = InitialBinaries['metallicity'] # Applying HS formula to every binary/row in Initial Binary Table InitialBinaries['m3'] = 0.5 * np.ones( len(InitialBinaries)) #Setting up m3 values (0.5 Msun) InitialBinaries['sigma'] = 0.8 * np.ones( len(InitialBinaries )) #Sample velocity dispersion, will use cluster sigma values InitialBinaries['HS_Cutoff'] = InitialBinaries.apply( cls.get_Phs, axis=1 ) #args = (row['mass1_binary'], row['mass2_binary'], 0.5, 1)) InitialBinaries['HS_Cutoff'] = InitialBinaries['HS_Cutoff'] / ( 24 * 3600) #converting from days to seconds HS_Cutoff = InitialBinaries['HS_Cutoff'] # Throwing out soft binaries InitialBinaries = InitialBinaries.loc[np.where( p_i < HS_Cutoff)] #Throwing out soft binaries return (InitialBinaries)
def Initial_Binary_Sample(self): """ Creates and evolves a set of binaries with given age (to evolve to), number of binaries, metallicity, and velocity dispersion. """ # Initial (input) binares -- using sampler method from cosmic #1234 - random seed print(self.random_seed, self.age, self.Z, self.Nbin, self.period_hardsoft) InitialBinaries, sampled_mass, n_sampled = InitialBinaryTable.sampler('multidim',\ [0,14], [0,14],self.random_seed,1, 'delta_burst', self.age, self.Z, self.Nbin, porb_lo = 0.15, porb_hi = self.period_hardsoft) # Input binary params p_i = InitialBinaries['porb'] m1_i = InitialBinaries['mass1_binary'] #In Msun units m2_i = InitialBinaries['mass2_binary'] ecc_i = InitialBinaries['ecc'] tphysf_i = InitialBinaries['tphysf'] #Time to evolve to (Myr) Z_i = InitialBinaries['metallicity'] self.InitialBinaries = InitialBinaries
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
1, 'ST_tide': 1, 'bdecayfac': 1, 'rembar_massloss': 0.5, 'kickflag': 0, 'zsun': 0.014, 'bhms_coll_flag': 0, 'don_lim': -1, 'acc_lim': -1 } binary_set = InitialBinaryTable.InitialBinaries(m1=[85.543645, 11.171469], m2=[84.99784, 9.67305], porb=[446.795757, 370.758343], ecc=[0.448872, 0.370], tphysf=[13700.0, 13700.0], kstar1=[1, 1], kstar2=[1, 1], metallicity=[0.002, 0.02]) fig = evolve_and_plot(binary_set, t_min=None, t_max=[6.0, 60.0], BSEDict=BSEDict, sys_obs={})
from cosmic.sample.initialbinarytable import InitialBinaryTable from cosmic.plotting import evolve_and_plot single_binary = InitialBinaryTable.InitialBinaries(m1=85.543645, m2=84.99784, porb=446.795757, ecc=0.448872, tphysf=13700.0, kstar1=1, kstar2=1, metallicity=0.002) BSEDict = { 'xi': 1.0, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'wdflag': 1, '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} # Final kstar types to evolve up to (10- max evolution time, 11 - binary disruption, 12 - begin simbiotic phase): https://cosmic-popsynth.github.io/examples/index.html final_kstar1 = [11, 12] 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']
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')
from cosmic.utils import a_from_p from cosmic.sample.initialbinarytable import InitialBinaryTable import pandas as pd import numpy as np import matplotlib.pyplot as plt final_kstar = np.linspace(0, 14, 15) colors = {'green': '#1b9e77', 'purple': '#d95f02', 'orange': '#7570b3'} initC_logP, m_sin_logP, m_bin_logP, n_sin_logP, n_bin_logP = InitialBinaryTable.sampler( 'independent', final_kstar1=final_kstar, final_kstar2=final_kstar, binfrac_model=1.0, primary_model='kroupa01', ecc_model='thermal', porb_model='log_uniform', qmin=-1, SF_start=13700.0, SF_duration=0.0, met=0.02, size=100000) initC_Sana, m_sin_Sana, m_bin_Sana, n_sin_Sana, n_bin_Sana = InitialBinaryTable.sampler( 'independent', final_kstar1=final_kstar, final_kstar2=final_kstar, binfrac_model=1.0, primary_model='kroupa01', ecc_model='sana12', porb_model='sana12', qmin=-1, SF_start=13700.0, SF_duration=0.0,
] TEST_DATA_DIR = os.path.join(os.path.split(__file__)[0], 'data') BPP_ARRAY = np.load(os.path.join(TEST_DATA_DIR, 'bpp_array_ind_sampling.npy')) INIT_CONDITIONS = np.load( os.path.join(TEST_DATA_DIR, 'init_conditions_ind_sampling.npy')) bppDF = pd.DataFrame(BPP_ARRAY, columns=bpp_columns, index=[int(INIT_CONDITIONS[35])] * len(BPP_ARRAY)) bppDF['bin_num'] = int(INIT_CONDITIONS[35]) SINGLE_BINARY = InitialBinaryTable.SingleBinary(m1=INIT_CONDITIONS[2], m2=INIT_CONDITIONS[3], porb=INIT_CONDITIONS[4], ecc=INIT_CONDITIONS[5], tphysf=INIT_CONDITIONS[7], kstar1=INIT_CONDITIONS[0], kstar2=INIT_CONDITIONS[1], metallicity=0.02) BSEDict = { 'xi': 0.5, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'wdflag': 0, 'alpha1': 1.0, 'pts1': 0.05, 'pts3': 0.02, 'pts2': 0.01, 'epsnov': 0.001,
from cosmic.utils import a_from_p from cosmic.sample.initialbinarytable import InitialBinaryTable import pandas as pd import numpy as np import matplotlib.pyplot as plt final_kstar = np.linspace(0, 14, 15) colors = {'green': '#1b9e77', 'purple': '#d95f02', 'orange': '#7570b3'} final_kstar = np.linspace(0, 14, 15) initC_mult, m_sin_mult, m_bin_mult, n_sin_mult, n_bin_mult = InitialBinaryTable.sampler( 'multidim', final_kstar1=final_kstar, final_kstar2=final_kstar, rand_seed=2, nproc=1, SF_start=13700.0, SF_duration=0.0, met=0.02, size=100000) initC_mult['sep'] = a_from_p(p=initC_mult.porb, m1=initC_mult.mass_1, m2=initC_mult.mass_2)
'cehestarflag' : 0, 'cemergeflag' : 0, 'ecsnp' : 2.5, 'ecsn_mlow' : 1.6, 'aic' : 1, 'sigmadiv' :-20.0} # Setting up input parameters n_grid = 1000 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) * 13500.0 # Generating BSE test - gives random binary properties binary_grid = InitialBinaryTable.MultipleBinary(m1=m1, m2=m2, \ porb=porb, ecc=ecc, tphysf=t_p,\ kstar1=k1, kstar2=k2, metallicity=metal) # 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']