Exemplo n.º 1
0
def ref_properties_from_header(filename):
    """Look inside FITS `filename` header to determine:

    (path, "hst", instrument, filekind, serial, ext) 
    """
    # For legacy files,  just use the root filename as the unique id
    path, _parts, ext = _get_fields(filename)
    serial = os.path.basename(os.path.splitext(filename)[0])
    header = data_file.get_free_header(filename)
    instrument = header["INSTRUME"].lower()
    if instrument in INSTRUMENT_FIXERS:
        instrument = INSTRUMENT_FIXERS[instrument]
    try:
        filetype = header["FILETYPE"].lower()
    except KeyError:
        try:
            filetype = header["CDBSFILE"].lower()
        except KeyError:
            raise CrdsError("File '{}' missing FILETYPE and CDBSFILE,  type not identifiable.".format(os.path.basename(filename)))
    filetype = TYPE_FIXERS.get((instrument, filetype), filetype)
    try:
        filekind = TYPES.filetype_to_filekind(instrument, filetype)
    except KeyError:
        raise CrdsError("Invalid FILETYPE (or CDBSFILE) of '{}' for instrument '{}'." .format(filetype, instrument))
    return path, "hst", instrument, filekind, serial, ext
Exemplo n.º 2
0
Arquivo: locate.py Projeto: nden/crds
def ref_properties_from_header(filename):
    """Look inside FITS `filename` header to determine:

    (path, "hst", instrument, filekind, serial, ext) 
    """
    # For legacy files,  just use the root filename as the unique id
    path, _parts, ext = _get_fields(filename)
    serial = os.path.basename(os.path.splitext(filename)[0])
    header = data_file.get_free_header(filename)
    instrument = header["INSTRUME"].lower()
    if instrument in INSTRUMENT_FIXERS:
        instrument = INSTRUMENT_FIXERS[instrument]
    try:
        filetype = header["FILETYPE"].lower()
    except KeyError:
        try:
            filetype = header["CDBSFILE"].lower()
        except KeyError:
            raise CrdsError(
                "File '{}' missing FILETYPE and CDBSFILE,  type not identifiable."
                .format(os.path.basename(filename)))
    filetype = TYPE_FIXERS.get((instrument, filetype), filetype)
    try:
        filekind = TYPES.filetype_to_filekind(instrument, filetype)
    except KeyError:
        raise CrdsError(
            "Invalid FILETYPE (or CDBSFILE) of '{}' for instrument '{}'.".
            format(filetype, instrument))
    return path, "hst", instrument, filekind, serial, ext
Exemplo n.º 3
0
def ref_properties_from_cdbs_path(filename):
    """Based on a HST CDBS `filename`,  return

    (path, "hst", instrument, filekind, serial, ext)

    Raise AssertionError if it's not a good filename.
    """
    path, fields, extension = _get_fields(filename)
    # For legacy files,  just use the root filename as the unique id
    serial = os.path.basename(os.path.splitext(filename)[0])
    # First try to figure everything out by decoding filename. fast
    instrument = siname.WhichCDBSInstrument(os.path.basename(filename)).lower()
    if instrument == "synphot":
        if filename.endswith("_syn.fits"):
            filekind = "thruput"
        elif filename.endswith("_th.fits"):
            filekind = "thermal"
        elif filename.endswith("_tmt.fits"):
            filekind = "tmttab"
        elif filename.endswith("_tmg.fits"):
            filekind = "tmgtab"
        elif filename.endswith("_tmc.fits"):
            filekind = "tmctab"
        else:
            assert False, "Uknown synphot filetype for: " + repr(filename)
        suffix = filename.split("_")[-1][:-len(".fits")]
    elif extension == ".fits":
        suffix = fields[1]
    else:
        suffix = GEIS_EXT_TO_SUFFIX[extension[1:3]]
    try:
        filekind = TYPES.suffix_to_filekind(instrument, suffix)
    except KeyError:
        assert False, "Couldn't map extension/suffix " + repr(suffix) + " to filekind."
    return path, "hst", instrument, filekind, serial, extension
Exemplo n.º 4
0
def ref_properties_from_cdbs_path(filename):
    """Based on a HST CDBS `filename`,  return 
    
    (path, "hst", instrument, filekind, serial, ext)

    Raise AssertionError if it's not a good filename.
    """
    path, fields, extension = _get_fields(filename)
    # For legacy files,  just use the root filename as the unique id
    serial = os.path.basename(os.path.splitext(filename)[0])
    # First try to figure everything out by decoding filename. fast
    instrument = siname.WhichCDBSInstrument(os.path.basename(filename)).lower()
    if instrument == "synphot":
        if filename.endswith("_syn.fits"):
            filekind = "thruput"
        elif filename.endswith("_th.fits"):
            filekind = "thermal"
        elif filename.endswith("_tmt.fits"):
            filekind = "tmttab"
        elif filename.endswith("_tmg.fits"):
            filekind = "tmgtab"
        elif filename.endswith("_tmc.fits"):
            filekind = "tmctab"
        else:
            assert False, "Uknown synphot filetype for: " + repr(filename)
        suffix = filename.split("_")[-1][:-len(".fits")]
    elif extension == ".fits":
        suffix = fields[1]
    else:
        suffix = GEIS_EXT_TO_SUFFIX[extension[1:3]]
    try:
        filekind = TYPES.suffix_to_filekind(instrument, suffix)
    except KeyError:
        assert False, "Couldn't map extension/suffix " + repr(suffix) + " to filekind."
    return path, "hst", instrument, filekind, serial, extension
Exemplo n.º 5
0
def ref_properties_from_header(filename):
    """Look inside FITS `filename` header to determine:

    (path, "hst", instrument, filekind, serial, ext)
    """
    # For legacy files,  just use the root filename as the unique id
    path, _parts, ext = _get_fields(filename)
    serial = os.path.basename(os.path.splitext(filename)[0])
    header = data_file.get_free_header(filename, (), None, "hst")
    try:
        if "DBTABLE" not in header or header["DBTABLE"] in ["IMPHTTAB"]:
            instrument = header["INSTRUME"].lower()
        else:
            instrument = "synphot"
        instrument = INSTRUMENT_FIXERS.get(instrument, instrument)
    except KeyError as exc:
        raise CrdsNamingError("Can't determine instrument for",
                              repr(os.path.basename(filename)) + ".",
                              "CAL references must define INSTRUME,",
                              "SYNPHOT references define DBTABLE.") from exc
    try:
        filetype = header.get("FILETYPE",
                              header.get("DBTABLE", header.get("CDBSFILE")))
        if filetype is None:
            raise KeyError
        else:
            filetype = filetype.lower()
    except KeyError:
        observatory = header.get("TELESCOP", header.get("TELESCOPE", None))
        if observatory is not None and observatory.upper() != "HST":
            raise CrdsNamingError(
                "CRDS is configured for 'HST' but file",
                repr(os.path.basename(filename)), "is for the",
                repr(observatory),
                "telescope.  Reconfigure CRDS_PATH or CRDS_SEVER_URL.")
        else:
            raise CrdsNamingError(
                "Can't determine HST file type for",
                repr(os.path.basename(filename)) + ".",
                "Check FILETYPE, CDBSFILE, DBTABLE, TELESCOP, and/or TELESCOPE."
            )
    filetype = TYPE_FIXERS.get((instrument, filetype), filetype)
    try:
        filekind = TYPES.filetype_to_filekind(instrument, filetype)
    except KeyError:
        raise CrdsNamingError(
            f"Invalid FILETYPE (or CDBSFILE) of '{filetype}' for instrument '{instrument}'."
        )
    return path, "hst", instrument, filekind, serial, ext
Exemplo n.º 6
0
def ref_properties_from_header(filename):
    """Look inside FITS `filename` header to determine:

    (path, "hst", instrument, filekind, serial, ext) 
    """
    # For legacy files,  just use the root filename as the unique id
    path, _parts, ext = _get_fields(filename)
    serial = os.path.basename(os.path.splitext(filename)[0])
    header = data_file.get_free_header(filename, (), None, "hst")
    if "DBTABLE" not in header or header["DBTABLE"] in ["IMPHTTAB"]:
        instrument = header["INSTRUME"].lower()
    else:
        instrument = "synphot"
    instrument = INSTRUMENT_FIXERS.get(instrument, instrument)
    try:
        filetype = header.get(
            "FILETYPE", header.get(
                "DBTABLE", header.get(
                    "CDBSFILE"))).lower()
    except KeyError:
        observatory = header.get(
        "TELESCOP", header.get(
            "TELESCOPE", None))
        if observatory is not None and observatory.upper() != "HST":
            raise CrdsNamingError(
                "CRDS is configured for 'HST' but file", 
                repr(os.path.basename(filename)),
                "is for the", repr(observatory), 
                "telescope.  Reconfigure CRDS_PATH or CRDS_SEVER_URL.")
        else:
            raise CrdsNamingError(
                "File", repr(os.path.basename(filename)),
                "is missing FILETYPE, CDBSFILE, DBTABLE, TELESCOP, and TELESCOPE;",
                "CRDS cannot identify HST file type.")
    filetype = TYPE_FIXERS.get((instrument, filetype), filetype)
    try:
        filekind = TYPES.filetype_to_filekind(instrument, filetype)
    except KeyError:
        raise CrdsNamingError(f"Invalid FILETYPE (or CDBSFILE) of '{filetype}' for instrument '{instrument}'.")
    return path, "hst", instrument, filekind, serial, ext
Exemplo n.º 7
0
def reference_name_to_ld_tpn_text(filename):
    """Given reference `filename`,  return the text of the corresponding _ld.tpn"""
    path = rmap.locate_file(filename, "hst")
    key = TYPES.reference_name_to_ld_tpn_key(path)
    return get_tpn_text(*key)