Exemple #1
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    ant_list = [
        "1c", "1e", "1g", "1h", "2a", "2b", "2c", "2e", "2h", "2j", "2k", "2l",
        "2m", "3c", "3d", "3l", "4j", "5b", "4g"
    ]  # whats going on with 1k? 2k points somewhere else

    ant_2k = ['2k']

    lo = 'B'
    antlo_list = [ant + lo for ant in ant_list]

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {antlo + pol: 20 for antlo in antlo_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1600

    #snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)
    ata_control.set_freq([freq] * len(ant_list), ant_list, lo='b')

    obs_time = 60

    az = 203.323  #121.96
    el = 40.119  #23.63
    #step = 2

    #az_list = np.arange(goes_az - 10, goes_az + 10, step)
    #el_list = np.arange(goes_el - 10, goes_el + 10, step)

    #for az in az_list:
    #    for el in el_list

    print("az: %.2f, el: %.2f" % (az, el))
    os.system("killall ata_udpdb")
    ata_control.set_az_el(ant_2k, az, el)

    utc = snap_dada.start_recording(antlo_list,
                                    obs_time,
                                    acclen=120 * 16,
                                    disable_rfi=True)
    time.sleep(10)
Exemple #2
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    ant_list = ['2k', '2e', '2m', '2j', '3d', '1k']
    lo = 'B'
    antlo_list = [ant + lo for ant in ant_list]

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {antlo + pol: 20 for antlo in antlo_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1600

    #snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)
    ata_control.set_freq([freq] * len(ant_list), ant_list, lo='b')

    obs_time = 20

    #goes 17
    goes_az = 203.323  #121.96 (goes 16)
    goes_el = 40.119  #23.63
    step = 0.5

    az_list = np.arange(goes_az - 3, goes_az + 3, step)[6:]
    el_list = np.arange(goes_el - 3, goes_el + 3, step)

    for az in az_list:
        for el in el_list:
            print("az: %.2f, el: %.2f" % (az, el))
            os.system("killall ata_udpdb")
            ata_control.set_az_el(ant_list, az, el)
            utc = snap_dada.start_recording(antlo_list,
                                            obs_time,
                                            acclen=120 * 16,
                                            disable_rfi=True)
        time.sleep(10)
Exemple #3
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    ant_list = ['2b']
    #pms = {ant:ata_pointing.PointingModel(ant) for ant in ant_list}
    #pm = ata_pointing.PointingModel('3c')

    ata_control.reserve_antennas(ant_list)
    atexit.register(ata_control.release_antennas, ant_list, False)

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {ant + pol: 20 for ant in ant_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1575

    snap_dada.set_freq_auto([freq] * len(ant_list), ant_list)

    # define how to grid the sky
    pbfwhm = (3.5 / freq * 1000.0)
    delta = pbfwhm / 2.0
    obs_time = 30

    # elevation then azimuth
    offsets = [[0., 4 * delta], [0., delta], [0., 0.], [0., -delta],
               [0., -4 * delta], [-4 * delta, 0.], [-delta, 0.], [0., 0.],
               [delta, 0.], [4 * delta, 0.]]

    obs_time = 20

    utcs = []
    sats_observed = []
    time_obs = []
    t = time.time()

    ofile = open("/home/obsuser/pointing/%i_atapointer.txt" % t, "w")
    tpoints = {
        ant: open("/home/obsuser/pointing/%i_%s_tpoint.txt" % (t, ant), "w")
        for ant in ant_list
    }

    atexit.register(ofile.close)
    for tpoint in tpoints.values():
        atexit.register(tpoint.close)
    while True:
        #utc = snap_dada.start_recording(ant_list, obs_time, acclen=120*16,
        #        disable_rfi=True)
        #utcs.append(utc)
        #for ant in ant_list:
        #    p = get_power(utc, ant)
        #    print(ant, p, 10*np.log10(p), "dB")
        sats = ata_sources.get_sats()['GPS']

        setting_sats, rising_sats = select_group_sats(sats)

        to_observe = None
        # select a rising satellite from rising group first
        # then check if there's any setting satellite, and observe
        # that instead. The rising satellite will be selected in the
        # following iteration
        for sat_group in [rising_sats, setting_sats]:
            for sat in sat_group:
                name, az, el = sat['name'], float(sat['az']), float(sat['el'])

                # skip if satellite has been observed in the last 5 times
                if name in sats_observed[-5:]:
                    continue

                to_observe = sat
                ofile.write("will observe: %s, state: %s\n" %
                            (name, sat['state']))
                break

        # if all the satellites have been observed
        if not to_observe:
            # chose a random satellite that is setting, in case there's one
            if len(setting_sats) != 0:
                to_observe = random.choice(setting_sats)
            # else chose one that is rising, if there's one
            if len(rising_sats) != 0:
                to_observe = random.choice(rising_sats)

        if to_observe:
            az, el = float(sat['az']), float(sat['el'])
            name = sat['name']
            ofile.write("%s: Observing: %s\n" %
                        (datetime.datetime.now(), to_observe['name']))
            ofile.write("%s: Az, el, state: %.2f, %.2f, %s\n" %
                        (datetime.datetime.now(), az, el, sat['state']))
            ata_control.create_ephem(name, **{'duration': 2, 'interval': 1})

            # offsets = az/el
            for i in range(nRepeats):
                azs = {ant: [] for ant in ant_list}
                els = {ant: [] for ant in ant_list}
                az_offs = {ant: [] for ant in ant_list}
                el_offs = {ant: [] for ant in ant_list}
                meas = {ant: [] for ant in ant_list}
                igrid = 0

                # now do the cross pattern
                for offset in offsets:
                    ofile.write("%s: %s" % (datetime.datetime.now(), offset))
                    ofile.write("\n")
                    ata_control.track_and_offset(name,
                                                 ant_list,
                                                 xoffset=offset)

                    for ant in ant_list:
                        # XXX: what az/el are these? Encoder or astronomical?
                        az_el = ata_control.get_az_el(ant_list)[ant]

                        # Determine the true position of satellite
                        x_el_off = offset[0]
                        el_off = offset[1]
                        az_off = x_el_off / np.cos(np.deg2rad(az_el[1]))

                        azs[ant].append(az_el[0] - az_off)
                        els[ant].append(az_el[1] - el_off)

                        az_offs[ant].append(az_off)
                        el_offs[ant].append(el_off)

                    # record data
                    utc = snap_dada.start_recording(ant_list,
                                                    obs_time,
                                                    acclen=120 * 16,
                                                    disable_rfi=True)
                    # get the measurement data
                    for ant in ant_list:
                        try:
                            meas[ant].append(get_power(utc, ant))
                        except:
                            meas[ant].append(np.nan)

                for ant in ant_list:
                    ofile.write(ant + "\n")
                    az_avg = np.array(azs[ant]).mean()
                    el_avg = np.array(els[ant]).mean()
                    ofile.write("%s: azimuths: " % (datetime.datetime.now()) +
                                float_arr_to_str(azs[ant]) + "\n")
                    ofile.write("%s: elevations: " %
                                (datetime.datetime.now()) +
                                float_arr_to_str(els[ant]) + "\n")
                    ofile.write("%s: az_offsets: " %
                                (datetime.datetime.now()) +
                                float_arr_to_str(az_offs[ant]) + "\n")
                    ofile.write("%s: el_offsets: " %
                                (datetime.datetime.now()) +
                                float_arr_to_str(el_offs[ant]) + "\n")
                    ofile.write("%s: meas: " % (datetime.datetime.now()) +
                                float_arr_to_str(meas[ant]) + "\n")
                    ofile.write("%s: source az_avg: " %
                                (datetime.datetime.now()) + str(az_avg) + "\n")
                    ofile.write("%s: source el_avg: " %
                                (datetime.datetime.now()) + str(el_avg) + "\n")

                    try:
                        peak_el = analyzeFivePoints(el_offs[ant][:5],
                                                    meas[ant][:5])
                        peak_pos_el, peak_val_el, peak_width_el = peak_el

                        peak_az = analyzeFivePoints(az_offs[ant][5:],
                                                    meas[ant][5:])
                        peak_pos_az, peak_val_az, peak_width_az = peak_az

                        peak_sbr = np.sqrt(peak_val_az**2 + peak_val_el**2)
                    except:
                        ofile.write(
                            "%s: Something went wrong with measuring power with ant: %s\n"
                            % (datetime.datetime.now(), ant))
                        continue

                    ofile.write("%f %f %f\n" %
                                (peak_pos_el, peak_val_el, peak_width_el))
                    ofile.write("%f %f %f\n" %
                                (peak_pos_az, peak_val_az, peak_width_az))

                    meas_az = (az_avg + peak_pos_az)
                    meas_el = (el_avg + peak_pos_el)

                    #meas_az, meas_el, ir = pms[ant].applyTPOINTCorrections(meas_az, meas_el, 0)
                    dt = datetime.datetime.now()
                    hour = dt.hour + dt.minute / 60.

                    tpoints[ant].write(
                        "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n" %
                        (az_avg, el_avg, meas_az, meas_el, peak_sbr, hour))
                    tpoints[ant].flush()

                os.system("killall ata_udpdb")

            sats_observed.append(to_observe['name'])
        else:
            # wait for 20 minutes and see what other satellite pops up
            ofile.write("%s: nothing to observe, waiting\n" %
                        (datetime.datetime.now()))
            #sats_observed = []
            time.sleep(20 * 60)
        ofile.flush()
Exemple #4
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    ant_list = ['1k', '2k', '2e', '2j', '2m']
    lo = 'B'
    antlo_list = [ant + lo for ant in ant_list]

    ata_control.reserve_antennas(ant_list)
    atexit.register(ata_control.release_antennas, ant_list, False)

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {antlo + pol: 20 for antlo in antlo_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1600

    #obs_time = 70

    ###snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)
    ata_control.set_freq([freq] * len(ant_list), ant_list, lo='b')

    goes_az = 203.323  #121.96 (goes 16)
    goes_el = 40.119  #23.63

    #el swivel

    #az_list = np.linspace(goes_az - 10, goes_az + 10, 60 // 5)
    spac = 0.05

    az_list = np.arange(goes_az - 3, goes_az + 3 + spac, spac)

    el_start = goes_el + 3
    el_end = goes_el - 3

    #az swivel

    #el_start = goes_el # - 10
    #az_start = goes_az - 10
    #az_end   = goes_az + 10

    for az_start in az_list:
        os.system("killall ata_udpdb")
        invr = 2.55e-5
        print("az: %.2f, el: %.2f" % (az_start, el_start))

        ata_control.set_az_el(ant_list, az_start, el_start)

        #_ = input("enter to continue")

        grace_time = 15  # time between now and antenna actually moving

        t_start = time.time()
        t_start += 37  #leap seconds
        t_start += grace_time  #let's start this in X seconds into the future

        t_span = 30  #seconds
        obs_time = int(t_span + 1 * grace_time)

        steps = t_span // 5  #5 seconds per step

        ephem = generate_ephem_el_swivel(az_start, el_start, el_end, t_start,
                                         t_span, steps, invr)

        #ephem = generate_ephem_az_swivel(az_start, az_end, el_start, t_start, t_span,  steps, invr)
        print(ephem)

        ephem_name = "/tmp/ephem_goes17_az_%.3f.txt" % az_start

        ephem_to_txt(ephem_name, ephem)
        print("ephem file saved to disk")

        id = upload_ephemeris(ephem_name)

        ata_control.track_ephemeris(id, ant_list)
        #_ = input("tracking..., hit enter to continue")

        utc = snap_dada.start_recording(antlo_list,
                                        obs_time,
                                        acclen=120 * 4,
                                        disable_rfi=True)

        this_utc_basedir = os.path.join(snap_config.ATA_CFG['OBSDIR'], utc)
        dst_ephem_file = os.path.join(this_utc_basedir,
                                      os.path.basename(ephem_name))

        copyfile(ephem_name, dst_ephem_file)

    time.sleep(10)
Exemple #5
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    #ant_list = ['2b']
    #ant_list = ["1a", "1f", "1c", "2a", "2b", "2h",
    #        "3c", "4g", "1k", "5c", "1h", "4j"]
    #ant_list = ["1a", "1f", "1c", "2a", "2b", "3d",
    #        "3c", "4g", "1k", "5c", "1h", "4j"]

    ant_list = [
        "1c", "1e", "1g", "1h", "2a", "2b", "2c", "2e", "2h", "2j", "2k", "2l",
        "2m", "3c", "3d", "3l", "4j", "5b", "4g"
    ]  #1k left out cuz of weird movement

    #    ant_list = ["1c", "1e", "1g", "1h", "2a", "2b", "2c",
    #            "2h", "2j", "2k", "2l", "3c", "3d",
    #            "3l", "4j", "5b", "4g"] #2e,2m and 1k left out cuz of Danni + weird movement

    lo = "B"
    antlo_list = [ant + lo for ant in ant_list]

    #ant_list = ["2a", "2b", "5c"]
    pms = {ant: ata_pointing.PointingModel(ant) for ant in ant_list}
    #pm = ata_pointing.PointingModel('3c')

    ata_control.reserve_antennas(ant_list)
    atexit.register(ata_control.release_antennas, ant_list, False)

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {antlo + pol: 20 for antlo in antlo_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1600

    #snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)
    ata_control.set_freq([freq] * len(ant_list), ant_list, lo='b')

    # define how to grid the sky
    pbfwhm = (3.5 / freq * 1000.0)
    delta = pbfwhm / 2.0
    obs_time = 30

    # elevation then azimuth
    offsets = [[0., 4 * delta], [0., delta], [0., 0.], [0., -delta],
               [0., -4 * delta], [-4 * delta, 0.], [-delta, 0.], [0., 0.],
               [delta, 0.], [4 * delta, 0.]]

    obs_time = 20

    sats_observed = []
    time_obs = []
    t = time.time()

    basedir = "/home/obsuser/pointing_goes_2pol"
    # create directory for the pointing
    os.mkdir("%s/%i" % (basedir, t))

    ofile = open("%s/%i/%i_atapointer.txt" % (basedir, t, t), "w")

    #tpoints = {ant:open("/home/obsuser/pointing/%i/%i_%s_%p.tpoint" %(t,t,ant,polr), "w")
    #       for ant in ant_list}

    tpoints_x = {
        ant: open("%s/%i/%i_%s_x.tpoint" % (basedir, t, t, ant), "w")
        for ant in ant_list
    }
    tpoints_y = {
        ant: open("%s/%i/%i_%s_y.tpoint" % (basedir, t, t, ant), "w")
        for ant in ant_list
    }

    atexit.register(ofile.close)

    for tpointx in tpoints_x.values():
        atexit.register(tpointx.close)

    for tpointy in tpoints_y.values():
        atexit.register(tpointy.close)

    for ant in ant_list:
        tpoint_file = tpoints_x[ant]
        pm = pms[ant]
        write_header(tpoint_file, pm, freq, "x")

    for ant in ant_list:
        tpoint_file = tpoints_y[ant]
        pm = pms[ant]
        write_header(tpoint_file, pm, freq, "y")

    sats = ['GOES-16', 'GOES-17']

    for sat_name in sats:
        name = sat_name

        ephem = ata_control.create_ephem(name, **{
            'duration': 2,
            'interval': 1
        })
        ephem = np.array(ephem)

        # offsets = az/el
        for i in range(nRepeats):
            utcs = []
            got_nan = False
            azs = {ant: [] for ant in ant_list}
            els = {ant: [] for ant in ant_list}
            az_offs = {ant: [] for ant in ant_list}
            el_offs = {ant: [] for ant in ant_list}
            meas_x = {ant: [] for ant in ant_list}
            meas_y = {ant: [] for ant in ant_list}
            igrid = 0

            t1 = time.time() * 1e9  #nanoseconds
            # now do the cross pattern
            for offset in offsets:
                ofile.write("%s: %s" % (datetime.datetime.now(), offset))
                ofile.write("\n")
                ata_control.track_and_offset(name, ant_list, xoffset=offset)

                for ant in ant_list:
                    # XXX: what az/el are these? Encoder or astronomical?
                    az_el = ata_control.get_az_el(ant_list)[ant]

                    # Determine the true position of satellite
                    x_el_off = offset[0]
                    el_off = offset[1]
                    az_off = x_el_off / np.cos(np.deg2rad(az_el[1]))

                    azs[ant].append(az_el[0] - az_off)
                    els[ant].append(az_el[1] - el_off)

                    az_offs[ant].append(az_off)
                    el_offs[ant].append(el_off)

                # record data
                utc = snap_dada.start_recording(antlo_list,
                                                obs_time,
                                                acclen=120 * 16,
                                                disable_rfi=True)
                utcs.append(utc)
                os.system("killall ata_udpdb")
                # move data from antlo to ant format in /mnt/buf0/obs/utc
                mv_utc_antlo_to_ant(utc)
                # get the measurement data
                for ant in ant_list:
                    try:
                        meas_x[ant].append(get_power(utc, ant, 'x'))
                    except:
                        got_nan = True
                        meas_x[ant].append(np.nan)

                for ant in ant_list:
                    try:
                        meas_y[ant].append(get_power(utc, ant, 'y'))
                    except:
                        got_nan = True
                        meas_y[ant].append(np.nan)

            t2 = time.time() * 1e9  #nanoseconds
            az_avg_src, el_avg_src = get_ephem_az_el(ephem, t1, t2)

            base_utcs = " ".join(["/mnt/buf0/obs/%s" % utc for utc in utcs])
            #os.system("mv /mnt/buf0/obs/%s /mnt/datax-netStorage-40G/pointing_obs/" %utc)
            os.system("mv " + base_utcs +
                      " /mnt/datax-netStorage-40G/pointing_obs/")

            for ant in ant_list:
                ofile.write(ant + "\n")
                az_avg = np.array(azs[ant]).mean()
                el_avg = np.array(els[ant]).mean()
                ofile.write("%s: azimuths: " % (datetime.datetime.now()) +
                            float_arr_to_str(azs[ant]) + "\n")
                ofile.write("%s: elevations: " % (datetime.datetime.now()) +
                            float_arr_to_str(els[ant]) + "\n")
                ofile.write("%s: az_offsets: " % (datetime.datetime.now()) +
                            float_arr_to_str(az_offs[ant]) + "\n")
                ofile.write("%s: el_offsets: " % (datetime.datetime.now()) +
                            float_arr_to_str(el_offs[ant]) + "\n")
                ofile.write("%s: meas: " % (datetime.datetime.now()) +
                            float_arr_to_str(meas_x[ant]) + "\n")
                ofile.write("%s: meas: " % (datetime.datetime.now()) +
                            float_arr_to_str(meas_y[ant]) + "\n")
                ofile.write("%s: source az_avg: " % (datetime.datetime.now()) +
                            str(az_avg) + "\n")
                ofile.write("%s: source el_avg: " % (datetime.datetime.now()) +
                            str(el_avg) + "\n")
                ofile.write("%s: source ephem az_avg: " %
                            (datetime.datetime.now()) + str(az_avg_src) + "\n")
                ofile.write("%s: source ephem el_avg: " %
                            (datetime.datetime.now()) + str(el_avg_src) + "\n")

                #xpol
                try:
                    peak_el_x = analyzeFivePoints(el_offs[ant][:5],
                                                  meas_x[ant][:5])
                    peak_pos_el_x, peak_val_el_x, peak_width_el_x = peak_el_x

                    peak_az_x = analyzeFivePoints(az_offs[ant][5:],
                                                  meas_x[ant][5:])
                    peak_pos_az_x, peak_val_az_x, peak_width_az_x = peak_az_x

                    peak_sbr_x = np.sqrt(peak_val_az_x**2 + peak_val_el_x**2)
                except:
                    ofile.write(
                        "%s: Something went wrong with measuring power with ant: %s, pol x\n"
                        % (datetime.datetime.now(), ant))
                    continue

                ofile.write("El: %f %f %f\n" %
                            (peak_pos_el_x, peak_val_el_x, peak_width_el_x))
                ofile.write("Az: %f %f %f\n" %
                            (peak_pos_az_x, peak_val_az_x, peak_width_az_x))

                meas_az_x = (az_avg + peak_pos_az_x)
                meas_el_x = (el_avg + peak_pos_el_x)

                meas_az_x, meas_el_x, ir = pms[ant].applyTPOINTCorrections(
                    meas_az_x, meas_el_x, 0)
                dt = datetime.datetime.now()
                hour = dt.hour + dt.minute / 60.

                tpoints_x[ant].write(
                    "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f ! %.3f, %.3f\n" %
                    (az_avg, el_avg, meas_az_x, meas_el_x, peak_sbr_x, hour,
                     peak_pos_az_x, peak_pos_el_x))
                tpoints_x[ant].flush()

                #ypol
                try:
                    peak_el_y = analyzeFivePoints(el_offs[ant][:5],
                                                  meas_y[ant][:5])
                    peak_pos_el_y, peak_val_el_y, peak_width_el_y = peak_el_y

                    peak_az_y = analyzeFivePoints(az_offs[ant][5:],
                                                  meas_y[ant][5:])
                    peak_pos_az_y, peak_val_az_y, peak_width_az_y = peak_az_y

                    peak_sbr_y = np.sqrt(peak_val_az_y**2 + peak_val_el_y**2)
                except:
                    ofile.write(
                        "%s: Something went wrong with measuring power with ant: %s pol y\n"
                        % (datetime.datetime.now(), ant))
                    continue

                #ofile.write("El: %f %f %f\n" %(peak_pos_el, peak_val_el, peak_width_el))
                #ofile.write("Az: %f %f %f\n" %(peak_pos_az, peak_val_az, peak_width_az))

                meas_az_y = (az_avg + peak_pos_az_y)
                meas_el_y = (el_avg + peak_pos_el_y)

                meas_az_y, meas_el_y, ir = pms[ant].applyTPOINTCorrections(
                    meas_az_y, meas_el_y, 0)
                dt = datetime.datetime.now()
                hour = dt.hour + dt.minute / 60.

                tpoints_y[ant].write(
                    "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f ! %.3f, %.3f\n" %
                    (az_avg, el_avg, meas_az_y, meas_el_y, peak_sbr_y, hour,
                     peak_pos_az_y, peak_pos_el_y))
                tpoints_y[ant].flush()

            if got_nan:
                #os.system("bash ~/backends/frb_backend/snap_init_spec_skipprog.bash")
                os.system(
                    "bash /home/obsuser/src/ata_snap_rfsoc/program_rfsoc_spec.sh"
                )

    ofile.flush()
Exemple #6
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    #ant_list = ['2b']
    #ant_list = ["1a", "1f", "1c", "2a", "2b", "2h",
    #        "3c", "4g", "1k", "5c", "1h", "4j"]
    ant_list = [
        "1a", "1f", "1c", "2a", "2b", "3d", "3c", "4g", "1k", "5c", "1h", "4j"
    ]

    ant_list = [
        "1c", "1e", "1g", "1h", "1k", "2a", "2b", "2c", "2e", "2h", "2j", "2k",
        "2l", "2m", "3c", "3d", "3l", "4j", "5b", "4g"
    ]

    lo = "B"
    antlo_list = [ant + lo for ant in ant_list]

    #ant_list = ["2a", "2b", "5c"]
    pms = {ant: ata_pointing.PointingModel(ant) for ant in ant_list}
    #pm = ata_pointing.PointingModel('3c')

    ata_control.reserve_antennas(ant_list)
    atexit.register(ata_control.release_antennas, ant_list, False)

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {antlo + pol: 20 for antlo in antlo_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1575

    #snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)
    ata_control.set_freq([freq] * len(ant_list), ant_list, lo='b')

    # define how to grid the sky
    pbfwhm = (3.5 / freq * 1000.0)
    delta = pbfwhm / 2.0
    obs_time = 30

    # elevation then azimuth
    offsets = [[0., 4 * delta], [0., delta], [0., 0.], [0., -delta],
               [0., -4 * delta], [-4 * delta, 0.], [-delta, 0.], [0., 0.],
               [delta, 0.], [4 * delta, 0.]]

    obs_time = 20

    utcs = []
    sats_observed = []
    time_obs = []
    t = time.time()

    basedir = "/home/obsuser/pointing_2pol"
    # create directory for the pointing
    os.mkdir("%s/%i" % (basedir, t))

    ofile = open("%s/%i/%i_atapointer.txt" % (basedir, t, t), "w")

    #tpoints = {ant:open("/home/obsuser/pointing/%i/%i_%s_%p.tpoint" %(t,t,ant,polr), "w")
    #       for ant in ant_list}

    tpoints_x = {
        ant: open("%s/%i/%i_%s_x.tpoint" % (basedir, t, t, ant), "w")
        for ant in ant_list
    }
    tpoints_y = {
        ant: open("%s/%i/%i_%s_y.tpoint" % (basedir, t, t, ant), "w")
        for ant in ant_list
    }

    atexit.register(ofile.close)

    for tpointx in tpoints_x.values():
        atexit.register(tpointx.close)

    for tpointy in tpoints_y.values():
        atexit.register(tpointy.close)

    for ant in ant_list:
        tpoint_file = tpoints_x[ant]
        pm = pms[ant]
        write_header(tpoint_file, pm, freq, "x")

    for ant in ant_list:
        tpoint_file = tpoints_y[ant]
        pm = pms[ant]
        write_header(tpoint_file, pm, freq, "y")

    while True:
        sats = ata_sources.get_sats()['GPS']

        setting_sats, rising_sats = select_group_sats(sats)

        to_observe = None
        # select a rising satellite from rising group first
        # then check if there's any setting satellite, and observe
        # that instead. The rising satellite will be selected in the
        # following iteration
        for sat_group in [rising_sats, setting_sats]:
            for sat in sat_group:
                name, az, el = sat['name'], float(sat['az']), float(sat['el'])

                # skip if satellite has been observed in the last 5 times
                if name in sats_observed[-5:]:
                    continue

                to_observe = sat
                ofile.write("will observe: %s, state: %s\n" %
                            (name, sat['state']))
                break

        # if all the satellites have been observed
        if not to_observe:
            # chose a random satellite that is setting, in case there's one
            if len(setting_sats) != 0:
                to_observe = random.choice(setting_sats)
            # else chose one that is rising, if there's one
            if len(rising_sats) != 0:
                to_observe = random.choice(rising_sats)

        if to_observe:
            az, el = float(sat['az']), float(sat['el'])
            name = sat['name']
            ofile.write("%s: Observing: %s\n" %
                        (datetime.datetime.now(), to_observe['name']))
            ofile.write("%s: Az, el, state: %.2f, %.2f, %s\n" %
                        (datetime.datetime.now(), az, el, sat['state']))

            ephem = ata_control.create_ephem(name, **{
                'duration': 2,
                'interval': 1
            })
            ephem = np.array(ephem)

            # offsets = az/el
            for i in range(nRepeats):
                got_nan = False
                azs = {ant: [] for ant in ant_list}
                els = {ant: [] for ant in ant_list}
                az_offs = {ant: [] for ant in ant_list}
                el_offs = {ant: [] for ant in ant_list}
                meas_x = {ant: [] for ant in ant_list}
                meas_y = {ant: [] for ant in ant_list}
                igrid = 0

                t1 = time.time() * 1e9  #nanoseconds
                # now do the cross pattern
                for offset in offsets:
                    ofile.write("%s: %s" % (datetime.datetime.now(), offset))
                    ofile.write("\n")
                    ata_control.track_and_offset(name,
                                                 ant_list,
                                                 xoffset=offset)

                    for ant in ant_list:
                        # XXX: what az/el are these? Encoder or astronomical?
                        az_el = ata_control.get_az_el(ant_list)[ant]

                        # Determine the true position of satellite
                        x_el_off = offset[0]
                        el_off = offset[1]
                        az_off = x_el_off / np.cos(np.deg2rad(az_el[1]))

                        azs[ant].append(az_el[0] - az_off)
                        els[ant].append(az_el[1] - el_off)

                        az_offs[ant].append(az_off)
                        el_offs[ant].append(el_off)

                    # record data
                    utc = snap_dada.start_recording(antlo_list,
                                                    obs_time,
                                                    acclen=120 * 16,
                                                    disable_rfi=True)
                    os.system("killall ata_udpdb")
                    # move data from antlo to ant format in /mnt/buf0/obs/utc
                    mv_utc_antlo_to_ant(utc)
                    # get the measurement data
                    for ant in ant_list:
                        try:
                            meas_x[ant].append(get_power(utc, ant, 'x'))
                        except:
                            got_nan = True
                            meas_x[ant].append(np.nan)

                    for ant in ant_list:
                        try:
                            meas_y[ant].append(get_power(utc, ant, 'y'))
                        except:
                            got_nan = True
                            meas_y[ant].append(np.nan)

                t2 = time.time() * 1e9  #nanoseconds
                az_avg_src, el_avg_src = get_ephem_az_el(ephem, t1, t2)

                for ant in ant_list:
                    ofile.write(ant + "\n")
                    az_avg = np.array(azs[ant]).mean()
                    el_avg = np.array(els[ant]).mean()
                    ofile.write("%s: azimuths: " % (datetime.datetime.now()) +
                                float_arr_to_str(azs[ant]) + "\n")
                    ofile.write("%s: elevations: " %
                                (datetime.datetime.now()) +
                                float_arr_to_str(els[ant]) + "\n")
                    ofile.write("%s: az_offsets: " %
                                (datetime.datetime.now()) +
                                float_arr_to_str(az_offs[ant]) + "\n")
                    ofile.write("%s: el_offsets: " %
                                (datetime.datetime.now()) +
                                float_arr_to_str(el_offs[ant]) + "\n")
                    ofile.write("%s: meas: " % (datetime.datetime.now()) +
                                float_arr_to_str(meas_x[ant]) + "\n")
                    ofile.write("%s: meas: " % (datetime.datetime.now()) +
                                float_arr_to_str(meas_y[ant]) + "\n")
                    ofile.write("%s: source az_avg: " %
                                (datetime.datetime.now()) + str(az_avg) + "\n")
                    ofile.write("%s: source el_avg: " %
                                (datetime.datetime.now()) + str(el_avg) + "\n")
                    ofile.write("%s: source ephem az_avg: " %
                                (datetime.datetime.now()) + str(az_avg_src) +
                                "\n")
                    ofile.write("%s: source ephem el_avg: " %
                                (datetime.datetime.now()) + str(el_avg_src) +
                                "\n")

                    #xpol
                    try:
                        peak_el_x = analyzeFivePoints(el_offs[ant][:5],
                                                      meas_x[ant][:5])
                        peak_pos_el_x, peak_val_el_x, peak_width_el_x = peak_el_x

                        peak_az_x = analyzeFivePoints(az_offs[ant][5:],
                                                      meas_x[ant][5:])
                        peak_pos_az_x, peak_val_az_x, peak_width_az_x = peak_az_x

                        peak_sbr_x = np.sqrt(peak_val_az_x**2 +
                                             peak_val_el_x**2)
                    except:
                        ofile.write(
                            "%s: Something went wrong with measuring power with ant: %s, pol x\n"
                            % (datetime.datetime.now(), ant))
                        continue

                    ofile.write(
                        "El: %f %f %f\n" %
                        (peak_pos_el_x, peak_val_el_x, peak_width_el_x))
                    ofile.write(
                        "Az: %f %f %f\n" %
                        (peak_pos_az_x, peak_val_az_x, peak_width_az_x))

                    meas_az_x = (az_avg + peak_pos_az_x)
                    meas_el_x = (el_avg + peak_pos_el_x)

                    meas_az_x, meas_el_x, ir = pms[ant].applyTPOINTCorrections(
                        meas_az_x, meas_el_x, 0)
                    dt = datetime.datetime.now()
                    hour = dt.hour + dt.minute / 60.

                    tpoints_x[ant].write(
                        "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f ! %.3f, %.3f\n" %
                        (az_avg, el_avg, meas_az_x, meas_el_x, peak_sbr_x,
                         hour, peak_pos_az_x, peak_pos_el_x))
                    tpoints_x[ant].flush()

                    #ypol
                    try:
                        peak_el_y = analyzeFivePoints(el_offs[ant][:5],
                                                      meas_y[ant][:5])
                        peak_pos_el_y, peak_val_el_y, peak_width_el_y = peak_el_y

                        peak_az_y = analyzeFivePoints(az_offs[ant][5:],
                                                      meas_y[ant][5:])
                        peak_pos_az_y, peak_val_az_y, peak_width_az_y = peak_az_y

                        peak_sbr_y = np.sqrt(peak_val_az_y**2 +
                                             peak_val_el_y**2)
                    except:
                        ofile.write(
                            "%s: Something went wrong with measuring power with ant: %s pol y\n"
                            % (datetime.datetime.now(), ant))
                        continue

                    #ofile.write("El: %f %f %f\n" %(peak_pos_el, peak_val_el, peak_width_el))
                    #ofile.write("Az: %f %f %f\n" %(peak_pos_az, peak_val_az, peak_width_az))

                    meas_az_y = (az_avg + peak_pos_az_y)
                    meas_el_y = (el_avg + peak_pos_el_y)

                    meas_az_y, meas_el_y, ir = pms[ant].applyTPOINTCorrections(
                        meas_az_y, meas_el_y, 0)
                    dt = datetime.datetime.now()
                    hour = dt.hour + dt.minute / 60.

                    tpoints_y[ant].write(
                        "%.3f, %.3f, %.3f, %.3f, %.3f, %.3f ! %.3f, %.3f\n" %
                        (az_avg, el_avg, meas_az_y, meas_el_y, peak_sbr_y,
                         hour, peak_pos_az_y, peak_pos_el_y))
                    tpoints_y[ant].flush()

                if got_nan:
                    #os.system("bash ~/backends/frb_backend/snap_init_spec_skipprog.bash")
                    os.system(
                        "bash /home/obsuser/src/ata_snap_rfsoc/program_rfsoc_spec.sh"
                    )

            sats_observed.append(to_observe['name'])
        else:
            # wait for 20 minutes and see what other satellite pops up
            print(rising_sats)
            print(setting_sats)
            ofile.write("%s: nothing to observe, waiting\n" %
                        (datetime.datetime.now()))
            #sats_observed = []
            time.sleep(20 * 60)
        ofile.flush()
Exemple #7
0
def main():
    logger = logger_defaults.getProgramLogger("observe", 
            loglevel=logging.INFO)
    
    ant_list = ['3c']
    #pms = {ant:ata_pointing.PointingModel(ant) for ant in ant_list}
    pm = ata_pointing.PointingModel('3c')

    ata_control.reserve_antennas(ant_list)
    atexit.register(ata_control.release_antennas, ant_list, False)

    pams = {ant+pol:27 for ant in ant_list for pol in ["x","y"]}
    ifs  = {ant+pol:27 for ant in ant_list for pol in ["x","y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1575

    snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)

    obs_time = 10

    utcs = []
    sats_observed = []
    time_obs = []
    ofile = open("./atapointer.txt", "w")
    tpoint = open("./3c_tpoint.txt", "w")
    atexit.register(ofile.close)
    atexit.register(tpoint.close)
    while True:
        #utc = snap_dada.start_recording(ant_list, obs_time, acclen=120*16,
        #        disable_rfi=True)
        #utcs.append(utc)
        #for ant in ant_list:
        #    p = get_power(utc, ant)
        #    print(ant, p, 10*np.log10(p), "dB")
        sats = ata_sources.get_sats()['GPS']

        setting_sats, rising_sats = select_group_sats(sats)

        to_observe = None
        # select a rising satellite from rising group first
        # then check if there's any setting satellite, and observe
        # that instead. The rising satellite will be selected in the 
        # following iteration
        for sat_group in [rising_sats, setting_sats]:
            for sat in sat_group:
                name, az, el = sat['name'], float(sat['az']), float(sat['el'])

                # skip if satellite has been observed in the last 5 times
                if name in sats_observed[-5:]:
                    continue

                to_observe = sat
                #print("will observe: %s, state: %s" %(name, sat['state']))
                break

        # if all the satellites have been observed
        if not to_observe:
            # chose a random satellite that is setting, in case there's one
            if len(setting_sats) != 0:
                to_observe = random.choice(setting_sats)
            # else chose one that is rising, if there's one
            if len(rising_sats) != 0:
                to_observe = random.choice(rising_sats)

        if to_observe:
            az, el = float(sat['az']), float(sat['el'])
            name = sat['name']
            ofile.write("%s: Observing: %s\n" %(
                datetime.datetime.now(), to_observe['name']))
            ofile.write("%s: Az, el, state: %.2f, %.2f, %s\n" %(
                datetime.datetime.now(),az, el, sat['state']))
            ata_control.create_ephem(name, 
                    **{'duration': 2, 'interval': 1})

            pbfwhm = (3.5 / freq * 1000.0);
            delta = pbfwhm / 2.0
            obs_time = 30

            # elevation then azimuth
            offsets = [
                    [0., 4*delta],
                    [0., delta],
                    [0., 0.],
                    [0., -delta],
                    [0., -4*delta],
                    [-4*delta, 0.],
                    [-delta, 0.],
                    [0., 0.],
                    [delta, 0.],
                    [4*delta, 0.]
                    ]


            # offsets = az/el
            for i in range(nRepeats):
                azs = []
                els = []
                az_offs = []
                el_offs = []
                meas = []
                igrid = 0
                for offset in offsets:
                    ofile.write("%s %s" %(datetime.datetime.now(), offset))
                    ofile.write("\n")
                    ata_control.track_and_offset(name, ant_list, xoffset=offset)

                    az_el = ata_control.get_az_el(ant_list)['3c'] #XXX

                    # Determine the true position of satellite
                    x_el_off = offset[0]
                    el_off = offset[1]
                    az_off = x_el_off / np.cos(np.deg2rad(az_el[1]))

                    azs.append(az_el[0] - az_off)
                    els.append(az_el[1] - el_off)

                    az_offs.append(az_off)
                    el_offs.append(el_off)

                    time.sleep(30)
                    utc = snap_dada.start_recording(ant_list, obs_time, acclen=120*16,            
                            disable_rfi=True)
                    meas.append(get_power(utc, "3c"))

                az_avg = np.array(azs).mean()
                el_avg = np.array(els).mean()
                print(azs)
                print(els)
                print(az_offs)
                print(el_offs)
                print(meas)
                print(az_avg)
                print(el_avg)

                peak_el = analyzeFivePoints(el_offs[:5], meas[:5])
                peak_pos_el, peak_val_el, peak_width_el = peak_el

                peak_az = analyzeFivePoints(az_offs[5:], meas[5:])
                peak_pos_az, peak_val_az, peak_width_az = peak_az

                peak_sbr = np.sqrt(peak_val_az**2 + peak_val_el**2)

                print(peak_pos_el, peak_val_el, peak_width_el)
                print(peak_pos_az, peak_val_az, peak_width_az)

                meas_az = (az_avg + peak_pos_az)
                meas_el = (el_avg + peak_pos_el)

                meas_az, meas_el, ir = pm.applyTPOINTCorrections(meas_az, meas_el, 0)
                dt = datetime.datetime.now()
                hour = dt.hour + dt.minute/60.
                tpoint.write("! %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n"
                        %(az_avg, el_avg, meas_az, meas_el, peak_sbr, hour))

            sats_observed.append(to_observe['name'])
        else:
            # wait for 20 minutes and see what other satellite pops up
            ofile.write("%s: nothing to observe, waiting\n" %(
                datetime.datetime.now()))
            #sats_observed = []
            time.sleep(20*60)
        ofile.flush()
Exemple #8
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    ant_list = ['1k', '2a', '2b', '2c', '2e', '2j', '2m']
    lo = 'B'
    antlo_list = [ant + lo for ant in ant_list]

    ata_control.reserve_antennas(ant_list)
    atexit.register(ata_control.release_antennas, ant_list, False)

    pams = {ant + pol: 27 for ant in ant_list for pol in ["x", "y"]}
    ifs = {antlo + pol: 20 for antlo in antlo_list for pol in ["x", "y"]}

    ata_control.set_pams(pams)
    snap_if.setatten(ifs)
    freq = 1600

    obs_time = 70

    ###snap_dada.set_freq_auto([freq]*len(ant_list), ant_list)
    ata_control.set_freq([freq] * len(ant_list), ant_list, lo='b')

    os.system("killall ata_udpdb")

    goes_az = 203.323  #121.96 (goes 16)
    goes_el = 40.119  #23.63

    #el swivel

    #az_start = goes_az
    #el_start = goes_el + 10
    #el_end   = goes_el - 10

    #az swivel

    el_start = goes_el  # - 10
    az_start = goes_az - 10
    az_end = goes_az + 10

    invr = 2.55e-5
    print("az: %.2f, el: %.2f" % (az_start, el_start))

    ata_control.set_az_el(ant_list, az_start, el_start)

    _ = input("enter to continue")

    grace_time = 15  # time between now and antenna actually moving

    t_start = time.time()
    t_start += 37  #leap seconds
    t_start += grace_time  #let's start this in X seconds into the future

    t_span = 60  #seconds
    obs_time = int(t_span + 2 * grace_time)

    steps = t_span // 5  #5 seconds per step

    #print(t_start)
    #print(t_span)

    #ephem = generate_ephem_el_swivel(az_start, el_start, el_end, t_start, t_span,  steps, invr)

    ephem = generate_ephem_az_swivel(az_start, az_end, el_start, t_start,
                                     t_span, steps, invr)
    print(ephem)

    ephem_to_txt("test_ephem_goes17_az.txt", ephem)
    print("ephem file saved to disk")

    id = upload_ephemeris("test_ephem_goes17_az.txt")

    ata_control.track_ephemeris(id, ant_list)

    #t = time.time()
    utc = snap_dada.start_recording(antlo_list,
                                    obs_time,
                                    acclen=120,
                                    disable_rfi=True)