Пример #1
0
    def test_bandpass(self):
        """Test the AIPS IDI BANDPASS table."""

        testTime = time.time() - 2 * 86400.0
        testFile = os.path.join(self.testPath, 'idi-test-BP.fits')

        # Get some data
        data = self.__initData()

        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(testTime, 6.0, data['bl'], data['vis'])
        fits.write()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        bp = hdulist['BANDPASS'].data
        # Correct number of entries
        self.assertEqual(len(data['antennas']), len(bp.field('ANTENNA_NO')))

        # Correct Source ID number
        for src in bp.field('SOURCE_ID'):
            self.assertEqual(src, 0)

        # Correct FREQIDs
        for freqid in bp.field('FREQID'):
            self.assertEqual(freqid, 1)

        hdulist.close()
Пример #2
0
    def test_source(self):
        """Test the AIPS IDI SOURCE table."""

        testTime = time.time() - 2 * 86400.0
        testFile = os.path.join(self.testPath, 'idi-test-SO.fits')

        # Get some data
        data = self.__initData()

        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(testTime, 6.0, data['bl'], data['vis'])
        fits.write()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        so = hdulist['SOURCE'].data
        # Correct number of entries
        self.assertEqual(len(so.field('SOURCE_ID')), 1)

        # Correct Source ID number
        self.assertEqual(so.field('SOURCE_ID'), 1)

        hdulist.close()
Пример #3
0
    def test_antenna(self):
        """Test the AIPS IDI ANTENNA table."""

        testTime = time.time() - 2 * 86400.0
        testFile = os.path.join(self.testPath, 'idi-test-AN.fits')

        # Get some data
        data = self.__initData()

        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(testTime, 6.0, data['bl'], data['vis'])
        fits.write()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        an = hdulist['ANTENNA'].data
        # Correct number of stands
        self.assertEqual(len(data['antennas']), len(an.field('ANTENNA_NO')))

        # Correct FREQIDs
        for freqid in an.field('FREQID'):
            self.assertEqual(freqid, 1)

        hdulist.close()
Пример #4
0
    def test_array_geometry(self):
        """Test the AIPS IDI ARRAY_GEOMETRY table."""

        testTime = time.time() - 2 * 86400.0
        testFile = os.path.join(self.testPath, 'idi-test-AG.fits')

        # Get some data
        data = self.__initData()

        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(testTime, 6.0, data['bl'], data['vis'])
        fits.write()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        ag = hdulist['ARRAY_GEOMETRY'].data
        # Correct number of stands
        self.assertEqual(len(data['antennas']), len(ag.field('NOSTA')))

        # Correct stand names
        names = ['L%03i' % ant.stand.id for ant in data['antennas']]
        for name, anname in zip(names, ag.field('ANNAME')):
            self.assertEqual(name, anname)

        hdulist.close()
Пример #5
0
    def test_write_tables(self):
        """Test if the AIPS IDI writer writes all of the tables."""

        testTime = time.time() - 2 * 86400.0
        testFile = os.path.join(self.testPath, 'idi-test-W.fits')

        # Get some data
        data = self.__initData()

        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_comment('This is a comment')
        fits.add_history('This is history')
        fits.add_data_set(testTime, 6.0, data['bl'], data['vis'])
        fits.write()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        # Check that all of the extensions are there
        extNames = [hdu.name for hdu in hdulist]
        for ext in [
                'ARRAY_GEOMETRY', 'FREQUENCY', 'ANTENNA', 'BANDPASS', 'SOURCE',
                'UV_DATA'
        ]:
            self.assertTrue(ext in extNames)
        # Check the comments and history
        self.assertTrue('This is a comment' in str(
            hdulist[0].header['COMMENT']).split('\n'))
        self.assertTrue(
            'This is history' in str(hdulist[0].header['HISTORY']).split('\n'))

        hdulist.close()
Пример #6
0
    def test_frequency(self):
        """Test the AIPS IDI FREQUENCY table."""

        testTime = time.time() - 2*86400.0
        testFile = os.path.join(self.testPath, 'idi-test-FQ.fits')
        
        # Get some data
        data = self._init_data()
        
        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(unix_to_taimjd(testTime), 6.0, data['bl'], data['vis'])
        fits.write()
        fits.close()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        fq = hdulist['FREQUENCY'].data
        # Correct number of FREQIDs
        self.assertEqual(len(fq.field('FREQID')), 1)

        # Correct channel width
        self.assertAlmostEqual(fq.field('CH_WIDTH')[0], numpy.abs(data['freq'][1]-data['freq'][0]), 4)

        # Correct bandwidth
        self.assertAlmostEqual(fq.field('TOTAL_BANDWIDTH')[0], numpy.abs(data['freq'][-1]-data['freq'][0]).astype(numpy.float32), 4)

        # Correct sideband
        self.assertEqual(fq.field('SIDEBAND')[0], 1)

        hdulist.close()
Пример #7
0
    def test_mapper(self):
        """Test the AIPS IDI NOSTA_MAPPER table."""

        testTime = time.time() - 2*86400.0
        testFile = os.path.join(self.testPath, 'idi-test-SM.fits')
        
        # Get some data
        data = self._init_data()
        
        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(unix_to_taimjd(testTime), 6.0, data['bl'], data['vis'])
        fits.write()
        fits.close()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        extNames = [hdu.name for hdu in hdulist]
        maxStand = -1
        for ant in data['antennas']:
            if ant.stand.id > maxStand:
                maxStand = ant.stand.id
        if maxStand > 99:
            self.assertTrue('NOSTA_MAPPER' in extNames)

            # Make sure the mapper makes sense
            mp = hdulist['NOSTA_MAPPER'].data
            ag = hdulist['ARRAY_GEOMETRY'].data
            mNoSta = mp.field('NOSTA')
            aNoSta = ag.field('NOSTA')
            mNoAct = mp.field('NOACT')
            aAnNam = ag.field('ANNAME')
            for msta, mact, asta, anam in zip(mNoSta, mNoAct, aNoSta, aAnNam):
                self.assertEqual(msta, asta)
                self.assertEqual(mact, int(anam[1:]))

        hdulist.close()
Пример #8
0
    def test_uvdata(self):
        """Test the AIPS IDI UV_DATA table."""

        testTime = time.time() - 2 * 86400.0
        testFile = os.path.join(self.testPath, 'idi-test-UV.fits')

        # Get some data
        data = self.__initData()

        # Start the file
        fits = fitsidi.Aips(testFile, ref_time=testTime)
        fits.set_stokes(['xx'])
        fits.set_frequency(data['freq'])
        fits.set_geometry(data['site'], data['antennas'])
        fits.add_data_set(testTime, 6.0, data['bl'], data['vis'])
        fits.write()

        # Open the file and examine
        hdulist = astrofits.open(testFile)
        uv = hdulist['UV_DATA'].data

        # Load the mapper
        try:
            mp = hdulist['NOSTA_MAPPER'].data
            nosta = mp.field('NOSTA')
            noact = mp.field('NOACT')
        except KeyError:
            ag = hdulist['ARRAY_GEOMETRY'].data
            nosta = ag.field('NOSTA')
            noact = ag.field('NOSTA')
        mapper = {}
        for s, a in zip(nosta, noact):
            mapper[s] = a

        # Correct number of visibilities
        self.assertEqual(len(uv.field('FLUX')), data['vis'].shape[0])

        # Correct number of frequencies
        for vis in uv.field('FLUX'):
            self.assertEqual(len(vis), 2 * len(data['freq']))

        # Correct values
        for bl, vis in zip(uv.field('BASELINE'), uv.field('FLUX')):
            # Convert mapped stands to real stands
            stand1 = mapper[(bl >> 8) & 255]
            stand2 = mapper[bl & 255]

            # Find out which visibility set in the random data corresponds to the
            # current visibility
            i = 0
            for ant1, ant2 in data['bl']:
                if ant1.stand.id == stand1 and ant2.stand.id == stand2:
                    break
                else:
                    i = i + 1

            # Extract the data and run the comparison
            visData = numpy.zeros(len(data['freq']), dtype=numpy.complex64)
            visData.real = vis[0::2]
            visData.imag = vis[1::2]
            for vd, sd in zip(visData, data['vis'][i, :]):
                self.assertAlmostEqual(vd, sd, 8)
            i = i + 1

        hdulist.close()