Beispiel #1
0
 def test_separate_multiply_line():
     '''        
     Test separate_multiply_line from the plot_computation module.
     '''
     a = np.repeat(np.array(range(20)),2)
     b=np.hstack((0, np.repeat(np.array(range(1,20)),2), 20))
     new_a,new_b=separate_multiply_line(a,b,tracelength=3.5)
     correct_a = \
     [np.array([ 0. ,  0. ,  1. ,  1. ,  2. ,  2. ,  3. ,  3. ,  3.5]),
      np.array([ 3.5,  4. ,  4. ,  5. ,  5. ,  6. ,  6. ,  7. ,  7. ]),
      np.array([  8. ,   8. ,   9. ,   9. ,  10. ,  10. ,  10.5]),
      np.array([ 10.5,  11. ,  11. ,  12. ,  12. ,  13. ,  13. ,  14. ,  14. ]),
      np.array([ 15. ,  15. ,  16. ,  16. ,  17. ,  17. ,  17.5]),
      np.array([ 17.5,  18. ,  18. ,  19. ,  19. ])]
     correct_b = \
     [np.array([0, 1, 1, 2, 2, 3, 3, 4, 4]),
      np.array([4, 4, 5, 5, 6, 6, 7, 7, 8]),
      np.array([ 8,  9,  9, 10, 10, 11, 11]),
      np.array([11, 11, 12, 12, 13, 13, 14, 14, 15]),
      np.array([15, 16, 16, 17, 17, 18, 18]),
      np.array([18, 18, 19, 19, 20])]
     for i in range(6):
         if (new_a[i] == correct_a[i]).all() and (new_b[i] == correct_b[i]).all():
             pass
         else:
             print('separate_multiply_line didn\'t pass test.')
Beispiel #2
0
    def plot_multitrace(self, func_list = ('compute_original', 'compute_popen'),
                        tracelength = 5e3, trace_number = 10):
        '''
        Get the data from the func list and plot the data.
        '''
        x_list = []
        y_list = []
        for func in func_list:
            x,y = getattr(self.cluster_data, func)()
            x_list.append(x)
            y_list.append(y)
        
        sep_x_list = []
        sep_y_list = []
        for x,y in zip(x_list, y_list):
            sep_x, sep_y = separate_multiply_line(x,y,tracelength = tracelength)
            sep_x_list.append(sep_x)
            sep_y_list.append(sep_y)
        
        page_number = int(np.ceil(len(sep_x)/trace_number))
        fig_list = []
        for i in range(page_number):
            fig = plt.figure()
            fig.set_size_inches(22,17)

            for j in range(min([trace_number, len(sep_x_list[0]) - i*trace_number])):
                ax1 = fig.add_subplot(trace_number, 1, j+1)
                
                # plot original trace
                x = sep_x_list[0][i*trace_number+j]
                y = sep_y_list[0][i*trace_number+j]
                ax1.plot(x, y, color = 'black', lw=1)
                ax1.set_xlim([x[0], x[0] + tracelength])
                ax1.set_ylim([-1, 9])
                
                # plot Popen
                ax2 = ax1.twinx()
                x = sep_x_list[1][i*trace_number+j]
                y = sep_y_list[1][i*trace_number+j]
                ax2.plot(x, y, color = 'blue')
                ax2.set_xlim([x[0], x[0] + tracelength])
                ax2.set_ylim([0, 1])
            fig.suptitle(self.name+'/'+str(i))
            fig.savefig(os.path.join(self.filepath,self.name+'Joint'+str(i)+'.png'))
            fig_list.append(fig)