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
def is_installed(cls, **kwargs): code_path = common_path data_path = get_data_path(cls.get_qualified_class_name()) result = True if kwargs["code"]: result &= is_installed_clik(os.path.realpath( os.path.join(kwargs["path"], "code", code_path))) if kwargs["data"]: _, filename = get_product_id_and_clik_file(cls.get_qualified_class_name()) result &= os.path.exists(os.path.realpath( os.path.join(kwargs["path"], "data", data_path, filename))) # Check for additional data and covmats from cobaya.likelihoods.planck_2018_lensing import native result &= native.is_installed(**kwargs) return result
def is_installed(cls, reload=False, **kwargs): code_path = common_path data_path = get_data_path(cls.get_qualified_class_name()) result = True if kwargs.get("code", True): result &= bool(is_installed_clik( os.path.realpath(os.path.join(kwargs["path"], "code", code_path)), reload=reload)) if kwargs.get("data", True): # NB: will never raise VersionCheckerror, since version number is in the path _, filename = get_product_id_and_clik_file(cls.get_qualified_class_name()) result &= os.path.exists(os.path.realpath( os.path.join(kwargs["path"], "data", data_path, filename))) # Check for additional data and covmats -- can raise VersionCheckerror from cobaya.likelihoods.planck_2018_lensing import native result &= native.is_installed(**kwargs) return result