Example #1
0
def simple_plot(means_filename, stdev_filename):
    #graph 1

    baseAngle, armAngle, intensitiesMean = csvinterface.read_csv(
        means_filename)
    baseAngle, armAngle, intensitiesStdev = csvinterface.read_csv(
        means_filename)

    intensityMean0 = intensitiesMean[0]
    intensityMean90 = intensitiesMean[1]
    intensityStdev0 = intensitiesStdev[0]
    intensityStdev90 = intensitiesStdev[1]

    directivity_mean_0_x = []
    directivity_mean_0_y = []
    directivity_mean_90_x = []
    directivity_mean_90_y = []

    for angle, intensity in zip(armAngle, intensityMean0):
        x, y = translatecoords(angle, intensity)
        directivity_mean_0_x.append(x)
        directivity_mean_0_y.append(y)

    for angle, intensity in zip(armAngle, intensityMean90):
        x, y = translatecoords(angle, intensity)
        directivity_mean_90_x.append(x)
        directivity_mean_90_y.append(y)

    snr0 = []
    snr90 = []

    for val, err in zip(intensityMean0, intensityStdev0):
        snr0.append(20 * math.log10(val / err))

    for val, err in zip(intensityMean90, intensityStdev90):
        snr90.append(20 * math.log10(val / err))

    plt.subplot(1, 2, 1)
    plt.plot(directivity_mean_0_x, directivity_mean_0_y, '.-')
    plt.plot(directivity_mean_90_x, directivity_mean_90_y, '.-')
    plt.title('Mean Directivity')
    plt.legend(['Base: 0 Deg', 'Base: 90 Deg'])
    #plt.xlim([-0.1,0.1])
    #plt.ylim([0,0.2])

    plt.subplot(1, 2, 2)
    plt.plot(armAngle, snr0, '.-')
    plt.plot(armAngle, snr90, '.-')
    plt.title('Signal to Noise Ratio')
    plt.xlabel('Arm Angle')
    plt.ylabel('SNR (dB, approx from σ)')
    plt.legend(['Base: 0 Deg', 'Base: 90 Deg'])

    plt.show()
Example #2
0
def plot_surface_file(ax, filename):
        xData, yData, zData = csvinterface.read_csv(means_filename)

            corrected_x_data = []
            corrected_y_data = []
            corrected_z_data = []

            for phiindex in range(len(zdata)):
                    phirow = zdata[thetaindex]
                    for thetaindex in range(len(phirow)):
                            intensity = thetarow[thetaindex]
                            phi = xData[phiindex]
                            theta = yData[thetaindex]

                            x, y, z = transform_val(phi, theta, intensity)

                            corrected_x_data.append(x)
                            corrected_y_data.append(y)
                            corrected_z_data.append(z)


            # Plot the surface.
            ax1 = fig.gca(projection='3d')
            surf = ax1.plot_trisurf(xData, yData, zData, cmap=cm.viridis,
                                   linewidth=0, antialiased=False)
Example #3
0
def one_axis_plot(means_filename, stdev_filename):

    baseAngle, armAngle, intensityMean = csvinterface.read_csv(means_filename)
    baseAngle, armAngle, intensityStdev = csvinterface.read_csv(stdev_filename)

    intensityMean = intensityMean[0]
    intensityStdev = intensityStdev[0]

    directivity_mean_x = []
    directivity_mean_y = []

    for angle, intensity in zip(armAngle, intensityMean):
        x, y = translatecoords(angle, intensity)
        directivity_mean_x.append(x)
        directivity_mean_y.append(y)

    snr = []

    for val, err in zip(intensityMean, intensityStdev):
        if val == 0 or err == 0:
            snr.append(0)
        else:
            snr.append(20 * math.log10(val / err))

    plt.subplot(1, 2, 1)
    plt.plot(directivity_mean_x, directivity_mean_y, '.-')
    plt.title('Mean Directivity')
    plt.legend(['Base: 0 Deg'])

    plt.subplot(1, 2, 2)
    plt.plot(armAngle, snr, '.-')
    plt.title('Signal to Noise Ratio')
    plt.xlabel('Arm Angle')
    plt.ylabel('SNR (dB, approx from σ)')
    plt.legend(['Base: 0 Deg'])
    plt.show()
Example #4
0
def plot_surface_file(ax, filename, scatter=False):
    xData, yData, zData = csvinterface.read_csv(filename)

    # assume constant baseline and linear scaling - subtract off mininum value

    minval = 10  # max of 5v on ADC, so this is absurdly high

    for row in zData:
        for el in row:
            if el < minval: minval = el

    corrected_x_data = []
    corrected_y_data = []
    corrected_z_data = []

    for phiindex in range(len(zData)):
        phirow = zData[phiindex]
        for thetaindex in range(len(phirow)):

            intensity = phirow[thetaindex]
            phi = xData[phiindex]
            theta = yData[thetaindex]

            x, y, z = transform_val(phi, theta, intensity - minval)

            corrected_x_data.append(x)
            corrected_y_data.append(y)
            corrected_z_data.append(z)

    if scatter:
        surf = ax.scatter(corrected_x_data,
                          corrected_y_data,
                          corrected_z_data,
                          marker='.',
                          c=corrected_z_data,
                          s=20,
                          alpha=1)
        #ax.contourf(corrected_x_data, corrected_y_data, corrected_z_data)
    else:

        # generating a triangular mesh

        num_phipoints = len(zData[0])

        # points are theta, phi 0-180
        # first 91 points for theta = 0, next for theta = 1, etc

        # connect points in consecutive theta

        triangles = []

        # there will be as many triangles as there are points - 2

        for theta_index in range(len(zData) - 1):
            for phi_index in range(len(zData[0]) - 1):
                # indices will be two consecutive points for theta = base, then one point for theta = base + 1
                first_point_index = theta_index * num_phipoints + phi_index
                second_point_index = theta_index * num_phipoints + phi_index + 1
                third_point_index = (theta_index +
                                     1) * num_phipoints + phi_index
                fourth_point_index = (theta_index +
                                      1) * num_phipoints + phi_index + 1

                triangles.append(
                    [first_point_index, second_point_index, third_point_index])
                triangles.append([
                    fourth_point_index, second_point_index, third_point_index
                ])

        triang = mtri.Triangulation(corrected_x_data,
                                    corrected_y_data,
                                    triangles=triangles)

        surf = ax.plot_trisurf(triang,
                               np.array(corrected_z_data),
                               linewidths=0.1,
                               edgecolor='black',
                               cmap=cm.viridis,
                               antialiased=True)

    return surf, zData
Example #5
0
def plot_everything(means_filename, stdev_filename):

    print("Plotting in Matplotlib")
    #set up a figure
    fig = plt.figure(figsize=plt.figaspect(0.3))

    ax1 = fig.add_subplot(1, 2, 1, projection='3d')
    ax1 = fig.gca(projection='3d')

    surf, zDataAbs = plot_surface_file(ax1, means_filename)

    # Title
    # Placement 0, 0 would be the bottom left, 1, 1 would be the top right.
    ax1.text2D(0.05,
               0.95,
               "Mean Directivity (Unnormalized)",
               transform=ax1.transAxes)

    # Tweaking display region and labels
    #ax1.set_xlim(0, 180)
    #ax1.set_ylim(0, 180)
    #ax1.set_xlabel('Base', color='crimson')
    #ax1.set_ylabel('Base', color='crimson')
    #ax1.set_zlabel('Z Magnitude', color='crimson')

    # Customize the z axis.
    #ax1.set_zlim(0, 5)

    #Second graph
    ax2 = fig.add_subplot(1, 2, 2, projection='3d')

    xData2, yData2, zData2 = csvinterface.read_csv(stdev_filename)

    # Dividing by mag
    for i in range(len(zData2)):
        ilist = zData2[i]
        for j in range(len(ilist)):
            jval = ilist[j]
            if jval == 0: zData2[i][j] == 0
            elif zDataAbs[i][j] == 0: zData2[i][j] == 0
            else: zData2[i][j] = 20 * math.log10(zDataAbs[i][j] / jval)

    xData2, yData2 = np.meshgrid(yData2, xData2)

    # Plot the surface.
    ax2 = fig.gca(projection='3d')
    surf = ax2.plot_surface(xData2,
                            yData2,
                            zData2,
                            cmap=cm.viridis,
                            linewidths=0.1,
                            edgecolor='black',
                            antialiased=True)

    # Title
    # Placement 0, 0 would be the bottom left, 1, 1 would be the top right.
    ax2.text2D(0.05, 0.95, "Signal to Noise Ratio", transform=ax2.transAxes)

    # Tweaking display region and labels
    ax2.set_xlim(0, 180)
    ax2.set_ylim(0, 180)
    ax2.set_ylabel('θ (base, degrees)', color='crimson')
    ax2.set_xlabel('ɸ (arm, degrees)', color='crimson')
    ax2.set_zlabel('SNR (dB, approx from σ)', color='crimson')

    # Customize the z axis.
    #ax2.set_zlim(0, 5)
    #ax2.zaxis.set_major_locator(LinearLocator(10))
    #ax2.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

    # Add a color bar which maps values to colors.
    fig.colorbar(surf, shrink=0.5, aspect=5, ax=ax2)

    plt.show()