diff --git a/args.py b/args.py index 7298bce485a494e520475261e105b741d87960d8..32eeed42aa9818719019d328dd3c117fb01bd849 100644 --- a/args.py +++ b/args.py @@ -110,9 +110,7 @@ def fetch_inputs(): # verifying arguments try: assert (os.path.exists(outputs)), ( - f"\nInputError: Could not find dir '{outputs}'." - "\n\tCreate a folder that will contain outputs," - " or type in an existing folder with `-out folder_name`.") + f"\nInputError: Could not find dir '{outputs}'.") assert (os.path.exists(explore)), ( f"\nInputError: Could not find dir '{explore}'.") if modify_file: diff --git a/line_clicker/line_clicker.py b/line_clicker/line_clicker.py index 103db70fcf7d583c4ad81eba03345e937ccd02b0..8b689089580bad3b305d93cc1501ee9d48c347d4 100644 --- a/line_clicker/line_clicker.py +++ b/line_clicker/line_clicker.py @@ -3,6 +3,7 @@ Add default parameters for keys and mousebutton so it can be customized """ ##### IMPORTATIONS ###### +import warnings import numpy as np import matplotlib.pyplot as plt from matplotlib.backend_bases import MouseButton @@ -11,7 +12,7 @@ import matplotlib.lines as mlines from scipy.interpolate import interp1d ##### FUNCTIONS ##### -def to_curve(x, y, kind): +def to_curve(x, y, kind="quadratic"): """ A function to compute a curvy line between two points. It interpolates a line with 100 points. @@ -36,12 +37,14 @@ def to_curve(x, y, kind): yi : numpy array List of the coordinates of the curve on y-axis. """ - i = np.arange(len(x)) - interp_i = np.linspace(0, i.max(), 100 * i.max()) + y = y[np.argsort(x)] + x = np.sort(x) - xi = interp1d(i, x, kind=kind)(interp_i) - yi = interp1d(i, y, kind=kind)(interp_i) + f = interp1d(x,y, kind=kind) + + xi = np.linspace(x.min(), x.max(), 100 * (len(x)-1)) + yi = f(xi) return xi, yi @@ -360,7 +363,16 @@ class clicker(object): None : updates coords, figure_lines, figure. """ if self.legend_labels[self.current_line] in list(self.coords.keys()): - self.coords[self.legend_labels[self.current_line]] += [[x, y]] + # does this point already exists ? + if [x,y] in self.coords[self.legend_labels[self.current_line]]: + warnings.warn("This point already exists!", UserWarning, stacklevel=2) + else: + # where should it be inserted ? + here = np.where(np.array(self.coords[self.legend_labels[self.current_line]])[:,0] > x)[0] + if len(here): + self.coords[self.legend_labels[self.current_line]].insert(here[0] ,[x, y]) + else: + self.coords[self.legend_labels[self.current_line]] += [[x, y]] else: self.coords[self.legend_labels[self.current_line]] = [[x, y]] @@ -392,7 +404,7 @@ class clicker(object): curves = to_curve( np.array(self.coords[legend_label])[:,0], np.array(self.coords[legend_label])[:,1], - kind="quadratic") + kind=self.bspline) self.figure_bsplines += [mlines.Line2D(curves[0], curves[1], label=legend_label, color=self.colors[idx%len(self.colors)],