Example #1
0
def remove_checksum(file_):
    """Remove checksums from `file_`."""
    log.info("Removing checksum for", repr(file_))
    if config.is_reference(file_):
        data_file.remove_checksum(file_)
    elif rmap.is_mapping(file_):
        raise exceptions.CrdsError("Mapping checksums cannot be removed for:",
                                   repr(file_))
    else:
        raise exceptions.CrdsError(
            "File", repr(file_),
            "does not appear to be a CRDS reference or mapping file.")
Example #2
0
def reference_uri_to_cache_path(reference_uri, observatory=None):
    """Convert an abstract CRDS reference file URI into an absolute path for the
    file as located in the CRDS cache.

    Parameters
    ----------

    reference_uri :  string identifying an abstract CRDS reference file,
                      .e.g. 'crds://jwst_miri_flat_0177.fits'

    observatory : string naming the telescope/project for CRDS, e.g. 'jwst'
           `observatory` should be omitted, None,  or defined as a literal string value.
           Omission and the value None are interpreted as 'jwst'.

    Returns
    -------

    reference_path : absolute file path to reference_uri in the CRDS cache,
           .e.g. '/grp/crds/cache/references/jwst/jwst_miri_flat_0177.fits'

    Standard CRDS cache paths are typically defined relative to the CRDS_PATH
    environment variable.  See https://jwst-crds.stsci.edu guide and top level
    page for more info on configuring CRDS.

    The default CRDS_PATH value is /grp/crds/cache, currently on the Central Store.
    """
    if not reference_uri.startswith("crds://"):
        raise exceptions.CrdsError(
            "CRDS reference URI's should start with 'crds://' but got",
            repr(reference_uri))
    observatory = (observatory or 'jwst').lower()
    basename = config.pop_crds_uri(reference_uri)
    return crds.locate_file(basename, observatory)
Example #3
0
def get_parameter_index(parkey, parameter_name):
    """Return the 2D parkey index for `parameter_name`:  (which_sub_tuple,  index_in_subtuple)."""
    for i, pars in enumerate(parkey):
        for j, par in enumerate(pars):
            if par.lower() == parameter_name.lower():
                return i, j
    raise crexc.CrdsError("Can't find index for", repr(parameter_name),
                          "in parkey", repr(parkey))
Example #4
0
def add_checksum(file_):
    """Add checksums to file_."""
    log.info("Adding checksum for", repr(file_))
    if config.is_reference(file_):
        with log.error_on_exception("Failed updating checksum for",
                                    repr(file_)):
            data_file.add_checksum(file_)
    elif rmap.is_mapping(file_):
        update_mapping_checksum(file_)
    else:
        raise exceptions.CrdsError(
            "File", repr(file_),
            "does not appear to be a CRDS reference or mapping file.")
Example #5
0
def verify_checksum(file_):
    """Verify checksums in `file_`."""
    log.info("Verifying checksum for", repr(file_))
    if config.is_reference(file_):
        data_file.verify_checksum(file_)
    elif rmap.is_mapping(file_):
        if config.CRDS_IGNORE_MAPPING_CHECKSUM.get():
            log.warning(
                "Mapping checksums are disabled by config.CRDS_IGNORE_MAPPING_CHECKSM."
            )
        rmap.load_mapping(file_)
    else:
        raise exceptions.CrdsError(
            "File", repr(file_),
            "does not appear to be a CRDS reference or mapping file.")
Example #6
0
def reference_uri_to_cache_path(reference_uri):
    """Convert an abstract CRDS reference file URI into an absolute path for the
    file as located in the CRDS cache.

    e.g. 'crds://jwst_miri_flat_0177.fits'  -->  
            '/grp/crds/cache/references/jwst/jwst_miri_flat_0177.fits'

    Standard CRDS cache paths are typically defined relative to the CRDS_PATH
    environment variable.  See https://jwst-crds.stsci.edu guide and top level
    page for more info on configuring CRDS.

    The default CRDS_PATH value is /grp/crds/cache, currently on the Central Store.
    """
    if not reference_uri.startswith("crds://"):
        raise exceptions.CrdsError(
            "CRDS reference URI's should start with 'crds://' but got",
            repr(reference_uri))
    basename = config.pop_crds_uri(reference_uri)
    return crds.locate_file(basename, "jwst")