예제 #1
0
def main_lensing(argv):
    lklfile = argv[1]
    lkl = clik.clik_lensing(lklfile)
    for clfile in argv[2:]:
        cls = nm.loadtxt(clfile)
        nres = lkl(cls.flat[:])
        print(nres)
예제 #2
0
def main_lensing(argv):
    lkl = clik.clik_lensing(sys.argv[1])
    print("clik lensing file = %s" % sys.argv[1])
    print("  lmax = %d" % lkl.lmax)
    print("  number of extra parameters %d" % len(lkl.extra_parameter_names))
    for nn in lkl.extra_parameter_names:
        print("     %s" % nn)
예제 #3
0
def main_lensing(argv):
  lkl = clik.clik_lensing(sys.argv[1])
  print("clik lensing file = %s"%sys.argv[1])
  if hpy.cldf.is_cldf(argv[1]):
    ff = hpy.File(argv[1])
    ty = ff["clik_lensing/itype"]
    if ty==0:
      renorm = 1
      ren1 = 0
    else:
      renorm = ff["clik_lensing/renorm"]
      ren1 = 0
      if ty in [3,4]:
        ren1 = ff["clik_lensing/ren1"]
  else:
    rr = file(argv[1]).read()
    if ("# format: mono") in rr:
      renorm = 1
      ren1 = 0
    elif ("# format: qecl") in rr:
      renorm = 1
      ren1 = 0
    else:
      renorm = 1
      ren1 = 1
    
  print("  Renormalization: %s\n  N1 computation: %s"%(["Off","On"][renorm],["Off","On"][ren1]))
  print("  lmax = %s (PP TT EE BB TE TB EB)"%lkl.lmax)
  print("  number of extra parameters %d"%len(lkl.extra_parameter_names))
  for nn in lkl.extra_parameter_names:
    print("     %s"%nn)
예제 #4
0
 def initialise(self):
     # Importing Planck's clik library (only once!)
     try:
         clik
     except NameError:
         if not self.path:
             path_to_installation = get_path_to_installation()
             if path_to_installation:
                 self.path_clik = os.path.join(path_to_installation, "code",
                                               common_path)
                 self.path_data = os.path.join(path_to_installation, "data",
                                               common_path)
             else:
                 self.log.error(
                     "No path given to the Planck likelihood. Set the "
                     "likelihood property 'path' or the common property "
                     "'%s'.", _path_install)
                 raise HandledException
         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
     clik_file = os.path.join(self.path_data, self.clik_file)
     # for lensing, some routines change. Intializing a flag for easier
     # testing of this condition
     self.lensing = "lensing" in self.name
     try:
         self.clik = (clik.clik_lensing(clik_file)
                      if self.lensing else clik.clik(clik_file))
     except clik.lkl.CError:
         self.log.error(
             "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'",
             clik_file)
         raise HandledException
     self.expected_params = list(self.clik.extra_parameter_names)
     # line added to deal with a bug in planck likelihood release:
     # A_planck called A_Planck in plik_lite
     if "plikHM_lite" in self.name:
         i = self.expected_params.index('A_Planck')
         self.expected_params[i] = 'A_planck'
         self.log.info(
             "Corrected nuisance parameter name A_Planck to A_planck")
     # Check that the parameters are the right ones
     assert set(self.input_params.keys()) == set(self.expected_params), (
         "Likelihoods parameters do not coincide with the ones clik understands."
     )
     # 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 main_lensing(argv):
    lkl = clik.clik_lensing(argv[1])
    n = len(lkl.get_extra_parameter_names())
    cls = nm.concatenate((lkl.get_clpp_fid(), lkl.get_clcmb_fid(), nm.ones(n)))
    if len(argv) == 2:
        clfile = argv[1] + ".cls"
    else:
        clfile = argv[2]
    cls.tofile(clfile, sep=" ")
예제 #6
0
    def __init__(self,
                 clik_file,
                 auto_reject_errors=False,
                 lensing=None,
                 **nuisance):

        super().__init__(**arguments())

        from clik import clik, clik_lensing

        if lensing or "lensing" in clik_file:
            loaded_cliks[clik_file] = self.clik = loaded_cliks[
                clik_file] if clik_file in loaded_cliks else clik_lensing(
                    clik_file)
            self.lensing = True
            self.clik_specs = ['pp'] + clik_specs

        else:
            loaded_cliks[clik_file] = self.clik = loaded_cliks[
                clik_file] if clik_file in loaded_cliks else clik(clik_file)
            self.lensing = False
            self.clik_specs = clik_specs
예제 #7
0
 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))
예제 #8
0
import os
import clik
import numpy as np

### Some important variables ###
clik_root = os.environ.get('PLANCK_2015_DATA')
if clik_root == None:
    raise ValueError('The environment variable PLANCK_2015_DATA is not set.')

### Planck 2015 lensing T only
lensT = clik.clik_lensing(clik_root + '/lensing/smica_g30_ftl_full_pttptt.clik_lensing')
lensT_pars = lensT.get_extra_parameter_names()
def get_loglike(class_input, likes_input, class_run):
    args = np.concatenate((
        class_run.lensed_cl()['pp'][:2049],
        class_run.lensed_cl()['tt'][:2049] * 1e12 * class_run.T_cmb()**2.,
        np.array([likes_input[par] for par in lensT_pars])
    ))
    return lensT(args)
예제 #9
0
import os
import clik
import numpy as np

### Some important variables ###
clik_root = os.environ.get('PLANCK_2015_DATA')
if clik_root == None:
    raise ValueError('The environment variable PLANCK_2015_DATA is not set.')

### Planck 2015 lensing full T+P
lensTP = clik.clik_lensing(clik_root + '/lensing/smica_g30_ftl_full_pp.clik_lensing')
lensTP_pars = lensTP.get_extra_parameter_names()
def get_loglike(class_input, likes_input, class_run):
    args = np.concatenate((
        class_run.lensed_cl()['pp'][:2049],
        class_run.lensed_cl()['tt'][:2049] * 1e12 * class_run.T_cmb()**2.,
        class_run.lensed_cl()['ee'][:2049] * 1e12 * class_run.T_cmb()**2.,
        class_run.lensed_cl()['te'][:2049] * 1e12 * class_run.T_cmb()**2.,
        np.array([likes_input[par] for par in lensTP_pars])
    ))
    return lensTP(args)
예제 #10
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))
예제 #11
0
파일: __init__.py 프로젝트: s-ilic/ECLAIR
import os
import clik
import numpy as np

### Some important variables ###
clik_root = os.environ.get('PLANCK_2018_DATA')
if clik_root == None:
    raise ValueError('The environment variable PLANCK_2018_DATA is not set.')

### Planck 2018 lensing CMB-dependent
lens_CMBdep = clik.clik_lensing(
    clik_root +
    '/lensing/smicadx12_Dec5_ftl_mv2_ndclpp_p_teb_consext8.clik_lensing')
lens_CMBdep_pars = lens_CMBdep.get_extra_parameter_names()


def get_loglike(class_input, likes_input, class_run):
    args = np.concatenate(
        (class_run.lensed_cl()['pp'][:2501],
         class_run.lensed_cl()['tt'][:2501] * 1e12 * class_run.T_cmb()**2.,
         class_run.lensed_cl()['ee'][:2501] * 1e12 * class_run.T_cmb()**2.,
         class_run.lensed_cl()['te'][:2501] * 1e12 * class_run.T_cmb()**2.,
         np.array([likes_input[par] for par in lens_CMBdep_pars])))
    return lens_CMBdep(args)
예제 #12
0
파일: clik.py 프로젝트: marius311/cosmoslik
    def __init__(self,
                 clik_file,
                 auto_reject_errors=False,
                 lensing=None,
                 **nuisance):

        super().__init__(**arguments())

        from clik import clik, clik_lensing
        
        if lensing or "lensing" in clik_file:
            loaded_cliks[clik_file] = self.clik = loaded_cliks[clik_file] if clik_file in loaded_cliks else clik_lensing(clik_file)
            self.lensing = True
            self.clik_specs = ['pp'] + clik_specs
            
        else:
            loaded_cliks[clik_file] = self.clik = loaded_cliks[clik_file] if clik_file in loaded_cliks else clik(clik_file)
            self.lensing = False
            self.clik_specs = clik_specs