Beispiel #1
0
def install_clik(path, no_progress_bars=False):
    log = get_logger("clik")
    log.info("Installing pre-requisites...")
    for req in ("cython", "astropy"):
        exit_status = pip_install(req)
        if exit_status:
            raise LoggedError(log, "Failed installing '%s'.", req)
    log.info("Downloading...")
    click_url = pla_url_prefix + '152000'
    if not download_file(click_url,
                         path,
                         decompress=True,
                         no_progress_bars=no_progress_bars,
                         logger=log):
        log.error("Not possible to download clik.")
        return False
    source_dir = get_clik_source_folder(path)
    log.info('Installing from directory %s' % source_dir)
    cwd = os.getcwd()
    try:
        os.chdir(source_dir)
        log.info("Configuring... (and maybe installing dependencies...)")
        flags = ["--install_all_deps", "--extra_lib=m"
                 ]  # missing for some reason in some systems, but harmless
        if not execute([sys.executable, "waf", "configure"] + flags):
            log.error("Configuration failed!")
            return False
        log.info("Compiling...")
        if not execute([sys.executable, "waf", "install"]):
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("Finished!")
    return True
Beispiel #2
0
 def install(cls, path=None, data=True, no_progress_bars=False, **_kwargs):
     if not data:
         return True
     log = logging.getLogger(cls.get_qualified_class_name())
     opts = cls.get_install_options()
     if not opts:
         log.info("No install options. Nothing to do.")
         return True
     repo = opts.get("github_repository", None)
     if repo:
         from cobaya.install import download_github_release
         log.info("Downloading %s data..." % repo)
         return download_github_release(os.path.join(path, "data"),
                                        repo,
                                        opts.get("github_release",
                                                 "master"),
                                        no_progress_bars=no_progress_bars,
                                        logger=log)
     else:
         full_path = cls.get_path(path)
         if not os.path.exists(full_path):
             os.makedirs(full_path)
         if not data:
             return True
         url = opts["download_url"]
         log.info("Downloading likelihood data file: %s...", url)
         from cobaya.install import download_file
         if not download_file(url,
                              full_path,
                              decompress=True,
                              logger=log,
                              no_progress_bars=no_progress_bars):
             return False
         log.info("Likelihood data downloaded and uncompressed correctly.")
         return True
Beispiel #3
0
 def install(cls, path=None, force=False, code=True, data=True,
             no_progress_bars=False):
     name = cls.get_qualified_class_name()
     log = get_logger(name)
     path_names = {"code": common_path, "data": get_data_path(name)}
     import platform
     if platform.system() == "Windows":
         log.error("Not compatible with Windows.")
         return False
     global _clik_install_failed
     if _clik_install_failed:
         log.info("Previous clik install failed, skipping")
         return False
     # Create common folders: all planck likelihoods share install
     # folder for code and data
     paths = {}
     for s in ("code", "data"):
         if eval(s):
             paths[s] = os.path.realpath(os.path.join(path, s, path_names[s]))
             if not os.path.exists(paths[s]):
                 os.makedirs(paths[s])
     success = True
     # Install clik
     if code and (not is_installed_clik(paths["code"]) or force):
         log.info("Installing the clik code.")
         success *= install_clik(paths["code"], no_progress_bars=no_progress_bars)
         if not success:
             log.warning("clik code installation failed! "
                         "Try configuring+compiling by hand at " + paths["code"])
             _clik_install_failed = True
     if data:
         # 2nd test, in case the code wasn't there but the data is:
         if force or not cls.is_installed(path=path, code=False, data=True):
             log.info("Downloading the likelihood data.")
             product_id, _ = get_product_id_and_clik_file(name)
             # Download and decompress the particular likelihood
             url = pla_url_prefix + product_id
             # Helper for the progress bars: some known product download sizes
             # (no actual effect if missing or wrong!)
             size = {"1900": 314153370, "1903": 4509715660, "151902": 60293120,
                     "151905": 5476083302, "151903": 8160437862}.get(product_id)
             if not download_file(url, paths["data"], size=size, decompress=True,
                                  logger=log, no_progress_bars=no_progress_bars):
                 log.error("Not possible to download this likelihood.")
                 success = False
             # Additional data and covmats, stored in same repo as the
             # 2018 python lensing likelihood
             from cobaya.likelihoods.planck_2018_lensing import native
             if not native.is_installed(data=True, path=path):
                 success *= native.install(path=path, force=force, code=code,
                                           data=data,
                                           no_progress_bars=no_progress_bars)
     return success
Beispiel #4
0
def install_clik(path, no_progress_bars=False):
    log = logging.getLogger("clik")
    log.info("Installing pre-requisites...")
    for req in ("cython", "astropy"):
        exit_status = pip_install(req)
        if exit_status:
            raise LoggedError(log, "Failed installing '%s'.", req)
    log.info("Downloading...")
    click_url = pla_url_prefix + '151912'
    if not download_file(click_url,
                         path,
                         decompress=True,
                         no_progress_bars=no_progress_bars,
                         logger=log):
        log.error("Not possible to download clik.")
        return False
    source_dir = get_clik_source_folder(path)
    log.info('Installing from directory %s' % source_dir)
    # The following code patches a problem with the download source of cfitsio.
    # Left here in case the FTP server breaks again.
    if True:  # should be fixed: maybe a ping to the FTP server???
        log.info("Patching origin of cfitsio")
        cfitsio_filename = os.path.join(source_dir, "waf_tools", "cfitsio.py")
        with open(cfitsio_filename, "r") as cfitsio_file:
            lines = cfitsio_file.readlines()
            i_offending = next(i for i, l in enumerate(lines)
                               if ".tar.gz" in l)
            lines[i_offending] = lines[i_offending].replace(
                "ftp://heasarc.gsfc.nasa.gov/software/fitsio/c/cfitsio3280.tar.gz",
                "https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio3280.tar.gz"
            )
        with open(cfitsio_filename, "w") as cfitsio_file:
            cfitsio_file.write("".join(lines))
    cwd = os.getcwd()
    try:
        os.chdir(source_dir)
        log.info("Configuring... (and maybe installing dependencies...)")
        flags = ["--install_all_deps", "--extra_lib=m"
                 ]  # missing for some reason in some systems, but harmless
        if not execute([sys.executable, "waf", "configure"] + flags):
            log.error("Configuration failed!")
            return False
        log.info("Compiling...")
        if not execute([sys.executable, "waf", "install"]):
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("Finished!")
    return True
def install(path=None, name=None, force=False, code=True, data=True,
            no_progress_bars=False):
    log = logging.getLogger(name)
    import platform
    if platform.system() == "Windows":
        log.error("Not compatible with Windows.")
        return False
    global _clik_install_failed
    if _clik_install_failed:
        log.info("Previous clik install failed, skipping")
        return False
    # Create common folders: all planck likelihoods share install folder for code and data
    paths = {}
    for s in ("code", "data"):
        if eval(s):
            paths[s] = os.path.realpath(os.path.join(path, s, common_path))
            if not os.path.exists(paths[s]):
                os.makedirs(paths[s])
    success = True
    # Install clik
    if code and (not is_installed_clik(paths["code"]) or force):
        log.info("Installing the clik code.")
        success *= install_clik(paths["code"], no_progress_bars=no_progress_bars)
        if not success:
            log.warning("clik code installation failed! "
                        "Try configuring+compiling by hand at " + paths["code"])
        _clik_install_failed = True
    if data:
        # 2nd test, in case the code wasn't there but the data is:
        if force or not is_installed(path=path, name=name, code=False, data=True):
            # Extract product_id
            product_id, _ = get_product_id_and_clik_file(name)
            # Download and decompress the particular likelihood
            log.info("Downloading likelihood data...")
            prefix = (r"https://pla.esac.esa.int/pla-sl/"
                      "data-action?COSMOLOGY.COSMOLOGY_OID=")
            if not download_file(prefix + product_id, paths["data"], decompress=True,
                                 logger=log, no_progress_bars=no_progress_bars):
                log.error("Not possible to download this likelihood.")
                success = False
            # Additional data and covmats
            from cobaya.likelihoods.planck_2015_lensing_cmblikes import \
                install as install_supp
            success *= install_supp(path=path, force=force, code=code, data=data,
                                    no_progress_bars=no_progress_bars)
    return success
def install_clik(path, no_progress_bars=False):
    log = logging.getLogger("clik")
    log.info("Installing pre-requisites...")
    for req in ("cython", "astropy"):
        exit_status = pip_install(req)
        if exit_status:
            log.error("Failed installing '%s'.", req)
            raise HandledException
    log.info("Downloading...")
    click_url = 'https://cdn.cosmologist.info/cosmobox/plc-2.1_py3.tar.bz2'
    if not download_file(click_url, path, decompress=True,
                         no_progress_bars=no_progress_bars, logger=log):
        log.error("Not possible to download clik.")
        return False
    source_dir = os.path.join(path, os.listdir(path)[0])
    log.info('Installing from directory %s' % source_dir)
    if True:  # should be fixed
        log.info("Patching origin of cfitsio")
        cfitsio_filename = os.path.join(source_dir, "waf_tools", "cfitsio.py")
        with open(cfitsio_filename, "r") as cfitsio_file:
            lines = cfitsio_file.readlines()
            i_offending = next(i for i, l in enumerate(lines) if ".tar.gz" in l)
            lines[i_offending] = (
                "  atl.installsmthg_pre(ctx,"
                "'http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio3280.tar.gz',"
                "'cfitsio3280.tar.gz')\n")
        with open(cfitsio_filename, "w") as cfitsio_file:
            cfitsio_file.write("".join(lines))
    cwd = os.getcwd()
    try:
        os.chdir(source_dir)
        log.info("Configuring... (and maybe installing dependencies...)")
        if not execute([sys.executable, "waf", "configure", "--install_all_deps"]):
            log.error("Configuration failed!")
            return False

        log.info("Compiling...")
        if not execute([sys.executable, "waf", "install"]):
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("Finished!")
    return True
Beispiel #7
0
def install(path=None,
            name=None,
            force=False,
            code=False,
            data=True,
            no_progress_bars=False):
    log = logging.getLogger(__name__.split(".")[-1])
    full_path = get_path(path)
    if not os.path.exists(full_path):
        os.makedirs(full_path)
    if not data:
        return True
    log.info("Downloading likelihood data...")
    # Refuses http[S]!  (check again after new release)
    filename = r"http://bicepkeck.org/BK15_datarelease/BK15_cosmomc.tgz"
    if not download_file(filename,
                         full_path,
                         decompress=True,
                         logger=log,
                         no_progress_bars=no_progress_bars):
        return False
    log.info("Likelihood data downloaded and uncompressed correctly.")
    return True
 def install(cls,
             path=None,
             force=False,
             code=False,
             data=True,
             no_progress_bars=False):
     if not data:
         return True
     log = logging.getLogger(cls.get_module_name())
     opts = cls.get_install_options()
     repo = opts.get("github_repository", None)
     if repo:
         from cobaya.install import download_github_release
         log.info("Downloading %s data..." % repo)
         return download_github_release(os.path.join(path, "data"),
                                        repo,
                                        opts.get("github_release",
                                                 "master"),
                                        no_progress_bars=no_progress_bars,
                                        logger=log)
     else:
         full_path = cls.get_path(path)
         if not os.path.exists(full_path):
             os.makedirs(full_path)
         if not data:
             return True
         filename = opts["download_url"]
         log.info("Downloading likelihood data file: %s...", filename)
         from cobaya.install import download_file
         if not download_file(filename,
                              full_path,
                              decompress=True,
                              logger=log,
                              no_progress_bars=no_progress_bars):
             return False
         log.info("Likelihood data downloaded and uncompressed correctly.")
         return True
 def install(cls,
             path=None,
             force=False,
             code=True,
             data=True,
             no_progress_bars=False):
     name = cls.get_module_name()
     log = logging.getLogger(name)
     path_names = {"code": common_path, "data": get_data_path(name)}
     import platform
     if platform.system() == "Windows":
         log.error("Not compatible with Windows.")
         return False
     global _clik_install_failed
     if _clik_install_failed:
         log.info("Previous clik install failed, skipping")
         return False
     # Create common folders: all planck likelihoods share install folder for code and data
     paths = {}
     for s in ("code", "data"):
         if eval(s):
             paths[s] = os.path.realpath(
                 os.path.join(path, s, path_names[s]))
             if not os.path.exists(paths[s]):
                 os.makedirs(paths[s])
     success = True
     # Install clik
     if code and (not is_installed_clik(paths["code"]) or force):
         log.info("Installing the clik code.")
         success *= install_clik(paths["code"],
                                 no_progress_bars=no_progress_bars)
         if not success:
             log.warning("clik code installation failed! "
                         "Try configuring+compiling by hand at " +
                         paths["code"])
             _clik_install_failed = True
     if data:
         # 2nd test, in case the code wasn't there but the data is:
         if force or not cls.is_installed(path=path, code=False, data=True):
             log.info("Downloading the likelihood data.")
             product_id, _ = get_product_id_and_clik_file(name)
             # Download and decompress the particular likelihood
             url = pla_url_prefix + product_id
             # url = get_default_info(name, _likelihood)[_likelihood][name].get("url", url)
             if not download_file(url,
                                  paths["data"],
                                  decompress=True,
                                  logger=log,
                                  no_progress_bars=no_progress_bars):
                 log.error("Not possible to download this likelihood.")
                 success = False
             # Additional data and covmats, stored in same repo as the 2018 python lensing likelihood
             from cobaya.likelihoods.planck_2018_lensing.native import native
             if not native.is_installed(data=True, path=path):
                 success *= native.install(
                     path=path,
                     force=force,
                     code=code,
                     data=data,
                     no_progress_bars=no_progress_bars)
     return success