def main(argv): if len(sys.argv)!=2: print("usage : %s lkl_file") sys.exit(1) if clik.try_lensing(argv[1]): main_lensing(argv) return main_CMB(argv)
def main(argv): if clik.try_lensing(argv[1]): main_lensing(argv) return main_CMB(argv)
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))
def initialize(self): if "2015" in self.get_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_qualified_class_name()) if self.path: has_clik = False else: try: import clik has_clik = True except ImportError: clik = None has_clik = False if not has_clik: if not self.path: if self.packages_path: self.path_clik = os.path.join(self.packages_path, "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'.", _packages_path) 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.packages_path, "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 self.l_maxs = self.clik.get_lmax() # calculate requirements here so class can also be separately instantiated requested_cls = ["tt", "ee", "bb", "te", "tb", "eb"] if self.lensing: has_cl = [lmax != -1 for lmax in self.l_maxs] requested_cls = ["pp"] + requested_cls else: has_cl = self.clik.get_has_cl() self.requested_cls = [cl for cl, i in zip(requested_cls, has_cl) if int(i)] self.l_maxs_cls = [lmax for lmax, i in zip(self.l_maxs, has_cl) if int(i)] self.expected_params = list(self.clik.extra_parameter_names) # Placeholder for vector passed to clik 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))
def main(argv): if len(sys.argv) < 4: print( "usage : %s lkl_file_1 lkl_file_2 [lkl_file_3 ...] result_lkl_file" ) sys.exit(1) for fl in sys.argv[1:-1]: if clik.try_lensing(fl): print("clik_join doesn't work yet with lensing likelihood, sorry") sys.exit(1) lkls = [hpy.File(ll)["clik"] for ll in sys.argv[1:-1]] reslkl = hpy.File(sys.argv[-1], "w", ty=lkls[0]) nlkl = 0 lmax = -nm.ones(6, dtype=nm.int) resclik = reslkl.create_group("clik") name = [] loc = [] defn = [] defloc = [] var = nm.zeros((0, 0)) for lklin in lkls: if "prior" in lklin: prid = lklin["prior"] pname = [n.strip() for n in prid.attrs["name"].split('\0') if n] for n in name: if n in pname: raise Exception("already got a prior on %s" % n) ploc = prid["loc"][:] pvar = prid["var"][:] if len(pvar) == len(ploc): pvar = nm.diag(pvar) pvar.shape = (len(ploc), -1) nvar = nm.zeros((len(loc) + len(ploc), len(loc) + len(ploc))) nvar[:len(loc), :len(loc)] = var nvar[len(loc):, len(loc):] = pvar var = nvar name = list(name) + list(pname) loc = nm.concatenate((loc, ploc)) lmaxin = lklin.attrs["lmax"] lmax = nm.max((lmax, lmaxin), 0) nlklin = lklin.attrs["n_lkl_object"] for i in range(nlklin): grpin = "lkl_%d" % i grpout = "lkl_%d" % nlkl nlkl += 1 lklin.copy(lklin[grpin], resclik, grpout) if "default" in lklin: prid = lklin["default"] pname = [n.strip() for n in prid.attrs["name"].split('\0') if n] ploc = prid["loc"][:] for i, n in enumerate(pname): l = ploc[i] add = True for ii, nn in enumerate(defn): if n == nn: if l != defloc[ii]: raise Exception( "cannot fix the same parameter with different values" ) add = False break if add: defn += [n] defloc += [l] if len(name): prid = resclik.create_group("prior") prid.attrs["name"] = php.pack256(*name) prid.create_dataset("loc", data=loc.flat[:]) prid.create_dataset("var", data=var.flat[:]) if len(defn): prid = resclik.create_group("default") prid.attrs["name"] = php.pack256(*defn) prid.create_dataset("loc", data=nm.array(defloc).flat[:]) resclik.attrs["lmax"] = lmax.astype(nm.int) resclik.attrs["n_lkl_object"] = nlkl reslkl.close()