posydon.popsyn
posydon.popsyn.GRB
posydon.popsyn.analysis
Module for analyzing binary population simulation results.
- posydon.popsyn.analysis.get_subsets(path, find_n=None, select_oneline=None, select_history=None, select_columns=None, verbose=True)[source]
Get the oneline and history subsets for a selection of binaries.
You select binaries from an HDF5 population by providing a function that operates either on oneline or history and returns a boolean mask in- dicating which rows correspond to the binaries of interest. E.g.,
- def find_no_end(df):
return df[“event_f”] != “END”
can be used to find binaries that ended abruptly, based on the information in the oneline table. Therefore, we set select_oneline=find_no_end. If no selector has been set, all binaries are selected (combine this with the select_columns argument to get a column subset of the data.)
- Parameters:
path (str) – The fullpath of the HDF5 file.
find_n (int or None) – The number of binaries to select (at most) or None to select all.
select_oneline (function or None) – The function to operate on chunks of the oneline table.
select_history (function or None) – The function to operate on chunks of the oneline table.
select_columns (None or str or array) – If None, all columns will be returned. If a string, only those columns with name containing this string will be returned. An array of strings can be used for multiple such patterns.
- Returns:
The subsets of the dataframes with the data for the selected binaries.
- Return type:
oneline, history
posydon.popsyn.binarypopulation
posydon.popsyn.defaults
Default binary population parameters.
posydon.popsyn.independent_sample
Generate the initial parameters for a binary population.
- posydon.popsyn.independent_sample.binary_fraction_value(binary_fraction_const=1, binary_fraction_scheme='const', m1=None, **kwargs)[source]
Getting the binary fraction depending on the scheme. The two possible option are a constant binary fraction and a binary fraction based on the values given in Moe and Di Stefano (2017).
- posydon.popsyn.independent_sample.generate_eccentricities(number_of_binaries=1, eccentricity_scheme='thermal', **kwargs)[source]
Generate random eccentricities.
Use the scheme defined in this particular instance of BinaryPopulation.
- Parameters:
number_of_binaries (int) – Number of binaries that require randomly sampled orbital separations
eccentricity_scheme (string) – Distribution from which eccentricities are randomly drawn
**kwargs (dictionary) – kwargs from BinaryPopulation class
- Returns:
eccentricities – Randomly drawn eccentricities
- Return type:
ndarray of floats
- posydon.popsyn.independent_sample.generate_independent_samples(orbital_scheme='period', **kwargs)[source]
Randomly generate a population of binaries at ZAMS.
- Parameters:
orbital_scheme (str (default: 'period')) – The scheme to use to get either orbital periods or separations
**kwargs (dictionary) – kwargs from BinaryPopulation class
- Returns:
orbital_scheme_set (ndarray of floats) – Randomly drawn orbital separations/periods depending on the scheme
eccentricity_set (ndarray of floats) – Randomly drawn eccentricities
m1_set (ndarray of floats) – Randomly drawn primary masses
m2_set (ndarray of floats) – Randomly drawn secondary masses
- posydon.popsyn.independent_sample.generate_orbital_periods(primary_masses, number_of_binaries=1, orbital_period_min=0.35, orbital_period_max=10**3.5, orbital_period_scheme='Sana+12_period_extended', **kwargs)[source]
Randomaly generate orbital periods for a sample of binaries.
- posydon.popsyn.independent_sample.generate_orbital_separations(number_of_binaries=1, orbital_separation_min=5, orbital_separation_max=1e5, log_orbital_separation_mean=None, log_orbital_separation_sigma=None, orbital_separation_scheme='log_uniform', **kwargs)[source]
Generate random orbital separations.
Use the scheme defined in this particular instance of BinaryPopulation.
- Parameters:
number_of_binaries (int) – Number of binaries that require randomly sampled orbital separations
orbital_separation_min (float) – Minimum orbital separation in solar radii
orbital_separation_max (float) – Maximum orbital separation in solar radii
log_orbital_separation_mean (float) – Mean of the lognormal distribution.
log_orbital_separation_sigma (float) – Standard deviation of the lorgnormal distribution.
orbital_separation_scheme (string) – Distribution from which the orbital separations are randomly drawn
- Returns:
orbital_separations – Randomly drawn orbital separations
- Return type:
ndarray of floats
- posydon.popsyn.independent_sample.generate_primary_masses(number_of_binaries=1, primary_mass_min=7, primary_mass_max=120, primary_mass_scheme='Salpeter', **kwargs)[source]
Generate random primary masses.
Use the scheme defined in this particular instance of BinaryPopulation.
- Parameters:
- Returns:
primary_masses – Randomly drawn primary masses
- Return type:
ndarray of floats
- posydon.popsyn.independent_sample.generate_secondary_masses(primary_masses, number_of_binaries=1, secondary_mass_min=0.35, secondary_mass_max=120, secondary_mass_scheme='flat_mass_ratio', **kwargs)[source]
Generate random secondary masses.
Use the scheme defined in this particular instance of BinaryPopulation.
- Parameters:
primary_masses (ndarray of floats) – Previously drawn primary masses
number_of_binaries (int) – Number of binaries that require randomly sampled orbital separations
secondary_mass_min (float) – Minimum secondary mass
secondary_mass_max (float) – Maximum secondary mass
secondary_mass_scheme (string) – Distribution from which the secondary masses are randomly drawn
- Returns:
secondary_masses – Randomly drawn secondary masses
- Return type:
ndarray of floats
posydon.popsyn.io
Handle I/O operations for the population synthesis code.
- posydon.popsyn.io.binarypop_kwargs_from_ini(path, verbose=False)[source]
Convert an inifile into kwargs for the BinaryPopulation class.
- posydon.popsyn.io.clean_binary_history_df(binary_df, extra_binary_dtypes_user=None, extra_S1_dtypes_user=None, extra_S2_dtypes_user=None)[source]
Take a posydon binary history DataFrame from the BinaryStar.to_df method and clean the data for saving by setting Data Types of the columns explicitly.
- Parameters:
binary_df (DataFrame) – A pandas Dataframe containing binary history
extra_binary_dtypes_user (dict, optional) – A dictionary with extra column names as keys, and their associated data types as values.
extra_S1_dtypes_user (dict, optional) – Same as above, but only for star 1.
extra_S2_dtypes_user (dict, optional) – Same as above, but only for star 2.
- Returns:
binary_df – A cleaned binary history ready for saving to HDF.
- Return type:
DataFrame
- posydon.popsyn.io.clean_binary_oneline_df(oneline_df, extra_binary_dtypes_user=None, extra_S1_dtypes_user=None, extra_S2_dtypes_user=None)[source]
Take a posydon binary oneline DataFrame from the BinaryStar.to_oneline_df method and clean the data for saving by setting Data Types of the columns explicitly.
This method is similar to clean_binary_history_df since they have many overalapping columns, with a few extras and different naming.
Note: there may be edge cases not handed if new scalar_names are added.
- Parameters:
binary_df (DataFrame) – A pandas Dataframe containing binary history
extra_binary_dtypes_user (dict, optional) – A dictionary with extra column names as keys, and their associated data types as values.
extra_S1_dtypes_user (dict, optional) – Same as above, but only for star 1.
extra_S2_dtypes_user (dict, optional) – Same as above, but only for star 2.
- Returns:
binary_df – A cleaned binary history ready for saving to HDF.
- Return type:
DataFrame
- posydon.popsyn.io.parse_inifile(path, verbose=False)[source]
Parse an inifile for evolving binary populations.
posydon.popsyn.normalized_pop_mass
Compute the underlying stellar population mass for a given simulation.
- posydon.popsyn.normalized_pop_mass.initial_total_underlying_mass(simulated_mass=None, simulated_mass_single=None, simulated_mass_binaries=None, f_bin=0.7, **kwargs)[source]
Compute the initial total mass of the population.
- Parameters:
- simulated_mass, simulated_mass_single, simulated_mass_binariesfloat
Total simulated mass, simulated mass of binary systems and simulated mass of single stars, respectively.
- f_bin: float
The binary fraction of your population in “nature”. If not provided, the default value is set to 0.7
- primary_mass_min: float
minimum initial mass of the primary star
- primary_mass_max: float
maximum initial mass of the primary star
- binary_fraction_const: float
Binary fraction used in the simulations
- primary_mass_scheme: string
Kroupa2001 or Salpeter options
- secondary_mass_scheme: string
mass ratio distribution
- ———-
- :returns: * **underlying_total_mass (float) – The underlying total mass of the population: float**
f_corr_single_stars, f_corr_binaries; float – Correction factors for singles and binaries, respectively.
posydon.popsyn.rate_calculation
- posydon.popsyn.rate_calculation.get_comoving_distance_from_redshift(z)[source]
Compute the comoving distance from redshift.
- Parameters:
z (double) – Cosmological redshift.
- Returns:
Comoving distance in Mpc corresponding to the redhisft z.
- Return type:
double
- posydon.popsyn.rate_calculation.get_cosmic_time_from_redshift(z)[source]
Compute the cosmic time from redshift.
- Parameters:
z (double) – Cosmological redshift.
- Returns:
Return age of the cosmic time in Gyr given the redshift z.
- Return type:
double
- posydon.popsyn.rate_calculation.get_redshift_bin_centers(delta_t)[source]
Compute the redshift bin centers.
- Parameters:
delta_t (double) – Time interval in Myr.
- Returns:
Redshift bin centers.
- Return type:
array doubles
- posydon.popsyn.rate_calculation.get_redshift_bin_edges(delta_t)[source]
Compute the redshift bin edges.
- Parameters:
delta_t (double) – Time interval in Myr.
- Returns:
Redshift bin edges.
- Return type:
array doubles
- posydon.popsyn.rate_calculation.get_redshift_from_cosmic_time(t_cosm)[source]
Compute the cosmological redshift given the cosmic time.
- Parameters:
t_cosm (float, ndarray of floats) – Cosmic time(s) for which you want to know the redhisft.
- Returns:
Cosmolgocial redshift(s) corresponding to t_cosm.
- Return type:
ndarray of floats
Note
The function uses the interpolator redshift_from_cosmic_time_interpolator,
which is created each time the function is called. z_at_value from astropy can be used for single values, but it is too slow for arrays.
- posydon.popsyn.rate_calculation.get_shell_comoving_volume(z_hor_i, z_hor_f, sensitivity='infinite')[source]
Compute comoving volume corresponding to a redshift shell.
- Parameters:
z_hor_i (double) – Cosmological redshift. Lower bound of the integration.
z_hor_f (double) – Cosmological redshift. Upper bound of the integration.
sensitivity (string) – hoose which GW detector sensitivity you want to use. At the moment only ‘infinite’ is available, i.e. p_det = 1.
- Returns:
Retruns the comoving volume between the two shells z_hor_i and z_hor_f in Gpc^3.
- Return type:
double
posydon.popsyn.sample_from_file
Get the initial parameters for a binary population.
- posydon.popsyn.sample_from_file.get_kick_samples_from_file(**kwargs)[source]
Read a kicks for population of binaries from a file.
- Parameters:
**kwargs (dictionary) – kwargs from BinaryPopulation class, which should contain read_samples_from_file
- Returns:
s1_natal_kick_array_set (ndarray of floats) – natal kick array for the primary star containing: kick velocity, azimuthal angle, polar angle, mean anomaly
s2_natal_kick_array_set (ndarray of floats) – natal kick array for the secondary star containing: kick velocity, azimuthal angle, polar angle, mean anomaly
- posydon.popsyn.sample_from_file.get_samples_from_file(orbital_scheme='', **kwargs)[source]
Read a population of binaries at ZAMS from a file.
- Parameters:
orbital_scheme (str) – Scheme to get the orbit: ‘separation’, ‘period’
**kwargs (dictionary) – kwargs from BinaryPopulation class, which should contain read_samples_from_file
- Returns:
orbital_scheme_set (ndarray of floats) – orbital separations/periods depending on the scheme
eccentricity_set (ndarray of floats) – eccentricities
m1_set (ndarray of floats) – primary masses
m2_set (ndarray of floats) – secondary masses
posydon.popsyn.selection_effects
Simple utility for generating detection weights
Uses grid of detection probabilities to estimate detection probabilities
Anticipates data as Pandas dataframe with series [‘m1’, ‘q’, ‘z’, ‘chieff’]
- class posydon.popsyn.selection_effects.KNNmodel(grid_path, sensitivity_key, verbose=False)[source]
Bases:
object
K-nearest neighbor model that instantiates based on detection probability grid
When instantiating, must supply path to the grid, and key that represents GW network and sensitivity.
Instantiates KNNmodel class and trains the KNN.
- grid_pathstring
Path to grid of detection probabilities.
- sensitivity_keystring
- GW detector sensitivity and network configuration you want to use,
see arXiv:1304.0670v3
- detector sensitivities are taken from: https://dcc.ligo.org/LIGO-T2000012-v2/public
- available sensitivity keys (for Hanford, Livingston, Virgo network):
‘O3actual_H1L1V1’ : aligo_O3actual_H1.txt, aligo_O3actual_L1.txt, avirgo_O3actual.txt ‘O4low_H1L1V1’ : aligo_O4low.txt, aligo_O4low.txt, avirgo_O4high_NEW.txt ‘O4high_H1L1V1’ : aligo_O4high.txt, aligo_O4high.txt, avirgo_O4high_NEW.txt ‘design_H1L1V1’ : AplusDesign.txt, AplusDesign.txt, avirgo_O5high_NEW.txt
detection probabilities are calculated using the IMRPhenomXHM approximant with a network SNR threshold of 10
- verboseboolean
Adds verbosity.
- predict_pdet(data, verbose=False)[source]
Gives relative weight to each system in data based on its proximity to the points on the grid. Each system in data should have a primary mass m1, mass ratio q, redshift z, and effective spin chieff This function will determine detection probabilities using nearest neighbor algorithm in [log(m1), q, log(z), chieff] space Need to specify bounds (based on the trained grid) so that the grid and data get normalized properly
- dataPandas dataframe
Data you wish to predict detection probabilities for. Required series in the dataframe:
‘m1’ : primary source-frame mass ‘q’ : mass ratio (secondary mass/primary mass) ‘z’ : redshift of merger ‘chieff’ : effective inspiral spin
- verboseboolean
Adds verbosity.