fruitbat.utils¶
The collection of utility functions for Fruitbat.
-
fruitbat.utils.
check_keys_in_dict
(dictionary, keys)[source]¶ Checks that a list of keys exist in a dictionary.
Parameters: - dictionary (dict) – The input dictionary.
- keys (list of strings) – The keys that the dictionary must contain.
Returns: bool – Returns True is all required keys exist in the dictionary. Otherwise a KeyError is raised.
-
fruitbat.utils.
check_type
(value_name, value, dtype, desire=True)[source]¶ Checks the type of a variable and raises an error if not the desired type.
Parameters: - value_name (str) – The name of the variable that will be printed in the error message.
- value – The value of the variable
- dtype (dtype) – The data type to compare with isinstance
- desire (boolean, optional) – If desire = True, then the error will be raised if value does not have a data type of dtype. If desire = False, then the error will be raised if value does have a data type of dtype.
Returns: None
-
fruitbat.utils.
calc_mean_from_pdf
(x, pdf, dx=None)[source]¶ Calculates the mean of a probability density function
Parameters: - x (np.ndarray) – The x values.
- pdf (np.ndarray) – The value of the PDF at x.
- dx (np.ndarray or None, optional) – The spacing between the x bins. If None, then the bins are assumed to be linearly spaced.
Returns: mean (float) – The mean of the PDF.
-
fruitbat.utils.
calc_median_from_pdf
(x, pdf)[source]¶ Calculates the median of a PDF.
Parameters: - x (np.ndarray) – The x values.
- pdf (np.ndarray) – The value of the PDF at x.
Returns: median (float) – The median of the PDF.
-
fruitbat.utils.
calc_std_from_pdf
(x, pdf, dx=None)[source]¶ Calculates the standard deviation from a probability density function.
Parameters: - x (np.ndarray) – The x values.
- pdf (np.ndarray) – The value of the PDF at x.
- dx (np.ndarray or None, optional) – The spacing between the x bins. If None, then the bins are assumed to be linearly spaced.
Returns: std (float) – The standard deviation of the PDF.
-
fruitbat.utils.
calc_variance_from_pdf
(x, pdf, dx=None)[source]¶ Calculates the variance from a probability density function.
Parameters: - x (np.ndarray) – The x values.
- pdf (np.ndarray) – The value of the PDF at x.
- dx (np.ndarray or None, optional) – The spacing between the x bins. If None, then the bins are assumed to be linearly spaced.
Returns: variance (float) – The variance of the PDF.
-
fruitbat.utils.
calc_z_from_pdf_percentile
(x, pdf, percentile)[source]¶ Parameters: - x (np.ndarray) – The x values of the PDF.
- pdf (np.ndarray) – The value of the PDF at x.
- percentile (float) – The percentile of the PDF.
Returns: redshift (float) – The redshift at the given percentile.
-
fruitbat.utils.
sigma_to_pdf_percentiles
(sigma)[source]¶ Looks up the percentile range of Gaussian for a given standard deviation.
Parameters: sigma ([1, 2, 3, 4, 5]) – The standard deviation to calculate a percentile. Returns: - Lower (float) – The lower percentile
- Higher (float) – The higher percentile
Example
>>> sigma_to_pdf_percentiles(1) (0.158655254, 0.841344746)