Utilities Module

Utility Functions Module

This module contains utility functions for various operations used throughout the COBI package, including logging, coordinate transformations, map operations, and numerical utilities.

Functions

Logger

Configurable logging class for debugging and information messages

inrad

Convert angles from degrees to radians

cli

Compute inverse of array elements (safe for zeros)

download_file

Download files with progress bar

deconvolveQU

Deconvolve beam from polarization maps

change_coord

Transform HEALPix maps between coordinate systems

slice_alms

Slice spherical harmonic coefficients to new lmax

The module provides essential functionality for: - Logging with configurable verbosity levels - Angular unit conversions - Safe numerical operations (division, inversion) - File downloading with progress tracking - HEALPix map manipulations (coordinate transforms, beam operations) - Spherical harmonic coefficient operations

class Logger(name, verbose=False)[source]

Bases: object

Parameters:
__init__(name, verbose=False)[source]

Initializes the logger.

Parameters: name (str): Name of the logger, typically the class name or module name. verbose (bool): If True, set logging level to DEBUG, otherwise to WARNING.

Parameters:
log(message, level='info')[source]

Logs a message at the specified logging level.

Parameters: message (str): The message to log. level (str): The logging level (debug, info, warning, error, critical).

Parameters:
inrad(alpha)[source]

Converts an angle from degrees to radians.

Parameters: alpha (float): The angle in degrees.

Returns: float: The angle in radians.

Parameters:

alpha (float)

Return type:

float

cli(cl)[source]

Computes the inverse of each element in the input array cl.

Parameters: cl (np.ndarray): Input array for which the inverse is calculated.

Only positive values will be inverted; zeros and negative values will remain zero.

Returns: np.ndarray: An array where each element is the inverse of the corresponding element in cl,

with zeros or negative values left unchanged.

Parameters:

cl (numpy.ndarray)

Return type:

numpy.ndarray

download_file(url, filename)[source]

Download a file with a progress bar.

deconvolveQU(QU, beam)[source]

Deconvolves a beam from a QU map.

Parameters: QU (np.ndarray): The input QU map. beam (np.ndarray): The beam to deconvolve.

Returns: np.ndarray: The deconvolved QU map.

change_coord(m, coord=['C', 'G'])[source]
slice_alms(teb, lmax_new)[source]

Returns the input teb alms sliced to the new lmax.

teb(numpy array): input teb alms lmax_new(int): new lmax

Logger Class

class Logger(name, verbose=False)[source]
Parameters:
__init__(name, verbose=False)[source]

Initializes the logger.

Parameters: name (str): Name of the logger, typically the class name or module name. verbose (bool): If True, set logging level to DEBUG, otherwise to WARNING.

Parameters:
log(message, level='info')[source]

Logs a message at the specified logging level.

Parameters: message (str): The message to log. level (str): The logging level (debug, info, warning, error, critical).

Parameters:

Utility Functions

inrad(alpha)[source]

Converts an angle from degrees to radians.

Parameters: alpha (float): The angle in degrees.

Returns: float: The angle in radians.

Parameters:

alpha (float)

Return type:

float

cli(cl)[source]

Computes the inverse of each element in the input array cl.

Parameters: cl (np.ndarray): Input array for which the inverse is calculated.

Only positive values will be inverted; zeros and negative values will remain zero.

Returns: np.ndarray: An array where each element is the inverse of the corresponding element in cl,

with zeros or negative values left unchanged.

Parameters:

cl (numpy.ndarray)

Return type:

numpy.ndarray

download_file(url, filename)[source]

Download a file with a progress bar.

deconvolveQU(QU, beam)[source]

Deconvolves a beam from a QU map.

Parameters: QU (np.ndarray): The input QU map. beam (np.ndarray): The beam to deconvolve.

Returns: np.ndarray: The deconvolved QU map.

change_coord(m, coord=['C', 'G'])[source]
slice_alms(teb, lmax_new)[source]

Returns the input teb alms sliced to the new lmax.

teb(numpy array): input teb alms lmax_new(int): new lmax