posydon.binary_evol

posydon.binary_evol.binarystar

The binary object describes current and past state of the binary.

The binary object is composed of two star objects and contains the current and past states of the binary. Only parameters in the BINARYPROPERTIES list are stored in the history.

The current parameter value of the star object is accessed as, e.g. binary.orbital_period while its past history with binary.orbital_period_history.

The two stars are accessed as, e.g. binary.star_1.mass while their past history with binary.star_1.mass_history.

class posydon.binary_evol.binarystar.BinaryStar(star_1=None, star_2=None, index=None, properties=None, **binary_kwargs)[source]

Bases: object

A class containing the state and history of a stellar binary.

Initialize a binary star.

Parameters:
  • properties (SimulationProperties) – Instance of the SimulationProperties class (default: None)

  • star_1 (SingleStar) – The first star of the binary.

  • star_2 (Star) – The second star of the binary.

  • **binary_kwargs (dictionary) – List of initialization parameters for a binary

append_state()[source]

Update the history of the binaries’ properties.

evolve()[source]

Evolve a binary from start to finish.

classmethod from_df(dataframe, **kwargs)[source]

Convert a binary from a pandas DataFrame to BinaryStar instance.

Parameters:
  • dataframe (Pandas DataFrame) – data to turn into a BinaryStar instance.

  • index (int, optional) – Sets the binary index.

  • extra_columns (dict, optional) – Column names to be added directly to binary not in BINARYPROPERTIES.

Return type:

New instance of BinaryStar

classmethod from_oneline_df(oneline_df, **kwargs)[source]

Convert a oneline DataFrame into a BinaryStar.

The oneline DataFrame is expected to have initial-final values from history and any individual values that don’t have histories.

Parameters:
  • oneline_df (DataFrame) – A oneline DataFrame describing a binary.

  • index (int, None) – Binary index

  • extra_columns (dict) – Names of any extra history columns not inlcuded in BINARYPROPERTIES

Return type:

A new BinaryStar instance.

static from_run(run, history=False, profiles=False)[source]

Create a BinaryStar object from a PSyGrid run.

reset(properties=None)[source]

Reset the binary to its ZAMS state.

Parameters:

properties (SimulationProperties) – Instance of the SimulationProperties class (default: None)

restore(i=0)[source]

Restore the BinaryStar() object to its i-th state, keeping the binary history before the i-th state.

Parameters:

i (int) – The index of the binary object history to reset the binary to. By default 0, i.e. the star will be restored to its initial state.

run_step()[source]

Evolve the binary through one evolutionary step.

switch_star()[source]

Switch stars.

to_df(**kwargs)[source]

Return history parameters from the binary in a DataFrame.

Includes star 1 and 2 (S1, S2) data and an extra column ‘binary_index’.

Parameters:
  • extra_columns (dict( 'name':dtype, .... )) – Extra binary parameters to return in DataFrame that are not included in BINARYPROPERTIES. All columns must have an associated pandas data type. Can be used in combination with only_select_columns. Assumes names have no suffix.

  • ignore_columns (list) – Names of binary parameters to ignore. Assumes names have _history suffix.

  • only_select_columns (list) – Names of the only columns to include. Assumes names have _history suffix. Can be used in combination with extra_columns.

  • null_value (float) – Replace all None values with something else (for saving). Default is np.nan.

  • include_S1 (bool) – Choose to include star 1 or 2 data to the DataFrame. The default is to include both.

  • include_S2 (bool) – Choose to include star 1 or 2 data to the DataFrame. The default is to include both.

  • S1_kwargs (dict) – kwargs to pass to each star’s ‘to_df’ method (extra/ignore columns)

  • S2_kwargs (dict) – kwargs to pass to each star’s ‘to_df’ method (extra/ignore columns)

Return type:

pandas DataFrame

to_oneline_df(scalar_names=[], history=True, **kwargs)[source]

Convert binary into a single row DataFrame.

update_star_states()[source]

Update the states of the two stars in the binary.

posydon.binary_evol.binarystar.signal_handler(signum, frame)[source]

React to a maximum time signal.

posydon.binary_evol.flow_chart

Module setting the default evolution flow and allowing alterations.

This file contains the offical POSYDON flow chart binary evolution. To support future development and deal with complexity it is build dynamically.

posydon.binary_evol.flow_chart.flow_chart(FLOW_CHART=None, CHANGE_FLOW_CHART=None)[source]

Generate the flow chart.

Default step nomenclature: - step_SN : StepSN in posydon/bianry_evol/SN/step_SN.py - step_HMS_HMS : MS_MS_step in posydon/binary_evol/mesa_step.py - step_CO_HMS_RLO : CO_HMS_RLO_step in posydon/binary_evol/mesa_step.py - step_CO_HeMS : CO_HeMS_step in posydon/binary_evol/mesa_step.py - step_detached : detached_step in posydon/binary_evol/detached_step.py - step_CE : StepCEE in posydon/binary_evol/CE/step_CEE.py - step_dco : DoubleCO in posydon/binary_evol/double_CO.py - step_end

Parameters:
  • FLOW_CHART (dict) – Flow chart that maps the tuple (star_1_state, star_1_state, binary_state, binary_event) to a step.

  • CHANGE_FLOW_CHART (dict) –

    Flow chart to change the default FLOW_CHART. E.g. CHANGE_FLOW_CHART = {(‘NS’, ‘NS’, ‘detached’, None) : ‘step_end’,

    (‘NS’, ‘HeMS’, ‘RLO1’, ‘pRLO1’) : ‘step_my_RLO1’}

Returns:

Flow chart.

Return type:

dict

posydon.binary_evol.flow_chart.initial_eccentricity_flow_chart(FLOW_CHART=None, CHANGE_FLOW_CHART=None)[source]
Modify POSYDON’s default flow to:

ZAMS binaries -> detached oRLO1/oRLO2 -> HMS-HMS RLO grid

Parameters:
  • FLOW_CHART (dict or None)

  • CHANGE_FLOW_CHART (dict or None)

Returns:

Modified flow chart.

Return type:

dict

posydon.binary_evol.simulationproperties

Simulation properties for the population class.

This class contains the simulation properties, e.g. flow, steps and max_time.

class posydon.binary_evol.simulationproperties.EvolveHooks[source]

Bases: object

Base class for hooking into binary evolution.

Add any new output columns to the hooks constructor. Example for extra binary columns:

self.extra_binary_col_names = [“column_name_1”, “column_name_2”]

Example for extra star columns:

self.extra_star_col_names = [“column_name_1”, “column_name_2”]

post_evolve(binary)[source]

Perform actions after a binary exits the evolution loop.

post_step(binary, step_name)[source]

Perform acctions after every evolution step.

pre_evolve(binary)[source]

Perform actions before a binary evolves.

pre_step(binary, step_name)[source]

Perform actions before every evolution step.

class posydon.binary_evol.simulationproperties.PrintStepInfoHooks[source]

Bases: EvolveHooks

Simple example for adding extra print info.

Add any new output columns to the hooks constructor. Example for extra binary columns:

self.extra_binary_col_names = [“column_name_1”, “column_name_2”]

Example for extra star columns:

self.extra_star_col_names = [“column_name_1”, “column_name_2”]

post_evolve(binary)[source]

Report at the end of the evolution of each binary.

pre_step(binary, step_name)[source]

Print the step name for each binary, before taking it.

class posydon.binary_evol.simulationproperties.SimulationProperties(properties=None, **kwargs)[source]

Bases: object

Class describing the properties of a population synthesis simulation.

Construct the simulation properties object.

Parameters:
  • properties (object) – Simulation Properties class containing, e.g. flow, steps.

  • extra_hooks (list of tuples) – Each tuple contains a hooks class and kwargs or the extra step name (‘extra_pre_evolve’, ‘extra_pre_step’, ‘extra_post_step’, ‘extra_post_evolve’) and the corresponding function.

close()[source]

Close hdf5 files before exiting.

load_steps(verbose=False)[source]

Instantiate step classes and set as instance attributes.

Parameters:

verbose (bool) – Print extra information.

Return type:

None

post_evolve(binary)[source]

Finalize the evolution of the binary.

The method is called after a binary exits the evolution loop. Uses all extra hooks classes or extra functions.

Parameters:

binary (instance of <class, BinaryStar>) – The binary after evolution is ended.

Returns:

binary

Return type:

instance of <class, BinaryStar>

post_step(binary, step_name)[source]

Finalize step.

The method is called after every evolution step; uses all extra hooks classes or extra functions (except for undefined next step errors).

Parameters:
  • binary (instance of <class, BinaryStar>) – The binary before evolution starts.

  • step_name (str) – The name of the step about to be called (as defined in the flow).

Returns:

binary

Return type:

instance of <class, BinaryStar>

pre_evolve(binary)[source]

Functions called before a binary evolves.

Uses all extra hooks classes or extra functions.

Parameters:

binary (instance of <class, BinaryStar>) – The binary before evolution starts.

Returns:

binary

Return type:

instance of <class, BinaryStar>

pre_step(binary, step_name)[source]

Prepare for step.

The method is called before every evolution step; uses all extra hooks classes or extra functions (except for undefined next step errors).

Parameters:
  • binary (instance of <class, BinaryStar>) – The binary before evolution starts.

  • step_name (str) – The name of the step about to be called (as defined in the flow).

Returns:

binary

Return type:

instance of <class, BinaryStar>

class posydon.binary_evol.simulationproperties.StepNamesHooks[source]

Bases: EvolveHooks

Add history column ‘step_name’ to each binary.

Name of evolutionary step as defined in SimulationProperties.

>>> pop.to_df(extra_columns={'step_names': str})

Add any new output columns to the hooks constructor. Example for extra binary columns:

self.extra_binary_col_names = [“column_name_1”, “column_name_2”]

Example for extra star columns:

self.extra_star_col_names = [“column_name_1”, “column_name_2”]

post_evolve(binary)[source]

Ensure None’s are append to step_names to match rows in history.

post_step(binary, step_name)[source]

Record the step name.

pre_evolve(binary)[source]

Initialize the step name to match history.

pre_step(binary, step_name)[source]

Do not do anything before the step.

class posydon.binary_evol.simulationproperties.TimingHooks[source]

Bases: EvolveHooks

Add history column ‘step_times’ (time taken by step) to each binary.

Example

>>> pop.to_df(extra_columns={'step_times': float})

Add any new output columns to the hooks constructor. Example for extra binary columns:

self.extra_binary_col_names = [“column_name_1”, “column_name_2”]

Example for extra star columns:

self.extra_star_col_names = [“column_name_1”, “column_name_2”]

post_evolve(binary)[source]

Add None’s to step_times to match history rows.

post_step(binary, step_name)[source]

Record the duration of the step.

pre_evolve(binary)[source]

Initialize the step time to match history.

pre_step(binary, step_name)[source]

Record the wall time before taking the step.

posydon.binary_evol.singlestar

The star object describe the star current and past state.

The star object contains the current and past states of the star. Only parameters in the STARPROPERTIES list are stored in the history. The current parameter value of the star object is accessed as, e.g. star.mass, while his past history with star.mass_history.

class posydon.binary_evol.singlestar.SingleStar(**kwargs)[source]

Bases: object

Class describing a single star.

Initialize the star.

Parameters:

**kwargs (dict) – List of initialization parameters for a star.

append_state()[source]

Append the new version of the star to the end of the star state.

static from_run(run, history=False, profile=False, which_star=None)[source]

Create a SingleStar object from a single-star grid run.

restore(i=0, hooks=None)[source]

Restore the SingleStar() object to its i-th state, keeping the star history before the i-th state.

Parameters:
  • i (int) – Index of the star object history to reset the star to. By default i == 0, i.e. the star will be restored to its initial state.

  • hooks (list) – List of extra hooks associated with the SimulationProperties() of the BinaryStar() object containing this SingleStar(), if applicable. This parameter is automatically set when restoring a BinaryStar() object.

to_df(**kwargs)[source]

Return history parameters from the star in a DataFrame.

By default all parameters in STARPROPERTIES are included.

Parameters:
  • extra_columns (dict( 'name':dtype, .... )) – Extra star history parameters to return in DataFrame that are not included in STARPROPERTIES. All columns must have an associated pandas data type. Can be used in combination with only_select_columns. Assumes names have no suffix.

  • ignore_columns (list) – Names of STARPROPERTIES parameters to ignore. Assumes names have _history suffix.

  • only_select_columns (list) – Names of the only columns to include. Can be used in combination with extra_columns. Assumes names have _history suffix.

  • include_profile (bool) – Include the star’s profile in the dataframe (NOT RECOMMENDED)

  • null_value (float, optional) – Replace all None values with something else (for saving). Default is np.nan.

  • prefix (str, optional) – Prefix to all column names. (e.g. ‘star_1’, ‘S1’) Default has no prefix.

Return type:

pandas DataFrame

to_oneline_df(history=True, prefix='', **kwargs)[source]

Convert SingleStar into a single row DataFrame.

By default, initial final values of history are used with the to_df method. Any scalar values can also be added.

Parameters:
  • scalar_names (list of str) – Names of any values to be added to the oneline DataFrame.

  • history (bool) – Include the history initial-final values from to_df method.

  • prefix (str) – Any prefix to go at the beginning of all columns names.

  • **kwargs – All options for the to_df method.

Return type:

oneline_df

posydon.binary_evol.singlestar.convert_star_to_massless_remnant(star)[source]
posydon.binary_evol.singlestar.properties_massless_remnant()[source]

posydon.binary_evol.step_end

Class defining the default step at the end of evolution of a binary.

class posydon.binary_evol.step_end.step_end[source]

Bases: object

Default end step.