Beispiel #1
0
    def run_correlator_test_real(self,
                                 dtype,
                                 nchan=256,
                                 window=fx.null_window):
        fakeData = 10.0 * numpy.random.rand(self.nAnt, nchan * 8) + 3.0
        fakeData = fakeData.astype(dtype)

        station = stations.parse_ssmif(_SSMIF)
        antennas = station.antennas

        freq, cps = fx.FXStokes(fakeData,
                                antennas[:self.nAnt],
                                LFFT=nchan,
                                window=window)

        # Numpy comparison
        for i in range(self.nAnt):
            antennas[i].stand.x = 0.0
            antennas[i].stand.y = 0.0
            antennas[i].stand.z = 0.0
            antennas[i].cable.length = 0.0

        freq, cps = fx.FXStokes(fakeData,
                                antennas[:self.nAnt],
                                LFFT=nchan,
                                window=window)

        cps2 = numpy.zeros_like(cps)
        LFFT = cps.shape[2]
        nFFT = fakeData.shape[1] // 2 // LFFT
        wndw = window(2 * LFFT)
        blc = 0
        for i in range(0, self.nAnt // 2):
            for j in range(i + 1, self.nAnt // 2):
                for k in range(nFFT):
                    f1X = numpy.fft.fft(
                        fakeData[2 * i + 0, k * 2 * LFFT:(k + 1) * 2 * LFFT] *
                        wndw)[:LFFT]
                    f1Y = numpy.fft.fft(
                        fakeData[2 * i + 1, k * 2 * LFFT:(k + 1) * 2 * LFFT] *
                        wndw)[:LFFT]
                    f2X = numpy.fft.fft(
                        fakeData[2 * j + 0, k * 2 * LFFT:(k + 1) * 2 * LFFT] *
                        wndw)[:LFFT]
                    f2Y = numpy.fft.fft(
                        fakeData[2 * j + 1, k * 2 * LFFT:(k + 1) * 2 * LFFT] *
                        wndw)[:LFFT]

                    cps2[0, blc, :] += f1X * f2X.conj() + f1Y * f2Y.conj()
                    cps2[1, blc, :] += f1X * f2X.conj() - f1Y * f2Y.conj()
                    cps2[2, blc, :] += f1X * f2Y.conj() + f1X.conj() * f2Y
                    cps2[3,
                         blc, :] += (f1X * f2Y.conj() - f1X.conj() * f2Y) / 1j
                blc += 1
        cps2 /= (2 * LFFT * nFFT)
        lsl.testing.assert_allclose(cps, cps2)
Beispiel #2
0
    def test_correlator_complex_pfb(self):
        """Test the C-based PFB version of the correlator on complex-valued data."""

        fakeData = numpy.random.rand(
            self.nAnt, 1024 * 4) + 1j * numpy.random.rand(self.nAnt, 1024 * 4)
        fakeData = fakeData.astype(numpy.csingle)

        station = stations.parse_ssmif(_SSMIF)
        antennas = station.antennas

        freq, cps = fx.FXStokes(fakeData,
                                antennas[:self.nAnt],
                                pfb=True,
                                sample_rate=1e5,
                                central_freq=38e6)

        # Numpy comparison
        for i in range(self.nAnt):
            antennas[i].stand.x = 0.0
            antennas[i].stand.y = 0.0
            antennas[i].stand.z = 0.0
            antennas[i].cable.length = 0.0

        freq, cps = fx.FXStokes(fakeData,
                                antennas[:self.nAnt],
                                pfb=True,
                                sample_rate=1e5,
                                central_freq=38e6)

        cps2 = numpy.zeros_like(cps)
        LFFT = cps.shape[2]
        nFFT = fakeData.shape[1] // LFFT
        blc = 0
        for i in range(0, self.nAnt // 2):
            for j in range(i + 1, self.nAnt // 2):
                for k in range(nFFT):
                    f1X = numpy.fft.fftshift(
                        _pfb(fakeData[2 * i + 0, :], k * LFFT, LFFT))
                    f1Y = numpy.fft.fftshift(
                        _pfb(fakeData[2 * i + 1, :], k * LFFT, LFFT))
                    f2X = numpy.fft.fftshift(
                        _pfb(fakeData[2 * j + 0, :], k * LFFT, LFFT))
                    f2Y = numpy.fft.fftshift(
                        _pfb(fakeData[2 * j + 1, :], k * LFFT, LFFT))

                    cps2[0, blc, :] += f1X * f2X.conj() + f1Y * f2Y.conj()
                    cps2[1, blc, :] += f1X * f2X.conj() - f1Y * f2Y.conj()
                    cps2[2, blc, :] += f1X * f2Y.conj() + f1X.conj() * f2Y
                    cps2[3,
                         blc, :] += (f1X * f2Y.conj() - f1X.conj() * f2Y) / 1j
                blc += 1
        cps2 /= (LFFT * nFFT)
        lsl.testing.assert_allclose(cps, cps2)
Beispiel #3
0
    def test_correlator_real_pfb(self):
        """Test the C-based PFB version of the correlator on real-valued data."""

        for dtype in (numpy.int8, numpy.int16, numpy.int32, numpy.int64,
                      numpy.float32, numpy.float64):
            fakeData = 10.0 * numpy.random.rand(self.nAnt, 1024 * 4) + 3.0
            fakeData = fakeData.astype(dtype)

            station = stations.parse_ssmif(_SSMIF)
            antennas = station.antennas

            freq, cps = fx.FXStokes(fakeData, antennas[:self.nAnt], pfb=True)

            # Numpy comparison
            for i in range(self.nAnt):
                antennas[i].stand.x = 0.0
                antennas[i].stand.y = 0.0
                antennas[i].stand.z = 0.0
                antennas[i].cable.length = 0.0

            freq, cps = fx.FXStokes(fakeData, antennas[:self.nAnt], pfb=True)

            cps2 = numpy.zeros_like(cps)
            LFFT = cps.shape[2]
            nFFT = fakeData.shape[1] // 2 // LFFT
            blc = 0
            for i in range(0, self.nAnt // 2):
                for j in range(i + 1, self.nAnt // 2):
                    for k in range(nFFT):
                        f1X = _pfb(fakeData[2 * i + 0, :], k * 2 * LFFT,
                                   2 * LFFT)[:LFFT]
                        f1Y = _pfb(fakeData[2 * i + 1, :], k * 2 * LFFT,
                                   2 * LFFT)[:LFFT]
                        f2X = _pfb(fakeData[2 * j + 0, :], k * 2 * LFFT,
                                   2 * LFFT)[:LFFT]
                        f2Y = _pfb(fakeData[2 * j + 1, :], k * 2 * LFFT,
                                   2 * LFFT)[:LFFT]

                        cps2[0, blc, :] += f1X * f2X.conj() + f1Y * f2Y.conj()
                        cps2[1, blc, :] += f1X * f2X.conj() - f1Y * f2Y.conj()
                        cps2[2, blc, :] += f1X * f2Y.conj() + f1X.conj() * f2Y
                        cps2[3, blc, :] += (f1X * f2Y.conj() -
                                            f1X.conj() * f2Y) / 1j
                    blc += 1
            cps2 /= (2 * LFFT * nFFT)
            lsl.testing.assert_allclose(cps, cps2)
Beispiel #4
0
    def test_correlator_baselines(self):
        """Test that the return_baselines keyword works."""

        fakeData = numpy.random.rand(
            self.nAnt, 1024) + 1j * numpy.random.rand(self.nAnt, 1024)
        fakeData = fakeData.astype(numpy.csingle)

        station = stations.parse_ssmif(_SSMIF)
        antennas = station.antennas

        blList, freq, cps = fx.FXStokes(fakeData,
                                        antennas[:self.nAnt],
                                        sample_rate=1e5,
                                        central_freq=38e6,
                                        return_baselines=True)
Beispiel #5
0
    def test_correlator_gaincorrect(self):
        """Test appling gain correction to the correlator output."""

        fakeData = numpy.random.rand(
            self.nAnt, 1024) + 1j * numpy.random.rand(self.nAnt, 1024)
        fakeData = fakeData.astype(numpy.csingle)

        station = stations.parse_ssmif(_SSMIF)
        antennas = station.antennas

        freq, cps = fx.FXStokes(fakeData,
                                antennas[:self.nAnt],
                                sample_rate=1e5,
                                central_freq=38e6,
                                gain_correct=True)