class cosmic.output.BoundaryNorm(boundaries, ncolors, clip=False, *, extend='neither')

Bases: Normalize

Generate a colormap index based on discrete intervals.

Unlike Normalize or LogNorm, BoundaryNorm maps values to integers instead of to the interval 0-1.

__call__(value, clip=None)

This method behaves similarly to .Normalize.__call__, except that it returns integers or arrays of int16.

__doc__ = '\n    Generate a colormap index based on discrete intervals.\n\n    Unlike `Normalize` or `LogNorm`, `BoundaryNorm` maps values to integers\n    instead of to the interval 0-1.\n    '
__init__(boundaries, ncolors, clip=False, *, extend='neither')
Parameters:
boundariesarray-like

Monotonically increasing sequence of at least 2 bin edges: data falling in the n-th bin will be mapped to the n-th color.

ncolorsint

Number of colors in the colormap to be used.

clipbool, optional

If clip is True, out of range values are mapped to 0 if they are below boundaries[0] or mapped to ncolors - 1 if they are above boundaries[-1].

If clip is False, out of range values are mapped to -1 if they are below boundaries[0] or mapped to ncolors if they are above boundaries[-1]. These are then converted to valid indices by Colormap.__call__.

extend{‘neither’, ‘both’, ‘min’, ‘max’}, default: ‘neither’

Extend the number of bins to include one or both of the regions beyond the boundaries. For example, if extend is ‘min’, then the color to which the region between the first pair of boundaries is mapped will be distinct from the first color in the colormap, and by default a ~matplotlib.colorbar.Colorbar will be drawn with the triangle extension on the left or lower end.

Notes

If there are fewer bins (including extensions) than colors, then the color index is chosen by linearly interpolating the [0, nbins - 1] range onto the [0, ncolors - 1] range, effectively skipping some colors in the middle of the colormap.

__module__ = 'matplotlib.colors'
inverse(value)
Raises:
ValueError

BoundaryNorm is not invertible, so calling this method will always raise an error

class cosmic.output.COSMICOutput(bpp=None, bcm=None, initC=None, kick_info=None, file=None, label=None, file_key_suffix='')

Bases: object

__dict__ = mappingproxy({'__module__': 'cosmic.output', '__init__': <function COSMICOutput.__init__>, '__len__': <function COSMICOutput.__len__>, '__repr__': <function COSMICOutput.__repr__>, '__getitem__': <function COSMICOutput.__getitem__>, 'final_bpp': <property object>, 'save': <function COSMICOutput.save>, 'rerun_with_settings': <function COSMICOutput.rerun_with_settings>, 'plot_detailed_evolution': <function COSMICOutput.plot_detailed_evolution>, 'plot_distribution': <function COSMICOutput.plot_distribution>, '__dict__': <attribute '__dict__' of 'COSMICOutput' objects>, '__weakref__': <attribute '__weakref__' of 'COSMICOutput' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__getitem__(key)

Subselect binaries by bin_num across all data components. Keys can be integers or lists/arrays of integers or slices. If the key is an array of bools, mask initC to get the corresponding bin_nums.

__init__(bpp=None, bcm=None, initC=None, kick_info=None, file=None, label=None, file_key_suffix='')

Container for COSMIC output data components.

Can be initialized either from data components directly or by loading from an HDF5 file.

Parameters:
bpppandas.DataFrame, optional

Important evolution timestep table, by default None

bcmpandas.DataFrame, optional

User-defined timestep table, by default None

initCpandas.DataFrame, optional

Initial conditions table, by default None

kick_infopandas.DataFrame, optional

Natal kick information table, by default None

filestr, optional

Filename/path to HDF5 file to load data from, by default None

labelstr, optional

Optional label for the output instance, by default None

file_key_suffixstr, optional

Suffix to append to dataset keys when loading from file, by default ‘’. E.g. if set to ‘_singles’, datasets ‘bpp_singles’, ‘bcm_singles’, etc. will be loaded as bpp, bcm, etc.

Raises:
ValueError

If neither file nor all data components are provided.

__len__()
__module__ = 'cosmic.output'
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property final_bpp

Get the final timestep for each binary from the bpp table.

Returns:
final_bpppandas.DataFrame

DataFrame containing only the final timestep for each binary.

plot_detailed_evolution(bin_num, show=True, **kwargs)

Plot detailed evolution for a specific binary.

Parameters:
bin_numint

Index of the binary to plot.

**kwargs

Additional keyword arguments passed to the plotting function (plotting.plot_binary_evol).

plot_distribution(x_col, y_col=None, c_col=None, when='final', fig=None, ax=None, show=True, xlabel='auto', ylabel='auto', clabel='auto', **kwargs)

Plot distribution of binaries in specified columns.

Plots can be histograms (if only x_col is given) or scatter plots (if both x_col and y_col are given). Optionally, colour coding can be applied using c_col.

Parameters:
x_colstr

Column name for x-axis.

y_colstr, optional

Column name for y-axis. If None, a histogram will be plotted. By default None.

c_colstr, optional

Column name for colour coding. By default None.

whenstr, optional

When to take the values from: ‘initial’ or ‘final’. By default ‘final’.

figmatplotlib.figure.Figure, optional

Figure to plot on. If None, a new figure is created. By default None.

axmatplotlib.axes.Axes, optional

Axes to plot on. If None, new axes are created. By default None.

showbool, optional

If True, display the plot immediately. By default True.

xlabelstr, optional

Label for x-axis. If ‘auto’, uses the column name. By default ‘auto’.

ylabelstr, optional

Label for y-axis. If ‘auto’, uses the column name or ‘Count’ for histogram. By default ‘auto’.

clabelstr, optional

Label for colorbar. If ‘auto’, uses the column name. By default ‘auto

**kwargs

Additional keyword arguments passed to the plotting function.

Returns:
figmatplotlib.figure.Figure

The figure containing the plot.

axmatplotlib.axes.Axes

The axes containing the plot.

rerun_with_settings(new_settings, reset_kicks=False, inplace=False)

Rerun the simulation with new settings.

Parameters:
new_settingsdict

Dictionary of new settings to apply. Any setting not included will retain its original value.

reset_kicksbool, optional

If True, reset natal kicks to be randomly sampled again. If False, retain original kicks. By default False. (You may want to reset the kicks if changing settings that affect remnant masses or kick distribution.)

inplacebool, optional

If True, update the current instance. If False, return a new instance. By default False.

Returns:
new_outputCOSMICOutput

New COSMICOutput instance with updated simulation results (only if inplace is False).

save(output_file)

Save all data components to an HDF5 file

Parameters:
output_filestr

Filename/path to the HDF5 file

class cosmic.output.COSMICPopOutput(file, label=None)

Bases: object

__dict__ = mappingproxy({'__module__': 'cosmic.output', '__init__': <function COSMICPopOutput.__init__>, '__repr__': <function COSMICPopOutput.__repr__>, '__len__': <function COSMICPopOutput.__len__>, 'to_combined_output': <function COSMICPopOutput.to_combined_output>, '__dict__': <attribute '__dict__' of 'COSMICPopOutput' objects>, '__weakref__': <attribute '__weakref__' of 'COSMICPopOutput' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__init__(file, label=None)
__len__()
__module__ = 'cosmic.output'
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

to_combined_output()

Combine binaries and singles into a single COSMICOutput instance.

Returns:
combined_outputCOSMICOutput

COSMICOutput instance containing both binaries and singles.

Raises:
ValueError

If singles output is not available.

class cosmic.output.Evolve

Bases: object

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'cosmic.evolve', '__init__': <function Evolve.__init__>, 'evolve': <classmethod(<function Evolve.evolve>)>, '__dict__': <attribute '__dict__' of 'Evolve' objects>, '__weakref__': <attribute '__weakref__' of 'Evolve' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__init__()

initialize Evolve

__module__ = 'cosmic.evolve'
__weakref__

list of weak references to the object (if defined)

classmethod evolve(initialbinarytable, pool=None, bpp_columns=None, bcm_columns=None, **kwargs)

After setting a number of initial conditions we evolve the system.

Parameters:
initialbinarytableDataFrame

Initial conditions of the binary

poolMultiprocessing pool

Pool of workers to use to evolve systems in parallel

bpp_columnslist, optional, default: None

Columns to save in the bpp table (key evolutionary stage table)

bcm_columnslist, optional, default: None

Columns to save in the bcm table (detailed evolution table)

**kwargs:

There are three ways to tell evolve and thus the fortran what you want all the flags and other BSE specific parameters to be. If you pass both a dictionary of flags and/or a inifile and a table with the BSE parameters in the columns, the column values will be overwritten by what is in the dictionary or ini file.

NUMBER 1: PASS A DICTIONARY OF FLAGS

BSEDict

NUMBER 2: PASS A PANDAS DATA FRAME WITH PARAMS DEFINED AS COLUMNS

All you need is the initialbinarytable if the all the BSE parameters are defined as columns

NUMBER 3: PASS PATH TO A INI FILE WITH THE FLAGS DEFINED

params

randomseedint, optional, default let numpy choose for you

If you would like the random seed that the underlying fortran code uses to be the same for all of the initial conditions you passed then you can send this keyword argument in. It is recommended to just let numpy choose a random number as the Fortran random seed and then this number will be returned as a column in the initial binary table so that you can reproduce the results.

nprocint, optional, default: 1

number of CPUs to use to evolve systems in parallel

idxint, optional, default: 0

initial index of the bcm/bpp arrays

dtpfloat, optional: default: tphysf

timestep size in Myr for bcm output where tphysf is total evolution time in Myr

n_per_blockint, optional, default: -1

number of systems to evolve in a block with _evolve_multi_system, to allow larger multiprocessing queues and reduced overhead. If less than 1 use _evolve_single_system

Returns:
output_bpppandas.DataFrame

Table of key evolutionary stages for each binary

output_bcmpandas.DataFrame

Table of detailed evolution for each binary

initialbinarytableDataFrame

Initial conditions for each binary

class cosmic.output.ListedColormap(colors, name='from_list', N=None)

Bases: Colormap

Colormap object generated from a list of colors.

This may be most useful when indexing directly into a colormap, but it can also be used to generate special colormaps for ordinary mapping.

Parameters:
colorslist, array

Sequence of Matplotlib color specifications (color names or RGB(A) values).

namestr, optional

String to identify the colormap.

Nint, optional

Number of entries in the map. The default is None, in which case there is one colormap entry for each element in the list of colors. If

N < len(colors)

the list will be truncated at N. If

N > len(colors)

the list will be extended by repetition.

__doc__ = '\n    Colormap object generated from a list of colors.\n\n    This may be most useful when indexing directly into a colormap,\n    but it can also be used to generate special colormaps for ordinary\n    mapping.\n\n    Parameters\n    ----------\n    colors : list, array\n        Sequence of Matplotlib color specifications (color names or RGB(A)\n        values).\n    name : str, optional\n        String to identify the colormap.\n    N : int, optional\n        Number of entries in the map. The default is *None*, in which case\n        there is one colormap entry for each element in the list of colors.\n        If ::\n\n            N < len(colors)\n\n        the list will be truncated at *N*. If ::\n\n            N > len(colors)\n\n        the list will be extended by repetition.\n    '
__init__(colors, name='from_list', N=None)
Parameters:
namestr

The name of the colormap.

Nint

The number of RGB quantization levels.

__module__ = 'matplotlib.colors'
_init()

Generate the lookup table, self._lut.

resampled(lutsize)

Return a new colormap with lutsize entries.

reversed(name=None)

Return a reversed instance of the Colormap.

Parameters:
namestr, optional

The name for the reversed colormap. If None, the name is set to self.name + "_r".

Returns:
ListedColormap

A reversed instance of the colormap.

cosmic.output.load_initC(filename, key='initC', settings_key='initC_settings')

Load an initC table from an HDF5 file.

If settings were saved separately, they are merged back into the main table.

Parameters:
filenamestr

Filename/path to the HDF5 file

keystr, optional

Dataset key to use for main table, by default “initC”

settings_keystr, optional

Dataset key to use for settings table, by default “initC_settings”

Returns:
initCpandas.DataFrame

Initial conditions table

cosmic.output.plot_binary_evol(bcm, sys_obs={}, ktype_kwargs={}, t_min=None, t_max=None)

Plots the full set of plots and kstar bar plots

Parameters:
bcmpandas.DataFrame

binary evolution data form BSE’s bcm dict

sys_obsDict

Dictionary containing keys for binary parameters with values to plot as vertical lines for each stellar component

Returns:
figmatplotlib.figure

Figure containing all the plots!

cosmic.output.save_initC(filename, initC, key='initC', settings_key='initC_settings', force_save_all=False)

Save an initC table to an HDF5 file.

Any column where every binary has the same value (setting) is saved separately with only a single copy to save space.

This will take slightly longer (a few seconds instead of 1 second) to run but will save you around a kilobyte per binary, which adds up!

Parameters:
filenamestr

Filename/path to the HDF5 file

initCpandas.DataFrame

Initial conditions table

keystr, optional

Dataset key to use for main table, by default “initC”

settings_keystr, optional

Dataset key to use for settings table, by default “initC_settings”

force_save_allbool, optional

If true, force all settings columns to be saved in the main table, by default False