示例#1
0
    def __init__(self,
                 CAMBGenerator,
                 smooth_type="hinton2017",
                 recon_smoothing_scale=15,
                 mpi_comm=None):
        """ 
        Precomputes certain integrals over the camb power spectrum for efficiency given a list of smoothing scales. Access ks via self.ks, and use get_data for an array
        of all the Perturbation Theory integrals.
        """
        self.logger = logging.getLogger("barry")
        self.smooth_type = smooth_type.lower()
        self.mpi_comm = mpi_comm
        if not validate_smooth_method(smooth_type):
            exit(0)
        self.recon_smoothing_scale = recon_smoothing_scale

        # We should check here that CAMBGenerator points to some pk_lin.
        self.CAMBGenerator = CAMBGenerator

        self.data_dir = os.path.dirname(os.path.abspath(
            inspect.stack()[0][1])) + os.sep + "data/"
        self.filename = self.data_dir + f"PT_{CAMBGenerator.filename_unique}_{self.smooth_type}_{int(self.recon_smoothing_scale * 100)}.pkl"

        self.data = None
        self.logger.info(
            f"Creating PT data with {self.CAMBGenerator.om_resolution} x {self.CAMBGenerator.h0_resolution}"
        )
示例#2
0
    def __init__(self, name="Pk Basic", smooth_type="hinton2017", fix_params=("om"), postprocess=None, smooth=False, correction=None):
        """ Generic power spectrum function model

        Parameters
        ----------
        name : str, optional
            Name of the model
        smooth_type : str, optional
            The sort of smoothing to use. Either 'hinton2017' or 'eh1998'
        fix_params : list[str], optional
            Parameter names to fix to their defaults. Defaults to just `[om]`.
        postprocess : `Postprocess` object
            The class to postprocess model predictions. Defaults to none.
        smooth : bool, optional
            Whether to generate a smooth model without the BAO feature. Defaults to `false`.
        correction : `Correction` enum.
            Defaults to `Correction.SELLENTIN
        """
        super().__init__(name, postprocess=postprocess, correction=correction)
        self.smooth_type = smooth_type.lower()
        if not validate_smooth_method(smooth_type):
            exit(0)

        self.declare_parameters()
        self.set_fix_params(fix_params)

        # Set up data structures for model fitting
        self.smooth = smooth
示例#3
0
    def __init__(
            self,
            name="Corr Basic",
            smooth_type="hinton2017",
            fix_params=("om"),
            smooth=False,
            correction=None,
            isotropic=True,
            poly_poles=(0, 2),
            marg=None,
    ):
        """Generic correlation function model

        Parameters
        ----------
        name : str, optional
            Name of the model
        smooth_type : str, optional
            The sort of smoothing to use. Either 'hinton2017' or 'eh1998'
        fix_params : list[str], optional
            Parameter names to fix to their defaults. Defaults to just `[om]`.
        smooth : bool, optional
            Whether to generate a smooth model without the BAO feature. Defaults to `false`.
        correction : `Correction` enum. Defaults to `Correction.SELLENTIN
        """
        super().__init__(name,
                         correction=correction,
                         isotropic=isotropic,
                         marg=marg)
        self.parent = PowerSpectrumFit(fix_params=fix_params,
                                       smooth_type=smooth_type,
                                       correction=correction,
                                       isotropic=isotropic,
                                       marg=marg)
        self.poly_poles = poly_poles
        self.smooth_type = smooth_type.lower()
        if not validate_smooth_method(smooth_type):
            exit(0)

        self.declare_parameters()
        self.set_fix_params(fix_params)

        # Set up data structures for model fitting
        self.smooth = smooth

        self.nmu = 100
        self.mu = np.linspace(0.0, 1.0, self.nmu)
        self.pk2xi_0 = None
        self.pk2xi_2 = None
        self.pk2xi_4 = None
示例#4
0
    def __init__(self,
                 name="BAO Correlation Polynomial Fit",
                 smooth_type="hinton2017",
                 fix_params=("om"),
                 smooth=False,
                 correction=None):
        """ Generic correlation function model

        Parameters
        ----------
        name : str, optional
            Name of the model
        smooth_type : str, optional
            The sort of smoothing to use. Either 'hinton2017' or 'eh1998'
        fix_params : list[str], optional
            Parameter names to fix to their defaults. Defaults to just `[om]`.
        smooth : bool, optional
            Whether to generate a smooth model without the BAO feature. Defaults to `false`.
        correction : `Correction` enum. Defaults to `Correction.SELLENTIN
        """
        super().__init__(name, correction=correction)

        self.smooth_type = smooth_type.lower()
        if not validate_smooth_method(smooth_type):
            exit(0)

        self.declare_parameters()
        self.set_fix_params(fix_params)

        # Set up data structures for model fitting
        self.smooth = smooth
        self.camb = None
        self.PT = None
        self.pk2xi = None
        self.recon_smoothing_scale = None
        self.cosmology = None
示例#5
0
    def __init__(
        self,
        name="Pk Basic",
        smooth_type="hinton2017",
        fix_params=("om"),
        postprocess=None,
        smooth=False,
        recon=None,
        correction=None,
        isotropic=True,
        poly_poles=(0, 2),
        marg=None,
        n_poly=0,
        n_data=1,
        data_share_bias=False,
        data_share_poly=False,
    ):
        """Generic power spectrum function model

        Parameters
        ----------
        name : str, optional
            Name of the model
        smooth_type : str, optional
            The sort of smoothing to use. Either 'hinton2017' or 'eh1998'
        fix_params : list[str], optional
            Parameter names to fix to their defaults. Defaults to just `[om]`.
        postprocess : `Postprocess` object
            The class to postprocess model predictions. Defaults to none.
        smooth : bool, optional
            Whether to generate a smooth model without the BAO feature. Defaults to `false`.
        correction : `Correction` enum.
            Defaults to `Correction.SELLENTIN
        """
        super().__init__(name,
                         postprocess=postprocess,
                         correction=correction,
                         isotropic=isotropic,
                         marg=marg,
                         n_data=n_data)
        self.smooth_type = smooth_type.lower()
        if not validate_smooth_method(smooth_type):
            exit(0)

        self.n_data_bias = 1 if data_share_bias else self.n_data
        self.n_data_poly = 1 if data_share_poly else self.n_data

        if n_poly > 0 and self.isotropic:
            poly_poles = [0]

        self.n_poly = n_poly
        self.poly_poles = poly_poles
        self.data_share_poly = data_share_poly

        self.recon = False
        self.recon_type = "None"
        if recon is not None:
            if recon.lower() != "None":
                if recon.lower() == "iso":
                    self.recon_type = "iso"
                elif recon.lower() == "ani":
                    self.recon_type = "ani"
                elif recon.lower() == "sym":
                    self.recon_type = "sym"
                else:
                    raise ValueError(
                        "recon not recognised, must be 'iso', 'ani' or 'sym'")
                self.recon = True

        self.declare_parameters()

        # Set up data structures for model fitting
        self.smooth = smooth

        self.nmu = 100
        self.mu = np.linspace(0.0, 1.0, self.nmu)

        self.kvals = None
        self.pksmooth = None
        self.pkratio = None