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

Style refactoting.

parent 7fb58e6c
......@@ -2,12 +2,10 @@
# -*- coding: utf-8 -*-
"""
Module containing functions for visualizing a CellFile object and its
evolution.
Module containing functions for visualizing a CellFile object and its evolution.
"""
from __future__ import (unicode_literals, absolute_import,
division, print_function)
from __future__ import unicode_literals, absolute_import, division, print_function
import numpy as np
from math import factorial
......@@ -20,10 +18,10 @@ from matplotlib.patches import Arrow
def savitzky_golay(y, window_size, order, deriv=0, rate=1):
r"""Smooth (and optionally differentiate) data with a Savitzky-Golay filter.
The Savitzky-Golay filter removes high frequency noise from data.
It has the advantage of preserving the original shape and
features of the signal better than other types of filtering
approaches, such as moving averages techniques.
The Savitzky-Golay filter removes high frequency noise from data. It has the advantage
of preserving the original shape and features of the signal better than other types of
filtering approaches, such as moving averages techniques.
Parameters
----------
......@@ -45,10 +43,9 @@ def savitzky_golay(y, window_size, order, deriv=0, rate=1):
Notes
-----
The Savitzky-Golay is a type of low-pass filter, particularly
suited for smoothing noisy data. The main idea behind this
approach is to make for each point a least-square fit with a
polynomial of high order over a odd-sized window centered at
The Savitzky-Golay is a type of low-pass filter, particularly suited for smoothing
noisy data. The main idea behind this approach is to make for each point a
least-square fit with a polynomial of high order over a odd-sized window centered at
the point.
Examples
......@@ -99,7 +96,7 @@ def savitzky_golay(y, window_size, order, deriv=0, rate=1):
def resample_uniformly(X, Y, dx=None):
""""""
"""Resample array Y based on X, but with constant stepwidth."""
if dx is None:
# Finest sampling by default.
dx = min(X[1:] - X[:-1])
......@@ -163,8 +160,6 @@ def init_cell_file_drawing(
axis.spines['top'].set_visible(False)
axis.set_xlim(*xlim)
axis.set_ylim(*ylim)
# axis.set_xlabel("Distance from cambial initials" + r" ($\mu m$)",
# size=fontsize)
axis.set_xlabel(r"$\mu m$", size=fontsize)
ylabel = "Signal concentration"
if fixed_cambium_right:
......@@ -300,9 +295,9 @@ def fill_cell_file_drawing(
# an arrow on each membrane
if show_transport_polarity == "each":
for x_pos in rectangle_positions[1:]:
arrows.append(Arrow(x_pos - polarity * arrow_stem/2,
y_pos, polarity * arrow_stem, 0,
width=arrow_stem, color=color))
arrows.append(Arrow(x_pos - polarity * arrow_stem/2, y_pos,
polarity * arrow_stem, 0, width=arrow_stem,
color=color))
# an arrow on one well-selected membrane
elif show_transport_polarity == "one":
zone_1, zone_2, zone_3 = cf.get_cell_zones_anatomy(time)
......@@ -312,18 +307,17 @@ def fill_cell_file_drawing(
cell_index = nb_cells // 2
x_pos = rectangle_positions[cell_index]
arrows.append(Arrow(x_pos - polarity * arrow_stem/2, y_pos,
polarity * arrow_stem, 0,
width=arrow_width, color=color))
polarity * arrow_stem, 0, width=arrow_width,
color=color))
# an arrow on given membranes
else:
if not np.iterable(show_transport_polarity):
show_transport_polarity = [show_transport_polarity]
for index in show_transport_polarity:
x_pos = rectangle_positions[index]
arrows.append(Arrow(x_pos - polarity * arrow_stem/2,
y_pos,
polarity * arrow_stem, 0,
width=arrow_width, color=color))
arrows.append(Arrow(x_pos - polarity * arrow_stem/2, y_pos,
polarity * arrow_stem, 0, width=arrow_width,
color=color))
for patch in rects + arrows:
axis.add_patch(patch)
# Add a wider line at the boundary of the file so that it is visible.
......@@ -335,8 +329,7 @@ def fill_cell_file_drawing(
if mechanism == "uniform diffusion":
axis.plot(x, concentrations, colors[i % nb_signals] + "o")
else:
axis.plot(x_cell_centers, concentrations,
colors[i % nb_signals] + "o")
axis.plot(x_cell_centers, concentrations, colors[i % nb_signals] + "o")
if cell_concentrations is not None:
conc_operator = cf.compute_concentration_operator(nodes_per_cell)
cell_conc = cf.get_cell_concentrations(u, conc_operator)
......@@ -345,25 +338,23 @@ def fill_cell_file_drawing(
axis.plot(x_cell_centers, C, colors[i % nb_signals] + "o")
if threshold_list is not None:
for threshold in threshold_list:
threshold_line = Line2D(xlim, (threshold, threshold),
color='darkviolet')
threshold_line = Line2D(xlim, (threshold, threshold), color='darkviolet')
threshold_line.set_linewidth(2*threshold_line.get_linewidth())
axis.add_line(threshold_line)
if strain_rates is not None:
S = 1.05 * t_diameter * strain_rates
axis.plot(x_cell_centers, S, 'ko')
if cell_indices:
display_cell_indices(axis, x_cell_centers, t_diameter,
fontsize=fontsize)
display_cell_indices(axis, x_cell_centers, t_diameter, fontsize=fontsize)
if date:
day = cf.date_list[time].date()
daystr = day.strftime("%d %B").decode('utf8')
axis.annotate(
daystr,
xy=(.5, .95), xycoords='axis fraction',
fontsize="medium",
horizontalalignment='center',
verticalalignment='center')
daystr,
xy=(.5, .95), xycoords='axis fraction',
fontsize="medium",
horizontalalignment='center',
verticalalignment='center')
return axis
......@@ -404,8 +395,7 @@ def draw_cell_file(
signal : bool, optional, default: True
If True (default), signal concentrations are drawn.
transport_polarity : [None, "each", "one", int], optional, default: "one"
If not None, the polarity of a transport mechanism is pictured with
arrows.
If not None, the polarity of a transport mechanism is pictured with arrows.
"each": an arrow on each membrane
"one": an arrow on a well-selected membrane
int: index of the cell where the arrow is placed
......@@ -415,16 +405,15 @@ def draw_cell_file(
arrow_width : float, optional, default: 0.25
Stem width of the arrows picturing transport polarity.
cell_concentrations : list of ints, optional, default: None
Indices of signals whose cell concentrations (mean concentrations
within a cell) will be drawn.
Indices of signals whose cell concentrations (mean concentrations within a cell)
will be drawn.
thresholds : list, optional, default: None
List of thresholds (division_threshold, enlargement_threshold...)
to be drawn as 2DLines.
List of thresholds (division_threshold, enlargement_threshold...) to be drawn as
2DLines.
strain_rates : Boolean, optional, default: False
If True, plots strain rates.
colored_zones : Boolean, optional, default: True
If True, cells are filled with colors depending on the zone they
belong to.
If True, cells are filled with colors depending on the zone they belong to.
cell_indices : Boolean, optional, default: False
If True, the index of each cell is displayed on it.
tangential_diameter : float, optional, default: None
......@@ -447,18 +436,18 @@ def draw_cell_file(
figsize : tuple of two floats, optional, default: None
Size of the figure (figsize argument in plt.subplot).
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
axis : Axis instance, default: None
If not None, axis is used for plotting and is returned as second
element of the output tuple.
If not None, axis is used for plotting and is returned as second element of the
output tuple.
save : bool, optional, default: False
If True, the output figure is saved.
base_name : str, optional, default: ""
Base name (path) of the file if the figure is saved.
Output : If the 'save' parameter evaluates to False, returns a Figure
instance and an Axis instance.
Output : If the 'save' parameter evaluates to False, returns a Figure instance and an
Axis instance.
"""
cf = cell_file
if axis is None:
......@@ -491,24 +480,23 @@ def draw_cell_file(
else:
S = None
axis = fill_cell_file_drawing(
cf,
axis,
time,
xlim,
signal=signal,
show_transport_polarity=show_transport_polarity,
arrow_stem=arrow_stem,
arrow_width=arrow_width,
cell_concentrations=cell_concentrations,
threshold_list=threshold_list,
colored_zones=colored_zones,
cell_indices=cell_indices,
tangential_diameter=tangential_diameter,
strain_rates=S,
date=date,
colors=colors,
linewidth=linewidth
)
cf,
axis,
time,
xlim,
signal=signal,
show_transport_polarity=show_transport_polarity,
arrow_stem=arrow_stem,
arrow_width=arrow_width,
cell_concentrations=cell_concentrations,
threshold_list=threshold_list,
colored_zones=colored_zones,
cell_indices=cell_indices,
tangential_diameter=tangential_diameter,
strain_rates=S,
date=date,
colors=colors,
linewidth=linewidth)
figure.tight_layout()
if save:
figure.savefig("{0}{1}.png".format(base_name, time))
......@@ -700,8 +688,7 @@ def draw_extruded_cell_file(
final_nb_nodes_per_cells, final_x, final_D, final_u = \
cf.values_for_drawing(t)
# Cell borders are drawn as lines.
boundaries = match_cell_boundaries_within_an_extrusion_layer(initial_D,
final_D)
boundaries = match_cell_boundaries_within_an_extrusion_layer(initial_D, final_D)
initial_left_boundary, final_left_boundary = boundaries[0]
lines.append(Line2D([initial_left_boundary, final_left_boundary],
[y_pos, y_pos+dy],
......@@ -749,8 +736,7 @@ def init_diameter_plot(
figure=None,
axis=None):
"""
Create and return a Figure object and an Axes object ready for plotting
the diameters.
Create and return a Figure object and an Axes object ready for plotting the diameters.
Parameters
----------
......@@ -759,11 +745,11 @@ def init_diameter_plot(
ylim : tuple of two floats
Limits of the y-axis: ax1.set_ylim(*ylim).
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
axis : Axis instance, default: None
If not None, axis is used for plotting and is returned as second
element of the output tuple.
If not None, axis is used for plotting and is returned as second element of the
output tuple.
See the plot_diameters function for definitions of other parameters.
......@@ -855,11 +841,11 @@ def plot_diameters(
fixed_cambium_right : Boolean, optional, default: True
If True, the cambium is fixed on the right side of the plot.
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
axis : Axis instance, default: None
If not None, axis is used for plotting and is returned as second
element of the output tuple.
If not None, axis is used for plotting and is returned as second element of the
output tuple.
Outputs : figure, axis
"""
......@@ -874,17 +860,17 @@ def plot_diameters(
if ylim is None:
ylim = (0, cell_file.diameters(time).max() + 4)
figure, axis = init_diameter_plot(
xlim, ylim,
fontsize=fontsize,
figsize=figsize,
figure=figure,
axis=axis)
xlim, ylim,
fontsize=fontsize,
figsize=figsize,
figure=figure,
axis=axis)
axis = fill_diameter_plot(
axis,
cell_file,
time,
fixed_cambium_right=fixed_cambium_right,
color=color, marker=marker, linestyle=linestyle, linewidth=linewidth)
axis,
cell_file,
time,
fixed_cambium_right=fixed_cambium_right,
color=color, marker=marker, linestyle=linestyle, linewidth=linewidth)
return figure, axis
# End of diameter plotting utilities.
......@@ -900,8 +886,7 @@ def init_strain_plot(
figsize=None,
figure=None):
"""
Create and return a Figure object and an Axes object ready for plotting
the strains.
Create and return a Figure object and an Axes object ready for plotting the strains.
Parameters
----------
......@@ -910,8 +895,8 @@ def init_strain_plot(
ylim : tuple of two floats
Limits of the y-axis: ax1.set_ylim(*ylim).
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
See the plot_strains function for definitions of other parameters.
......@@ -1002,15 +987,15 @@ def plot_strains(
if xlim is None:
xlim = (0, nb_cells + 1)
fig, axis = init_strain_plot(
xlim,
fontsize=fontsize,
figsize=figsize)
xlim,
fontsize=fontsize,
figsize=figsize)
axis = fill_strain_plot(
axis,
cell_file,
time,
fixed_cambium_right=fixed_cambium_right,
color=color, marker=marker, linestyle=linestyle, linewidth=linewidth)
axis,
cell_file,
time,
fixed_cambium_right=fixed_cambium_right,
color=color, marker=marker, linestyle=linestyle, linewidth=linewidth)
return fig
# End of strain plotting utilities.
......@@ -1053,11 +1038,11 @@ def plot_total_length(
figsize : tuple of two floats, optional, default: None
Size of the figure (figsize argument in plt.subplot).
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
axis : Axis instance, default: None
If not None, axis is used for plotting and is returned as second
element of the output tuple.
If not None, axis is used for plotting and is returned as second element of the
output tuple.
Outputs : figure, axis
"""
......@@ -1121,8 +1106,8 @@ def plot_total_speed(
figsize : tuple of two floats, optional, default: None
Size of the figure (figsize argument in plt.subplot).
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
Outputs : figure, axis
"""
......@@ -1205,8 +1190,8 @@ def plot_cell_accumulation(
figsize : tuple of two floats, optional, default: None
Size of the figure (figsize argument in plt.subplot).
figure : Figure instance, default: None
If not None, figure is used for creating Axes, and is return as first
element of the output tuple.
If not None, figure is used for creating Axes, and is return as first element of
the output tuple.
Outputs : figure, axis
"""
......@@ -1265,8 +1250,8 @@ def plot_cell_numbers(
number_data : tuple of three 1-D arrays, optional, default: None
Cell number values for the y axis.
smoothing : Boolean, default: False
If True, the cell number values for the number_data parameter are
smoothed using the Savitzky-Golay filter.
If True, the cell number values for the number_data parameter are smoothed using
the Savitzky-Golay filter.
window_size : int, default:31
Smoothing parameter, see the savitzky_golay function docstring.
order : int, default:1
......@@ -1285,8 +1270,8 @@ def plot_cell_numbers(
If not None, figure is used for creating Axes, and is returned as first
element of the output tuple.
axis : Axis instance, default: None
If not None, axis is used for plotting and is returned as second
element of the output tuple.
If not None, axis is used for plotting and is returned as second element of the
output tuple.
Outputs : figure, ax1
"""
......
Markdown is supported
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