Esempio n. 1
0
def get_best_references(pipeline_context, header, reftypes=None):
    """Get best references for dict-like `header` relative to 
    `pipeline_context`.
    
    pipeline_context  CRDS context for lookup,   e.g.   'hst_0001.pmap'
    header            dict-like mapping { lookup_parameter : value }
    reftypes         If None,  return all reference types;  otherwise return 
                     best refs for the specified list of reftypes. 

    Returns          { reftype : reference_basename ... }
    
    Raises           CrdsLookupError,  typically for problems with header values
    """
    header = { str(key):str(value) for (key,value) in header.items() }
    try:
        bestrefs = S.get_best_references(pipeline_context, dict(header), reftypes)
    except Exception as exc:
        raise CrdsLookupError(str(exc)) from exc
    # Due to limitations of jsonrpc,  exception handling is kludged in here.
    for filetype, refname in bestrefs.items():
        if "NOT FOUND" in refname:
            if refname.upper() == "NOT FOUND N/A":
                log.verbose("Reference type", srepr(filetype),
                            "not applicable.", verbosity=80)
            else:
                exc_str = str(refname)[len("NOT FOUND"):]
                raise CrdsLookupError(
                    "Error determining best reference for", 
                    srepr(filetype), "=", repr(exc_str))
    return bestrefs
Esempio n. 2
0
def _get_cache_filelist_and_report_errors(bestrefs):
    """Compute the list of files to download based on the `bestrefs` dictionary,
    skimming off and reporting errors, and raising an exception on the last error seen.

    Return the list of files to download,  collapsing complex return types like tuples
    and dictionaries into a list of simple filenames.
    """
    wanted = []
    last_error = None
    for filetype, refname in bestrefs.items():
        if isinstance(refname, tuple):
            wanted.extend(list(refname))
        elif isinstance(refname, dict):
            wanted.extend(refname.values())
        elif isinstance(refname, str):
            if "NOT FOUND" in refname:
                if "n/a" in refname.lower():
                    log.verbose("Reference type", srepr(filetype),
                                "NOT FOUND.  Skipping reference caching/download.", verbosity=70)
                else:
                    last_error = CrdsLookupError(
                        "Error determining best reference for",
                        srepr(filetype), " = ", str(refname)[len("NOT FOUND"):])
                    log.error(str(last_error))
            else:
                log.verbose("Reference type", srepr(filetype), "defined as", srepr(refname))
                wanted.append(refname)
        else:
            last_error = CrdsLookupError(
                "Unhandled bestrefs return value type for", srepr(filetype))
            log.error(str(last_error))
    if last_error is not None:
        raise last_error
    return wanted
Esempio n. 3
0
   def mock_get_reference_file(dataset,
                               reference_file_type,
                               observatory=None,
                               asn_exptypes=None):
       if reference_file_type in reference_file_map:
           return reference_file_map[reference_file_type]
       else:
           raise CrdsLookupError(
               f"Error determining best reference for '{reference_file_type}'  = \
 Unknown reference type '{reference_file_type}'")
Esempio n. 4
0
def get_aui_best_references(date, dataset_ids):
    """Get best references for date and reference types
    where a header is a dictionary of matching parameters.
      
    Returns { dataset_id : { reftype: bestref, ... }, ... }
    """
    try:
        bestrefs_map = S.get_aui_best_references(date, dataset_ids)
    except Exception as exc:
        raise CrdsLookupError(str(exc)) from exc
    return bestrefs_map
Esempio n. 5
0
def get_best_references_by_ids(context, dataset_ids, reftypes=None, include_headers=False):
    """Get best references for the specified `dataset_ids` and reference types.  If
    reftypes is None,  all types are returned.
    
    Returns { dataset_id : { reftype: bestref, ... }, ... }
    """
    try:
        bestrefs = S.get_best_references_by_ids(context, dataset_ids, reftypes, include_headers)
    except Exception as exc:
        raise CrdsLookupError(str(exc)) from exc
    return bestrefs
Esempio n. 6
0
def get_best_references_by_header_map(context, header_map, reftypes=None):
    """Get best references for header_map = { dataset_id : header, ...}, } and reference types
    where a header is a dictionary of matching parameters.
      
    If reftypes is None,  all types are returned.
    
    Returns { dataset_id : { reftype: bestref, ... }, ... }
    """
    try:
        bestrefs_map = S.get_best_references_by_header_map(context, header_map, reftypes)
    except Exception as exc:
        raise CrdsLookupError(str(exc)) from exc
    return bestrefs_map
Esempio n. 7
0
def _squash_unicode_in_bestrefs(bestrefs, localrefs):
    """Given bestrefs dictionariesy `bestrefs` and `localrefs`, make sure
    there are no unicode strings anywhere in the keys or complex
    values.
    """
    refs = {}
    for filetype, refname in bestrefs.items():
        if isinstance(refname, tuple):
            refs[str(filetype)] = tuple([str(localrefs[name]) for name in refname])
        elif isinstance(refname, dict):
            refs[str(filetype)] = { name : str(localrefs[name]) for name in refname }
        elif isinstance(refname, str):
            if "NOT FOUND" in refname:
                refs[str(filetype)] = str(refname)
            else:
                refs[str(filetype)] = str(localrefs[refname])
        else:  # can't really get here.
            raise CrdsLookupError(
                "Unhandled bestrefs return value type for", srepr(filetype))
    return refs
Esempio n. 8
0
def get_best_references(pipeline_context, header, reftypes=None):
    """Get best references for dict-like `header` relative to
    `pipeline_context`.

    pipeline_context  CRDS context for lookup,   e.g.   'hst_0001.pmap'
    header            dict-like mapping { lookup_parameter : value }
    reftypes         If None,  return all reference types;  otherwise return
                     best refs for the specified list of reftypes.

    Returns          { reftype : reference_basename ... }

    Raises           CrdsLookupError,  typically for problems with header values
    """
    header = {str(key): str(value) for (key, value) in header.items()}
    try:
        bestrefs = S.get_best_references(pipeline_context, dict(header),
                                         reftypes)
    except Exception as exc:
        raise CrdsLookupError(str(exc)) from exc
    return bestrefs