Esempio n. 1
0
def tile_integration(out_dir, rf_dir):
    """Calculate total integration at multiple pointings for all tiles

    :param out_dir: Path to root of directory where mwa metadata is saved :class:`~str`
    :param rf_dir: Path to root of directory with rf data files :class:`~str`

    :returns:
        A :class:`~dict` with keys being :samp:`tile_names` and values being :class:`~list` of integration hours at pointings 0, 2, 4 & 41

    """

    # Tile names
    tiles = tile_names()

    # lists of obs at each pointings
    with open(f"{out_dir}/obs_pointings.json") as table:
        data = json.load(table)
        start_date = data["start_date"]
        stop_date = data["stop_date"]
        point_0 = data["point_0"]
        point_2 = data["point_2"]
        point_4 = data["point_4"]
        point_41 = data["point_41"]

    tile_ints = {}
    for tile in tiles:

        # increment this by 0.5, for every obs which is in point_list.
        # 0.5 = 30 min
        p_0 = 0
        p_2 = 0
        p_4 = 0
        p_41 = 0

        # dates: list of days
        # date_time = list of 30 min observation windows
        dates, time_stamps = time_tree(start_date, stop_date)
        for day in range(len(dates)):
            for ts in range(len(time_stamps[day])):
                f_name = f"{tile}_{time_stamps[day][ts]}.txt"
                f_path = Path(f"{rf_dir}/{tile}/{dates[day]}/{f_name}")
                if f_path.is_file():
                    if time_stamps[day][ts] in point_0:
                        p_0 += 0.5
                    elif time_stamps[day][ts] in point_2:
                        p_2 += 0.5
                    elif time_stamps[day][ts] in point_4:
                        p_4 += 0.5
                    elif time_stamps[day][ts] in point_41:
                        p_41 += 0.5
                    # should there be an else statement here?

        tile_ints[f"{tile}"] = [p_0, p_2, p_4, p_41]

    return tile_ints
Esempio n. 2
0
def align_batch(
    start_date=None,
    stop_date=None,
    savgol_window_1=None,
    savgol_window_2=None,
    polyorder=None,
    interp_type=None,
    interp_freq=None,
    data_dir=None,
    out_dir=None,
    max_cores=None,
):
    """Temporally align all RF files within a date interval using :func:`~embers.rf_tools.align_data.save_aligned`.


    :param start_date: In YYYY-MM-DD format :class:`~str`
    :param stop_date: In YYYY-MM-DD format :class:`~str`
    :param savgol_window_1:  window size of savgol filer, must be odd :class:`~int`
    :param savgol_window_2:  window size of savgol filer, must be odd :class:`~int`
    :param polyorder: polynomial order to fit to savgol_window :class:`~int`
    :param interp_type: type of interpolation. Ex: 'cubic', 'linear' :class:`~str`
    :param interp_freq: freqency to which power array is interpolated :class:`~int`
    :param data_dir: root of data dir where rf data is located :class:`~str`
    :param out_dir: relative path to output directory :class:`~str`
    :param max_cores: Maximum number of cores to be used by this script. Default=None, which means that all available cores are used

    :return:
        - aligned rf data saved to :samp:`npz` file by :func:`~numpy.savez_compressed` in :samp:`out_dir`

    """

    dates, time_stamps = time_tree(start_date, stop_date)

    # Logging config
    log_dir = Path(f"{out_dir}")
    log_dir.mkdir(parents=True, exist_ok=True)
    logging.basicConfig(
        filename=f"{out_dir}/align_batch.log",
        level=logging.INFO,
        format="%(levelname)s: %(funcName)s: %(message)s",
    )

    for pair in tile_pairs(tile_names()):

        for day in range(len(dates)):

            with concurrent.futures.ProcessPoolExecutor(
                    max_workers=max_cores) as executor:
                results = executor.map(
                    save_aligned,
                    repeat(pair),
                    time_stamps[day],
                    repeat(savgol_window_1),
                    repeat(savgol_window_2),
                    repeat(polyorder),
                    repeat(interp_type),
                    repeat(interp_freq),
                    repeat(data_dir),
                    repeat(out_dir),
                )

            for result in results:
                logging.info(result)
Esempio n. 3
0
def plt_hist_array(tile_ints, out_dir):
    """A massive grid of histograms with a subplot for pointing integration of each tile.

    :param tile_ints: :class:`~dict` from :func:`~embers.mwa_utils.mwa_pointings.tile_integration`
    :param out_dir: Path to output directory :class:`~str`

    :returns:
        :samp:`tiles_pointing_integration.png` saved to :samp:`out_dir`

    """

    plt.style.use("seaborn")
    fig = plt.figure(figsize=(14, 10))

    # Tile names
    tiles = tile_names()

    def tile_pointing_hist(a, b, c, fig, int_dict=None, tile=None):

        ax = fig.add_subplot(a, b, c)

        y_max = max(i for v in int_dict.values() for i in v)
        int_list = int_dict[tile]
        x = range(len(int_list))
        leg = int_list

        pal = sns.cubehelix_palette(len(int_list),
                                    start=0.7,
                                    rot=-0.7,
                                    dark=0.4,
                                    reverse=True)
        barplot = plt.bar(x,
                          int_list,
                          color=sns.color_palette(pal),
                          edgecolor="black")

        def autolabel(rects):
            for idx, rect in enumerate(barplot):
                height = rect.get_height()
                ax.text(
                    rect.get_x() + rect.get_width() / 2.0,
                    height,
                    leg[idx],
                    ha="center",
                    va="bottom",
                    rotation=0,
                )

        autolabel(barplot)

        # these are matplotlib.patch.Patch properties
        props = dict(boxstyle="round", facecolor="wheat", alpha=0.5)

        # place a text box in upper left in axes coords
        ax.text(
            0.65,
            0.95,
            f"{tile}",
            transform=ax.transAxes,
            fontsize=10,
            verticalalignment="top",
            bbox=props,
        )

        plt.xlim(-0.5, len(int_list) - 0.5)
        ax.set_yticklabels([])

        ax.set_xticklabels([])
        ax.set_ylim(0, 1.1 * y_max)

    tile_pointing_hist(4, 8, 1, fig, int_dict=tile_ints, tile=tiles[0])
    tile_pointing_hist(4, 8, 2, fig, int_dict=tile_ints, tile=tiles[4])
    tile_pointing_hist(4, 8, 3, fig, int_dict=tile_ints, tile=tiles[5])
    tile_pointing_hist(4, 8, 4, fig, int_dict=tile_ints, tile=tiles[6])
    tile_pointing_hist(4, 8, 5, fig, int_dict=tile_ints, tile=tiles[7])
    tile_pointing_hist(4, 8, 6, fig, int_dict=tile_ints, tile=tiles[8])
    tile_pointing_hist(4, 8, 7, fig, int_dict=tile_ints, tile=tiles[9])
    tile_pointing_hist(4, 8, 8, fig, int_dict=tile_ints, tile=tiles[10])
    tile_pointing_hist(4, 8, 9, fig, int_dict=tile_ints, tile=tiles[1])
    tile_pointing_hist(4, 8, 10, fig, int_dict=tile_ints, tile=tiles[11])
    tile_pointing_hist(4, 8, 11, fig, int_dict=tile_ints, tile=tiles[12])
    tile_pointing_hist(4, 8, 12, fig, int_dict=tile_ints, tile=tiles[13])
    tile_pointing_hist(4, 8, 13, fig, int_dict=tile_ints, tile=tiles[14])
    tile_pointing_hist(4, 8, 14, fig, int_dict=tile_ints, tile=tiles[15])
    tile_pointing_hist(4, 8, 15, fig, int_dict=tile_ints, tile=tiles[16])
    tile_pointing_hist(4, 8, 16, fig, int_dict=tile_ints, tile=tiles[17])
    tile_pointing_hist(4, 8, 17, fig, int_dict=tile_ints, tile=tiles[2])
    tile_pointing_hist(4, 8, 18, fig, int_dict=tile_ints, tile=tiles[18])
    tile_pointing_hist(4, 8, 19, fig, int_dict=tile_ints, tile=tiles[19])
    tile_pointing_hist(4, 8, 20, fig, int_dict=tile_ints, tile=tiles[20])
    tile_pointing_hist(4, 8, 21, fig, int_dict=tile_ints, tile=tiles[21])
    tile_pointing_hist(4, 8, 22, fig, int_dict=tile_ints, tile=tiles[22])
    tile_pointing_hist(4, 8, 23, fig, int_dict=tile_ints, tile=tiles[23])
    tile_pointing_hist(4, 8, 24, fig, int_dict=tile_ints, tile=tiles[24])
    tile_pointing_hist(4, 8, 25, fig, int_dict=tile_ints, tile=tiles[3])
    tile_pointing_hist(4, 8, 26, fig, int_dict=tile_ints, tile=tiles[25])
    tile_pointing_hist(4, 8, 27, fig, int_dict=tile_ints, tile=tiles[26])
    tile_pointing_hist(4, 8, 28, fig, int_dict=tile_ints, tile=tiles[27])
    tile_pointing_hist(4, 8, 29, fig, int_dict=tile_ints, tile=tiles[28])
    tile_pointing_hist(4, 8, 30, fig, int_dict=tile_ints, tile=tiles[29])
    tile_pointing_hist(4, 8, 31, fig, int_dict=tile_ints, tile=tiles[30])
    tile_pointing_hist(4, 8, 32, fig, int_dict=tile_ints, tile=tiles[31])

    plt.tight_layout()
    fig.savefig(f"{out_dir}/tiles_pointing_integration.png")
    print(f"Tile integration plot saved to {out_dir}")
Esempio n. 4
0
def test_tile_names_length():
    tiles = tile_names()
    assert len(tiles) == 32
Esempio n. 5
0
def test_tile_names_last():
    tiles = tile_names()
    assert tiles[-1] == "S36YY"
Esempio n. 6
0
def test_tile_names_first():
    tiles = tile_names()
    assert tiles[0] == "rf0XX"