Пример #1
0
    def testclip(self):
        self.sp = S.FileSpectrum(self.fname)
        self.obs = Observation(self.sp, self.bp)
        rate = self.obs.countrate()

        self.assertTrue(abs(rate - self.refrate) < 1.0,
                        msg="tst %f ref %f" % (rate, self.refrate))
Пример #2
0
 def setUp(self):
     self.old_comptable = refs.COMPTABLE
     refs.COMPTABLE = locations._refTable(cmptb_name)
     self.oldpath = os.path.abspath(os.curdir)
     if os.path.isdir(os.path.join(locations.specdir, 'generic')):
         os.chdir(os.path.join(locations.specdir, 'generic'))
     else:
         os.chdir(locations.specdir)
     self.accuracy = 0.00109
     self.setparms()
     if self.sp is not None:  # Skip the base class!!
         self.obs = Observation(self.sp, self.bp)
Пример #3
0
def specrate(parlist):
    """Return the countrate of the spectrum as observed through the
    obsmode, based on the binned wavelength set; and write the resulting
    spectrum to a file, returning the filename."""

    d=getparms(parlist)
    sp=parse_spec(d['spectrum'])
    bp=ObsBandpass(d['instrument'])
    
    #Check overlap status & proceed accordingly
    ostat=bp.check_overlap(sp)

    try:
        obs=Observation(sp,bp,force=odict[ostat])
    except KeyError:
        obs=Observation(sp,bp,bp.wave,force=odict[ostat])

    obs.convert('counts')
    try:
        obs.writefits(d['output'],binned=True)
    except KeyError:
        d['output']=None

    if ostat == 'full':
        return "%g;%s"%(obs.countrate(),d['output'])
    else:
        return "%g;%s;%s"%(obs.countrate(),d['output'],owarn[ostat])
Пример #4
0
class ETCTestCase(testutil.FPTestCase):
    """Base class for cases generated from the ETC test listings"""
    def setUp(self):
        self.old_comptable = refs.COMPTABLE
        refs.COMPTABLE = locations._refTable(cmptb_name)
        self.oldpath = os.path.abspath(os.curdir)
        if os.path.isdir(os.path.join(locations.specdir, 'generic')):
            os.chdir(os.path.join(locations.specdir, 'generic'))
        else:
            os.chdir(locations.specdir)
        self.accuracy = 0.00109
        self.setparms()
        if self.sp is not None:  # Skip the base class!!
            self.obs = Observation(self.sp, self.bp)

    def setparms(self):
        self.sp = None
        self.bp = None
        self.ref_rate = None
        self.file = None
        self.cmd = None

    def tearDown(self):
        os.chdir(self.oldpath)
        refs.COMPTABLE = self.old_comptable

    def testrate(self):
        if self.sp is not None:
            self.assertApproxFP(self.obs.countrate(),
                                self.ref_rate,
                                accuracy=self.accuracy)
Пример #5
0
class Keepneg(testutil.FPTestCase):
    def setUp(self):
        self.fname=os.path.join(testdir,'us7.txt')
        self.refrate=2303.5 #provided by C. Oliveira
        self.bp=S.ObsBandpass('cos,fuv,g130m,c1309,psa')

    def testclip(self):
        self.sp=S.FileSpectrum(self.fname)
        self.obs=Observation(self.sp,self.bp)
        rate=self.obs.countrate()

        self.assertTrue(abs(rate-self.refrate)<1.0, msg="tst %f ref %f"%(rate,self.refrate))

    def testkeeprate(self):
        self.sp=S.FileSpectrum(self.fname,keepneg=True)
        self.obs=Observation(self.sp,self.bp)
        rate=self.obs.countrate()
        self.assertTrue(rate < self.refrate)

    def testkeepmin(self):
        self.sp=S.FileSpectrum(self.fname,keepneg=True)
        self.obs=Observation(self.sp,self.bp)
        self.assertTrue(self.obs.flux.min() < 0)

    def testarray(self):
        waves=N.arange(1000,6000,1000)
        flux=N.array([1.0,0.5,-0.5,0.75,1.0])
        self.sp=S.ArraySpectrum(wave=waves,flux=flux)
        self.assertEqual(self.sp.flux[2],0.0)



    def testarraykeep(self):
        waves=N.arange(1000,6000,1000)
        flux=N.array([1.0,0.5,-0.5,0.75,1.0])
        self.sp=S.ArraySpectrum(wave=waves,flux=flux,keepneg=True)
        self.assertEqual(self.sp.flux[2],-0.5)

    def testmagarray(self):
        waves=N.arange(1000,6000,1000)
        flux=N.array([1.0,0.5,-0.5,0.75,1.0])
        self.sp=S.ArraySpectrum(wave=waves,flux=flux,fluxunits='ABMag')
        self.assertAlmostEqual(self.sp.flux[2],-0.5,4)
Пример #6
0
class Keepneg(testutil.FPTestCase):
    def setUp(self):
        self.fname = os.path.join(testdir, 'us7.txt')
        self.refrate = 2303.5  #provided by C. Oliveira
        self.bp = S.ObsBandpass('cos,fuv,g130m,c1309,psa')

    def testclip(self):
        self.sp = S.FileSpectrum(self.fname)
        self.obs = Observation(self.sp, self.bp)
        rate = self.obs.countrate()

        self.assertTrue(abs(rate - self.refrate) < 1.0,
                        msg="tst %f ref %f" % (rate, self.refrate))

    def testkeeprate(self):
        self.sp = S.FileSpectrum(self.fname, keepneg=True)
        self.obs = Observation(self.sp, self.bp)
        rate = self.obs.countrate()
        self.assertTrue(rate < self.refrate)

    def testkeepmin(self):
        self.sp = S.FileSpectrum(self.fname, keepneg=True)
        self.obs = Observation(self.sp, self.bp)
        self.assertTrue(self.obs.flux.min() < 0)

    def testarray(self):
        waves = N.arange(1000, 6000, 1000)
        flux = N.array([1.0, 0.5, -0.5, 0.75, 1.0])
        self.sp = S.ArraySpectrum(wave=waves, flux=flux)
        self.assertEqual(self.sp.flux[2], 0.0)

    def testarraykeep(self):
        waves = N.arange(1000, 6000, 1000)
        flux = N.array([1.0, 0.5, -0.5, 0.75, 1.0])
        self.sp = S.ArraySpectrum(wave=waves, flux=flux, keepneg=True)
        self.assertEqual(self.sp.flux[2], -0.5)

    def testmagarray(self):
        waves = N.arange(1000, 6000, 1000)
        flux = N.array([1.0, 0.5, -0.5, 0.75, 1.0])
        self.sp = S.ArraySpectrum(wave=waves, flux=flux, fluxunits='ABMag')
        self.assertAlmostEqual(self.sp.flux[2], -0.5, 4)
Пример #7
0
def etccalc(obsmode, spectrum, filename=None):
    bp=ObsBandpass(obsmode)
    sp=parse_spec(spectrum)
    try:
        obs=Observation(sp,bp)
    except KeyError:
        obs=Observation(sp,bp,bp.wave)

    obs.convert('counts')
    if (filename is not None):
        if not filename.endswith('.fits'):
            filename=filename+'.fits'
        obs.writefits(filename)
        sp.writefits(filename.replace('.fits','_sp.fits'))
        bp.writefits(filename.replace('.fits','_bp.fits'))

    return obs.countrate(), obs.efflam(), obs.pivot()
Пример #8
0
def calcphot(parlist):
    """Calculate either effstim or efflam, depending on the input argument"""
    d=getparms(parlist)
    sp=parse_spec(d['spectrum'])
    bp=ObsBandpass(d['obsmode'])
    # obs=bp.observe(sp)
    
    ostat=bp.check_overlap(sp)
    
    try:
        obs=Observation(sp,bp,force=odict[ostat])
    except KeyError:
        obs=Observation(sp,bp,bp.wave,force=odict[ostat])

    obs.convert('counts')
    ans=obs.efflam()

    if ostat == 'full':
        return ans
    else:
        return ans, owarn[ostat]
Пример #9
0
def test_observation2():
    spec = FlatSpectrum(1)

    bp = ObsBandpass('acs,hrc,f555w', graphtable=GT_FILE_NO)

    obs = Observation(spec, bp)

    assert obs.primary_area == refs.PRIMARY_AREA

    # this should change the observations's area
    refs.setref(area=1.)
    assert refs.PRIMARY_AREA == 1.

    assert obs.primary_area == refs.PRIMARY_AREA
Пример #10
0
def test_observation1():
    spec = FlatSpectrum(1)

    bp = ObsBandpass('acs,hrc,f555w', graphtable=GT_FILE_100)

    obs = Observation(spec, bp)

    assert obs.primary_area != refs.PRIMARY_AREA
    assert obs.primary_area == 100.0

    # this should have no effect
    refs.setref(area=1.)
    assert refs.PRIMARY_AREA == 1.

    assert obs.primary_area != refs.PRIMARY_AREA
    assert obs.primary_area == 100.0
Пример #11
0
def countrate(parlist):
    """Return the pivot wavelength and countrate of the spectrum as
    observed through the obsmode, but based on the native waveset"""
    d=getparms(parlist)
    sp=parse_spec(d['spectrum'])
    bp=ObsBandpass(d['instrument'])


    #Check overlap status & proceed accordingly
    ostat=bp.check_overlap(sp)
    
    try:
        obs=Observation(sp,bp,force=odict[ostat])
    except KeyError:
        obs=Observation(sp,bp,bp.wave,force=odict[ostat])

    obs.convert('counts')
    efflam=obs.efflam()
    ans=obs.countrate(binned=False)

    if ostat == 'full':
        return ans,efflam
    else:
        return ans, efflam, owarn[ostat]
Пример #12
0
 def testkeepmin(self):
     self.sp = S.FileSpectrum(self.fname, keepneg=True)
     self.obs = Observation(self.sp, self.bp)
     self.assertTrue(self.obs.flux.min() < 0)
Пример #13
0
 def testkeeprate(self):
     self.sp = S.FileSpectrum(self.fname, keepneg=True)
     self.obs = Observation(self.sp, self.bp)
     rate = self.obs.countrate()
     self.assertTrue(rate < self.refrate)
Пример #14
0
 def testkeepmin(self):
     self.sp=S.FileSpectrum(self.fname,keepneg=True)
     self.obs=Observation(self.sp,self.bp)
     self.assertTrue(self.obs.flux.min() < 0)
Пример #15
0
 def testkeeprate(self):
     self.sp=S.FileSpectrum(self.fname,keepneg=True)
     self.obs=Observation(self.sp,self.bp)
     rate=self.obs.countrate()
     self.assertTrue(rate < self.refrate)
Пример #16
0
    def testclip(self):
        self.sp=S.FileSpectrum(self.fname)
        self.obs=Observation(self.sp,self.bp)
        rate=self.obs.countrate()

        self.assertTrue(abs(rate-self.refrate)<1.0, msg="tst %f ref %f"%(rate,self.refrate))