def test_init(): sobj = specobj.SpecObj('MultiSlit', 1, slitid=0) # Test assert sobj.PYPELINE == 'MultiSlit' assert sobj['PYPELINE'] == 'MultiSlit' assert sobj.NAME == 'SPAT-----SLIT0000-DET01' assert len(sobj._data.keys()) == 0
def test_geocorrect(fitstbl): """ """ # Specobj (wrap in a list to mimic a slit) npix = 1000 sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) sobj.BOX_WAVE = np.linspace(4000., 6000., npix) sobj.BOX_COUNTS = 50. * (sobj.BOX_WAVE / 5000.)**-1. sobj.BOX_COUNTS_IVAR = 1. / sobj.BOX_COUNTS.copy() # SpecObjs specObjs = specobjs.SpecObjs() specObjs.add_sobj(sobj) scidx = 5 obstime = Time(fitstbl['mjd'][scidx], format='mjd') #'%Y-%m-%dT%H:%M:%S.%f') maskslits = np.array([False] * specObjs.nobj) radec = ltu.radec_to_coord((fitstbl["ra"][scidx], fitstbl["dec"][scidx])) helio, hel_corr = wave.geomotion_correct(specObjs, radec, obstime, maskslits, lon, lat, alt, 'heliocentric') assert np.isclose(helio, -9.17461338, rtol=1e-5) # Checked against x_keckhelio #assert np.isclose(helio, -9.3344957, rtol=1e-5) # Original assert np.isclose(specObjs[0].BOX_WAVE[0], 3999.877589008, rtol=1e-8)
def test_geocorrect(fitstbl): """ """ # Specobj (wrap in a list to mimic a slit) scidx = 5 obstime = Time(fitstbl['mjd'][scidx], format='mjd') #'%Y-%m-%dT%H:%M:%S.%f') radec = ltu.radec_to_coord((fitstbl["ra"][scidx], fitstbl["dec"][scidx])) helio, hel_corr = wave.geomotion_correct(radec, obstime, lon, lat, alt, 'heliocentric') assert np.isclose(helio, -9.17461338, rtol=1e-5) # Checked against x_keckhelio #assert np.isclose(helio, -9.3344957, rtol=1e-5) # Original assert np.isclose(1 - hel_corr, 3.060273748e-05, rtol=1e-5) # Now apply to a specobj npix = 1000 sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) sobj.BOX_WAVE = np.linspace(4000., 6000., npix) sobj.BOX_COUNTS = 50. * (sobj.BOX_WAVE / 5000.)**-1. sobj.BOX_COUNTS_IVAR = 1. / sobj.BOX_COUNTS.copy() sobj.apply_helio(hel_corr, 'heliocentric') assert np.isclose(sobj.BOX_WAVE[0], 3999.877589008, rtol=1e-8)
def test_io(): sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) # Can we handle 1 array? sobj['BOX_WAVE'] = np.arange(100).astype(float) ofile = data_path('tmp.fits') sobj.to_file(ofile, overwrite=True) _sobj = specobj.SpecObj.from_file(ofile) assert np.array_equal(sobj.BOX_WAVE, _sobj.BOX_WAVE)
def test_copy(): sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) # sobj['BOX_WAVE'] = np.arange(100).astype(float) sobj.smash_nsig = 1. # Copy sobj2 = specobj.SpecObj.copy(sobj) assert np.isclose(sobj2.smash_nsig, 1.) # Check assert np.array_equal(sobj.BOX_WAVE, sobj2.BOX_WAVE)
def test_data(): sobj = specobj.SpecObj('MultiSlit', 1, slitid=0) # sobj['BOX_WAVE'] = np.arange(100).astype(float) sobj['BOX_COUNTS'] = np.ones_like(sobj.BOX_WAVE) sobj['TRACE_SPAT'] = np.arange(100) * 2. # Test assert isinstance(sobj._data, Table) assert 'TRACE_SPAT' in sobj._data.keys() assert 'SLITID' in sobj._data.meta.keys()
def test_assignment(): sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) # sobj.PYPELINE = 'Blah' # Quick test on datamodel with pytest.raises(TypeError): sobj.PYPELINE = 2 # sobj.SPAT_PIXPOS = 523.0 sobj.PYPELINE = 'MultiSlit' sobj.set_name() assert sobj.NAME == 'SPAT0523-SLIT0000-DET01'
def test_assignment(): sobj = specobj.SpecObj('MultiSlit', 1, slitid=0) # sobj.PYPELINE = 'Blah' # with pytest.raises(OSError): sobj.PYPELINE = 2 # sobj.SPAT_PIXPOS = 523.0 sobj.PYPELINE = 'MultiSlit' sobj.set_name() assert sobj.NAME == 'SPAT0523-SLIT0000-DET01'
def test_hdu(): sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) # sobj['BOX_WAVE'] = np.arange(100).astype(float) sobj['BOX_COUNTS'] = np.ones_like(sobj.BOX_WAVE) sobj['TRACE_SPAT'] = np.arange(100) * 2. # Test hdul = sobj.to_hdu() #force_dict_bintbl=True) assert len(hdul) == 1 # Should be one BinTableHDU assert isinstance(hdul[0], fits.hdu.table.BinTableHDU) assert len(hdul[0].data) == 100 assert 'TRACE_SPAT' in hdul[0].data.dtype.names assert 'SLITID' in hdul[0].header.keys()
def test_io(): sobj = specobj.SpecObj('MultiSlit', 1, slitid=0) # sobj['BOX_WAVE'] = np.arange(100).astype(float) sobj['BOX_COUNTS'] = np.ones_like(sobj.BOX_WAVE) sobj['TRACE_SPAT'] = np.arange(100) * 2. # Write table sobj._data.write(data_path('tmp.fits'), overwrite=True) tbl = Table.read(data_path('tmp.fits')) sobj2 = specobj.SpecObj.from_table(tbl) # assert isinstance(sobj2, specobj.SpecObj)
def test_iotwo(): sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) # sobj['BOX_WAVE'] = np.arange(100).astype(float) sobj['BOX_COUNTS'] = np.ones_like(sobj.BOX_WAVE) sobj['TRACE_SPAT'] = np.arange(100) * 2. sobj['BOX_MASK'] = np.arange(100).astype(bool) # Write table ofile = data_path('tmp.fits') sobj.to_file(ofile, overwrite=True) sobj2 = specobj.SpecObj.from_file(ofile) # assert isinstance(sobj2, specobj.SpecObj) assert np.array_equal(sobj.BOX_WAVE, sobj2.BOX_WAVE) assert sobj2.PYPELINE == 'MultiSlit'
def sobj2(): return specobj.SpecObj('MultiSlit', 2, SLITID=1)
def test_init(): sobj = specobj.SpecObj('MultiSlit', 1, SLITID=0) # Test assert sobj.PYPELINE == 'MultiSlit' assert sobj['PYPELINE'] == 'MultiSlit' assert sobj.NAME == 'SPAT-----SLIT0000-DET01'
def sobj1(): return specobj.SpecObj('MultiSlit', 'DET01', SLITID=0)
def sobj3(): return specobj.SpecObj('MultiSlit', 3, SLITID=0)
def sobj4(): return specobj.SpecObj('MultiSlit', 1, SLITID=10)
""" import os import numpy as np import pytest from pypeit import msgs from pypeit import specobjs from pypeit import specobj msgs.reset(verbosity=2) #def data_path(filename): # data_dir = os.path.join(os.path.dirname(__file__), 'files') # return os.path.join(data_dir, filename) sobj1 = specobj.SpecObj('MultiSlit', 1, slitid=0) sobj2 = specobj.SpecObj('MultiSlit', 1, slitid=1) sobj3 = specobj.SpecObj('MultiSlit', 1, slitid=2) def test_init(): """ Run the parameter setup script """ # Null sobjs1 = specobjs.SpecObjs() # With a few objs sobjs2 = specobjs.SpecObjs([sobj1, sobj2]) assert sobjs2.nobj == 2