Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #13

Merged
merged 5 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pliffy/estimate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import NamedTuple, Tuple, List
from pathlib import Path

from scipy.stats import t
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion pliffy/figure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .figure import Figure
from .figure_ab import FigureAB
from .figure_diff import FigureDiff
from .diff_axis import DiffAxCreator
from .diff_axis import DiffAxCreator
5 changes: 2 additions & 3 deletions pliffy/figure/diff_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
DIFF_X = 2.5
DIFF_WIDTH = 0.5

# TODO: Add tests


class DiffAxCreator:
"""Class to manage creation of floating diff axis
"""Class to create floating diff axis

Parameters
---------
Expand All @@ -34,6 +32,7 @@ class DiffAxCreator:
in data coordinates of the main ab_axis.

"""

def __init__(
self,
parent_figure: Subplot,
Expand Down
1 change: 1 addition & 0 deletions pliffy/figure/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class Figure:
"""Mixin class to add low-level plotting ability"""

def _remove_ax_spine(self, spine: Literal["top", "bottom", "left", "right"] = None):
self.ax.spines[spine].set_visible(False)

Expand Down
6 changes: 2 additions & 4 deletions pliffy/figure/figure_ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pliffy.figure import Figure
from pliffy import parser

# TODO: tests

WIDTH_HEIGHT_IN_INCHES = (8.2 / 2.54, 8.2 / 2.54)
EXTRA_Y_TICKS = 3

Expand Down Expand Up @@ -119,6 +119,4 @@ def _find_max_ytick(self, conservative_yticks: Tuple[float]) -> float:
return max_ytick

def _gen_optimised_yticks(self, min_ytick, max_ytick, ytick_step):
return tuple(
np.arange(min_ytick, max_ytick + ytick_step, ytick_step)
)
return tuple(np.arange(min_ytick, max_ytick + ytick_step, ytick_step))
3 changes: 1 addition & 2 deletions pliffy/figure/figure_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from pliffy.figure import Figure
from pliffy import parser

# TODO: tests


class FigureDiff(Figure):
"""Class to manage plotting Diff part of ABD figure
Expand All @@ -22,6 +20,7 @@ class FigureDiff(Figure):
NamedTuple containing parsed information related to saving figure

"""

def __init__(self, info: "parser.FigureInfoDiff", ax: Subplot, save: "parser.Save"):
self.info = info
self.ax = ax
Expand Down
18 changes: 14 additions & 4 deletions pliffy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
DIFF_XLIM = (0.0, 0.5)
JITTER_RANGE = 0.1

# TODO: add tests


def abd(info: "utils.PliffyInfoABD", estimates: "utils.ABD"):
"""Parse pliffy data and information to simplify plotting ABD figure"""
Expand Down Expand Up @@ -67,6 +65,7 @@ def _calc_jitter(info: "utils.PliffyInfoABD") -> float:

class Save(NamedTuple):
"""Helper namedtuple to store save-related details"""

name: str
yes_no: Literal[True, False]
path: Path
Expand All @@ -87,6 +86,7 @@ def _parse_save(info: "utils.PliffyInfoABD") -> Save:

class Xticks(NamedTuple):
"""Helper namedtuple to store xtick details"""

vals: Tuple[float, float, float] = tuple()
labels: Tuple[str, str, str] = tuple()

Expand All @@ -111,6 +111,7 @@ def _raw_format(color: str, marker: str, markersize: int, alpha: float) -> dict:

class Raw(NamedTuple):
"""Helper nametuple to store details for plotting raw data"""

data: List[float]
xval: float
jitter: float
Expand Down Expand Up @@ -157,6 +158,7 @@ def _parse_raw_abd(info: "utils.PliffyInfoABD", jitter: float) -> Tuple[Raw, Raw

class Mean(NamedTuple):
"""Helper namedtuple to store xy data and format details for mean"""

data: Tuple[float, float]
format_: dict

Expand All @@ -166,7 +168,9 @@ def _mean_format(color: str, marker: str, markersize: int) -> dict:
return {"color": color, "marker": marker, "markersize": markersize}


def _parse_mean_abd(info: "utils.PliffyInfoABD", estimates: "utils.ABD") ->Tuple[Mean, Mean, Mean]:
def _parse_mean_abd(
info: "utils.PliffyInfoABD", estimates: "utils.ABD"
) -> Tuple[Mean, Mean, Mean]:
"""Parse details and data to plot mean value"""
mean_a = Mean(
data=(ABD_XVALS.a, estimates.a.mean),
Expand All @@ -191,6 +195,7 @@ def _parse_mean_abd(info: "utils.PliffyInfoABD", estimates: "utils.ABD") ->Tuple

class CI(NamedTuple):
"""Helper namedtuple to store xy data and format details for CI"""

data: Tuple[Tuple[float, float], Tuple[float, float]]
format_: dict

Expand All @@ -200,7 +205,9 @@ def _ci_format(color: str, linewidth: int) -> dict:
return {"color": color, "linewidth": linewidth}


def _parse_ci_abd(info: "utils.PliffyInfoABD", estimates: "utils.ABD") -> Tuple[CI, CI, CI]:
def _parse_ci_abd(
info: "utils.PliffyInfoABD", estimates: "utils.ABD"
) -> Tuple[CI, CI, CI]:
"""Parse details and data to plot CI values"""
ci_a = CI(
data=((ABD_XVALS.a, ABD_XVALS.a), estimates.a.ci),
Expand All @@ -219,6 +226,7 @@ def _parse_ci_abd(info: "utils.PliffyInfoABD", estimates: "utils.ABD") -> Tuple[

class Paired(NamedTuple):
"""Helper namedtuple to store data and format details to plot paired lines"""

a: List[float]
b: List[float]
xvals: Tuple[float, float]
Expand Down Expand Up @@ -248,6 +256,7 @@ def _parse_paired_lines(info: "utils.PliffyInfoABD", jitter: float) -> Paired:

class FigureInfoAB(NamedTuple):
"""Helper namedtuple to hold data and details to plot AB part of figure"""

raw_a: "Raw"
raw_b: "Raw"
mean_a: "Mean"
Expand All @@ -265,6 +274,7 @@ class FigureInfoAB(NamedTuple):

class FigureInfoDiff(NamedTuple):
"""Helper namedtuple to hold data and details to plot diff part of figure"""

raw_diff: "Raw"
mean_diff: "Mean"
plot_raw_diff: Literal[True, False]
Expand Down
1 change: 0 additions & 1 deletion pliffy/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ def plot_abd(info: "utils.PliffyInfoABD", ax=None):
ab_ax = figure.FigureAB(ab_info, ax)
diff_ax = figure.DiffAxCreator(ab_ax, info, diff_info).diff_ax()
figure.FigureDiff(diff_info, diff_ax, save)

56 changes: 29 additions & 27 deletions pliffy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ABD(NamedTuple):
diff: Union[str, int, float, "estimate.Estimates"] = None

def __repr__(self):
return f'ABD(a={repr(self.a)}, b={repr(self.b)}, diff={repr(self.diff)})'
return f"ABD(a={repr(self.a)}, b={repr(self.b)}, diff={repr(self.diff)})"


class PliffyInfoABD(NamedTuple):
Expand Down Expand Up @@ -48,29 +48,31 @@ class PliffyInfoABD(NamedTuple):
show: Literal[True, False] = True

def __repr__(self):
return f'PliffyInfoABD(\n' \
f'\tdata_a={repr(self.data_a)},\n' \
f'\tdata_b={repr(self.data_b)},\n' \
f'\tci_percentage={repr(self.ci_percentage)},\n' \
f'\tdesign={repr(self.design)},\n' \
f'\tmeasure_units={repr(self.measure_units)},\n' \
f'\txtick_labels={repr(self.xtick_labels)},\n' \
f'\tdecimals={repr(self.decimals)},\n' \
f'\tplot_name={repr(self.plot_name)},\n' \
f'\tsave={repr(self.save)},\n' \
f'\tsave_path={repr(self.save_path)},\n' \
f'\tsave_type={repr(self.save_type)},\n' \
f'\tdpi={repr(self.dpi)},\n' \
f'\tmarker={repr(self.marker)},\n' \
f'\tmarker_color={repr(self.marker_color)},\n' \
f'\tsummary_marker_size={repr(self.summary_marker_size)},\n' \
f'\traw_marker_size={repr(self.raw_marker_size)},\n' \
f'\traw_marker_transparency={repr(self.raw_marker_transparency)},\n' \
f'\tpaired_data_joining_lines={repr(self.paired_data_joining_lines)},\n' \
f'\tpaired_data_line_color={repr(self.paired_data_line_color)},\n' \
f'\tpaired_line_transparency={repr(self.paired_line_transparency)},\n' \
f'\tpaired_data_plot_raw_diff={repr(self.paired_data_plot_raw_diff)},\n' \
f'\tci_line_width={repr(self.ci_line_width)},\n' \
f'\tfontsize={repr(self.fontsize)},\n' \
f'\tshow={repr(self.show)},\n' \
')'
return (
f"PliffyInfoABD(\n"
f"\tdata_a={repr(self.data_a)},\n"
f"\tdata_b={repr(self.data_b)},\n"
f"\tci_percentage={repr(self.ci_percentage)},\n"
f"\tdesign={repr(self.design)},\n"
f"\tmeasure_units={repr(self.measure_units)},\n"
f"\txtick_labels={repr(self.xtick_labels)},\n"
f"\tdecimals={repr(self.decimals)},\n"
f"\tplot_name={repr(self.plot_name)},\n"
f"\tsave={repr(self.save)},\n"
f"\tsave_path={repr(self.save_path)},\n"
f"\tsave_type={repr(self.save_type)},\n"
f"\tdpi={repr(self.dpi)},\n"
f"\tmarker={repr(self.marker)},\n"
f"\tmarker_color={repr(self.marker_color)},\n"
f"\tsummary_marker_size={repr(self.summary_marker_size)},\n"
f"\traw_marker_size={repr(self.raw_marker_size)},\n"
f"\traw_marker_transparency={repr(self.raw_marker_transparency)},\n"
f"\tpaired_data_joining_lines={repr(self.paired_data_joining_lines)},\n"
f"\tpaired_data_line_color={repr(self.paired_data_line_color)},\n"
f"\tpaired_line_transparency={repr(self.paired_line_transparency)},\n"
f"\tpaired_data_plot_raw_diff={repr(self.paired_data_plot_raw_diff)},\n"
f"\tci_line_width={repr(self.ci_line_width)},\n"
f"\tfontsize={repr(self.fontsize)},\n"
f"\tshow={repr(self.show)},\n"
")"
)
Loading