diff --git a/firecrown/connector/cobaya/ccl.py b/firecrown/connector/cobaya/ccl.py index 83920e07..34a9e766 100644 --- a/firecrown/connector/cobaya/ccl.py +++ b/firecrown/connector/cobaya/ccl.py @@ -11,7 +11,7 @@ from cobaya.theory import Theory -from firecrown.connector.mapping import mapping_builder +from firecrown.connector.mapping import mapping_builder, MappingCAMB class CCLConnector(Theory): @@ -19,7 +19,7 @@ class CCLConnector(Theory): input_style: str | None = None - def initialize(self): + def initialize(self) -> None: """Initialize a CCLConnector object. Required by Cobaya. @@ -28,14 +28,18 @@ def initialize(self): Cobaya does not allow us to override __init__. """ assert self.input_style - self.map = mapping_builder(input_style=self.input_style) + # We have to do some extra type-fiddling here because mapping_builder + # has a declared return type of the base class. + new_mapping = mapping_builder(input_style=self.input_style) + assert isinstance(new_mapping, MappingCAMB) + self.map = new_mapping self.a_bg = np.linspace(0.1, 1.0, 50) self.z_bg = 1.0 / self.a_bg - 1.0 self.z_Pk = np.arange(0.0, 6.0, 1) self.Pk_kmax = 1.0 - def initialize_with_params(self): + def initialize_with_params(self) -> None: """Complete the initialization of a CCLConnector object. Required by Cobaya. @@ -44,7 +48,7 @@ def initialize_with_params(self): that point. This version has nothing to do. """ - def initialize_with_provider(self, provider): + def initialize_with_provider(self, provider) -> None: """Set the object's provider. Required by Cobaya. @@ -53,7 +57,7 @@ def initialize_with_provider(self, provider): """ self.provider = provider - def get_can_provide_params(self): + def get_can_provide_params(self) -> list[str]: """Return the list of params provided. Required by Cobaya. @@ -70,7 +74,7 @@ def get_can_support_params(self) -> list[str]: """ return self.map.get_params_names() - def get_allow_agnostic(self): + def get_allow_agnostic(self) -> bool: """Is it allowed to pass all unassigned input parameters to this component. Required by Cobaya. @@ -100,7 +104,7 @@ def get_requirements( return pyccl_calculator_requires - def must_provide(self, **requirements): + def must_provide(self, **requirements) -> None: """Required by Cobaya. This version does nothing. diff --git a/firecrown/connector/cobaya/likelihood.py b/firecrown/connector/cobaya/likelihood.py index e9c74283..16c05d98 100644 --- a/firecrown/connector/cobaya/likelihood.py +++ b/firecrown/connector/cobaya/likelihood.py @@ -41,27 +41,35 @@ def initialize(self): ) def initialize_with_params(self) -> None: - """Required by Cobaya. + """Complete the initialization of a LikelihoodConnector object. + + Required by Cobaya. This version has nothing to do. """ def initialize_with_provider(self, provider) -> None: - """Required by Cobaya. + """Set the obejct's provider. - Sets instance's provided to the given provider. + Required by Cobaya. + + :param provider: A Cobaya provider. """ self.provider = provider def get_can_provide_params(self) -> list[str]: - """Required by Cobaya. + """Return the list of params provided. + + Required by Cobaya. Returns an empty list. """ return self.derived_parameters - def get_allow_agnostic(self): - """Required by Cobaya. + def get_allow_agnostic(self) -> bool: + """Is it allowed to pass all unassigned input parameters to this component. + + Required by Cobaya. Return False. """ @@ -70,10 +78,13 @@ def get_allow_agnostic(self): def get_requirements( self, ) -> dict[str, None | dict[str, npt.NDArray[np.float64]] | dict[str, object]]: - """Required by Cobaya. + """Returns a dictionary. Returns a dictionary with keys corresponding the contained likelihood's required parameter, plus "pyccl". All values are None. + + Required by Cobaya. + :return: a dictionary """ likelihood_requires: dict[ str, None | dict[str, npt.NDArray[np.float64]] | dict[str, object] @@ -87,16 +98,17 @@ def get_requirements( return likelihood_requires - def must_provide(self, **requirements): + def must_provide(self, **requirements) -> None: """Required by Cobaya. This version does nothing. """ def logp(self, **params_values) -> float: - """Required by Cobaya. + """Return the log of the calculated likelihood. - Return the (log) calculated likelihood. + Required by Cobaya. + :params values: The values of the parameters to use. """ pyccl = self.provider.get_pyccl() diff --git a/firecrown/connector/cosmosis/likelihood.py b/firecrown/connector/cosmosis/likelihood.py index e58823b4..c7446df3 100644 --- a/firecrown/connector/cosmosis/likelihood.py +++ b/firecrown/connector/cosmosis/likelihood.py @@ -22,7 +22,12 @@ def extract_section(sample: cosmosis.datablock, section: str) -> NamedParameters: - """Extract all the parameters from the name datablock section into a dictionary.""" + """Extract all the parameters from the name datablock section into a dictionary. + + :param sample: the CosmoSiS datablock to query + :param section: the name of the section desired + :return: a dictionary of the parameters in the section + """ if not sample.has_section(section): raise RuntimeError(f"Datablock section `{section}' does not exist.") sec_dict = {name: sample[section, name] for _, name in sample.keys(section=section)} @@ -30,18 +35,19 @@ def extract_section(sample: cosmosis.datablock, section: str) -> NamedParameters class FirecrownLikelihood: - """CosmoSIS likelihood module for calculating Firecrown likelihood. + """CosmoSIS likelihood module for calculating a Firecrown likelihood. In this simplest implementation, we have only a single module. This module is responsible for calling CCL to perform theory calculations, based on the output of CAMB, and also for calculating the data likelihood based on this theory. - - :param config: current CosmoSIS datablock """ - def __init__(self, config: cosmosis.datablock): - """Create the FirecrownLikelihood object from the given configuration.""" + def __init__(self, config: cosmosis.datablock) -> None: + """Create the FirecrownLikelihood object from the given configuration. + + :param config: the datablock the configuration + """ likelihood_source = config.get_string(option_section, "likelihood_source", "") if likelihood_source == "": likelihood_source = config[option_section, "firecrown_config"] @@ -67,9 +73,13 @@ def __init__(self, config: cosmosis.datablock): print(f"The Firecrown likelihood needs a required parameter: {err}") print("*" * 30) raise - self.map: MappingCosmoSIS = mapping_builder( + # We have to do some extra type-fiddling here because mapping_builder + # has a declared return type of the base class. + new_mapping = mapping_builder( input_style="CosmoSIS", require_nonlinear_pk=require_nonlinear_pk ) + assert isinstance(new_mapping, MappingCosmoSIS) + self.map = new_mapping # If sampling_sections is empty, but we have required parameters, then # we have a configuration problem, and ParamsMap can never be built @@ -92,7 +102,11 @@ def __init__(self, config: cosmosis.datablock): raise RuntimeError(msg) def execute(self, sample: cosmosis.datablock) -> int: - """This is the method called for each sample generated by the sampler.""" + """This is the method called for each sample generated by the sampler. + + :param sample: the sample generated by the sampler + :return: 0 + """ cosmological_params: NamedParameters = extract_section( sample, "cosmological_parameters" ) @@ -130,13 +144,16 @@ def execute(self, sample: cosmosis.datablock) -> int: self.tools.reset() return 0 - def special_gauss_family_handling(self, sample): + def special_gauss_family_handling(self, sample: cosmosis.datablock) -> None: """Special handling for the GaussFamily likelihood. We need to save concatenated data vector and inverse covariance to enable support for the CosmoSIS Fisher sampler. This can only work for likelihoods that have these quantities. Currently, this is only GaussFamily. + + :param sample: the sample generated by the sampler + :return: None """ assert isinstance(self.likelihood, GaussFamily) sample.put( @@ -166,8 +183,16 @@ def special_gauss_family_handling(self, sample): if isinstance(stat, TwoPoint): self.handle_twopoint_statistic(sample, stat) - def handle_twopoint_statistic(self, sample, stat): - """Handle the TwoPoint statistic for the GaussFamily likelihood.""" + def handle_twopoint_statistic( + self, sample: cosmosis.datablock, stat: TwoPoint + ) -> None: + """Handle the TwoPoint statistic for the GaussFamily likelihood. + + This puts the theory and data vectors in the data block. + + :param sample: the sample generated by the sampler + :param stat: a TwoPoint statistic + """ assert stat.sacc_tracers is not None tracer = f"{stat.sacc_tracers[0]}_{stat.sacc_tracers[1]}" if stat.ells is not None: @@ -194,7 +219,11 @@ def handle_twopoint_statistic(self, sample, stat): ) def update_likelihood_and_tools(self, firecrown_params: ParamsMap) -> None: - """Update the likelihood and tools with the new parameters.""" + """Update the likelihood and tools with the new parameters. + + :param firecrown_params: the new parameters + :return: None + """ try: self.likelihood.update(firecrown_params) self.tools.update(firecrown_params) @@ -207,6 +236,9 @@ def form_error_message(self, exc: MissingSamplerParameterError) -> str: This error message will also include when that parameter should have been supplied by the sampler. + + :param exc: the missing parameter error + :return: the error message """ msg = ( "A required parameter was not found in any of the " @@ -224,7 +256,11 @@ def form_error_message(self, exc: MissingSamplerParameterError) -> str: return msg def calculate_firecrown_params(self, sample: cosmosis.datablock) -> ParamsMap: - """Calculate the ParamsMap for this sample.""" + """Calculate the ParamsMap for this sample. + + :param sample: the sample generated by the sampler + :return: a ParamsMap with the firecrown parameters + """ firecrown_params = ParamsMap() for section in self.sampling_sections: section_params = extract_section(sample, section) @@ -245,9 +281,10 @@ def calculate_firecrown_params(self, sample: cosmosis.datablock) -> ParamsMap: def setup(config: cosmosis.datablock) -> FirecrownLikelihood: """Setup hook for a CosmoSIS module. - Returns an instance of - class FirecrownLikelihood. The same object will be passed to the CosmoSIS - execute hook. + The returned object will be passed to the CosmoSIS execute hook. + + :param config: the datablock the configuration + :return: an instance of class FirecrownLikelihood """ return FirecrownLikelihood(config) @@ -257,10 +294,17 @@ def execute(sample: cosmosis.datablock, instance: FirecrownLikelihood) -> int: Return 0 on success. The parameter `sample` represents the current MCMC sample; `instance` is the FirecrownLikelihood object created by `setup`. + + :param sample: the sample generated by the sampler + :param instance: the FirecrownLikelihood object + :return: the status of the call to the module's execute function """ return instance.execute(sample) def cleanup(_) -> int: - """Cleanup hook for a CosmoSIS module. This one has nothing to do.""" + """Cleanup hook for a CosmoSIS module. This one has nothing to do. + + :return: 0 + """ return 0 diff --git a/firecrown/connector/mapping.py b/firecrown/connector/mapping.py index 9fb2651f..ab1a61e0 100644 --- a/firecrown/connector/mapping.py +++ b/firecrown/connector/mapping.py @@ -25,8 +25,14 @@ def build_ccl_background_dict( a: npt.NDArray[np.float64], chi: npt.NDArray[np.float64], h_over_h0: npt.NDArray[np.float64], -): - """Builds the CCL dictionary of background quantities.""" +) -> dict[str, npt.NDArray[np.float64]]: + """Builds the CCL dictionary of background quantities. + + :param a: The scale factor array + :param chi: The comoving distance array + :param h_over_h0: The Hubble parameter divided by H0 + :return: the dictionary of background quantities + """ return {"a": a, "chi": chi, "h_over_h0": h_over_h0} @@ -60,7 +66,12 @@ class Mapping(ABC): wa = TypeFloat() T_CMB = TypeFloat() - def __init__(self, *, require_nonlinear_pk: bool = False): + def __init__(self, *, require_nonlinear_pk: bool = False) -> None: + """Initialize the Mapping object. + + :param require_nonlinear_pk: Whether the mapping requires the + non-linear power spectrum + """ self.require_nonlinear_pk = require_nonlinear_pk self.m_nu: float | list[float] | None = None @@ -75,17 +86,24 @@ def get_params_names(self) -> list[str]: return [] def transform_k_h_to_k(self, k_h): - """Transform the given k_h (k over h) to k.""" + """Transform the given k_h (k over h) to k. + + :param k_h: the array of wavenumber/h to be transformed + :return: the transformed array + """ assert k_h is not None # use assertion to silence pylint warning warnings.warn( "This method is implementation specific and should only be " - "implemented on the appropriated subclasses. This method" - "is going to be removed in the next major release.", + "implemented in the appropriat subclasses. This method is going to" + "be removed in the next major release.", category=DeprecationWarning, ) def transform_p_k_h3_to_p_k(self, p_k_h3): - r"""Transform the given :math:`p_k h^3 \to p_k`.""" + r"""Transform the given :math:`p_k h^3 \to p_k`. + + :param p_k_h3: the array of :math:`p_k h^3` to be transformed + """ assert p_k_h3 is not None # use assertion to silence pylint warning warnings.warn( "This method is implementation specific and should only be " @@ -95,7 +113,11 @@ def transform_p_k_h3_to_p_k(self, p_k_h3): ) def transform_h_to_h_over_h0(self, h): - """Transform distances h to :math:`h/h_0`.""" + """Transform distances h to :math:`h/h_0`. + + :param h: the array of distances to be transformed + :return: the transformed array + """ assert h is not None # use assertion to silence pylint warning warnings.warn( "This method is implementation specific and should only be " @@ -126,6 +148,22 @@ def set_params( See the documentation of that class for an explanation of the choices and meanings of default values of None. + + :param Omega_c: fraction of cold dark matter + :param Omega_b: fraction of baryons + :param h: dimensionless Hubble parameter; h = H0/(100 km/s/Mpc) + :param A_s: amplitude of the primordial power spectrum + :param sigma8: s.d. of the matter contrast on a scale of (8 Mpc)/h + :param n_s: scalar spectral index of primordial power spectrum + :param Omega_k: curvature of the universe + :param Neff: effective number of relativistic neutrino species + :param m_nu: effective mass of neutrinos + :param m_nu_type: type of massive neutrinos + :param w0: constant of the CPL parameterization of the dark energy + equation of state + :param wa: linear coefficient of the CPL parameterization of the + dark energy equation of state + :param T_CMB: cosmic microwave background temperature today """ # Typecheck is done automatically using the descriptors and is done to # avoid void very confusing error messages at a later time in case of @@ -154,28 +192,55 @@ def set_params( self.T_CMB = T_CMB @staticmethod - def redshift_to_scale_factor(z): + def redshift_to_scale_factor(z: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]: """Converts redshift to scale factor. Given arrays of redshift returns an array of scale factor with the inverse order. + + :param z: array of redshifts + :return: array of scale factors """ scale = np.flip(1.0 / (1.0 + z)) return scale @staticmethod - def redshift_to_scale_factor_p_k(p_k): + def redshift_to_scale_factor_p_k( + p_k: npt.NDArray[np.float64], + ) -> npt.NDArray[np.float64]: """Converts power spectrum from redshift to scale factor. Given an 2d arrays power spectrum ordered by (redshift, mode) - return a 2d array with the rows flipped to match the reorderning + return a 2d array with the rows flipped to match the reordering from redshift to scale factor. + + :param p_k: a power spectrum, ordered by (redshift, mode) + :return: array of power spectrum, ordered by (scale factor, mode) """ p_k_out = np.flipud(p_k) return p_k_out def asdict(self) -> dict[str, None | float | list[float] | str]: - """Return a dictionary containing the cosmological constants.""" + """Return a dictionary containing the cosmological constants. + + :return: the dictionary, containing keys: + + - ``Omega_c``: fraction of cold dark matter + - ``Omega_b``: fraction of baryons + - ``h``: dimensionless Hubble parameter; h = H0/(100 km/s/Mpc) + - ``A_s``: amplitude of the primordial power spectrum + - ``sigma8``: s.d. of the matter contrast on a scale of (8 Mpc)/h + - ``n_s``: scalar spectral index of primordial power spectrum + - ``Omega_k``: curvature of the universe + - ``Neff``: effective number of relativistic neutrino species + - ``m_nu``: effective mass of neutrinos + - ``m_nu_type``: type of massive neutrinos + - ``w0``: constant of the CPL parameterization of the dark energy + equation of state + - ``wa``: linear coefficient of the CPL parameterization of the + dark energy equation of state + - ``T_CMB``: cosmic microwave background temperature today + """ return { "Omega_c": self.Omega_c, "Omega_b": self.Omega_b, @@ -194,7 +259,10 @@ def asdict(self) -> dict[str, None | float | list[float] | str]: } def get_H0(self) -> float: - """Return the value of H0.""" + """Return the value of H0. + + :return: H0 in km/s/Mpc + """ return self.h * 100.0 @@ -209,8 +277,11 @@ class MappingCLASS(Mapping): class MappingCosmoSIS(Mapping): """Mapping support for CosmoSIS.""" - def get_params_names(self): - """Return the names of the expected cosmological parameters for this mapping.""" + def get_params_names(self) -> list[str]: + """Return the names of the expected cosmological parameters for this mapping. + + :return: a list of the cosmological parameter names + """ return [ "h0", "omega_b", @@ -224,24 +295,41 @@ def get_params_names(self): "wa", ] - def transform_k_h_to_k(self, k_h): - """Transform the given k_h (k over h) to k.""" + def transform_k_h_to_k( + self, k_h: npt.NDArray[np.float64] + ) -> npt.NDArray[np.float64]: + """Transform the given k_h (k over h) to k. + + :param k_h: the array of wavenumber/h to be transformeed + :return: the transformed array + """ return k_h * self.h - def transform_p_k_h3_to_p_k(self, p_k_h3): - r"""Transform the given :math:`p_k h^3 \to p_k`.""" + def transform_p_k_h3_to_p_k( + self, p_k_h3: npt.NDArray[np.float64] + ) -> npt.NDArray[np.float64]: + r"""Transform the given :math:`p_k h^3 \to p_k`. + + :param p_k_h3: the array of :math:`p_k h^3` to be transformed + :return: the transformed array + """ return p_k_h3 / (self.h**3) - def transform_h_to_h_over_h0(self, h): - """Transform distances h to :math:`h/h_0`.""" + def transform_h_to_h_over_h0( + self, h: npt.NDArray[np.float64] + ) -> npt.NDArray[np.float64]: + """Transform distances h to :math:`h/h_0`. + + :param h: the array of distances to be transformed + :return: the transformed distances + """ hubble_radius_today = physics.CLIGHT * 1e-5 / self.h return np.flip(h) * hubble_radius_today - def set_params_from_cosmosis(self, cosmosis_params: NamedParameters): - """Return a PyCCLCosmologyConstants object. + def set_params_from_cosmosis(self, cosmosis_params: NamedParameters) -> None: + """Set the parameters in this mapping from the given CosmoSIS parameters. - This object has parameters equivalent to those read from CosmoSIS when using - CAMB. + :param cosmosis_params: the cosmological parameters read from CosmoSIS """ # TODO: Verify that CosmoSIS/CAMB does not use Omega_g # TODO: Verify that CosmoSIS/CAMB uses delta_neff, not N_eff @@ -280,8 +368,12 @@ def set_params_from_cosmosis(self, cosmosis_params: NamedParameters): ) # pylint: enable=duplicate-code - def calculate_ccl_args(self, sample: cosmosis.datablock): - """Calculate the arguments necessary for CCL for this sample.""" + def calculate_ccl_args(self, sample: cosmosis.datablock) -> dict[str, Any]: + """Calculate the arguments necessary for CCL for this sample. + + :param sample: the datablock for the current sample + :return: the arguments required by CCL + """ ccl_args: dict[str, Any] = {} if sample.has_section("matter_power_lin"): k = self.transform_k_h_to_k(sample["matter_power_lin", "k_h"]) @@ -360,7 +452,11 @@ class MappingCAMB(Mapping): """ def get_params_names(self) -> list[str]: - """Return the list of parameters handled by this mapping.""" + """Return the names of the expected cosmological parameters for this mapping. + + :return: a list of the cosmological parameter names + + """ return [ "H0", "ombh2", @@ -375,11 +471,8 @@ def get_params_names(self) -> list[str]: "wa", ] - def set_params_from_camb(self, **params_values): - """Read the CAMB-style parameters from params_values. - - Then, translate them to our conventions, and store them. - """ + def set_params_from_camb(self, **params_values) -> None: + """Set the parameters in this mapping from the given CAMB-style parameters.""" # pylint: disable-msg=R0914 # CAMB can use different parameters in place of H0, we must deal with this @@ -435,10 +528,14 @@ def set_params_from_camb(self, **params_values): } -def mapping_builder(*, input_style: str, **kwargs): +def mapping_builder(*, input_style: str, **kwargs) -> Mapping: """Return the Mapping class for the given input_style. If input_style is not recognized raise an exception. + + :param input_style: the name of the mapping + :param kwargs: the parameters of the mapping + :return: the mapping object """ if input_style not in mapping_classes: raise ValueError(f"input_style must be {*mapping_classes, }, not {input_style}") diff --git a/firecrown/generators/inferred_galaxy_zdist.py b/firecrown/generators/inferred_galaxy_zdist.py index 5b229f71..8ac9fa50 100644 --- a/firecrown/generators/inferred_galaxy_zdist.py +++ b/firecrown/generators/inferred_galaxy_zdist.py @@ -38,10 +38,15 @@ class ZDistLSSTSRD: - """LSST Inferred galaxy redshift distributions. + r"""LSST Inferred galaxy redshift distributions. - Inferred galaxy redshift distribution based on the LSST Science Requirements - Document (SRD). + Inferred galaxy redshift distribution is based on the LSST Science + Requirements Document (SRD), equation 5. Note that the SRD fixes + $\beta = 2$. + + The values of $\alpha$ and $z_0$ are different for Year 1 and Year 10. + `ZDistLLSTSRD` provides these values as defaults and allows for greater + flexibility when desired. """ def __init__(self, alpha: float, beta: float, z0: float) -> None: @@ -64,9 +69,9 @@ def year_1( It uses the default values of the alpha, beta and z0 parameters from the LSST SRD Year 1. - :param alpha: The alpha parameter using the default value of 0.94. - :param beta: The beta parameter using the default value of 2.0. - :param z0: The z0 parameter using the default value of 0.26. + :param alpha: The alpha parameter of the distribution + :param beta: The beta parameter of the distribution + :param z0: The z0 parameter of the distribution :return: A ZDistLSSTSRD object. """ return cls(alpha=alpha, beta=beta, z0=z0) @@ -80,15 +85,19 @@ def year_10( It uses the default values of the alpha, beta and z0 parameters from the LSST SRD Year 10. - :param alpha: The alpha parameter using the default value of 0.90. - :param beta: The beta parameter using the default value of 2.0. - :param z0: The z0 parameter using the default value of 0.28. + :param alpha: The alpha parameter of the distribution + :param beta: The beta parameter of the distribution + :param z0: The z0 parameter of the distribution :return: A ZDistLSSTSRD object. """ return cls(alpha=alpha, beta=beta, z0=z0) def distribution(self, z: npt.NDArray) -> npt.NDArray: - """Generate the inferred galaxy redshift distribution.""" + """Generate the inferred galaxy redshift distribution. + + :param z: The redshifts at which to evaluate the distribution + :return: The inferred galaxy redshift distribution + """ norma = self.alpha / (self.z0 * gamma((1.0 + self.beta) / self.alpha)) return ( @@ -98,7 +107,14 @@ def distribution(self, z: npt.NDArray) -> npt.NDArray: def _integrated_gaussian_scalar( self, zpl: float, zpu: float, sigma_z: float, z: float ) -> float: - """Generate the integrated Gaussian distribution.""" + """Generate the integrated Gaussian distribution. + + :param zpl: The lower bound of the integration + :param zpu: The upper bound of the integration + :param sigma_z: The resolution parameter + :param z: The redshifts at which to evaluate the distribution + :return: The integrated distribution + """ denom = np.sqrt(2.0) * sigma_z * (1.0 + z) if (z - zpu) > 0.0: return -(erfc((z - zpl) / denom) - erfc((z - zpu) / denom)) / erfc( @@ -148,9 +164,26 @@ def binned_distribution( autoknots_reltol: float = 1.0e-4, autoknots_abstol: float = 1.0e-15, ) -> InferredGalaxyZDist: - """Generate the inferred galaxy redshift distribution in bins.""" + """Generate the inferred galaxy redshift distribution in bins. + + :param zpl: The lower bound of the integration + :param zpu: The upper bound of the integration + :param sigma_z: The resolution parameter + :param z: The redshifts at which to evaluate the distribution + :param name: The name of the distribution + :param measured_type: The measured type of the distribution + :param use_autoknot: Whether to use the NotAKnot algorithm of NumCosmo + :param autoknots_reltol: The relative tolerance for the NotAKnot algorithm + :param autoknots_abstol: The absolute tolerance for the NotAKnot algorithm + :return: The inferred galaxy redshift distribution + """ def _P(z, _): + """A local closure. + + Used to create a function that captures the ZDistLSSTSRD state and + provides an integrand suitable for scipy.integrate.quad. + """ return ( self.distribution(z) * self._integrated_gaussian_scalar(zpl, zpu, sigma_z, z) diff --git a/tests/connector/test_mapping.py b/tests/connector/test_mapping.py index 5d5592aa..3fef8693 100644 --- a/tests/connector/test_mapping.py +++ b/tests/connector/test_mapping.py @@ -6,7 +6,7 @@ import pytest import numpy as np from firecrown.connector import mapping -from firecrown.connector.mapping import Mapping, mapping_builder +from firecrown.connector.mapping import Mapping, mapping_builder, MappingCosmoSIS from firecrown.likelihood.likelihood import NamedParameters @@ -41,6 +41,7 @@ def test_conversion_from_cosmosis_camb(): } named_params = NamedParameters(cosmosis_params) p = mapping.mapping_builder(input_style="CosmoSIS") + assert isinstance(p, MappingCosmoSIS) p.set_params_from_cosmosis(named_params) assert p.Omega_c == cosmosis_params["omega_c"] assert p.Omega_b == cosmosis_params["omega_b"] @@ -89,6 +90,7 @@ def test_conversion_from_cosmosis_camb_using_delta_neff(): } named_params = NamedParameters(cosmosis_params) p = mapping.mapping_builder(input_style="CosmoSIS") + assert isinstance(p, MappingCosmoSIS) p.set_params_from_cosmosis(named_params) assert p.Neff == pytest.approx(3.171)