cosmicfish_pylib.utilitiesΒΆ

A collection of small utilities.

num_to_mant_exp This function returns the (base 10) exponent and mantissa of a number.
mant_exp_to_num This function returns a float built with the given (base 10) mantissa and exponent.
nice_number This function returns a nice number built with num.
significant_digits This function returns the number in num_err at the precision of error.
confidence_coefficient This function returns the number of sigmas given a confidence level.
print_table This function prints on the screen a nicely formatted table.
make_list Checks if elements is a list.
cosmicfish_pylib.utilities.CosmicFish_write_header(name)[source]

This function prints to screen the CosmicFish header. To be called at the beginning of the applications.

Parameters:name – string that contains the name of the program. This will be printed along the CosmicFish header.
cosmicfish_pylib.utilities.confidence_coefficient(confidence_level)[source]

This function returns the number of sigmas given a confidence level.

Parameters:confidence_level (float) – desired confidence level. Between 0 and 1.
Returns:the coefficient (number of sigmas) for the desired confidence level.
Return type:float
cosmicfish_pylib.utilities.grouper(n, iterable, fillvalue=None)[source]

This small function regroups a list in sub lists of n elements

Parameters:
  • n – an element or a list of elements
  • iterable – input list
  • fillvalue – value to put to fill if no element is present
Returns:

a list of list containing grouped elements

Return type:

list

cosmicfish_pylib.utilities.make_list(elements)[source]

Checks if elements is a list. If yes returns elements without modifying it. If not creates and return a list with elements inside.

Parameters:elements – an element or a list of elements
Returns:a list containing elements if elements is not a list, elements otherwise.
Return type:list
cosmicfish_pylib.utilities.mant_exp_to_num(mant_exp)[source]

This function returns a float built with the given (base 10) mantissa and exponent.

Parameters:mant_exp (tuple) – (mantissa, exponent) a tuple of two int with the mantissa and the exponent of the input number.
Returns:output number built as mantissa*10**exponent.
Return type:float
cosmicfish_pylib.utilities.nice_number(num, mode=0)[source]

This function returns a nice number built with num. This is useful to build the axes of a plot. The nice number is built by taking the first digit of the number.

Parameters:
  • num (float or int) – input number
  • mode (int) –

    (optional) operation to use to build the nice number

    0 – use ceil
    1 – use round
    2 – use floor
Returns:

a nice number!

Return type:

float

cosmicfish_pylib.utilities.num_to_mant_exp(num)[source]

This function returns the (base 10) exponent and mantissa of a number.

Parameters:num (int or float) – input number.
Returns:tuple (mantissa, exponent) of int containing the mantissa and the exponent of the input number.
Return type:tuple
cosmicfish_pylib.utilities.print_table(table)[source]

This function prints on the screen a nicely formatted table.

Parameters:table – a 2D list that should be printed on the screen.
cosmicfish_pylib.utilities.significant_digits(num_err, mode=0)[source]

This function returns the number in num_err at the precision of error.

Parameters:
  • num_err (tuple) – (number, error) input number and error in a tuple.
  • mode (int) –

    (optional) operation to use to build the number

    0 – use ceil
    1 – use round
    2 – use floor
Returns:

a number with all the significant digits according to error

Return type:

float