utils
- cosmic.utils.a_from_p(p, m1, m2)[source]¶
Computes the separation from orbital period with KEPLER III
- Parameters:
- pfloat/array
orbital period [day]
- m1float/array
primary mass [msun]
- m2float/array
secondary mass [msun]
- Returns:
- sepfloat/array
separation [rsun]
- cosmic.utils.check_initial_conditions(full_initial_binary_table)[source]¶
Checks initial conditions and reports warnings
Only warning provided right now is if star begins in Roche lobe overflow
- cosmic.utils.conv_select(bcm_save, bpp_save, final_kstar_1, final_kstar_2, method, conv_lims)[source]¶
Select bcm data for special convergence cases
- Parameters:
- bcm_savepandas.DataFrame
bcm dataframe containing all saved bcm data
- bpp_savepandas.DataFrame
bpp dataframe containing all saved bpp data
- final_kstar_1list
contains list of final primary kstars specified by user
- final_kstar_2list
contains list of final primary kstars specified by user
- methodstr
stage in binary evolution to check convergence for only one method may be supplied and they are specified in the inifile
- conv_limsdict
dictionary where keys are convergence params and the values are lists containing a [lo, hi] value to filter the convergence param between any non-specified convergence params will not be filtered
- Returns:
- conv_savepandas.DataFrame
filtered dataframe containing binaries that fulfill user-specified convergence criteria
- cosmic.utils.convert_kstar_evol_type(bpp)[source]¶
Provides way to convert integer values to their string counterpart
The underlying fortran code relies on integers to indicate things like the evoltuionary stage of the star as well as key moments in its evolutionary track. If you pass the data frame returned from running
`Evolve.evolve`you can convert the columns with these integer proxies to their true astrophysical meaning.
- cosmic.utils.dat_transform(dat, dat_list)[source]¶
Transform a data set to have limits between zero and one using param_transform, then transform to log space
- Parameters:
- dat “ DataFrame
Data to transform to eventually perform KDE
- dat_listlist
List of DataFrame columns to include in transformation
- Returns:
- dat_transarray
Transformed data for columns in dat_list
- cosmic.utils.dat_un_transform(dat_sample, dat_set, dat_list)[source]¶
Un-transform data that was transformed in dat_transform
- Parameters:
- dat_samplearray
Data sampled from kde generated with transformed data
- dat_setDataFrame
Un-transformed data (same as dat in dat_transform)
- dat_listlist
List of DataFrame columns to include in transformation
- Returns:
- datarray
Array of data sampled from kde that is transformed back to bounds of the un-transformed data set the kde is generated from
- cosmic.utils.error_check(BSEDict, SSEDict, filters=None, convergence=None, sampling=None)[source]¶
Checks that values in BSEDict, SSEDict,filters, and convergence are viable
- cosmic.utils.explain_setting(setting)[source]¶
Provides explanation for a BSE setting from the cosmic-settings.json file
- Parameters:
- settingstr
Name of BSE setting to explain
- cosmic.utils.filter_bin_state(bcm, bpp, method, kstar1_range, kstar2_range)[source]¶
Filter the output of bpp and bcm, where the kstar ranges have already been selected by the conv_select module
- Parameters:
- bcmpandas.DataFrame
bcm dataframe
- bpppandas.DataFrame
bpp dataframe
- methoddict,
one or more methods by which to filter the bpp or bcm table, e.g.
{'binary_state' : [0,1]}; This means you do not want to select the final state of the binaries in the bcm array- kstar1_rangelist
list containing all kstar1 values to retain
- kstar2_rangelist
list containing all kstar2 values to retain
- Returns:
- bcmpandas.DataFrame
filtered bcm dataframe
- cosmic.utils.get_FeH_from_Z(Z, Z_sun=0.02)[source]¶
Converts from Z to FeH under the assumption that all stars have the same abundance as the sun
- Parameters:
- Zarray
metallicities to convert to Fe/H
- Z_sunfloat
solar metallicity
- Returns:
- FeHarray
Fe/H corresponding to metallicities
- cosmic.utils.get_METISSE_metallicity_files(path_to_tracks)[source]¶
Returns the path to the METISSE files
- Parameters:
- path_to_tracksstr
Path to the directory containing the METISSE metallicity file(s) for hydrogen/helium tracks
- Returns:
- met_fileslist
List of paths to the METISSE metallicity files for hydrogen/helium tracks
- cosmic.utils.get_Z_from_FeH(FeH, Z_sun=0.02)[source]¶
Converts from FeH to Z under the assumption that all stars have the same abundance as the sun
- Parameters:
- FeHarray
Fe/H values to convert
- Z_sunfloat
solar metallicity
- Returns:
- Zarray
metallicities corresponding to Fe/H
- cosmic.utils.get_binfrac_of_Z(Z)[source]¶
Calculates the theoretical binary fraction as a function of metallicity. Following Moe+2019
- Parameters:
- Zarray
metallicity Z values
- Returns:
- binfracarray
binary fraction values
- cosmic.utils.get_met_dep_binfrac(met)[source]¶
Returns a population-wide binary fraction consistent with Moe+19 based on the supplied metallicity
- Parameters:
- metfloat
metallicity of the population
- Returns:
- binfracfloat
binary fraction of the population based on metallicity
- cosmic.utils.get_porb_norm(Z, close_logP=4.0, wide_logP=6.0, binfrac_tot_solar=0.66, Z_sun=0.02)[source]¶
Returns normalization constants to produce log normals consistent with Fig 19 of Moe+19 for the orbital period distribution
- Parameters:
- Zarray
metallicity values
- close_logPfloat
divding line beween close and intermediate orbits
- wide_logPfloat
dividing line between intermediate and wide orbits
- binfrac_totfloat
integrated total binary fraction at solar metallicity
- Returns:
- norm_widefloat
normalization factor for kde for wide binaries
- norm_closefloat
normalization factor for kde for wide binaries
- cosmic.utils.idl_tabulate(x, f, p=5)[source]¶
Function that replicates the IDL int_tabulated function which performs a p-point integration on a tabulated set of data
- Parameters:
- xarray
tabulated x-value data
- farray
tabulated f-value data, same size as x
- pint
number of chunks to divide tabulated data into Default: 5
- Returns:
- retfloat
Integration result
- cosmic.utils.knuth_bw_selector(dat_list)[source]¶
Selects the kde bandwidth using Knuth’s rule implemented in Astropy If Knuth’s rule raises error, Scott’s rule is used
- Parameters:
- dat_listlist
List of data arrays that will be used to generate a kde
- Returns:
- bw_minfloat
Minimum of bandwidths for all of the data arrays in dat_list
- cosmic.utils.mass_min_max_select(kstar_1, kstar_2, **kwargs)[source]¶
Select a minimum and maximum mass to filter out binaries in the initial parameter sample to reduce the number of unneccessary binaries evolved in BSE
- Parameters:
- kstar_1int, list
BSE stellar type for the primary or minimum and maximum stellar types for the primary
- kstar_2int, list
BSE stellar type for the secondary or minimum and maximum stellar types for the secondary
- Returns:
- min_mass[0]float
minimum primary mass for initial sample
- max_mass[0]float
maximum primary mass for initial sample
- min_mass[1]float
minimum secondary mass for initial sample
- max_mass[1]float
maximum secondary mass for initial sample
- cosmic.utils.p_from_a(sep, m1, m2)[source]¶
Computes separation from orbital period with kepler III
- Parameters:
- sepfloat/array
separation [rsun]
- m1float/array
primary mass [msun]
- m2float/array
secondary mass [msun]
- Returns:
- pfloat/array
orbital period [day]
- cosmic.utils.param_transform(dat)[source]¶
Transforms a data set to limits between zero and one Leaves some wiggle room on the edges of the data set
- Parameters:
- datarray
array of data to transform between 0 and 1
- Returns:
- datTransformedarray
array of data with limits between 0 and 1
- cosmic.utils.parse_inifile(inifile)[source]¶
Provides a method for parsing the inifile and returning dicts of each section
- cosmic.utils.pop_write(dat_store, log_file, mass_list, number_list, bcm, bpp, initC, conv, kick_info, bin_state_nums, match, idx, **kwargs)[source]¶
- Writes all the good stuff that you want to save from runFixedPop in a
single function
- Parameters:
- dat_storepandas HDFStore
H5 file to write to
- log_filefile write
log file to write to
- mass_listlist
list containing the mass of the singles, mass of the binaries, and mass of the stars
- n_listlist
list containing the number of singles, number of binaries, and number of stars
- bcmpandas.DataFrame
bcm array to write
- bpppandas.DataFrame
bpp array to write
- initCondpandas.DataFrame
initCond array to write
- convpandas.DataFrame
conv array to write
- kick_infopandas.DataFrame
kick_info array to write
- bin_state_numslist
contains the count of binstates 0,1,2
- matchpandas.DataFrame
contains the match values for each conv_param
- idxint
contains the index of the bcm so we can pick up where we left off if runFixedPop hits a wall time
- conv_singlespandas.DataFrame
kwargs conv_singles array to write
- bcm_singlespandas.DataFrame
kwargs bcm_singles array to write
- bpp_singlespandas.DataFrame
kwargs bpp_singles array to write
- initC_singlespandas.DataFrame
kwargs initC_singles array to write
- kick_info_singlespandas.DataFrame
kwargs kick_info_singles array to write
- Returns:
- Nothing!
- cosmic.utils.read_eep_directory(eep_dir, fmt_dict)[source]¶
Read all EEP files in a directory matching the given pattern
- Parameters:
- eep_dirstr or Path
Directory containing the EEP files.
- fmt_dictdict
Dictionary containing format file options, e.g., column names, EEP stages, flags.
- Returns:
- trackslist of dict
List of track dictionaries, each as returned by read_eep_file
- cosmic.utils.read_format_file(format_file_path)[source]¶
Read the format file associated with the metallicity namelist
- Parameters:
- format_file_pathstr or Path
Path to the format file.
- Returns:
- fmt_dictdict
Dictionary containing format file options, e.g., column names, EEP stages, flags.
Notes
Booleans (.true./.false.) are converted to Python True/False.
Fortran-style scientific notation with ‘d’ (e.g., 1.23d-04) is converted to float.
Strings in quotes are stripped of the quotes.
Stops parsing at the Fortran namelist terminator ‘/’.
- cosmic.utils.read_metallicity_file(met_file_path)[source]¶
Read a metallicity namelist
- Parameters:
- met_file_pathstr or Path
Path to the metallicity file (*.in).
- Returns:
- met_dictdict
Dictionary containing metallicity options, e.g., ‘eep_tracks_dir’, ‘Z_files’, ‘format_file’, etc. Paths are converted to Path objects.
Notes
Booleans (.true./.false.) are converted to Python True/False.
Fortran-style scientific notation with ‘d’ (e.g., 1.23d-04) is converted to float.
Strings in quotes are stripped of the quotes.
Stops parsing at the Fortran namelist terminator ‘/’.
- cosmic.utils.rndm(a, b, g, size)[source]¶
Power-law generator for pdf(x)propto x^{g} for a<=x<=b
- Parameters:
- afloat
Minimum of range for power law
- bfloat
Maximum of range for power law
- gfloat
Index for power law
- sizeint
Number of data points to draw
- Returns:
- powerarray
Array of data sampled from power law distribution with params fixed by inputs