Exemple #1
0
def draw_rectangle(image_in,width,height,xlb,xub,ylb,yub,image_out,color):
    # Drawing a rectangle in a picture
    dpi = 80
                  
    im  = Image.open(image_in)
    ratiox = im.size[0]/width
    ratioy = im.size[1]/height
    
    xlb = xlb*ratiox
    xub = xub*ratiox
    
    ylb = ylb*ratioy
    yub = yub*ratioy
    
    # What size does the figure need to be in inches to fit the image?
    figsize = width / float(dpi), height / float(dpi)
    
    figure = plt.figure(figsize=figsize)
    ax = figure.add_axes([0, 0, 1, 1])
    # Hide spines, ticks, etc.
    ax.axis('off')
    rect = matplotlib.patches.Rectangle((xlb,im.size[1]-yub),xub-xlb,yub-ylb, edgecolor=color, facecolor="none")   
    ax.imshow(im)
    ax.add_patch(rect)
    figure.savefig(image_out,dpi=dpi,transparent=True)
    return 0
def PCA_expansion(iq_mat, config):
    '''
    Calculate the PCA of the vector and generate samples from it
    '''
    mean = np.mean(iq_mat, axis=0)
    standardized_iq_mat = iq_mat - np.mean(iq_mat, axis=0)
    cov_mat = np.cov(standardized_iq_mat)  # Calculate the covariance matrix

    cov_mat = np.zeros((iq_mat.shape[0], iq_mat.shape[0]))

    for index in range(iq_mat.shape[1]):
        cov_mat += np.matmul(
            iq_mat[:, index] - mean,
            np.transpose(iq_mat[:, index] - mean)) / iq_mat.shape[1]
    '''
    Eigen Value decomposition
    '''
    eigen_values, eigen_vector = np.linalg.eig(
        cov_mat)  # Calculate the eigen values and eigen vectors
    idx = np.argsort(eigen_values)[::-1]
    eigen_vector = eigen_vector[:, idx]
    '''
    Generate new samples
    '''
    NUMBER_OF_KL_COEEFIECENT = config.number_of_pca_coeff
    VARIANCE_SCALING = config.pca_augmentation_scaling

    KL_mat = np.matmul(np.transpose(standardized_iq_mat), eigen_vector)
    KL_mat[:, :
           NUMBER_OF_KL_COEEFIECENT] = KL_mat[:, :
                                              NUMBER_OF_KL_COEEFIECENT] + VARIANCE_SCALING * np.multiply(
                                                  KL_mat[:, :
                                                         NUMBER_OF_KL_COEEFIECENT],
                                                  np.random.randn(
                                                      32,
                                                      NUMBER_OF_KL_COEEFIECENT))

    new_iq_mat = np.matmul(eigen_vector, np.transpose(KL_mat))

    figure, axes = plt.subplots(nrows=2, ncols=2)
    axes[0, 0].imshow(standardized_iq_mat)
    axes[0, 0].set_title('Freq Response Org')
    axes[0, 1].imshow(np.real(new_iq_mat))
    axes[0, 1].set_title('Freq Response Generated 1 ')
    axes[1, 0].imshow(np.real(new_iq_mat))
    axes[1, 0].set_title('Freq Response Generated 2 ')
    axes[1, 1].imshow(np.real(new_iq_mat))
    axes[1, 1].set_title('Freq Response Generated 3 ')

    figure.savefig('test_pca')

    return new_iq_mat
Exemple #3
0
def Sample_rectangle_from_spectrogram(iq_mat, config):
    NUM_OF_ROWS = config.rect_augment_num_of_rows
    NUM_OF_COLS = config.rect_augment_num_of_cols
    GAP_OF_DOPPLER_BURST_FROM_EDGE = config.rect_augment_gap_doppler_burst_from_edge
    MAX_NUM_OF_BINS = 126
    MAX_NUM_OF_TIMESTEPS = 32
    new_iq_list = []
    doppler_burst = np.argmax(
        iq_mat, axis=0)  # Extract the doppler burst from the matrix
    for row_ind in range(MAX_NUM_OF_BINS - NUM_OF_ROWS):
        for col_ind in range(MAX_NUM_OF_TIMESTEPS - NUM_OF_COLS):
            for col_sub_ind in range(col_ind, col_ind + NUM_OF_COLS):
                '''
                Check that we have Doppler Burst with a gap of GAP_OF_DOPPLER_BURST_FROM_EDGE from the edge from all options
                 ( if not discard this rect option ) 
                '''
                discard_rect_flag = False
                if doppler_burst[col_sub_ind] > (row_ind + NUM_OF_ROWS - GAP_OF_DOPPLER_BURST_FROM_EDGE)\
                        or doppler_burst[col_sub_ind] < (row_ind + GAP_OF_DOPPLER_BURST_FROM_EDGE):
                    discard_rect_flag = True
                    break

            if discard_rect_flag:
                continue
            new_iq_list.append(iq_mat[row_ind:row_ind + NUM_OF_ROWS,
                                      col_ind:col_ind + NUM_OF_COLS])

    figure, axes = plt.subplots(nrows=2, ncols=2)
    axes[0, 0].imshow(iq_mat)
    axes[0, 0].set_title('Freq Response Org')
    index = np.random.choice(range(len(new_iq_list)))
    axes[0, 1].imshow(new_iq_list[index])
    axes[0, 1].set_title('Freq Response Extracted index'.format(index))
    index = np.random.choice(range(len(new_iq_list)))
    axes[1, 0].imshow(new_iq_list[index])
    axes[1, 0].set_title('Freq Response Extracted {}'.format(index))
    index = np.random.choice(range(len(new_iq_list)))
    axes[1, 1].imshow(new_iq_list[index])
    axes[1, 1].set_title('Freq Response Extracted {} '.format(index))

    figure.savefig('test_rect_sample')

    return new_iq_list
    def Calculate(self, event):
        #Get Occupation selections and populate a list
        item_occ = self.tree_occ.GetSelections()
        self.calc_occ_list = listSetup(self, item_occ, self.tree_occ)

        #Get Territory selections and populate a list
        item_terr = self.tree_terr.GetSelections()
        self.calc_terr_list = listSetup(self, item_terr, self.tree_terr)
                
        if self.calc_occ_list != [] and self.calc_terr_list != []:
            #Generate the lists to be used for charts
            chart, other_chart = listGenerateCharts(self, self.calc_occ_list, self.calc_terr_list)

            #Sort the lists generated
            sorted_chart = chart
            sorted_other_chart = other_chart

            #Generate the charts
            figure = GenerateFigure(self, sorted_chart)
            figure.savefig('current.png')
            if sorted_other_chart != []:
                figure_other = GenerateFigure(self, sorted_other_chart)
                figure_other.savefig('current_other.png')
Exemple #5
0
grp.plot.bar()
grp.to_csv("CountryVsIncome.csv")

####Countplot
xx = train_df[['NativeCountry', 'Income']]
xx = xx[xx.NativeCountry != -999]
figure()
countplot(data=xx, y=xx.Income)
show()

xx = train_df[['Gender', 'Income']]
xx = xx[xx.Gender != -999]
#figure(figsize=(12,6))
svm = countplot(data=xx, x=xx.Income, hue="Gender")
figure = svm.get_figure()
figure.savefig('gender_income.png', dpi=400)
show()

xx = train_df[['WorkClass', 'Income']]

xx = xx[xx.WorkClass != -999]

svm = countplot(data=xx, x=xx.Income, hue="WorkClass")
figure = svm.get_figure()
figure.savefig('Work_income.png', dpi=400)
show()

xx = train_df[['HoursPerWeek', 'Income', 'NativeCountry']]

xx = xx[xx.NativeCountry != -999]
#yy=xx[xx['WorkClass']=='Private']