Example #1
0
    def test_compute_uvw(self):
        """Test the the compute_uvw function runs."""

        station = stations.lwa1
        antennas = station.antennas

        # Frequency is a scalar
        freq = 45e6
        out = uvutils.compute_uvw(antennas[0:60:2], freq=freq)
        self.assertEqual(len(out.shape), 3)
        self.assertEqual(out.shape[-1], 1)

        # Frequency is a list
        freq = [45e6, 60e6]
        out = uvutils.compute_uvw(antennas[0:60:2], freq=freq)
        self.assertEqual(len(out.shape), 3)
        self.assertEqual(out.shape[-1], 2)

        # Frequency is an array
        ## 1-D
        freq = numpy.linspace(45e6, 60e6, 1024)
        out0 = uvutils.compute_uvw(antennas[0:60:2], freq=freq)

        ## 2-D
        freq.shape = (512, 2)
        out1 = uvutils.compute_uvw(antennas[0:60:2], freq=freq)

        ## 3-D
        freq.shape = (128, 4, 2)
        out2 = uvutils.compute_uvw(antennas[0:60:2], freq=freq)

        shape0 = (out0.shape[0], 3, 1024)
        shape1 = (out0.shape[0], 3, 512, 2)
        shape2 = (out0.shape[0], 3, 128, 4, 2)

        # Make sure we have the right dimensions
        for i in range(len(shape0)):
            self.assertEqual(out0.shape[i], shape0[i])
        for i in range(len(shape1)):
            self.assertEqual(out1.shape[i], shape1[i])
        for i in range(len(shape2)):
            self.assertEqual(out2.shape[i], shape2[i])

        # Make sure the values are the same
        out1.shape = shape0
        out2.shape = shape0
        diff01 = ((out0 - out1)**2).sum()
        diff02 = ((out0 - out2)**2).sum()
        self.assertAlmostEqual(diff01, 0.0, 6)
        self.assertAlmostEqual(diff02, 0.0, 6)
Example #2
0
def getFringeRate(antenna1, antenna2, observer, src, freq):
    """
    Get the fringe rate for a baseline formed by antenna1-antenna2 for source src
    as observed by an observer.
    """
    
    # Update the source position
    src.compute(observer)
    
    # Calculate the hour angle
    HA = (float(observer.sidereal_time()) - float(src.ra))*12.0/numpy.pi
    dec = float(src.dec)*180/numpy.pi
    
    # Get the u,v,w coordinates
    uvw = compute_uvw([antenna1, antenna2], HA=HA, dec=dec, freq=freq)
    
    return -(2*numpy.pi/86164.0905)*uvw[0,0,0]*numpy.cos(src.dec)
Example #3
0
def main(args):
    # Build up the station
    site = stations.lwa1
    observer = site.get_observer()

    # Load in the file file to figure out what to do
    dataDict = numpy.load(args.filename[0])
    tStart = dataDict['tStart'].item()
    tInt = dataDict['tInt']
    freq = dataDict['freq1']
    junk0, refSrc, junk1, junk2, junk3, readers, antennas = read_correlator_configuration(
        dataDict)
    dataDict.close()

    # Prune down to a single polarization
    antennas = [ant for ant in antennas if ant.pol == 0]

    # Build up the list of baselines
    blList = uvutils.get_baselines(antennas)

    # Loop through the files and do what we need to do
    t = []
    uvw = []
    for filename in args.filename:
        ## Load in the integration
        dataDict = numpy.load(filename)

        tStart = dataDict['tStart'].item()
        tInt = dataDict['tInt'].item()

        dataDict.close()

        ## Update the observation
        observer.date = datetime.utcfromtimestamp(tStart).strftime(
            '%Y/%m/%d %H:%M:%S.%f')
        refSrc.compute(observer)
        HA = (observer.sidereal_time() - refSrc.ra) * 12 / numpy.pi
        dec = refSrc.dec * 180 / numpy.pi

        ## Compute u, v, and w
        t.append(datetime.utcfromtimestamp(tStart))
        uvw.append(
            uvutils.compute_uvw(antennas,
                                HA=HA,
                                dec=dec,
                                freq=freq.mean(),
                                site=observer))
    uvw = numpy.array(uvw) / 1e3

    # Compute the baseline lengths
    blLength = numpy.sqrt((uvw**2).sum(axis=2))
    print(len(blList), uvw.shape, blLength.shape)

    # Report
    print("Phase Center:")
    print("  Name: %s" % refSrc.name)
    print("  RA: %s" % refSrc._ra)
    print("  Dec: %s" % refSrc._dec)
    print("Antennas:")
    print("  Total: %i" % len(readers))
    print("  VDIF: %i" % sum([1 for rdr in readers if rdr is vdif]))
    print("  DRX: %i" % sum([1 for rdr in readers if rdr is drx]))
    print("Baselines:")
    print("  Total: %i" % (uvw.shape[0] * uvw.shape[1]))
    ## Minimum basline length
    m = numpy.argmin(blLength)
    b = m % uvw.shape[1]
    bl0 = blList[b][0].stand.id
    if bl0 < 50:
        bl0 = 'EA%02i' % bl0
    else:
        bl0 = 'LWA%i' % (bl0 - 50)
    bl1 = blList[b][1].stand.id
    if bl1 < 50:
        bl1 = 'EA%02i' % bl1
    else:
        bl1 = 'LWA%i' % (bl1 - 50)
    print("  Minimum: %.2f klambda (%s <-> %s)" % (blLength.min(), bl0, bl1))
    print("  Median: %.2f klambda" % numpy.median(blLength))
    ## Maximum baseline length
    m = numpy.argmax(blLength)
    b = m % uvw.shape[1]
    bl0 = blList[b][0].stand.id
    if bl0 < 50:
        bl0 = 'EA%02i' % bl0
    else:
        bl0 = 'LWA%i' % (bl0 - 50)
    bl1 = blList[b][1].stand.id
    if bl1 < 50:
        bl1 = 'EA%02i' % bl1
    else:
        bl1 = 'LWA%i' % (bl1 - 50)
    print("  Maximum %.2f klambda (%s <-> %s)" % (blLength.max(), bl0, bl1))

    # Plot
    fig = plt.figure()
    ax = fig.gca()
    for i in xrange(uvw.shape[0]):
        l, = ax.plot(uvw[i, :, 0],
                     uvw[i, :, 1],
                     linestyle='',
                     marker='o',
                     ms=3.0,
                     alpha=0.2)
        ax.plot(-uvw[i, :, 0],
                -uvw[i, :, 1],
                linestyle='',
                marker='o',
                ms=3.0,
                alpha=0.2,
                color=l.get_color())
    ax.set_xlabel('u [$k\\lambda$]')
    ax.set_ylabel('v [$k\\lambda$]')
    ax.set_title('%s\n%s to %s' %
                 (refSrc.name, min(t).strftime("%m/%d %H:%M:%S"),
                  max(t).strftime("%m/%d %H:%M:%S")))
    plt.show()
Example #4
0
def main(args):
    # Setup the LWA station information
    if args.metadata is not None:
        try:
            station = stations.parse_ssmif(args.metadata)
        except ValueError:
            try:
                station = metabundle.get_station(args.metadata, apply_sdm=True)
            except:
                station = metabundleADP.get_station(args.metadata,
                                                    apply_sdm=True)
    elif args.lwasv:
        station = stations.lwasv
    else:
        station = stations.lwa1

    antennas = []
    for ant in station.antennas[0::2]:
        if ant.combined_status == 33:
            antennas.append(ant)
    print("Displaying uv coverage for %i good stands" % len(antennas))

    HA = 0.0
    dec = station.lat * 180.0 / math.pi

    uvw = uvutils.compute_uvw(antennas, HA=HA, dec=dec, freq=args.frequency)
    uvw = numpy.squeeze(uvw[:, :, 0])

    # Coursely grid the uv data to come up with a rough beam
    grid = numpy.zeros((1 * 240, 1 * 240))
    for i in range(uvw.shape[0]):
        u = round((uvw[i, 0] + 120) * 1)
        v = round((uvw[i, 1] + 120) * 1)
        try:
            grid[u, v] += 1
        except IndexError:
            pass

    # Plot
    # Part 1 - Setup
    fig = plt.figure(figsize=(8, 8))
    ax1 = plt.axes([0.30, 0.30, 0.60, 0.60])
    ax2 = plt.axes([0.30, 0.05, 0.60, 0.15])
    ax3 = plt.axes([0.05, 0.30, 0.15, 0.60])
    ax4 = plt.axes([0.08, 0.08, 0.15, 0.15])
    ax5 = plt.axes([0.32, 0.32, 0.15, 0.15])

    # Part 2 - Beam response (in dB)
    beam = numpy.fft.fft2(grid)
    beam = numpy.fft.fftshift(beam)
    beam = numpy.abs(beam)**2
    beam = numpy.log10(beam) * 10.0
    ax5.imshow(beam[40:200, 40:200],
               interpolation="nearest",
               vmin=numpy.median(beam),
               vmax=beam.max())
    ax5.xaxis.set_major_formatter(NullFormatter())
    ax5.yaxis.set_major_formatter(NullFormatter())

    # Part 3 - uv plane plot
    c = ax1.scatter(uvw[:, 0], uvw[:, 1], c=uvw[:, 2], s=10.0, alpha=0.75)
    d = ax1.scatter(-uvw[:, 0], -uvw[:, 1], c=-uvw[:, 2], s=10.0, alpha=0.75)
    ax1.set_xlabel('u [$\\lambda$]')
    ax1.set_ylabel('v [$\\lambda$]')
    ax1.set_title(
        'UV Coverage for HA=%+.3f$^h$, $\delta$=%+.3f$^\circ$ at %s' %
        (HA, dec, station.name))

    # Part 4 - uw plane plot
    ax2.scatter(uvw[:, 0], uvw[:, 2], c=uvw[:, 2], s=10.0)
    ax2.scatter(-uvw[:, 0], -uvw[:, 2], c=-uvw[:, 2], s=10.0)
    ax2.xaxis.set_major_formatter(NullFormatter())
    ax2.set_ylabel('w [$\\lambda$]')

    # Part 5 - wv plane plot
    ax3.scatter(uvw[:, 2], uvw[:, 1], c=uvw[:, 2], s=10.0)
    ax3.scatter(-uvw[:, 2], -uvw[:, 1], c=-uvw[:, 2], s=10.0)
    ax3.yaxis.set_major_formatter(NullFormatter())
    ax3.set_xlabel('w [$\\lambda$]')

    # Part 6 - Histogram of uvw distances in lambda
    rad = numpy.zeros(uvw.shape[0])
    for i in range(rad.shape[0]):
        rad[i] = math.sqrt(uvw[i, 0]**2.0 + uvw[i, 1]**2.0 + uvw[i, 2]**2.0)
    try:
        ax4.hist(rad, 20)
    except TypeError:
        ## I don't know why this happens
        pass
    ax4.set_xlabel('uvw Radius [$\lambda$]')
    ax4.set_ylabel('Baselines')

    # Plot adjustment
    xlim = ax1.get_xlim()
    ylim = ax1.get_ylim()
    ax1.set_xlim([
        numpy.floor(xlim[0] / 25.0) * 25.0,
        numpy.ceil(xlim[1] / 25.0) * 25.0
    ])
    ax1.set_ylim([
        numpy.floor(ylim[0] / 25.0) * 25.0,
        numpy.ceil(ylim[1] / 25.0) * 25.0
    ])

    ax2.set_xlim(ax1.get_xlim())
    ax2.yaxis.set_major_locator(MaxNLocator(nbins=4))

    ax3.set_ylim(ax1.get_ylim())
    ax3.xaxis.set_major_locator(MaxNLocator(nbins=4))

    xlim = ax4.get_xlim()
    ylim = ax4.get_ylim()
    ax4.set_xlim([
        numpy.floor(xlim[0] / 25.0) * 25.0,
        numpy.ceil(xlim[1] / 25.0) * 25.0
    ])
    ax4.set_ylim([
        numpy.floor(ylim[0] / 5.e3) * 5.e3,
        numpy.ceil(ylim[1] / 5.e3) * 5.e3
    ])
    ax4.xaxis.set_major_locator(MaxNLocator(nbins=4))
    ax4.yaxis.set_major_locator(MaxNLocator(nbins=4))

    # Show n' save
    plt.show()
    if args.output is not None:
        fig.savefig(args.output)