Various utility functions used for the manipulating grid data.

posydon.utils.gridutils.T_merger_P(P, m1, m2)[source]

Merger time given initial orbital period and masses of binary.

Parameters
  • P (float) – Orbital period (days).

  • m1 (float) – Mass of first star (Msun).

  • m2 (float) – Mass of second star (Msun).

Returns

Merger time (Gyr)

Return type

float

posydon.utils.gridutils.T_merger_a(a, m1, m2)[source]

Merger time given initial orbital separation and masses of binary.

Parameters
  • a (float) – Orbital separation (Rsun).

  • m1 (float) – Mass of first star (Msun).

  • m2 (float) – Mass of second star (Msun).

Returns

Merger time (Gyr) following Peters (1964), eq. (5.10).

Return type

float

posydon.utils.gridutils.add_field(a, descr)[source]

Return a new array that is like a, but has additional fields.

The contents of a are copied over to the appropriate fields in the new array, whereas the new fields are uninitialized. The arguments are not modified.

Parameters
  • a (structured numpy array) – The base array.

  • descr (str) – A numpy type description of the new fields.

Returns

Description of returned object.

Return type

type

Example

>>> sa = numpy.array([(1, 'Foo'), (2, 'Bar')],
                     dtype=[('id', int), ('name', 'S3')])
>>> sa.dtype.descr == numpy.dtype([('id', int), ('name', 'S3')])
True
>>> sb = add_field(sa, [('score', float)])
>>> sb.dtype.descr == numpy.dtype([('id', int), ('name', 'S3'),
                                   ('score', float)])
True
>>> numpy.all(sa['id'] == sb['id'])
True
>>> numpy.all(sa['name'] == sb['name'])
True
posydon.utils.gridutils.beta_gw(m1, m2)[source]

Evaluate the “beta” (equation 5.9) from Peters (1964).

Parameters
  • m1 (float) – Mass of the first star.

  • m2 (type) – Mass of the second star.

Returns

Peters’ beta in cgs units.

Return type

float

posydon.utils.gridutils.clean_inlist_file(inlist, **kwargs)[source]

Get dictionary of possible parameters/values from the default inlist.

Parameters
  • inlist (str) – Path to inlist file.

  • **kwargs (dict) – TODO

Returns

Dictionary of parameters and values from inlist.

Return type

dict

posydon.utils.gridutils.convert_output_to_table(output_file, binary_history_file=None, star1_history_file=None, star2_history_file=None, column_names=['result', 'CE_flag', 'M_1f(Msun)', 'M_2f(Msun)', 'Porb_f(d)', 'tmerge(Gyr)', 'log_L_1', 'log_T_1', 'He_core_1(Msun)', 'C_core_1(Msun)', 'log_L_2', 'log_T_2', 'He_core_2(Msun)', 'C_core_2(Msun)'])[source]

Convert output of a run, to a pandas dataframe.

Parameters
  • output_file (str) – Path to MESA output file.

  • binary_history_file (str) – Path to binary history data.

  • star1_history_file (str) – Path to history data for star1.

  • star2_history_file (str) – Path to history data for star1.

  • column_names (list of str) – Which columns to return.

Returns

The table containing the requested columns from the run’s histories.

Return type

pandas dataframe

posydon.utils.gridutils.find_index_nearest_neighbour(array, value)[source]

Find the index of array closest to the value.

posydon.utils.gridutils.find_nearest(val, array)[source]

Find the element of array closest to the value val.

posydon.utils.gridutils.fix_He_core(history)[source]

Make He core mass/radius at least equal to CO core mass/radius.

posydon.utils.gridutils.get_cell_edges(grid_x, grid_y)[source]

Return the edges of grid cells to be used for plotting with pcolormesh.

Parameters
  • grid_x (array) – Center values of grid cells for X.

  • grid_y (array) – Center values of grid cells for Y.

Returns

  • array – X grid values.

  • array – Y grid values.

posydon.utils.gridutils.get_final_proposed_points(proposed_x, grid_x, proposed_y, grid_y)[source]

Map proposed simulation points to the center of a correspoding cell.

Only one mapped value is returned if more than one proposed point falls within one cell.

Parameters
  • proposed_x (array) – Proposed points for X.

  • grid_x (array) – The values of X at the center of the grid cells.

  • proposed_y (array) – Proposed points for Y.

  • grid_y (type) – The values of Y at the center of the grid cells.

Returns

  • array – Mapped X values.

  • array – Mapped Y values.

posydon.utils.gridutils.join_lists(A, B)[source]

Make a joint list of A and B without repetitions and keeping the order.

Parameters
  • A (iterable) – The baseline list to be extended.

  • B (iterable) – The second list from which additional elements will be appened.

Returns

The joint list by merging A and B.

Return type

list

posydon.utils.gridutils.kepler3_a(P, m1, m2)[source]

Calculate the semimajor axis of a binary from its period and masses.

Parameters
  • P (float) – Orbital period (days).

  • m1 (float) – Mass of first star.

  • m2 (type) – Mass of second star.

Returns

Semi-major axis (Rsun) using Kepler’s third law.

Return type

float

posydon.utils.gridutils.read_EEP_data_file(path, columns)[source]

Read an EEP file - similar to read_MESA_data_file().

posydon.utils.gridutils.read_MESA_data_file(path, columns)[source]

Read specific columns from a MESA output file to an array.

Parameters
  • path (str) – The path to the file.

  • columns (list of strings) – The list of names of the columns to be returned.

Returns

The array containing the MESA data, or None if path was None.

Return type

array or None