def generate_super_station(super_station_angle, lattice_angles,
                           align_sub_station_lattices=False):
    """Generate a v4a super-station layout with a specified super-station
       rotation angle and lattice angles

    Args:
        super_station_angle (float): super station rotation angle, in degrees
        lattice_angles (array_like): lattice angles in degrees wrt east,
                                     in degrees. Array of dimensions
                                     (num_stations = 6, num_sub_stations = 6)

    Returns:
        Arrays of x and y antenna coordinates with dimensions
         (station = 6, sub-station = 6, antenna = 48)
        Arrays of x and y centres of sub-substations with dimensions
         (station = 6, sub-station = 6)
    """
    num_stations = 6
    num_sub_stations = 6
    num_antennas = 24
    # align_sub_station_lattices = True
    lattice_angles = numpy.asarray(lattice_angles)
    # Work out some geometry for the sub-station and station pentagon
    sub_station_radius_m = 7.0
    # Sub-station circular radius
    r_max = sub_station_radius_m
    # Sub-station pentagon side length
    side = 2.0 * r_max * sin(radians(36.0))
    # Shortest distance to edge of sub-station pentagon
    r_min = r_max * cos(radians(36.0))
    # Sub-station separation
    p_sep = 2.0 * r_min + 0.5
    # Station separation
    s_sep = 2.0 * (r_max + side * cos(radians(18.0))) + 1.5
    # Lattice spacing / antenna diameter
    lattice_x_inc = 1.5
    lattice_y_inc = lattice_x_inc * sqrt(3.0) / 2.0
    lattice_size = int(ceil((3.0 * r_max) / lattice_x_inc))

    # Positions and orientation of sub-stations
    sub_station_angle = numpy.arange(num_sub_stations - 1) * \
                        (360.0 / (num_sub_stations - 1)) - 90.0
    sub_station_angle = numpy.insert(sub_station_angle, 0, 90.0)
    sub_station_angle = numpy.radians(sub_station_angle)
    x0 = numpy.zeros(num_sub_stations)
    y0 = numpy.zeros(num_sub_stations)
    for i in range(1, num_sub_stations):
        x0[i] = p_sep * cos(sub_station_angle[i])
        y0[i] = p_sep * sin(sub_station_angle[i])

    # Positions and orientation of stations.
    station_angles = numpy.arange(num_stations - 1) * \
                     (360.0 / (num_stations - 1)) + 90.0
    station_angles = numpy.insert(station_angles, 0, -90.0)
    station_angles = numpy.radians(station_angles)
    sx0 = numpy.zeros(num_stations)
    sy0 = numpy.zeros(num_stations)
    for i in range(1, num_stations):
        sx0[i] = s_sep * cos(station_angles[i])
        sy0[i] = s_sep * sin(station_angles[i])

    ant_x = numpy.zeros((num_stations, num_sub_stations, num_antennas))
    ant_y = numpy.zeros_like(ant_x)
    centre_x = numpy.zeros((num_stations, num_sub_stations))
    centre_y = numpy.zeros((num_stations, num_sub_stations))

    for j in range(num_stations):
        for i in range(num_sub_stations):

            # Obtain the coordinates of the sub-station centre
            cx, cy = rotate_coords(x0[i], y0[i],
                                   degrees(station_angles[j]) + 90.0)
            cx += sx0[j]
            cy += sy0[j]
            cx, cy = rotate_coords(cx, cy, super_station_angle)

            # Generate hexagonal lattice
            # xc, yc = generate_lattice(lattice_size, lattice_x_inc,
            #                           lattice_angles[j, i])

            # Adjust lattice center to be a multiple of the lattice spacing.
            # If enabled results in slightly different sub-station
            if align_sub_station_lattices:
                xc -= cx - round(cx / lattice_x_inc) * lattice_x_inc
                yc -= cy - round(cy / lattice_y_inc) * lattice_y_inc

            # TODO-BM change to fit as many points as possible after x trials...
            xc, yc, _ = gridgen_no_taper(500, 20, 1.5, 5000)
            print(j, i, len(xc))

            # Select points inside pentagon
            angle = degrees(sub_station_angle[i] + station_angles[j])
            angle += super_station_angle + 18.0
            xc, yc = select_antennas(xc, yc, r_max, num_antennas, angle)

            centre_x[j, i] = cx
            centre_y[j, i] = cy
            ant_x[j, i, :] = xc + centre_x[j, i]
            ant_y[j, i, :] = yc + centre_y[j, i]

    return ant_x, ant_y, centre_x, centre_y
    x2 = x1[:n_ok]
    y2 = y1[:n_ok]

    xe = rad_p * numpy.cos(theta + radians(angle))
    ye = rad_p * numpy.sin(theta + radians(angle))
    return x2, y2, xe, ye


if __name__ == '__main__':
    sub_station_radius_m = 7.0
    r_max = sub_station_radius_m
    sqinc = 2.0 * r_max / 9.33
    side = 2.0 * r_max * cos(radians(54.0))
    rmin = r_max * sin(radians(54.0))
    psep = 2.0 * rmin + 0.5
    ssep = 2.0 * (r_max + side * cos(radians(18.0))) + 1.5

    # Generate the lattice
    # x, y = generate_lattice_2(30, 30, sqinc/2.0)
    x, y, _ = gridgen_no_taper(90, 20, 1.5, 10000)

    xs, ys, xe, ye = select_antennas(x, y, angle=-90.0)

    fig1 = pyplot.figure(figsize=(16, 8))
    ax1 = fig1.add_subplot(111, aspect='equal')
    ax1.plot(xe, ye, 'bs', ms=1.0)
    ax1.plot(x, y, '+')
    ax1.plot(xs, ys, 'o')
    ax1.grid()
    pyplot.show()