Example #1
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()
Example #2
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()
Example #3
0
def main():
    logger = logger_defaults.getProgramLogger("observe", loglevel=logging.INFO)

    ant_list = ['1h', '2h']
    #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.make_and_track_source(name,
                                                      ant_list)  #track source
                    ata_control.autotune(ant_list)
                    snap_if.tune_if_antslo(antlo_list)

                    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()
Example #4
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()