def setUp(self): setref() self.gref = irafconvert('mtab$t2605492m_tmg.fits') self.cref = irafconvert('mtab$t260548pm_tmc.fits') setref(graphtable=self.gref, comptable=self.cref) self.pick = getref()
def test_things_in_cache(self): fail = False self.tra = { } Cache.reset_catalog_cache() sp = S.Icat('k93models', 6440, 0, 4.3) self.assertTrue(len(Cache.CATALOG_CACHE) == 1) k = next(key for key in Cache.CATALOG_CACHE.keys()) from pysynphot.locations import irafconvert import os.path f = irafconvert("$PYSYN_CDBS/grid/k93models/catalog.fits") f = os.path.normpath(f) f = os.path.normcase(f) fixed_k = os.path.normpath(k) fixed_k = os.path.normcase(fixed_k) if fixed_k != f : self.tra['cache_found'] = k self.tra['cache_found_fixed'] = fixed_k self.tra['cache_expect'] = f fail = True if not isinstance(Cache.CATALOG_CACHE[k],list) : self.tra['cache_type_mismatch'] = str(type(Cache.CATALOG_CACHE[k])) fail = True if fail : raise AssertionError()
def test_things_in_cache(self): fail = False self.tra = {} Cache.reset_catalog_cache() sp = S.Icat('k93models', 6440, 0, 4.3) self.assertTrue(len(Cache.CATALOG_CACHE) == 1) k = next(key for key in Cache.CATALOG_CACHE.keys()) from pysynphot.locations import irafconvert import os.path f = irafconvert("$PYSYN_CDBS/grid/k93models/catalog.fits") f = os.path.normpath(f) f = os.path.normcase(f) fixed_k = os.path.normpath(k) fixed_k = os.path.normcase(fixed_k) if fixed_k != f: self.tra['cache_found'] = k self.tra['cache_found_fixed'] = fixed_k self.tra['cache_expect'] = f fail = True if not isinstance(Cache.CATALOG_CACHE[k], list): self.tra['cache_type_mismatch'] = str(type(Cache.CATALOG_CACHE[k])) fail = True if fail: raise AssertionError()
def test_CONVERTDICT(): import pysynphot.locations as locations locations.CONVERTDICT['testjref'] = './data/cdbs/jref/' refpath = './data/cdbs/jref/empty_test_file.txt' filename = locations.irafconvert('testjref$empty_test_file.txt') assert refpath == filename
def test_CONVERTDICT(): import pysynphot.locations as locations locations.CONVERTDICT['testjref'] = './data/cdbs/jref/' refpath = './data/cdbs/jref/empty_test_file.txt' filename = locations.irafconvert('testjref$empty_test_file.txt') assert refpath == filename
def test1(self): ans = irafconvert(self.fstring) ans = os.path.normpath(ans) ref = os.path.normpath(self.ref) ans = os.path.normcase(ans) ref = os.path.normcase(ref) self.tra = dict(ans=ans, ref=ref) self.assertEqual(ref, ans)
def get_comptab_info(self, synname): """Dump the FILENAME column of the component table implied by `synname` (e.g. "tmc" --> something_tmc.fits) and use pysynphot to interpret the embedded iraf$-style path env var into a normal filepath. This is used to locate files within appropriate sub-directories of <synphot_dir>/comp. Return the mapping from a component file basename as defined in the CRDS rmap to the absolute path in a CDBS-style synphot file repo being created. Returns { component_basename : abs_pysyn_path, ...} """ for msg in SYNPHOT_IGNORE: warnings.filterwarnings("ignore", msg) from pysynphot import locations filekind = synname + "tab" rmap = self.imap.get_rmap(filekind) references = rmap.reference_names() assert len(references) == 1, \ "More than one '%s' reference name mentioned in '%s'." % \ (synname, rmap.name) tab_name = references[0] # rmap object locate() not module function. tab_path = rmap.locate_file(tab_name) # CRDS abstract table object nominally from HDU 1 table = tables.tables(tab_path)[0] fileinfo = {} for syn_name in table.columns["FILENAME"]: iraf_path, basename = syn_name.split("$") name = basename.split("[")[0] # remove parameterization dollar_syn_name = syn_name.split("[")[0] # Use pysynphot to interpret iraf_path cdbs_filepath = os.path.abspath( locations.irafconvert(dollar_syn_name)) fileinfo[name] = cdbs_filepath return fileinfo
def get_comptab_info(self, synname): """Dump the FILENAME column of the component table implied by `synname` (e.g. "tmc" --> something_tmc.fits) and use pysynphot to interpret the embedded iraf$-style path env var into a normal filepath. This is used to locate files within appropriate sub-directories of <synphot_dir>/comp. Return the mapping from a component file basename as defined in the CRDS rmap to the absolute path in a CDBS-style synphot file repo being created. Returns { component_basename : abs_pysyn_path, ...} """ for msg in SYNPHOT_IGNORE: warnings.filterwarnings("ignore",msg) from pysynphot import locations filekind = synname + "tab" rmap = self.imap.get_rmap(filekind) references = rmap.reference_names() assert len(references) == 1, \ "More than one '%s' reference name mentioned in '%s'." % \ (synname, rmap.name) tab_name = references[0] # rmap object locate() not module function. tab_path = rmap.locate_file(tab_name) # CRDS abstract table object nominally from HDU 1 table = tables.tables(tab_path)[0] fileinfo = {} for syn_name in table.columns["FILENAME"]: iraf_path, basename = syn_name.split("$") name = basename.split("[")[0] # remove parameterization dollar_syn_name = syn_name.split("[")[0] # Use pysynphot to interpret iraf_path cdbs_filepath = os.path.abspath( locations.irafconvert(dollar_syn_name)) fileinfo[name] = cdbs_filepath return fileinfo
def testiraf(self): fname = 'crcalspec$gd50_004.fits' tst = irafconvert(fname) self.assertTrue(self.ref == tst, msg="Expected %s, got %s" % (self.ref, tst))
def testplain(self): fname = 'gd50_004.fits' tst = irafconvert(fname) self.assertTrue(fname == tst, msg="Expected %s, got %s"%(fname,tst))
def testshell(self): fname = '$PYSYN_CDBS/calspec/gd50_004.fits' tst = irafconvert(fname) self.assertTrue(self.ref == tst, msg="Expected %s, got %s"%(self.ref,tst))
def testiraf(self): fname = 'crcalspec$gd50_004.fits' tst = irafconvert(fname) self.assertTrue(self.ref == tst, msg="Expected %s, got %s"%(self.ref,tst))
def testplain(self): fname = 'gd50_004.fits' tst = irafconvert(fname) self.assertTrue(fname == tst, msg="Expected %s, got %s" % (fname, tst))
from pysynphot import locations from pysynphot import refs from pysynphot import binning from pysynphot.tables import GraphTable from pysynphot.observationmode import ObservationMode from pysynphot.obsbandpass import ObsBandpass from pysynphot.spectrum import FlatSpectrum from pysynphot.spectrum import Integrator from pysynphot.spectrum import CompositeSpectralElement from pysynphot.observation import Observation from pysynphot.exceptions import IncompatibleSources import pysynphot.units as units # a stock graph table on CDBS GT_FILE_NO = locations.irafconvert('mtab$n9i1408hm_tmg.fits') # this copy of a graph table has been modified to have PRIMAREA = 100.0 GT_FILE_100 = os.path.join(os.path.dirname(__file__), 'data', 'cdbs', 'mtab', 'n9i1408hm_tmg.fits') def setUpModule(): pass def tearDownModule(): # Reset refs reload(refs)
def testset(self): tst=getref()[self.ttype] self.assertEquals(irafconvert(self.ref), irafconvert(tst), "(ref,tst)=(%s,%s)"%(self.ref,tst) )
def testget(self): tst = getref() ref = copy.deepcopy(startup) ref[self.ttype]=irafconvert(self.ref) self.assertEqual(ref,tst,"(ref,test):\n (%s\n%s)"%(ref,tst))
def testshell(self): fname = '$PYSYN_CDBS/calspec/gd50_004.fits' tst = irafconvert(fname) self.assertTrue(self.ref == tst, msg="Expected %s, got %s" % (self.ref, tst))
from pysynphot import locations from pysynphot import refs from pysynphot import binning from pysynphot.tables import GraphTable from pysynphot.observationmode import ObservationMode from pysynphot.obsbandpass import ObsBandpass from pysynphot.spectrum import FlatSpectrum from pysynphot.spectrum import Integrator from pysynphot.spectrum import CompositeSpectralElement from pysynphot.observation import Observation from pysynphot.exceptions import IncompatibleSources import pysynphot.units as units # a stock graph table on CDBS GT_FILE_NO = locations.irafconvert('mtab$n9i1408hm_tmg.fits') # this copy of a graph table has been modified to have PRIMAREA = 100.0 GT_FILE_100 = os.path.join(os.path.dirname(__file__), 'data', 'cdbs', 'mtab', 'n9i1408hm_tmg.fits') def setUpModule(): pass def tearDownModule(): # Reset refs reload(refs)