Exemple #1
0
def ref_properties_from_header(filename):
    """Look inside ASDF `filename` header to determine instrument, filekind.

    >>> ref_properties_from_header('tests/data/roman_wfi16_f158_flat_small.asdf')
    ('tests/data', 'roman', 'wfi', 'flat', 'roman_wfi16_f158_flat_small', '.asdf')

    >>> ref_properties_from_header('tests/data/s7g1700gl_dead_bad_xsum.fits')
    Traceback (most recent call last):
    ...
    crds.core.exceptions.CrdsNamingError: Can't identify instrument of 's7g1700gl_dead_bad_xsum.fits' : Invalid instrument 'cos'
    """
    # 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, "roman")
    header["ROMAN.META.TELESCOPE"] = "roman"
    name = os.path.basename(filename)
    try:
        instrument = utils.header_to_instrument(header).lower()
        assert instrument in INSTRUMENTS, "Invalid instrument " + repr(
            instrument)
    except Exception as exc:
        raise exceptions.CrdsNamingError("Can't identify instrument of",
                                         repr(name), ":", str(exc)) from exc
    try:
        filekind = header.get('ROMAN.META.REFTYPE', 'UNDEFINED').lower()
        assert filekind in FILEKINDS, "Invalid file type " + repr(filekind)
    except Exception as exc:
        raise exceptions.CrdsNamingError(
            "Can't identify ROMAN.META.REFTYPE of", repr(name))
    return path, "roman", instrument, filekind, serial, ext
Exemple #2
0
def ref_properties_from_header(filename):
    """Look inside FITS `filename` header to determine instrument, filekind.
    """
    # 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, "jwst")
    header["TELESCOP"] = header["TELESCOPE"] = header[
        "META.TELESCOPE"] = "jwst"
    name = os.path.basename(filename)
    try:
        instrument = utils.header_to_instrument(header).lower()
        assert instrument in INSTRUMENTS, "Invalid instrument " + repr(
            instrument)
    except Exception as exc:
        raise exceptions.CrdsNamingError("Can't identify instrument of",
                                         repr(name), ":", str(exc)) from exc
    try:
        filekind = utils.get_any_of(header, FILEKIND_KEYWORDS,
                                    "UNDEFINED").lower()
        assert filekind in FILEKINDS, "Invalid file type " + repr(filekind)
    except Exception as exc:
        raise exceptions.CrdsNamingError("Can't identify REFTYPE of",
                                         repr(name))
    return path, "jwst", instrument, filekind, serial, ext
Exemple #3
0
def ref_properties_from_header(filename):
    """Look inside FITS `filename` header to determine instrument, filekind.
    """
    # 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, "jwst")
    header["TELESCOP"] = header["TELESCOPE"] = header["META.TELESCOPE"] = "jwst"
    instrument = utils.header_to_instrument(header).lower()
    filekind = utils.get_any_of(header, FILEKIND_KEYWORDS, "UNDEFINED").lower()
    assert instrument in INSTRUMENTS, "Invalid instrument " + repr(instrument)
    assert filekind in FILEKINDS, "Invalid file type " + repr(filekind)
    return path, "jwst", instrument, filekind, serial, ext
Exemple #4
0
 def __iter__(self):
     """Return the sources from self with EXPTIME >= self.datasets_since."""
     for source in sorted(self.sources):
         with log.error_on_exception("Failed loading source", repr(source),
                                     "from", repr(self.__class__.__name__)):
             instrument = utils.header_to_instrument(self.header(source))
             exptime = matches.get_exptime(self.header(source))
             since = self.datasets_since(instrument)
             # since == None when no command line argument given.
             if since is None or exptime >= since:
                 yield source
             else:
                 log.verbose("Dropping source", repr(source),
                             "with EXPTIME =", repr(exptime),
                             "< --datasets-since =", repr(since))
Exemple #5
0
 def get_old_bestrefs(self, source):
     """Return the historical best references corresponding to `source`.  Always define old bestrefs
     in terms of filekind/typename rather than in terms of FITS keyword.
     """
     header = add_instrument(self.header(source))
     instrument = utils.header_to_instrument(header)
     pmap = crds.get_pickled_mapping(self.context)
     result = {}
     for filekind in pmap.get_imap(instrument).selections:
         keyword = pmap.locate.filekind_to_keyword(filekind)
         filekind = filekind.upper()
         try:
             result[filekind] = header[keyword]
         except KeyError:
             result[filekind] = header.get(filekind, "UNDEFINED")
     return result
Exemple #6
0
def add_instrument(header):
    """Add INSTRUME keyword."""
    instrument = utils.header_to_instrument(header)
    header["INSTRUME"] = instrument
    header["META.INSTRUMENT.NAME"] = instrument
    return header