Skip to content
Snippets Groups Projects
Commit 6c450291 authored by Loic-Lenof's avatar Loic-Lenof
Browse files

Sorting points

+added sorting of points

=> points can be added anywhere on a line
parent 29bfa794
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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,6 +363,15 @@ class clicker(object):
None : updates coords, figure_lines, figure.
"""
if self.legend_labels[self.current_line] in list(self.coords.keys()):
# 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)],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment