firecrown.utils =============== .. py:module:: firecrown.utils .. autoapi-nested-parse:: Some utility functions for patterns common in Firecrown. Attributes ---------- .. autoapisummary:: firecrown.utils.ST Classes ------- .. autoapisummary:: firecrown.utils.YAMLSerializable Functions --------- .. autoapisummary:: firecrown.utils.base_model_from_yaml firecrown.utils.base_model_to_yaml firecrown.utils.upper_triangle_indices firecrown.utils.save_to_sacc firecrown.utils.compare_optional_arrays firecrown.utils.compare_optionals firecrown.utils.cached_angular_cl firecrown.utils.make_log_interpolator Module Contents --------------- .. py:data:: ST .. py:class:: YAMLSerializable Protocol for classes that can be serialized to and from YAML. .. py:method:: to_yaml() Return the YAML representation of the object. .. py:method:: from_yaml(yaml_str) :classmethod: Load the object from YAML. .. py:function:: base_model_from_yaml(cls, yaml_str) Create a base model from a yaml string. .. py:function:: base_model_to_yaml(model) Convert a base model to a yaml string. .. py:function:: upper_triangle_indices(n) Returns the upper triangular indices for an (n x n) matrix. generator that yields a sequence of tuples that carry the indices for an (n x n) upper-triangular matrix. This is a replacement for the nested loops: for i in range(n): for j in range(i, n): ... :param n: the size of the matrix :return: the generator .. py:function:: save_to_sacc(sacc_data, data_vector, indices, strict = True) Save a data vector into a (new) SACC object, copied from `sacc_data`. Note that the original object `sacc_data` is not modified. Its contents are copied into a new object, and the new information is put into that copy, which is returned by this method. If `strict` is True (the default), then we must overwrite the entire data vector. If `strict` is False, then we only overwrite the data at the specified indices. :param sacc_data: SACC object to be copied. It is not modified. :param data_vector: Data vector to be saved to the new copy of `sacc_data`. :param indices: SACC indices where the data vector should be written. :param strict: Whether to check if the data vector covers all the data already present in the sacc_data. :return: A copy of `sacc_data`, with data at `indices` replaced with `data_vector`. .. py:function:: compare_optional_arrays(x, y) Compare two arrays, allowing for either or both to be None. :param x: first array :param y: second array :return: whether the arrays are equal .. py:function:: compare_optionals(x, y) Compare two objects, allowing for either or both to be None. :param x: first object :param y: second object :return: whether the objects are equal .. py:function:: cached_angular_cl(cosmo, tracers, ells, p_of_k_a=None | Callable[[npt.NDArray[np.int64]], npt.NDArray[np.float64]]) Wrapper for pyccl.angular_cl, with automatic caching. :param cosmo: the current cosmology :param tracers: tracers indicating the measurements to be correlated :param ells: ell values at which to calculate the power spectrum :param p_of_k_a: function that computes the power spectrum .. py:function:: make_log_interpolator(x, y) Return a function object that does 1D spline interpolation. If all the y values are greater than 0, the function interpolates log(y) as a function of log(x). Otherwise, the function interpolates y as a function of log(x). The resulting interpolater will not extrapolate; if called with an out-of-range argument it will raise a ValueError.