Пример #1
0
def get_dataset(filename):
    """
    Returns the full file path to an auxiliary dataset needed by 
    ctapipe, given the dataset's full name (filename with no directory).

    This will first search for the file in directories listed in 
    tne environment variable CTAPIPE_SVC_PATH (if set), and if not found,  
    will look in the ctapipe_resources module 
    (installed with the ctapipe-extra package), which contains the defaults.

    Parameters
    ----------
    filename: str
        name of dataset to fetch

    Returns
    -------
    string with full path to the given dataset
    """
    searchpath = os.getenv("CTAPIPE_SVC_PATH")

    if searchpath:
        filepath = find_in_path(filename=filename, searchpath=searchpath)
        if filepath:
            return filepath

    logger.debug("Resource '{}' not found in CTAPIPE_SVC_PATH, looking in "
                 "ctapipe_resources...".format(filename))

    return ctapipe_resources.get(filename)
Пример #2
0
def get_dataset(filename):
    """
    Returns the full file path to an auxiliary dataset needed by 
    ctapipe, given the dataset's full name (filename with no directory).
      
    This will first search for the file in directories listed in 
    tne environment variable CTAPIPE_SVC_PATH (if set), and if not found,  
    will look in the ctapipe_resources module 
    (installed with the ctapipe-extra package), which contains the defaults.
    
    Parameters
    ----------
    filename: str
        name of dataset to fetch

    Returns
    -------
    string with full path to the given dataset
    """
    searchpath = os.getenv("CTAPIPE_SVC_PATH")

    if searchpath:
        filepath = find_in_path(filename=filename, searchpath=searchpath)
        if filepath:
            return filepath

    logger.debug("Resource '{}' not found in CTAPIPE_SVC_PATH, looking in "
                 "ctapipe_resources...".format(filename))

    return ctapipe_resources.get(filename)
Пример #3
0
def get_dataset_path(filename, url=DEFAULT_URL):
    """
    Returns the full file path to an auxiliary dataset needed by
    ctapipe, given the dataset's full name (filename with no directory).

    This will first search for the file in directories listed in
    tne environment variable CTAPIPE_SVC_PATH (if set), and if not found,
    will look in the ctapipe_resources module
    (if installed with the ctapipe-extra package), which contains the defaults.

    Parameters
    ----------
    filename: str
        name of dataset to fetch

    Returns
    -------
    string with full path to the given dataset
    """
    searchpath = os.getenv("CTAPIPE_SVC_PATH")

    if searchpath:
        filepath = find_in_path(filename=filename, searchpath=searchpath, url=url)

        if filepath:
            return filepath

    if has_resources:
        logger.debug(
            "Resource '{}' not found in CTAPIPE_SVC_PATH, looking in "
            "ctapipe_resources...".format(filename)
        )

        return Path(ctapipe_resources.get(filename))

    # last, try downloading the data
    try:
        return download_file_cached(filename, default_url=url, progress=True)
    except HTTPError as e:
        # let 404 raise the FileNotFoundError instead of HTTPError
        if e.response.status_code != 404:
            raise

    raise FileNotFoundError(
        f"Couldn't find resource: '{filename}',"
        " You might want to install ctapipe_resources"
    )