def remove_beat( beatdf: pd.DataFrame, ekgdf: pd.DataFrame, tochangedf: pd.DataFrame, fig: plt.figure, lim: Tuple = None, ) -> pd.DataFrame: """ remove a beat coordinate from the figure to the tochangedf['toRemove'] Parameters ---------- beatdf : pd.Dataframe beat position (point based location : p_locs) ekgdf : pd.Dataframe waves data (wekg_lowpass). tochangedf : pd.Dataframe the beat to add or remove (point based toAppend & toRemove) fig : plt.Figure the figure to get the location. lim : TYPE, optional (default is None) ptBasedLim optional to give it manually yscale : TYPE, optional (default is 1) amplitude mutliplication factor for detection. Returns ------- tochangedf : pd.DataFrame incremented changedf (pt location). locate the beat in the figure, append to a dataframe['toRemove'] 0.: if not present build a dataframe: >>> to_change_df = pd.DataFrame(columns=['toAppend', 'toRemove']) 1.: locate the extra beat in the figure (cf plot_beats()) and zoom to observe only a negative peak 2.: call the function::: >>> to_change_df = remove_beat(beatdf, ekgdf, tochangedf, fig) -> the beat parameters will be added the dataFrame .(in the end of the manual check, update the beat_df - first : save beat_df and to_change_df - second : run >>> beat_df = update_beat_df()) """ # find the limits of the figure if lim is None: lims = fig.get_axes()[0].get_xlim() lim = (int(lims[0]), int(lims[1])) position = beatdf.p_loc[(lim[0] < beatdf.p_loc) & (beatdf.p_loc < lim[1])] iloc = position.index.values[0] ptloc = position.values # pt values of the peak if len(ptloc) > 1: print("several beats detected") return tochangedf pos = int(ptloc[0]) # array -> value # mark on the graph p_loc, y_loc = beatdf.loc[iloc, ["p_loc", "y_loc"]] p_loc = int(p_loc) ax = fig.get_axes()[0] ax.plot(p_loc, y_loc, "Xr") # mark to remove onepoint_beatdf = beatdf.loc[iloc].copy() onepoint_beatdf["action"] = "remove" tochangedf = tochangedf.append(onepoint_beatdf, ignore_index=True) # beatdf.loc[pos, ['y_loc']] = np.NaN print("position is ", pos) return tochangedf