Commit f2eeb71f authored by Félix Hartmann's avatar Félix Hartmann
Browse files

Full support of Lagrangian marks in the "Angles and curvatures" floating window.

parent 52766cb9
......@@ -117,6 +117,7 @@ tk_list_images = None # Contient l'objet TK listbox qui accueil les noms des ima
tk_toplevel_listimages = None # Contient la fenetre TK qui contient la list des images
hdf5file = None #Contient l'emplacement du fichier hdf5 qui contient les données
PAS_TRAITEMENT = 0.3
CURVATURE_AVERAGING_LENGTH = 2 # Length (in cm) of the zone over which the curvature is averaged
tiges_names = [] #Contient un nom pour les tiges
def reset_graph_data():
......@@ -998,23 +999,30 @@ def find_mark_tige_intersection(mark):
continue
if do_intersect(A, B, C, D):
mark["tige"] = tige
mark["intersection_index"] = i
# Retrieve tige ids from the h5 file
hdf_tiges_id = h5store.get_tiges_indices(hdf5file)
hdfid = hdf_tiges_id[tige]
_, _, s, _, angles, _, _, _ = load_postprocessed_data(hdf5file, hdfid)
smoothed_x, smoothed_y, s, _, angles, _, _, _ = \
load_postprocessed_data(hdf5file, hdfid)
s, angles = s[image], angles[image]
# mark-tige intersection coordinates
intersection_point = array([smoothed_x[image, i], smoothed_y[image, i]])
base_point = array([smoothed_x[image, 0], smoothed_y[image, 0]])
intersection_point_from_base = intersection_point - base_point
averaging_zone = 80 # in pixels
if scale_cmpix is not None:
s *= scale_cmpix
averaging_zone = int(round(2 / scale_cmpix)) # 2cm
averaging_points = int(round(averaging_zone / PAS_TRAITEMENT))
averaging_zone = int(round(CURVATURE_AVERAGING_LENGTH / scale_cmpix))
intersection_point *= scale_cmpix
intersection_point_from_base *= scale_cmpix
mark["s"] = s[i]
mark["intersection_point"] = intersection_point
mark["intersection_point_from_base"] = intersection_point_from_base
W = int(4 * round(tiges_data.diam[cur_tige].mean() / PAS_TRAITEMENT))
curvature = get_tige_curvature(angles, W, cutoff=15, pas=PAS_TRAITEMENT,
scale_cmpix=scale_cmpix)
# print("Curvature averaged over %i points."%averaging_points)
# print("Between points {} and {}".format(i, i+averaging_points))
# print("Total of %i points."%len(curvature))
averaging_points = int(round(averaging_zone / PAS_TRAITEMENT))
if i + averaging_points <= len(curvature):
mean_curvature = mean(curvature[i:i+averaging_points])
mark["curvature"] = curvature[i]
......@@ -1043,6 +1051,7 @@ def plot_marks(force_redraw=False, ratio=1):
name = mark["name"]
tige = mark['tige']
image = mark['image']
time = mark.get("image")
start, end = mark["start"], mark["end"]
if len(mark_plt) <= i:
......@@ -1060,10 +1069,9 @@ def plot_marks(force_redraw=False, ratio=1):
[start[1] * ratio, end[1] * ratio])
text = "%i\n"%(name)
if get_photo_datetime.get() and dtphoto != []:
if time is not None:
# Time in minutes
tps = int((dtphoto[image] - dtphoto[0]).total_seconds() / 60.)
text += "%imin"%tps
text += "%imin"%time
else:
# Image number
text += "i%i"%(image+1)
......@@ -1081,7 +1089,8 @@ def plot_marks(force_redraw=False, ratio=1):
text += "\n{:.2f}{}".format(s, unit)
# text += "\n{:.2e}{}".format(curvature, inv_unit)
text += "\n{:.2e}{}".format(mean_curvature, inv_unit)
if mean_curvature is not None:
text += "\n{:.2e}{}".format(mean_curvature, inv_unit)
if mark_text[i] is None:
mark_text[i] = ax.text(start[0] * ratio, start[1] * ratio, text, color=color)
......@@ -2940,39 +2949,18 @@ def show_angle_and_curvature(tige_id=None):
tname = h5store.get_tiges_names(hdf5file, tige_hdf_id)
# Récuperation des données dont on a besoin
_, _, s, _, angle, _, _, lines = load_postprocessed_data(hdf5file, tige_hdf_id)
# Infos sur les marques lagrangiennes
images, names, marks_s = [], [], []
for mark in marks:
image, name, mark_s = mark["image"], mark["name"], mark["s"]
images.append(image)
if get_photo_datetime.get() and dtphoto != []:
# Time in minutes
t = int((dtphoto[image] - dtphoto[0]).total_seconds() / 60.)
name = "mark " + str(name) + " (t = %imin)"%t
else:
# Image number
name = "mark " + str(name) + " (t = %i)"%image
names.append(name)
marks_s.append(mark_s)
if cur_image not in images:
images.append(cur_image)
if get_photo_datetime.get() and dtphoto != []:
# Time in minutes
t = int((dtphoto[cur_image] - dtphoto[0]).total_seconds() / 60.)
name = "t = %imin"%t
else:
# Image number
name = "t = %i"%cur_image
names.append(name)
_, _, s, _, angles, _, _, lines = load_postprocessed_data(hdf5file, tige_hdf_id)
# Scaling
scale_cmpix = h5store.get_pixelscale(hdf5file)
unit, inv_unit = "(pix)", r"(pix$^{-1}$)"
nb_averaging_points = 80 # default
if scale_cmpix is not None:
unit, inv_unit = "(cm)", r"(cm$^{-1}$)"
s *= scale_cmpix
lines *= scale_cmpix
nb_averaging_points = int(round(CURVATURE_AVERAGING_LENGTH
/ (scale_cmpix * PAS_TRAITEMENT)))
# Size of the averaging window
W = int(4 * round(tiges_data.diam[cur_tige].mean() / PAS_TRAITEMENT))
......@@ -2996,42 +2984,93 @@ def show_angle_and_curvature(tige_id=None):
axCurvature.set_ylabel("Courbure %s"%inv_unit)
axCurvature.grid(True)
for i, (image, name) in enumerate(zip(images, names)):
s_i, angle_i, lines_i = s[image], angle[image], lines[image]
for mark in marks:
image, name = mark["image"], mark["name"]
mark_index = mark["intersection_index"]
time = mark.get("time")
if time is not None:
# Time in minutes
name = "mark " + str(name) + " (t = %imin)"%time
else:
# Image number
name = "mark " + str(name) + " (t = %i)"%image
s_i, angles_i, lines_i = s[image], angles[image], lines[image]
x, y = lines_i[:, 0], lines_i[:, 1]
# Enlève les valeurs non-renseignée
imax = find(angle_i.mask == False).max()
# Remove non-valid values
imax = find(angles_i.mask == False).max()
cutoff = 15 # ça c'est une rustine, et je ne comprends pas le problème profond
angle_i = angle_i[:imax-cutoff]
angles_i = angles_i[:imax-cutoff]
s_i = s_i[:imax-cutoff]
x = x[:imax-cutoff]
y = y[:imax-cutoff]
smooth_angle = moving_avg_cookbook(angle_i, window_len=W)
curvature = gradient(angle_i, PAS_TRAITEMENT)
smooth_curvature = gradient(smooth_angle, PAS_TRAITEMENT)
# Scaling
if scale_cmpix is not None:
x, y = x*scale_cmpix, y*scale_cmpix
s_i *= scale_cmpix
angle_i = rad2deg(angle_i)
smooth_angle = rad2deg(smooth_angle)
smooth_angles = moving_avg_cookbook(angles_i, window_len=W)
smooth_curvatures = gradient(smooth_angles, PAS_TRAITEMENT)
smooth_angles = rad2deg(smooth_angles)
if angle_0_360.get():
angle_i = convert_angle(angle_i)
smooth_angle = convert_angle(smooth_angle)
# axAngle.plot(s, angle, '-', color=tiges_colors[cur_tige], lw=2)
l, = axAngle.plot(s_i, smooth_angle, '-', lw=1, label=name)
axCurvature.plot(s_i, smooth_curvature, '-', lw=1, label=name)
angles = convert_angle(angles)
smooth_angles = convert_angle(smooth_angles)
l, = axAngle.plot(s_i, smooth_angles, '-', label=name)
color = l.get_color()
# Big point where the mark is placed
axAngle.plot(s_i[mark_index], smooth_angles[mark_index], 'o', color=color, ms=4)
axCurvature.plot(s_i, smooth_curvatures, '--', color=color, label=name)
# Big point where the mark is placed
axCurvature.plot(s_i[mark_index], smooth_curvatures[mark_index],
'o', color=color, ms=4)
# The averaging zone (used for computing mean curvature) as a continuous line
averaging_zone = slice(mark_index, mark_index+nb_averaging_points)
axCurvature.plot(s_i[averaging_zone], smooth_curvatures[averaging_zone], '-',
color=color)
profile = mpl.Line2D(x, y)
profile.set_linestyle("-")
profile.set_linewidth(1)
profile.set_color(l.get_color())
profile.set_color(color)
axProfile.add_line(profile)
# Big point where the mark is placed
xy_mark = mark["intersection_point_from_base"]
axProfile.plot(xy_mark[0], xy_mark[1], 'o', color=color, ms=4)
# The averaging zone (used for computing mean curvature) as a thicker line
averaging_line = mpl.Line2D(x[averaging_zone], y[averaging_zone])
averaging_line.set_linestyle("-")
averaging_line.set_linewidth(2)
averaging_line.set_color(color)
axProfile.add_line(averaging_line)
if cur_image not in [mark["image"] for mark in marks]:
if get_photo_datetime.get() and dtphoto != []:
time = int((dtphoto[cur_image] - dtphoto[0]).total_seconds() / 60.)
name = "t = %imin"%time # time in minutes
else:
name = "t = %i"%cur_image # image number
s_i, angles_i, lines_i = s[cur_image], angles[cur_image], lines[cur_image]
x, y = lines_i[:, 0], lines_i[:, 1]
# Remove non-valid values
imax = find(angles_i.mask == False).max()
cutoff = 15 # ça c'est une rustine, et je ne comprends pas le problème profond
angles_i = angles_i[:imax-cutoff]
s_i = s_i[:imax-cutoff]
x = x[:imax-cutoff]
y = y[:imax-cutoff]
smooth_angles = moving_avg_cookbook(angles_i, window_len=W)
smooth_curvatures = gradient(smooth_angles, PAS_TRAITEMENT)
smooth_angles = rad2deg(smooth_angles)
if angle_0_360.get():
angles_i = convert_angle(angles_i)
smooth_angles = convert_angle(smooth_angles)
l, = axAngle.plot(s_i, smooth_angles, '-', lw=1, label=name)
color = l.get_color()
axCurvature.plot(s_i, smooth_curvatures, '-', color=color, lw=1, label=name)
profile = mpl.Line2D(x, y)
profile.set_linestyle("-")
profile.set_linewidth(1)
profile.set_color(color)
axProfile.add_line(profile)
axProfile.axis('equal')
......@@ -3885,6 +3924,11 @@ if __name__ == '__main__':
mark = {"name": len(marks) + 1,
"image": cur_image,
"start": xy_scaled}
if get_photo_datetime.get() and dtphoto != []:
# Time in minutes
t = int((dtphoto[cur_image] - dtphoto[0]).total_seconds()
/ 60.)
mark["time"] = t
marks.append(mark)
nbclick += 1
ax.plot(x, y, 'b+')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment