示例#1
0
 def initialize_with_params(self):
     # Check that the parameters are the right ones
     differences = are_different_params_lists(
         self.input_params, self.expected_params, name_A="given", name_B="expected")
     if differences:
         raise LoggedError(
             self.log, "Configuration error in parameters: %r. "
                       "If this has happened without you fiddling with the defaults, "
                       "please open an issue in GitHub.", differences)
示例#2
0
 def initialize_with_params(self):
     # Check that the parameters are the right ones
     differences = are_different_params_lists(
         self.input_params, self.expected_params,
         name_A="given", name_B="expected")
     if differences:
         raise LoggedError(
             self.log, "Configuration error in parameters: %r.",
             differences)
示例#3
0
    def _check_speeds_of_params(self, blocking):
        """
        Checks the correct formatting of the given parameter blocking.

        `blocking` is a list of tuples `(speed, (param1, param2, etc))`.

        Returns tuples of ``(speeds), (params_in_block)``.
        """
        try:
            speeds, blocks = zip(*list(blocking))
            speeds = np.array(speeds)
        except:
            raise LoggedError(
                self.log,
                "Manual blocking not understood. Check documentation.")
        sampled_params = list(self.sampled_like_dependence)
        check = are_different_params_lists(list(chain(*blocks)),
                                           sampled_params)
        duplicate = check.pop("duplicate_A", None)
        missing = check.pop("B_but_not_A", None)
        unknown = check.pop("A_but_not_B", None)
        if duplicate:
            raise LoggedError(self.log,
                              "Manual blocking: repeated parameters: %r",
                              duplicate)
        if missing:
            raise LoggedError(self.log,
                              "Manual blocking: missing parameters: %r",
                              missing)
        if unknown:
            raise LoggedError(self.log,
                              "Manual blocking: unkown parameters: %r",
                              unknown)
        if (speeds != np.sort(speeds)).all():
            self.log.warning(
                "Manual blocking: speed-blocking *apparently* non-optimal: "
                "sort by ascending speed when possible")
        return speeds, blocks
示例#4
0
    def initialize(self):
        self.log.info("Initialising.")
        if not getattr(self, "path", None) and not getattr(
                self, "path_install", None):
            raise LoggedError(
                self.log,
                "No path given to MFLike data. Set the likelihood property "
                "'path' or the common property '%s'.", _path_install)
        # If no path specified, use the modules path
        data_file_path = os.path.normpath(
            getattr(self, "path", None)
            or os.path.join(self.path_install, "data"))

        self.data_folder = os.path.join(data_file_path, self.data_folder)
        if not os.path.exists(self.data_folder):
            raise LoggedError(
                self.log, "The 'data_folder' directory does not exist. "
                "Check the given path [%s].", self.data_folder)

        # State requisites to the theory code
        self.requested_cls = ["tt", "te", "ee"]

        self.expected_params = [
            "a_tSZ", "a_kSZ", "a_p", "beta_p", "a_c", "beta_c", "n_CIBC",
            "a_s", "T_d"
        ]
        if hasattr(self, "input_params"):
            # Check that the parameters are the right ones
            differences = are_different_params_lists(self.input_params,
                                                     self.expected_params,
                                                     name_A="given",
                                                     name_B="expected")
            if differences:
                raise LoggedError(self.log,
                                  "Configuration error in parameters: %r.",
                                  differences)
        self._prepare_data()
示例#5
0
 def initialize(self):
     if "2015" in self.name:
         for line in _deprecation_msg_2015.split("\n"):
             self.log.warning(line)
     code_path = common_path
     data_path = get_data_path(self.__class__.get_module_name())
     if self.path:
         has_clik = False
     else:
         try:
             import clik
             has_clik = True
         except ImportError:
             has_clik = False
     if not has_clik:
         if not self.path:
             if self.path_install:
                 self.path_clik = os.path.join(self.path_install, "code",
                                               code_path)
             else:
                 raise LoggedError(
                     self.log,
                     "No path given to the Planck likelihood. Set the "
                     "likelihood property 'path' or the common property "
                     "'%s'.", _path_install)
         else:
             self.path_clik = self.path
         self.log.info("Importing clik from %s", self.path_clik)
         # test and import clik
         is_installed_clik(self.path_clik,
                           log_and_fail=True,
                           import_it=False)
         import clik
     # Loading the likelihood data
     if not os.path.isabs(self.clik_file):
         self.path_data = getattr(
             self, "path_data",
             os.path.join(self.path or self.path_install, "data",
                          data_path))
         self.clik_file = os.path.join(self.path_data, self.clik_file)
     # Differences in the wrapper for lensing and non-lensing likes
     self.lensing = clik.try_lensing(self.clik_file)
     try:
         self.clik = (clik.clik_lensing(self.clik_file)
                      if self.lensing else clik.clik(self.clik_file))
     except clik.lkl.CError:
         # Is it that the file was not found?
         if not os.path.exists(self.clik_file):
             raise LoggedError(
                 self.log,
                 "The .clik file was not found where specified in the "
                 "'clik_file' field of the settings of this likelihood. Maybe the "
                 "'path' given is not correct? The full path where the .clik file was "
                 "searched for is '%s'", self.clik_file)
         # Else: unknown clik error
         self.log.error(
             "An unexpected error occurred in clik (possibly related to "
             "multiple simultaneous initialization, or simultaneous "
             "initialization of incompatible likelihoods (e.g. polarised "
             "vs non-polarised 'lite' likelihoods. See error info below:")
         raise
     # Check that the parameters are the right ones
     self.expected_params = list(self.clik.extra_parameter_names)
     differences = are_different_params_lists(self.input_params,
                                              self.expected_params,
                                              name_A="given",
                                              name_B="expected")
     if differences:
         raise LoggedError(
             self.log, "Configuration error in parameters: %r. "
             "If this has happened without you fiddling with the defaults, "
             "please open an issue in GitHub.", differences)
     # Placeholder for vector passed to clik
     self.l_maxs = self.clik.get_lmax()
     length = (len(self.l_maxs)
               if self.lensing else len(self.clik.get_has_cl()))
     self.vector = np.zeros(
         np.sum(self.l_maxs) + length + len(self.expected_params))