def instrument_from_refname(filename): """Based on `filename` rather than it's contents, determine the associated instrument or raise an exception. >>> instrument_from_refname('hst_cos_spottab_0052.fits') 'cos' >>> instrument_from_refname('zas1615jl_spot.fits') 'cos' >>> instrument_from_refname('foobar.fits') Traceback (most recent call last): ... AssertionError: Cannot determine instrument for filename 'foobar.fits' """ try: # Hopefully it's a nice new standard filename, easy return decompose_newstyle_name(filename)[2] except AssertionError: # cryptic legacy paths & names, i.e. reality try: instrument = siname.WhichCDBSInstrument(os.path.basename(filename)).lower() if instrument == "multi": instrument = "synphot" return instrument except Exception: assert False, "Cannot determine instrument for filename '{}'".format(filename)
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