Пример #1
0
def multiprocessing_instance(output_file_name):
    """Pretend to do something generic."""
    output_file = open(output_file_name, "a")
    with crds_cache_locking.get_cache_lock():
        for char in "testing":
            output_file.write(char)
            output_file.flush()
            time.sleep(0.2)
        output_file.write("\n")
        output_file.flush()
Пример #2
0
def _get_refpaths(data_dict, reference_file_types, observatory):
    """Tailor the CRDS core library getreferences() call to the JWST CAL code by
    adding locking and truncating expected exceptions.   Also simplify 'NOT FOUND n/a' to
    'N/A'.  Re-interpret empty reference_file_types as "no types" instead of core
    library default of "all types."
    """
    if not reference_file_types:   # [] interpreted as *all types*.
        return {}
    with crds_cache_locking.get_cache_lock():
        bestrefs = crds.getreferences(
            data_dict, reftypes=reference_file_types, observatory=observatory)
    refpaths = {filetype: filepath if "N/A" not in filepath.upper() else "N/A"
                for (filetype, filepath) in bestrefs.items()}
    return refpaths
Пример #3
0
def _get_refpaths(data_dict, reference_file_types, observatory):
    """Tailor the CRDS core library getreferences() call to the JWST CAL code by
    adding locking and truncating expected exceptions.   Also simplify 'NOT FOUND n/a' to
    'N/A'.  Re-interpret empty reference_file_types as "no types" instead of core
    library default of "all types."
    """
    if not reference_file_types:   # [] interpreted as *all types*.
        return {}
    with crds_cache_locking.get_cache_lock():
        bestrefs = crds.getreferences(
            data_dict, reftypes=reference_file_types, observatory=observatory)
    refpaths = {filetype: filepath if "N/A" not in filepath.upper() else "N/A"
                for (filetype, filepath) in bestrefs.items()}
    return refpaths
Пример #4
0
def get_multiple_reference_paths(input_file, reference_file_types):
    """Aligns JWST pipeline requirements with CRDS library top
    level interfaces.

    get_multiple_reference_paths() layers these additional tasks onto
    crds.getreferences():

    It converts an input file into a flat dictionary of JWST data
    model dotted parameters for defining CRDS best references.

    Returns { filetype : filepath or "N/A", ... }
    """
    from .. import datamodels

    gc.collect()

    if not reference_file_types:  # [] interpreted as *all types*.
        return {}

    if isinstance(input_file, (six.string_types, datamodels.DataModel)):
        with datamodels.open(input_file) as dm:
            data_dict = dm.to_flat_dict(include_arrays=False)
    else:  # XXX not sure what this does... seems unneeded.
        data_dict = _flatten_dict(input_file)

    gc.collect()

    try:
        if crds_cache_locking is not None:
            with crds_cache_locking.get_cache_lock():
                bestrefs = crds.getreferences(data_dict,
                                              reftypes=reference_file_types,
                                              observatory="jwst")
        else:
            bestrefs = crds.getreferences(data_dict,
                                          reftypes=reference_file_types,
                                          observatory="jwst")
    except crds.CrdsBadRulesError as exc:
        raise crds.CrdsBadRulesError(str(exc))
    except crds.CrdsBadReferenceError as exc:
        raise crds.CrdsBadReferenceError(str(exc))

    refpaths = {
        filetype: filepath if "N/A" not in filepath.upper() else "N/A"
        for (filetype, filepath) in bestrefs.items()
    }

    return refpaths
Пример #5
0
def _get_refpaths(data_dict, reference_file_types):
    """Tailor the CRDS core library getreferences() call to the JWST CAL code by
    adding locking and truncating expected exceptions.   Also simplify 'NOT FOUND n/a' to
    'N/A'.  Re-interpret empty reference_file_types as "no types" instead of core
    library default of "all types."
    """
    if not reference_file_types:   # [] interpreted as *all types*.
        return {}
    try: # catch exceptions to truncate expected tracebacks
        with crds_cache_locking.get_cache_lock():
            bestrefs = crds.getreferences(data_dict, reftypes=reference_file_types, observatory="jwst")
    except crds.CrdsBadRulesError as exc:
        raise crds.CrdsBadRulesError(str(exc))
    except crds.CrdsBadReferenceError as exc:
        raise crds.CrdsBadReferenceError(str(exc))
    except crds.CrdsLookupError as exc:
        raise crds.CrdsLookupError(str(exc))
    refpaths = {filetype: filepath if "N/A" not in filepath.upper() else "N/A"
                for (filetype, filepath) in bestrefs.items()}
    return refpaths
Пример #6
0
def _get_refpaths(data_dict, reference_file_types):
    """Tailor the CRDS core library getreferences() call to the JWST CAL code by
    adding locking and truncating expected exceptions.   Also simplify 'NOT FOUND n/a' to
    'N/A'.  Re-interpret empty reference_file_types as "no types" instead of core
    library default of "all types."
    """
    if not reference_file_types:  # [] interpreted as *all types*.
        return {}
    try:  # catch exceptions to truncate expected tracebacks
        with crds_cache_locking.get_cache_lock():
            bestrefs = crds.getreferences(data_dict,
                                          reftypes=reference_file_types,
                                          observatory="jwst")
    except crds.CrdsBadRulesError as exc:
        raise crds.CrdsBadRulesError(str(exc))
    except crds.CrdsBadReferenceError as exc:
        raise crds.CrdsBadReferenceError(str(exc))
    except crds.CrdsLookupError as exc:
        raise crds.CrdsLookupError(str(exc))
    refpaths = {
        filetype: filepath if "N/A" not in filepath.upper() else "N/A"
        for (filetype, filepath) in bestrefs.items()
    }
    return refpaths