Esempio n. 1
0
    def effectiv_plot(self, data, I_rms, U_rms, R, P, data_name: str,
                      save_pic: bool, plot_pic: bool, zoom: bool,
                      save_pic_path: str):
        '''
        ----------------
        DESCRIPTION
        ----------------
        A function to plot the effectiv data:
        I_rms: effectiv current
        U_rms: effectiv voltage
        R: resistance 
        P: power 
        ----------------
        PARAMETER
        ----------------
        data_name - name of the current data
        peak_id - peak index of the current
        valley_id - valley index of the current
        I_rms - effectiv current
        U_rms - effectiv voltage
        R - resistance 
        p - power
        plot_pic - bool
        zoom - bool show local zoom of current data
        save_pic - bool save the pic or not
        save_pic_path - if save pic is True, please gave the save path 
        '''
        begin_id, end_id = self.begin_id, self.end_id
        valley_id, peak_id = self.valley_id, self.peak_id

        font = {
            'family': 'serif',
            # 'color':  'darkred',
            'weight': 'normal',
            'size': 12
        }
        prop = {'family': 'serif', 'size': 10}

        with plt.rc_context({'axes.autolimit_mode': 'round_numbers'}):
            fig = plt.figure(constrained_layout=False, figsize=(10, 6))
            gs = fig.add_gridspec(nrows=2, ncols=2, wspace=0.2)
            t = data.Zeit[begin_id:end_id]
            ####current
            ax1 = fig.add_subplot(gs[0, 0])
            ax1.plot(t,
                     data.Schweissstrom[begin_id:end_id],
                     color='silver',
                     label='Schweißstrom roh')
            ax1.plot(t,
                     I_rms[begin_id:end_id],
                     color='k',
                     label='effektiver Schweißstrom')
            # ax1.scatter(data.loc[:,'Zeit'][peak_id], data.loc[:,'Schweissstrom'][peak_id], color = 'red', edgecolors = 'k', marker = 'o', alpha = 0.5, label = 'Peak')
            # ax1.scatter(data.loc[:,'Zeit'][valley_id], data.loc[:,'Schweissstrom'][valley_id], color = 'green', edgecolors = 'k', marker = 's', alpha = 0.5, label = 'Tal')
            ax1.legend(loc='best', prop=prop)
            # ax1.legend(loc='upper center', bbox_to_anchor=(0.5,1.2),frameon=False,ncol=2,prop = prop)
            ax1.set_ylabel('Schweissstrom $I_{s}$ / $kA$', fontdict=font)
            ax1.set_xlim(1.1, 1.9)
            # ax1.tick_params(axis='both',labelsize = 8,direction = 'in')
            # ax1.set_title('Schweißstrom',fontdict = font)
            # ax1.set_xlabel('Zeit $t$ / $s$',fontdict = font)
            ax1.tick_params(axis='both',
                            which='major',
                            labelsize=12,
                            direction='in')
            ax1.grid()
            plt.setp(ax1.get_xticklabels(), visible=False)
            if zoom:
                with plt.rc_context({'axes.autolimit_mode': 'round_numbers'}):
                    axins = ax1.inset_axes((0.2, 0.2, 0.45, 0.3))
                    axins.plot(t,
                               data.Schweissstrom[begin_id:end_id],
                               color='silver')
                    axins.plot(t, I_rms[begin_id:end_id], color='k')
                    axins.scatter(data.loc[:, 'Zeit'][peak_id],
                                  data.loc[:, 'Schweissstrom'][peak_id],
                                  color='red',
                                  edgecolors='k',
                                  marker='o',
                                  alpha=0.5)
                    axins.scatter(data.loc[:, 'Zeit'][valley_id],
                                  data.loc[:, 'Schweissstrom'][valley_id],
                                  color='green',
                                  edgecolors='k',
                                  marker='s',
                                  alpha=0.5)

                    zone_left = begin_id + 8000
                    zone_right = zone_left + 500

                    x_ratio = 0
                    y_ratio = 0.05

                    x_ = data.loc[:, 'Zeit']

                    xlim0 = x_[zone_left] - (x_[zone_right] -
                                             x_[zone_left]) * x_ratio
                    xlim1 = x_[zone_right] + (x_[zone_right] -
                                              x_[zone_left]) * x_ratio

                    y = data.loc[zone_left:zone_right, 'Schweissstrom']
                    ylim0 = np.min(y) - (np.max(y) - np.min(y)) * y_ratio - 0.5
                    ylim1 = np.max(y) + (np.max(y) - np.min(y)) * y_ratio + 0.5

                    axins.set_xlim(xlim0, xlim1)
                    axins.set_ylim(ylim0, ylim1)

                    axins.set_xticks([])
                    axins.set_yticks([])

                    tx0 = xlim0
                    tx1 = xlim1 + 0.01
                    ty0 = ylim0
                    ty1 = ylim1
                    sx = [tx0, tx1, tx1, tx0, tx0]
                    sy = [ty0, ty0, ty1, ty1, ty0]
                    ax1.plot(sx, sy, "darkred", alpha=0.5)

                    xy = (xlim0, ylim0)
                    xy2 = (xlim0, ylim1)
                    con = ConnectionPatch(xyA=xy2,
                                          xyB=xy,
                                          coordsA="data",
                                          coordsB="data",
                                          axesA=axins,
                                          axesB=ax1,
                                          color='darkred',
                                          alpha=0.5)
                    axins.add_artist(con)

                    xy = (xlim1, ylim0)
                    xy2 = (xlim1, ylim1)
                    con = ConnectionPatch(xyA=xy2,
                                          xyB=xy,
                                          coordsA="data",
                                          coordsB="data",
                                          axesA=axins,
                                          axesB=ax1,
                                          color='darkred',
                                          alpha=0.5)
                    axins.add_artist(con)

            # voltage
            ax2 = fig.add_subplot(gs[1, 0], sharex=ax1)
            ax2.plot(t,
                     data.Schweissspannung[begin_id:end_id],
                     color='silver',
                     label='Schweißspannung roh')
            ax2.plot(t,
                     U_rms[begin_id:end_id],
                     color='k',
                     label='effektive Schweißspannung')
            # ax2.scatter(data.loc[:,'Zeit'][valley_id], data.loc[:,'Schweissspannung'][valley_id], color = 'green', edgecolors = 'k', marker = 's', alpha = 0.5, label = 'Tal')
            ax2.legend(loc='best', prop=prop)
            # ax2.legend(loc='upper center', bbox_to_anchor=(0.5,1.2),frameon=False,ncol=2,prop = prop)
            ax2.set_ylabel('Schweißspannung $U_{s}$ / $V$', fontdict=font)
            ax2.set_xlabel('Zeit $t$ / $s$', fontdict=font)
            # ax2.tick_params(axis='both',labelsize = 8,direction = 'in')
            ax2.tick_params(axis='both',
                            which='major',
                            labelsize=12,
                            direction='in')
            # ax2.set_title('Schweißspannung',fontdict = font)
            ax2.grid()
            plt.setp(ax2.get_xticklabels(), visible=True)
            if zoom:
                with plt.rc_context({'axes.autolimit_mode': 'round_numbers'}):
                    axins2 = ax2.inset_axes((0.3, 0.2, 0.45, 0.3))
                    axins2.plot(t,
                                data.Schweissspannung[begin_id:end_id],
                                color='silver')
                    axins2.plot(t, U_rms[begin_id:end_id], color='k')
                    # axins2.scatter(data.loc[:,'Zeit'][peak_id], data.loc[:,'Schweissspannung'][peak_id], color = 'red', edgecolors = 'k', marker = 'o', alpha = 0.3)
                    axins2.scatter(data.loc[:, 'Zeit'][valley_id],
                                   data.loc[:, 'Schweissspannung'][valley_id],
                                   color='green',
                                   edgecolors='k',
                                   marker='s',
                                   alpha=0.5)

                    zone_left = begin_id + 8000
                    zone_right = zone_left + 500

                    x_ratio = 0
                    y_ratio = 0.05

                    x_ = data.loc[:, 'Zeit']

                    xlim0 = x_[zone_left] - (x_[zone_right] -
                                             x_[zone_left]) * x_ratio
                    xlim1 = x_[zone_right] + (x_[zone_right] -
                                              x_[zone_left]) * x_ratio

                    y = data.loc[zone_left:zone_right, 'Schweissspannung']
                    ylim0 = np.min(y) - (np.max(y) - np.min(y)) * y_ratio - 0.5
                    ylim1 = np.max(y) + (np.max(y) - np.min(y)) * y_ratio + 0.5

                    axins2.set_xlim(xlim0, xlim1)
                    axins2.set_ylim(ylim0, ylim1)

                    axins2.set_xticks([])
                    axins2.set_yticks([])

                    tx0 = xlim0
                    tx1 = xlim1 + 0.01
                    ty0 = ylim0
                    ty1 = ylim1
                    sx = [tx0, tx1, tx1, tx0, tx0]
                    sy = [ty0, ty0, ty1, ty1, ty0]
                    ax2.plot(sx, sy, "darkred", alpha=0.5)

                    xy = (xlim0, ylim0)
                    xy2 = (xlim0, ylim0)
                    con = ConnectionPatch(xyA=xy2,
                                          xyB=xy,
                                          coordsA="data",
                                          coordsB="data",
                                          axesA=axins2,
                                          axesB=ax2,
                                          color='darkred',
                                          alpha=0.5)
                    axins2.add_artist(con)

                    xy = (xlim1, ylim0)
                    xy2 = (xlim1, ylim0)
                    con = ConnectionPatch(xyA=xy2,
                                          xyB=xy,
                                          coordsA="data",
                                          coordsB="data",
                                          axesA=axins2,
                                          axesB=ax2,
                                          color='darkred',
                                          alpha=0.5)
                    axins2.add_artist(con)

            # resistance
            ax3 = fig.add_subplot(gs[0, 1])
            ax3.plot(t,
                     R[begin_id:end_id],
                     color='k',
                     label='dynamischer Widerstand')
            # ax3.legend(loc = 1,prop = prop,frameon=False)
            ax3.set_ylabel('dynamischer Widerstand $R$ / $mΩ$', fontdict=font)
            # ax3.text(max(t)*0.7,max(R[begin_id:end_id]),'$R = U_{eff} / I_{eff}$',fontdict=font)
            ax3.tick_params(axis='both', labelsize=12, direction='in')
            ax3.set_xlim(1.1, 1.9)
            # ax3.set_title('Prozesswiderstand',fontdict = font)
            # ax3.set_xlabel('Zeit $t$ / $s$',fontdict = font)
            ax3.grid()
            plt.setp(ax3.get_xticklabels(), visible=False)
            # power
            ax4 = fig.add_subplot(gs[1, 1], sharex=ax3)
            ax4.plot(t, P[begin_id:end_id], color='k', label='Prozessleistung')
            # ax4.legend(loc = 'best',prop = prop,frameon=False)
            ax4.set_ylabel('Prozessleistung $P$/ $kW$', fontdict=font)
            ax4.set_xlabel('Zeit $t$ / $s$', fontdict=font)
            # ax4.set_title('Prozessleistung',fontdict = font)
            # ax4.text(max(t)*0.7,max(P[begin_id:end_id]),'$P = I^{2}_{eff} · R$',fontdict=font)
            ax4.tick_params(axis='both', labelsize=12, direction='in')
            ax4.grid()
            plt.setp(ax4.get_xticklabels(), visible=True)

            # fig.suptitle('{}'.format(data_name), fontdict = font,y = 0.95, fontsize = 10)

            if save_pic:
                save_fig(image_path=save_pic_path, fig_name=data_name)
                print(save_pic_path)

            if plot_pic:
                plt.show()
Esempio n. 2
0
    def change_point(self,
                     width: int,
                     cut_off: list,
                     custom_cost,
                     jump: int,
                     pen: float,
                     results_show: bool,
                     title=None,
                     save_path=None,
                     fig_name=None):
        '''                
        ----------------
        DESCRIPTION
        ----------------
        The purpose of the change point detection is to check whether there is a large enough sudden change 
        in a specific interval interval of the resistance signal.
        If there is a large enough change, it means that the explosion phenomenon has occurred during this welding.
        the algorithms of detection can be fund by this link:
        
        https://centre-borelli.github.io/ruptures-docs/index.html#documentation

        for the resistance data especially MDK2 this methode can be used to detective if a change point in selectarea
        if there is a change point, mean value before change point and after change point will be compared --> delta R
        else no change point delta R = 0
        because of material loss the dalta R musst bigger than 0, if the there is a chagne point but delta R < 0, 
        this situation has nothing to do with spritzer rarely occurs delta R can also be 0 
        and as usaual the resistance curve is going down with the time  
        ----------------
        PARAMETER
        ----------------
        width: int windows width 40
        cutoff: list [float, float], float: 0...1 1 means all data length will be selected [0.15, 0.45]
        custom_cost:  https://centre-borelli.github.io/ruptures-docs/costs/index.html
        jump: int subsample (one every jump points) 5
        pen:  float penalty value (>0) 2
        result_show : show image evaluation to displan the detective result
        title: the image title
        save_path: the path to save the result image
        fig_name: the image name
        ----------------
        RETURN
        ----------------
        delta_R: the Variation before and after the change point of resistance signal
        '''

        ab_R = self.R_data[round(len(self.valley_id) * cut_off[0]
                                 ):round(len(self.valley_id) *
                                         cut_off[1])].values

        c = custom_cost

        algo = rpt.Window(width=width, custom_cost=c,
                          jump=jump).fit_predict(ab_R, pen=2)

        if len(algo) >= 2:
            delta_R = np.mean(ab_R[:algo[0]]) - np.mean(ab_R[algo[0]:])
            if delta_R < 0:
                # delta_R can not less than 0 bescause the the resistance curve is going down with the time
                delta_R = 0
        else:
            delta_R = 0

        if results_show:
            rpt.display(ab_R, algo)
            if title != None:
                plt.title(title)
            if save_path and fig_name is not None:
                save_fig(image_path=save_path, fig_name=fig_name)
            plt.show()

        return delta_R
Esempio n. 3
0
            ax3.set_xlabel('Festerbreite',fontdict = font)
            ax3.set_title('Bias$^2$',fontdict = font)

            ax4 = fig.add_subplot(232)
            ax4.plot(EF_arr, Var,color = 'gray',linestyle = '--')
            ax4.scatter(EF_arr, Var, c=Var, cmap = cm.viridis)
            ax4.set_xlim(1,max(EF_arr))
            ax4.yaxis.get_major_formatter().set_powerlimits((0,1))
            # ax3.set_ylim(min(Var)*0.99,max(Var)*1.01)
            ax4.tick_params(axis='both', which='major', labelsize=12,direction='in')
            ax4.set_xlabel('Festerbreite',fontdict = font)
            ax4.set_title('Varianz',fontdict = font)

            ax5 = fig.add_subplot(233)
            ax5.plot(EF_arr, min_ab_l,color = 'gray',linestyle = '--')
            ax5.scatter(EF_arr, min_ab_l, c=min_ab_l, cmap = cm.viridis)
            ax5.set_xlim(1,max(EF_arr))
            ax5.yaxis.get_major_formatter().set_powerlimits((0,1))
            # ax4.set_ylim(min(min_ab_l)*0.99,max(min_ab_l)*1.01)
            ax5.tick_params(axis='both', which='major', labelsize=12,direction='in')
            ax5.set_xlabel('Festerbreite',fontdict = font )
            ax5.set_title('Abweichung',fontdict = font)

            fig.canvas.manager.window.move(0,0)
            plt.subplots_adjust(left=None, bottom=None, right=None, top=None,
                        wspace=None, hspace=0.3)
            save_fig(image_path = r_path,fig_name = 'Beste_Fensterbreite_einzel_2')
            plt.show()


Esempio n. 4
0
    index.remove(target_col)
    index_ranking = abs(
        corr_matrix.loc[index, target_col]).sort_values(ascending=False)
    val_ranking = sorted(corr_matrix.loc[index, target_col],
                         key=abs,
                         reverse=True)
    corr_ranking = pd.DataFrame(val_ranking,
                                columns=[target_col],
                                index=index_ranking.index)
    return corr_ranking


corr_ranking(all_data, 'MEDV').plot.bar()
plt.title('Korrelationskoeffizient zum Target')
plt.grid(axis='y')
figsave.save_fig(IMAGES_PATH, 'Korrelationskoeffizient zum Target')
plt.show()

# # split the data to traindata and test data
X_train, X_test, y_train, y_test = train_test_split(X_all_data,
                                                    y_all_targe,
                                                    test_size=test_size,
                                                    random_state=my_seed)
# data normalisation
scaler = StandardScaler()
X_train_nor = pd.DataFrame(scaler.fit_transform(X_train.values),
                           index=X_train.index,
                           columns=X_train.columns)
X_test_nor = pd.DataFrame(scaler.transform(X_test.values),
                          index=X_test.index,
                          columns=X_test.columns)
Esempio n. 5
0
ax6.set_yticks([])
ax6.set_title('Q = {}'.format(Q_l[11]), fontdict=font)

left, bottom, width, height = 0.3, 0.7, 0.2, 0.15
ax7 = fig.add_axes([left, bottom, width, height])
ax7.plot(t, w_U, label='OG', color='gray')
ax7.plot(t, filenames_list_all[Q_l[13]][0], label='filted', color='k')
ax7.set_xticks([])
ax7.set_yticks([])
ax7.set_title('Q = {}'.format(Q_l[13]), fontdict=font)

left, bottom, width, height = 0.5, 0.7, 0.2, 0.15
ax8 = fig.add_axes([left, bottom, width, height])
ax8.plot(t, w_U, label='OG', color='gray')
ax8.plot(t, filenames_list_all[Q_l[17]][0], label='filted', color='k')
ax8.set_xticks([])
ax8.set_yticks([])
ax8.set_title('Q = {}'.format(Q_l[17]), fontdict=font)

left, bottom, width, height = 0.7, 0.7, 0.2, 0.15
ax9 = fig.add_axes([left, bottom, width, height])
ax9.plot(t, w_U, label='OG', color='gray')
ax9.plot(t, filenames_list_all[Q_l[19]][0], label='Kalman', color='k')
ax9.set_xticks([])
ax9.set_yticks([])
# ax9.legend(prop = legend_properties,loc = 4 )
ax9.set_title('Q = {}'.format(Q_l[19]), fontdict=font)

save_fig(image_path=s_path, fig_name='Kalmanfilter_Q_3')
plt.show()
Esempio n. 6
0
fig, ax = plt.subplots(figsize=(5, 4))
width = 0.6
index = y.index
y_ = y.reset_index(drop=True)

ax.bar(y_.index, y_.values, width, color='gray')
ax.bar(y_.index[-1], y_.values[-1], width, color='darkred')
ax.set_ylim(0.7, 0.8)
ax.set_xticks(np.arange(0, 32, 5))
ax.set_ylabel('Korrelationskoeffizient', fontdict=font)
ax.set_xlabel('partielle Wärmemenge Index', fontdict=font)
ax.set_xticklabels(index[::5], fontdict=font)
ax.tick_params(axis='y', which='major', labelsize=12, direction='in')
ax.tick_params(axis='x', rotation=45, which='major', labelsize=12)
ax.scatter(0, 0, alpha=0, label='$Q_{i}$ - ges. Wärmemenge je 20 ms')
plt.legend(frameon=False, prop=prop)
save_fig(image_path='C:/DA/Code/pywt/images/MDK2/',
         fig_name='dQ_dw_2',
         reselution=200)
plt.show()

# fig, ax = plt.subplots(figsize=(15,10))
# ax = sn.heatmap(data_transposed.corr(),ax = ax,annot = True,linewidths=.5,cbar_kws= {'label': 'Korrlationskoeffizient','aspect':40,'pad':0.01})
# ax.figure.axes[-1].yaxis.label.set_size(14)
# ax.tick_params(labelsize = 10)
# ax.set_ylabel('Parameternummer', fontsize = 14)
# ax.set_xlabel('Parameternummer', fontsize = 14)
# # save_fig(image_path=s_path, fig_name='Korrelation_Q_dw_2')
# plt.show()
# print(data_transposed.corr())