Beispiel #1
0
        relative_az=(-1)*scan_offset
        az=mars_altaz[0]+relative_az
        while j<array_sidelength: #azimuth loop

            print "ELEVATION INDEX: "+str(i) + ' RELATIVE ELEVATION: ' + str(relative_el)
            print "AZIMUTH INDEX: " +str(j) + ' RELATIVE AZIMUTH: ' + str(relative_az)

            #establish ra/dec for position
            radec=altaz_to_radec(az,el)
            ra=radec[0]
            dec=radec[1]

            #take data at current position and store
            point(az,el)
            wait(6)
            time=get_time() #so time will be the time at the start of the observation
            data=observe(int_time)
            file.write(str(az)+' ')
            file.write(str(el)+' ')
            file.write(str(ra)+' ')
            file.write(str(dec)+' ')
            file.write(str(time)+' ')
            file.write(str(data)+'\n \n')

            #integrate
           # print data
            integrated=sum(data)
            array[i][j]=integrated
            print integrated
            #print array
Beispiel #2
0
def main(top_block_cls=top_block, options=None):

    from distutils.version import StrictVersion
    if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
        style = gr.prefs().get_string('qtgui', 'style', 'raster')
        Qt.QApplication.setGraphicsSystem(style)
    qapp = Qt.QApplication(sys.argv)

    ######## ACTUALLY WHERE STUFF HAPPENS #######
    tb = top_block_cls()
    tb.start()
    tb.show()
    print('Receiving ...')

    global darksky
    global darksky_exists

    def snapshot(
            int_time):  #straight snapshot over a certain integration time.
        tb.set_integration_time(int_time)
        # print 'Integration time set to '+str(int_time)+ ' seconds.'
        print 'Snapshot ' + str(int_time) + ' sec'
        vec = tb.get_variable_function_probe()  #old vector
        pointa = vec[0]
        pointb = vec[-1]
        tb.toggle_copy(True)  #start copying
        while vec[0] == pointa and vec[-1] == pointb:
            pytime.sleep(1)
            vec = tb.get_variable_function_probe()
        tb.toggle_copy(False)  #stop copying
        return np.array(vec)

    def dark_sky_calib(int_time):  #for use when pointing at the dark sky
        global darksky
        darksky = snapshot(int_time)
        global darksky_exists
        darksky_exists = True
        return

    def observe(int_time):  #dark sky calbrated snapshot
        vec = snapshot(int_time)
        wait(int_time)
        global darksky_exists
        if darksky_exists:
            calib = vec - darksky
            return calib
        else:
            print('Warning: No dark sky calibration has been performed.')
            return vec

    def wait(sec):
        pytime.sleep(sec)
        return

    def graphing(int_time, iter=float('inf')):
        plt.ion()
        plt.figure()
        vec = tb.get_variable_function_probe()  #vector
        n = len(vec)
        x = np.linspace(flo, fhi, n)
        i = 0
        while (i < iter):
            plt.pause(int_time)
            y = observe(int_time)
            plt.clf()
            plt.xlabel('Frequency (MHz)')
            plt.ylabel('Scaled power')
            plt.axvline(x=1420.406, color='black', ls='--')
            plt.ticklabel_format(useOffset=False)
            plt.plot(x, y)
            plt.draw()
            i += 1
        return ()

    def track(N):
        client.track(N)

    #runs in background

    #usr/bin/python
    from galcoord import gal_to_altaz
    import matplotlib as mpl
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    from galcoord import get_time
    from math import sin

    gain = 60
    tb.set_sdr_gain(gain)
    freq = tb.get_sdr_frequency() / 1000000  #MHz
    freq_offset = tb.get_output_vector_bandwidth() / 2000000.  #MHz
    flo = freq - freq_offset
    fhi = freq + freq_offset
    num_chan = tb.get_num_channels()
    freq_range = np.linspace(flo, fhi, num_chan)

    #convert frequency f to radial velocity at galactic coordinate l
    #account for movement of the sun relative to galactic center
    def freq_to_vel(f, l):
        c = 2.998e5  #km/s
        v_rec = (freq - f) * c / freq
        v_sun = 220  #km/s
        correction = v_sun * np.sin(np.deg2rad(l))
        return v_rec + correction

    ############ Editable variables ###########
    savefolder = 'gal_scans/run26/'
    savetitle = 'vectors.txt'
    int_time = 30
    l_start = 0
    l_stop = 360
    l_step = 2.5
    #########################################
    # BEGIN COMMANDS #
    #########################################
    large_step = 1  #signals that the dish just moved a bunch and we need to wait longer for it to settle

    #print 'Moving to initial galactic longitude l=' + str(l)
    #point at galactic center and give time to settle
    l = l_start
    # pos=gal_to_altaz(l,0)
    # # while pos[1] <= 0:
    # #     pos=gal_to_altaz(l,0)
    # #     if pos[1] > 0: break
    # #     if l > l_stop: break
    # point(pos[0],pos[1])
    # wait(10)

    #do the survey
    file = open(savefolder + savetitle, 'w')
    file.write('Integration time ' + str(int_time) +
               ' seconds. Center frequency ' + str(freq) + ' MHz. \n \n')
    file.write('Azimuth Elevation RA DEC Time Center Data_vector \n \n')
    while l <= l_stop:
        #take data at a position
        pos = gal_to_altaz(l, 0)
        if pos[1] > 0:
            print 'Moving to galactic longitude l=' + str(l)
            point(pos[0], pos[1])
            if large_step:
                wait(10)
            else:
                wait(2)
            large_step = 0

            print "Observing at galactic coordinates (" + str(l) + ', 0).'
            time = get_time()
            data = observe(int_time)

            #write to file
            file.write(str(l) + ' ')
            file.write(str(0) + ' ')
            file.write(str(time) + ' ')
            file.write(str(data) + '\n \n')

            #frequency binned figure
            plt.figure()
            plt.title('l=' + str(l) + ' ' + str(time))
            plt.xlabel('Frequency (MHz)')
            plt.ylabel('Power at Feed (W/Hz)')
            plt.axvline(x=freq, color='black', ls='--')
            plt.ticklabel_format(useOffset=False)
            plt.plot(freq_range, data)
            plt.savefig(savefolder + 'lat' + str(l) + '_freq.pdf')
            wait(1)
            plt.close()

            #velocity binned figure
            vel_range = np.array([freq_to_vel(f, l) for f in freq_range])
            center_vel = freq_to_vel(freq, l)

            plt.figure()
            plt.title('l=' + str(l) + ' ' + str(time))
            plt.xlabel('Velocity (km/s)')
            plt.ylabel('Power at Feed (W)')
            plt.axvline(x=0, color='black', ls='--')
            plt.ticklabel_format(useOffset=False)
            plt.plot(vel_range, data)
            plt.savefig(savefolder + 'lat' + str(l) + '_vel.pdf')
            wait(1)
            plt.close()

            print 'Data logged.'
            print ' '

        else:
            large_step = 1

        l += l_step
        if l >= l_stop: break

        #move to next position
        # pos=gal_to_altaz(l,0)
        # point(pos[0],pos[1])
        # wait(2)

    file.close()

    #!/usr/bin/python

    def quitting():
        tb.stop()
        tb.wait()

    #    qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
    #    qapp.exec_()

    quitting()
Beispiel #3
0
def run_survey(tb, savefolder, iterator, gain=60, int_time=30):
    tb.set_sdr_gain(gain)
    freq = tb.get_sdr_frequency() / 1000000  #MHz
    freq_offset = tb.get_output_vector_bandwidth() / 2000000.  #MHz
    flo = freq - freq_offset
    fhi = freq + freq_offset
    num_chan = tb.get_num_channels()
    freq_range = np.linspace(flo, fhi, num_chan)

    #########################################
    # BEGIN COMMANDS #
    #########################################

    #do the survey
    file = open(os.path.join(savefolder, 'vectors.txt'), 'w')
    csvwriter = csv.writer(open(os.path.join(savefolder, 'vectors.csv'), 'w'))
    file.write('Integration time ' + str(int_time) +
               ' seconds. Center frequency ' + str(freq) + ' MHz. \n \n')
    csvwriter.writerow([
        '# Integration time: %d seconds Center frequency: %f MHz' %
        (int_time, freq)
    ])
    freq_count = 2 if 'pos' in iterator.fields else 1
    csvwriter.writerow(['time'] + list(iterator.fields) +
                       [str(f) for f in freq_range] * freq_count)
    file.write(' '.join(iterator.fields) + ' Time Center Data_vector \n \n')

    contour_iter_axes = {field: [] for field in iterator.axes}
    contour_freqs = []
    contour_vels = []
    contour_data = []

    for pos in iterator:
        tb.point(pos.azimuth, pos.elevation)

        print("Observing at coordinates " + str(pos) + '.')
        apytime = get_time()
        data = tb.observe(int_time)

        #write to file
        file.write(' '.join(str(x) for x in pos) + ' ')
        file.write(str(apytime) + ' ')
        file.write(str(data) + '\n \n')

        for field in iterator.axes:
            contour_iter_axes[field].append(
                np.full(len(freq_range), getattr(pos, field)))

        contour_freqs.append(freq_range)

        vel_range = None
        if hasattr(pos, 'longitude'):
            vel_range = np.array(
                freqs_to_vel(freq, freq_range, pos.longitude, pos.latitude))
            contour_vels.append(vel_range)

        contour_data.append(data)

        apytime.format = 'fits'
        row = [str(apytime)] + [str(x) for x in pos]
        if vel_range is not None:
            row += [str(f) for f in vel_range]
        row += [str(f) for f in data]
        csvwriter.writerow(row)

        plot.plot_freq(freq, freq_range, data,
                       iterator.format_title(pos) + ' ' + str(apytime))
        plot.plt.savefig(
            os.path.join(savefolder,
                         iterator.format_filename(pos) + '_freq.pdf'))
        plot.plt.close()

        if hasattr(pos, 'longitude'):
            plot.plot_velocity(vel_range, data,
                               iterator.format_title(pos) + ' ' + str(apytime))
            plot.plt.savefig(
                os.path.join(savefolder,
                             iterator.format_filename(pos) + '_vel.pdf'))
            plot.plt.close()

        print('Data logged.')
        print()

    file.close()

    contour_iter_axes = {x: np.array(y) for x, y in contour_iter_axes.items()}
    contour_freqs = np.array(contour_freqs)
    contour_data = np.array(contour_data)

    for field, data in contour_iter_axes.items():
        np.save(os.path.join(savefolder, 'contour_' + field + '.npy'), data)
    np.save(os.path.join(savefolder, 'contour_data.npy'), contour_data)
    np.save(os.path.join(savefolder, 'contour_freqs.npy'), contour_freqs)
    if contour_vels:
        contour_vels = np.array(contour_vels)
        np.save(os.path.join(savefolder, 'contour_vels.npy'), contour_vels)

    plot.plot_2d(contour_freqs, contour_vels, contour_data, contour_iter_axes,
                 savefolder)
Beispiel #4
0
    l=l_start
    print 'Moving to initial galactic longitude l=' + str(l)
    #point at galactic center and give time to settle
    pos=gal_to_altaz(l,0)
    point(pos[0],pos[1])
    wait(10)

    #do the survey
    file=open(savefolder+savetitle, 'w')
    file.write('Integration time '+str(int_time)+' seconds. Center frequency '+str(freq)+' MHz. \n \n')
    file.write('Azimuth Elevation RA DEC Time Center Data_vector \n \n')
    while l<=l_stop:
    	#take data at current position
        print "Observing at galactic coordinates ("+str(l)+', 0).'
        time=get_time()
    	data=observe(int_time) 

        #write to file
        file.write(str(l)+' ')
        file.write(str(0)+' ')
        file.write(str(time)+' ')
        file.write(str(data)+'\n \n')

        #frequency binned figure
    	plt.figure()
        plt.title('l='+str(l)+ ' '+ str(time))
    	plt.xlabel('Frequency (MHz)')
        plt.ylabel('Uncalibrated power (W)')
        plt.axvline(x=freq, color='black', ls='--')
        plt.ticklabel_format(useOffset=False)
Beispiel #5
0
def run_survey(tb, savefolder, iterator, gain=60, int_time=30):
    tb.set_sdr_gain(gain)
    freq = tb.get_sdr_frequency() / 1000000  #MHzx
    freq_offset = tb.get_output_vector_bandwidth() / 2000000.  #MHz
    flo = freq - freq_offset
    fhi = freq + freq_offset
    num_chan = tb.get_num_channels()
    freq_range = np.linspace(flo, fhi, num_chan)

    #########################################
    # BEGIN COMMANDS #
    #########################################
    large_step = 1  #signals that the dish just moved a bunch and we need to wait longer for it to settle

    #do the survey
    file = open(os.path.join(savefolder, 'vectors.txt'), 'w')
    csvwriter = csv.writer(open(os.path.join(savefolder, 'vectors.csv'), 'w'))
    file.write('Integration time ' + str(int_time) +
               ' seconds. Center frequency ' + str(freq) + ' MHz. \n \n')
    csvwriter.writerow([
        '# Integration time: %d seconds Center frequency: %f MHz' %
        (int_time, freq)
    ])
    freq_count = 2 if 'pos' in iterator.fields else 1
    csvwriter.writerow(['time'] + list(iterator.fields) +
                       [str(f) for f in freq_range] * freq_count)
    file.write(' '.join(iterator.fields) + ' Time Center Data_vector \n \n')

    contour_iter_axes = {field: [] for field in iterator.axes}
    contour_freqs = []
    contour_vels = []
    contour_data = []

    for pos in iterator:
        tb.point(pos.azimuth, pos.elevation)
        if large_step:
            time.sleep(10)
        else:
            time.sleep(2)
        large_step = 0

        print("Observing at coordinates " + str(pos) + '.')
        apytime = get_time()
        data = tb.observe(int_time)

        #write to file
        file.write(' '.join(str(x) for x in pos) + ' ')
        file.write(str(apytime) + ' ')
        file.write(str(data) + '\n \n')

        for field in iterator.axes:
            contour_iter_axes[field].append(
                np.full(len(freq_range), getattr(pos, field)))

        contour_freqs.append(freq_range)

        vel_range = None
        if hasattr(pos, 'longitude'):
            vel_range = np.array(
                [freq_to_vel(freq, f, pos.longitude) for f in freq_range])
            contour_vels.append(vel_range)

        contour_data.append(data)

        apytime.format = 'fits'
        row = [str(apytime)] + [str(x) for x in pos]
        if vel_range is not None:
            row += [str(f) for f in vel_range]
        row += [str(f) for f in data]
        csvwriter.writerow(row)

        #frequency binned figure
        plt.figure()
        plt.title(iterator.format_title(pos) + ' ' + str(apytime))
        plt.xlabel('Frequency (MHz)')
        plt.ylabel('Power at Feed (W/Hz)')
        plt.axvline(x=freq, color='black', ls='--')
        plt.ticklabel_format(useOffset=False)
        plt.plot(freq_range, data)
        plt.savefig(
            os.path.join(savefolder,
                         iterator.format_filename(pos) + '_freq.pdf'))
        plt.close()

        if hasattr(pos, 'longitude'):
            #velocity binned figure
            center_vel = freq_to_vel(freq, freq, pos.longitude)

            plt.figure()
            plt.title(iterator.format_title(pos) + ' ' + str(apytime))
            plt.xlabel('Velocity (km/s)')
            plt.ylabel('Power at Feed (W)')
            plt.axvline(x=0, color='black', ls='--')
            plt.ticklabel_format(useOffset=False)
            plt.plot(vel_range, data)
            plt.savefig(
                os.path.join(savefolder,
                             iterator.format_filename(pos) + '_vel.pdf'))
            plt.close()

        print('Data logged.')
        print()

    file.close()

    contour_iter_axes = {x: np.array(y) for x, y in contour_iter_axes.items()}
    contour_freqs = np.array(contour_freqs)
    contour_data = np.array(contour_data)

    for field, data in contour_iter_axes.items():
        np.save(os.path.join(savefolder, 'contour_' + field + '.npy'), data)
    np.save(os.path.join(savefolder, 'contour_data.npy'), contour_data)
    np.save(os.path.join(savefolder, 'contour_freqs.npy'), contour_freqs)

    # TODO: Plot both
    ydata = contour_freqs
    ylabel = 'Frequency (MHz)'
    if contour_vels:
        contour_vels = np.array(contour_vels)
        np.save(os.path.join(savefolder, 'contour_vels.npy'), contour_vels)
        ydata = contour_vels
        ylabel = 'Velocity (km/s)'

    for xaxis, xlabel in iterator.axes.items():
        plt.figure()
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.ticklabel_format(useOffset=False)
        plt.contourf(contour_iter_axes[xaxis],
                     ydata,
                     contour_data,
                     100,
                     vmin=0.8e-16,
                     vmax=3e-16)
        plt.savefig(os.path.join(savefolder, '2d_' + xaxis + '_contour.pdf'))
        plt.close()

        plt.figure()
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.ticklabel_format(useOffset=False)
        pcm = plt.pcolormesh(contour_iter_axes[xaxis],
                             ydata,
                             contour_data,
                             vmin=0.8e-16,
                             vmax=np.percentile(contour_data, 90),
                             shading='gouraud',
                             norm=colors.LogNorm())
        cbar = plt.colorbar(pcm, extend='max')
        cbar.ax.set_ylabel('Power at feed (W/Hz)', rotation=-90, va="bottom")
        plt.savefig(os.path.join(savefolder, '2d_' + xaxis + '_mesh.pdf'))
        plt.close()