コード例 #1
0
def test_hexgrid_in_box():
    import matplotlib.colors
    r = 70
    cs2 = hexgrid_in_box(3 * r, 7 * r, r)
    channels = list(matplotlib.colors.TABLEAU_COLORS.keys())
    freq_alloc3 = hexgrid_freq_reuse(cs2, num_channels=3, reuse_dist=1)
    freq_alloc7 = hexgrid_freq_reuse(cs2, num_channels=7, reuse_dist=2)
    assert len(cs2) == len(freq_alloc3)
    assert len(cs2) == len(freq_alloc7)
    if os.environ.get('INTERACTIVE'):
        import matplotlib.pyplot as plt
        plt.figure()
        for i, c in enumerate(cs2):
            freq = freq_alloc3[i]
            arr = hexgrid_polygon(c, r=r, closed=False)
            plt.fill(arr[:, 0], arr[:, 1], color=channels[freq])
            x, y, _ = hexgrid(c, r)
            plt.text(x - r / 3, y - r / 3, f"#{i} freq{freq} \n {c}")

        plt.title("Box of 200x300m with 50m cells, 3 channels")

        plt.figure()
        for i, c in enumerate(cs2):
            freq = freq_alloc7[i]
            arr = hexgrid_polygon(c, r=r, closed=False)
            plt.fill(arr[:, 0], arr[:, 1], color=channels[freq])
            x, y, _ = hexgrid(c, r)
            plt.text(x - r / 3, y - r / 3, f"#{i} freq{freq} \n {c}")

        plt.title("Box of 200x300m with 50m cells, 7 channels")
        plt.show()
        assert ask_user("Did the plot look OK? Make sure that cell reuse pattern was correct")
コード例 #2
0
def test_hexgrid_cells():
    # noinspection PyTypeChecker
    cs1 = hexgrid_cells(7)
    cs2 = hexgrid_cells(HexgridCluster.SEVEN)
    assert np.all(cs1 == cs2), "Should take ints and enum"

    for cls in HexgridCluster:
        assert len(hexgrid_cells(cls)) == int(cls)

    if os.environ.get('INTERACTIVE'):
        import matplotlib.pyplot as plt
        for cls in HexgridCluster:
            cs = hexgrid_cells(cls)
            plt.figure()
            for c in cs:
                print(c)
                arr = hexgrid_polygon(c, r=1, closed=True)
                plt.plot(arr[:, 0], arr[:, 1])
                x, y, _ = hexgrid(c, r=1)
                plt.text(x - 1 / 3, y - 1 / 3, f"{c}")
            plt.title(f"{cls} cells")

        plt.show()
        assert ask_user(
            "Did the plot look OK? Make sure that no parts of circles go outside of the grid."
        )
コード例 #3
0
def test_freq_reuse():
    import matplotlib.colors
    cells = hexgrid_cells(HexgridCluster.NINE)
    channels = list(matplotlib.colors.TABLEAU_COLORS.keys())
    freq_alloc3 = hexgrid_freq_reuse(cells, num_channels=3, reuse_dist=1)

    assert len(cells) == len(freq_alloc3)
    if os.environ.get('INTERACTIVE'):
        import matplotlib.pyplot as plt
        plt.figure()
        for i, c in enumerate(cells):
            freq = freq_alloc3[i]
            arr = hexgrid_polygon(c, r=1, closed=False)
            plt.fill(arr[:, 0], arr[:, 1], color=channels[freq])
            x, y, _ = hexgrid(c, 1)
            plt.text(x - 1 / 3, y - 1 / 3, f"#{i} freq{freq} \n {c}")

        plt.title("Nine cells, 3 channels, should look sane")

        plt.show()
        assert ask_user("Did the plot look OK? Make sure that cell reuse pattern was correct")
コード例 #4
0
def test_pos_around_hex():
    pos = np.array(list(pos_around_hex(0, 0, 0.0, 5, num_points=50000)))
    print(pos.shape)
    assert pos.shape

    if not os.environ.get('INTERACTIVE'):
        return
    import matplotlib.pyplot as plt

    plt.figure()
    plt.plot(pos[:, 0], pos[:, 1], '.')
    plt.axis('equal')
    plt.xlim([-20, 20])
    plt.ylim([-20, 20])
    plt.title("All points plotted, as dots on figure")

    plt.figure()
    plt.hist2d(pos[:, 0], pos[:, 1], bins=np.linspace(-5, 5, 40))
    plt.colorbar()
    plt.title("All points plotted, as 2D histogram.")
    plt.show()
    assert ask_user("Did the plot look OK?")