popsynth.utils package

Submodules

popsynth.utils.array_to_cmap module

popsynth.utils.array_to_cmap.array_to_cmap(values, cmap, use_log: bool = False)[source]

Generates a color map and color list that is normalized to the values in an array. Allows for adding a 3rd dimension onto a plot.

Parameters
  • values – A list a values to map into a cmap

  • cmap – The mpl colormap to use

  • use_log (bool) – True if the mapping should be done in log space False by default.

Returns

A color map and a normalized color list

popsynth.utils.configuration module

class popsynth.utils.configuration.LogConsole(on: bool = True, level: str = 'WARNING')[source]

Bases: object

on: bool = True
level: str = 'WARNING'
__init__(on: bool = True, level: str = 'WARNING') None
class popsynth.utils.configuration.LogFile(on: bool = True, level: str = 'WARNING')[source]

Bases: object

on: bool = True
level: str = 'WARNING'
__init__(on: bool = True, level: str = 'WARNING') None
class popsynth.utils.configuration.Logging(debug: bool = False, console: popsynth.utils.configuration.LogConsole = LogConsole(on=True, level='WARNING'), file: popsynth.utils.configuration.LogFile = LogFile(on=True, level='WARNING'))[source]

Bases: object

debug: bool = False
console: LogConsole = LogConsole(on=True, level='WARNING')
file: LogFile = LogFile(on=True, level='WARNING')
__init__(debug: bool = False, console: LogConsole = LogConsole(on=True, level='WARNING'), file: LogFile = LogFile(on=True, level='WARNING')) None
class popsynth.utils.configuration.Cosmology(Om: float = 0.307, h0: float = 67.7)[source]

Bases: object

Om: float = 0.307
h0: float = 67.7
__init__(Om: float = 0.307, h0: float = 67.7) None
class popsynth.utils.configuration.PopSynthConfig(logging: popsynth.utils.configuration.Logging = Logging(debug=False, console=LogConsole(on=True, level='WARNING'), file=LogFile(on=True, level='WARNING')), cosmology: popsynth.utils.configuration.Cosmology = Cosmology(Om=0.307, h0=67.7), show_progress: bool = True)[source]

Bases: object

logging: Logging = Logging(debug=False, console=LogConsole(on=True, level='WARNING'), file=LogFile(on=True, level='WARNING'))
cosmology: Cosmology = Cosmology(Om=0.307, h0=67.7)
show_progress: bool = True
__init__(logging: Logging = Logging(debug=False, console=LogConsole(on=True, level='WARNING'), file=LogFile(on=True, level='WARNING')), cosmology: Cosmology = Cosmology(Om=0.307, h0=67.7), show_progress: bool = True) None

popsynth.utils.cosmology module

popsynth.utils.hdf5_utils module

popsynth.utils.hdf5_utils.recursively_save_dict_contents_to_group(h5file, path, dic: Dict[Any, Any])[source]

Save dict to HDF5.

Parameters
  • h5file – HDF5 file

  • path – Path inside file

  • dic (Dict[Any, Any]) – Dictionary to save

popsynth.utils.hdf5_utils.recursively_load_dict_contents_from_group(h5file, path)[source]

Load files from hdf5.

Parameters
  • h5file – HDF5 file

  • path – Path in file

Returns

A dictionary

Return type

Dict[Any, Any]

popsynth.utils.hdf5_utils.fill_graph_dict(graph_dict, fill_value=1)[source]

Fill a networkx graph dict so that it can be stored in an HDF5 file.

popsynth.utils.hdf5_utils.clean_graph_dict(graph_dict)[source]

Clean networkx graph dict so that it can be stored in an HDF5 file.

popsynth.utils.logging module

class popsynth.utils.logging.ColoredFormatter(*args, colors: Optional[Dict[str, str]] = None, **kwargs)[source]

Bases: Formatter

Colored log formatter.

__init__(*args, colors: Optional[Dict[str, str]] = None, **kwargs) None[source]

Initialize the formatter with specified format strings.

format(record) str[source]

Format the specified record as text.

class popsynth.utils.logging.MyFilter(level)[source]

Bases: object

__init__(level)[source]
filter(logRecord)[source]
class popsynth.utils.logging.LoggingState(popsynth_usr_log_handler, popsynth_console_log_handler)[source]

Bases: object

__init__(popsynth_usr_log_handler, popsynth_console_log_handler)[source]

A container to store the state of the logs.

restore_last_state()[source]
silence_logs()[source]
loud_logs()[source]
debug_logs()[source]
popsynth.utils.logging.silence_warnings()[source]

Supress warning messages in console and file usr logs.

popsynth.utils.logging.activate_warnings()[source]

Supress warning messages in console and file usr logs.

popsynth.utils.logging.update_logging_level(level)[source]
popsynth.utils.logging.silence_logs()[source]

Turn off all logging.

popsynth.utils.logging.show_progress_bars()[source]
popsynth.utils.logging.silence_progress_bars()[source]
popsynth.utils.logging.quiet_mode()[source]

Turn off all logging and progress bars.

popsynth.utils.logging.loud_mode()[source]

Turn on all progress bars and logging.

popsynth.utils.logging.activate_logs()[source]

Re-activate silenced logs.

popsynth.utils.logging.debug_mode()[source]

Activate debug in the console.

popsynth.utils.logging.silence_console_log()[source]
popsynth.utils.logging.setup_logger(name)[source]

Set up a new logger.

Parameters

name – Name of the logger

popsynth.utils.meta module

class popsynth.utils.meta.Parameter(default: Optional[float] = None, vmin: Optional[float] = None, vmax: Optional[float] = None, free: bool = True, is_normalization: bool = False)[source]

Bases: object

__init__(default: Optional[float] = None, vmin: Optional[float] = None, vmax: Optional[float] = None, free: bool = True, is_normalization: bool = False)[source]

Parameter base class.

Parameters
  • default (Optional[float]) – Default parameter value

  • vmin (Optional[float]) – Minimum parameter value

  • vmax (Optional[float]) – Maximum parameter value

  • free – If True, parameter is free

property default: Optional[float]
property is_normalization: bool
property free

‘p.free = True’ or ‘p.free = False’.

Type

Gets or sets whether the parameter is free or not. Use booleans, like

property fix

‘p.fix = True’ or ‘p.fix = False’.

Type

Gets or sets whether the parameter is fixed or not. Use booleans, like

class popsynth.utils.meta.ParameterMeta(name, bases, attrs, **kwargs)[source]

Bases: type

popsynth.utils.package_data module

popsynth.utils.package_data.get_path_of_data_file(data_file) Path[source]
popsynth.utils.package_data.get_path_of_log_dir() Path[source]
popsynth.utils.package_data.get_path_of_log_file(file_name: str) Path[source]

popsynth.utils.progress_bar module

popsynth.utils.progress_bar.progress_bar(itr, **kwargs)[source]

popsynth.utils.registry module

popsynth.utils.rejection_sample module

popsynth.utils.rejection_sample.rejection_sample(size, ymax, xmax, func)[source]

Rejection sample func up to ymax and xmax.

Parameters
  • size – Number of samples

  • ymax – Maximum value of y

  • xmax – Maximum value of x

  • func – Function

popsynth.utils.spherical_geometry module

popsynth.utils.spherical_geometry.sample_theta_phi(size: int)[source]

Sample size samples uniformly on the surface of the unit sphere.

popsynth.utils.spherical_geometry.xyz(r, theta, phi)[source]

Convert spherical coordinates to Cartesian.

Module contents