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
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
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
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
def _header(self, filename): """Get the best references recommendations recorded in the header of file `dataset`.""" gc.collect() if filename not in self.headers: self.headers[filename] = data_file.get_free_header( filename, (), None, self.observatory) return self.headers[filename]
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, observatory="jwst") instrument = utils.header_to_instrument(header).lower() assert instrument in INSTRUMENTS, "Invalid instrument " + repr(instrument) filekind = utils.get_any_of(header, ["REFTYPE", "TYPE", "META.TYPE", "META.REFFILE.TYPE"], "UNDEFINED").lower() assert filekind in FILEKINDS, "Invalid file type " + repr(filekind) return path, "jwst", instrument, filekind, serial, ext
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, observatory="jwst") instrument = utils.header_to_instrument(header).lower() assert instrument in INSTRUMENTS, "Invalid instrument " + repr(instrument) filekind = utils.get_any_of(header, ["REFTYPE", "TYPE", "META.TYPE", "META.REFFILE.TYPE"], "UNDEFINED").lower() assert filekind in FILEKINDS, "Invalid file type " + repr(filekind) return path, "jwst", instrument, filekind, serial, ext
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, "tmt") header["TELESCOP"] = header["TELESCOPE"] = header["META.TELESCOPE"] = "tmt" 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, "tmt", instrument, filekind, serial, ext
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
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
def reference_name_to_validator_key(self, filename, field="tpn"): """Return the sequence of validator keys associated with `filename`. A validator key is nominally a .tpn filename and can vary by observatory, instrument, and type as well as by functions on the header of `filename`. """ header = data_file.get_free_header(filename) observatory = utils.header_to_observatory(header) instrument, filekind = utils.get_file_properties(observatory, filename) results = [] def append_tpn_level(results, instrument, filekind): """Append the validator key for associated with one level of the `instrument` and `filekind` to `results`. """ try: validator_key = self._reference_name_to_validator_key(filename, field, header, observatory, instrument, filekind) log.verbose("Adding validator key", repr(validator_key)) results.append(validator_key) except Exception as exc: log.verbose_warning("Can't find TPN key for", (filename, instrument, filekind), ":", str(exc), verbosity=75) append_tpn_level(results, "all", "all") append_tpn_level(results, instrument, "all") append_tpn_level(results, "all", filekind) append_tpn_level(results, instrument, filekind) return results
def reference_name_to_validator_key(self, filename, field="tpn"): """Return the sequence of validator keys associated with `filename`. A validator key is nominally a .tpn filename and can vary by observatory, instrument, and type as well as by functions on the header of `filename`. """ header = data_file.get_free_header(filename) observatory = utils.header_to_observatory(header) instrument, filekind = utils.get_file_properties(observatory, filename) results = [] def append_tpn_level(results, instrument, filekind): """Append the validator key for associated with one level of the `instrument` and `filekind` to `results`. """ try: validator_key = self._reference_name_to_validator_key(filename, field, header, observatory, instrument, filekind) log.verbose("Adding validator key", repr(validator_key)) results.append(validator_key) except Exception as exc: log.verbose_warning("Can't find TPN key for", (filename, instrument, filekind), ":", str(exc), verbosity=75) append_tpn_level(results, "all", "all") append_tpn_level(results, instrument, "all") append_tpn_level(results, "all", filekind) append_tpn_level(results, instrument, filekind) return results