From 1a755de538abdd77f9cb797373fbe94d4dde51d1 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Tue, 17 Jan 2017 14:55:31 +0000 Subject: [PATCH 1/9] Constraint: Fix indentation PEP8 doesn't seem to be clear on how this should be indented. However I feel pretty sure that breaking lines inside a destructuring expression (i.e. after the comma here) would be confusing to the majority of programmers. --- trappy/plotter/Constraint.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/trappy/plotter/Constraint.py b/trappy/plotter/Constraint.py index 1a5adc9..3f6fa9a 100644 --- a/trappy/plotter/Constraint.py +++ b/trappy/plotter/Constraint.py @@ -279,9 +279,7 @@ class ConstraintManager(object): """ min_len = min(self._lens) max_pos_comp = [ - i for i, - j in enumerate( - self._lens) if j != self._max_len] + i for i, j in enumerate(self._lens) if j != self._max_len] if self._max_len == 1 and min_len != 1: raise RuntimeError("Essential Arg Missing") -- GitLab From 923b68f5f02a48ab878a3d25f0d1c0d8ae31bb20 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Thu, 5 Jan 2017 14:38:28 +0000 Subject: [PATCH 2/9] Constraint: Note ability to use DataFrame in docstring --- trappy/plotter/Constraint.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trappy/plotter/Constraint.py b/trappy/plotter/Constraint.py index 3f6fa9a..b630a76 100644 --- a/trappy/plotter/Constraint.py +++ b/trappy/plotter/Constraint.py @@ -212,8 +212,8 @@ class ConstraintManager(object): :param traces: Input Trace data - :type traces: :mod:`trappy.trace.BareTrace`, list(:mod:`trappy.trace.BareTrace`) - (or a class derived from :mod:`trappy.trace.BareTrace`) + :type traces: a list of :mod:`trappy.trace.BareTrace` (or derived class), + or :mod:`pandas.DataFrame` or a single instance of them. :param columns: The column values from the corresponding :mod:`pandas.DataFrame` :type columns: str, list(str) -- GitLab From f5dacb02357f2bb20994c52f391df0be901ecca3 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Tue, 17 Jan 2017 15:46:54 +0000 Subject: [PATCH 3/9] [WIP/TODO] Constraint: Add to docstring I don't really understand this code but AFAICT you can plot the same column from multiple traces, i.e. len(columns) == 1 and len(traces) != 1. Not sure what role templates has here. --- trappy/plotter/Constraint.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/trappy/plotter/Constraint.py b/trappy/plotter/Constraint.py index b630a76..9dce3f3 100644 --- a/trappy/plotter/Constraint.py +++ b/trappy/plotter/Constraint.py @@ -276,6 +276,13 @@ class ConstraintManager(object): Len[columns] != 1 Len[templates] != 1 ) + + TODO is the following correct? + Permute( + Len[traces] != 1 + Len[columns] = 1 + Len[templates] != 1 + ) """ min_len = min(self._lens) max_pos_comp = [ -- GitLab From 52064f963544a5ffa44db17a690ae8c77831f7bd Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Thu, 5 Jan 2017 16:01:30 +0000 Subject: [PATCH 4/9] AbstractDataPlotter: Simplify `map(); reduce()` to `all` --- trappy/plotter/AbstractDataPlotter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trappy/plotter/AbstractDataPlotter.py b/trappy/plotter/AbstractDataPlotter.py index e4891d8..d0cf018 100644 --- a/trappy/plotter/AbstractDataPlotter.py +++ b/trappy/plotter/AbstractDataPlotter.py @@ -55,8 +55,7 @@ class AbstractDataPlotter(object): data = listify(self.traces) if len(data): - mask = map(lambda x: isinstance(x, DataFrame), data) - data_frame = reduce(lambda x, y: x and y, mask) + data_frame = all(isinstance(x, DataFrame) for x in data) sig_or_template = self.templates or "signals" in self._attr if not data_frame and not sig_or_template: -- GitLab From 365a758c04c4fbe5f08a7874a8d5c99ee3938f49 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Thu, 5 Jan 2017 16:04:29 +0000 Subject: [PATCH 5/9] AbstractDataPlotter: split long line --- trappy/plotter/AbstractDataPlotter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trappy/plotter/AbstractDataPlotter.py b/trappy/plotter/AbstractDataPlotter.py index d0cf018..0bbc443 100644 --- a/trappy/plotter/AbstractDataPlotter.py +++ b/trappy/plotter/AbstractDataPlotter.py @@ -60,7 +60,8 @@ class AbstractDataPlotter(object): if not data_frame and not sig_or_template: raise ValueError( - "Cannot understand data. Accepted DataFormats are pandas.DataFrame or trappy.FTrace/BareTrace/SysTrace (with templates)") + "Cannot understand data. Accepted types are pandas.DataFrame" + " or trappy.FTrace/BareTrace/SysTrace (with templates)") elif data_frame and "column" not in self._attr: raise ValueError("Column not specified for DataFrame input") else: -- GitLab From 197c0272f7c7c00cd66c7a1309ffffba942da68d Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Thu, 5 Jan 2017 14:38:15 +0000 Subject: [PATCH 6/9] ILinePlot: add docstring header --- trappy/plotter/ILinePlot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/trappy/plotter/ILinePlot.py b/trappy/plotter/ILinePlot.py index 2bcd6aa..3ada6e3 100644 --- a/trappy/plotter/ILinePlot.py +++ b/trappy/plotter/ILinePlot.py @@ -36,6 +36,11 @@ if not IPythonConf.check_ipython(): class ILinePlot(AbstractDataPlotter): """ + Interactive Line Plotter + + Creates line plots for use in IPython notebooks that can be zoomed and + scrolled interactively + This class uses :mod:`trappy.plotter.Constraint.Constraint` to represent different permutations of input parameters. These constraints are generated by creating an instance of -- GitLab From c202d903c682c4be72658ac735419850c98a5cf1 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Tue, 17 Jan 2017 15:43:10 +0000 Subject: [PATCH 7/9] ILinePlot: Clarify 'column' and 'signals' in doctstring --- trappy/plotter/ILinePlot.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/trappy/plotter/ILinePlot.py b/trappy/plotter/ILinePlot.py index 3ada6e3..e52f1a0 100644 --- a/trappy/plotter/ILinePlot.py +++ b/trappy/plotter/ILinePlot.py @@ -51,8 +51,11 @@ class ILinePlot(AbstractDataPlotter): :mod:`trappy.trace.SysTrace`, :mod:`trappy.trace.BareTrace` or :mod:`pandas.DataFrame` or a single instance of them. - :param column: specifies the name of the column to - be plotted. + :param column: When plotting DataFrames, specifies the name of the column to + be plotted. If plotting a single DataFrame, may be a list of columns + to use. If plotting multiple DataFrames, must be a single column name + or a list of respective column names such that ``columns[i]`` is + plotted from ``traces[i]`` for each ``i``. :type column: (str, list(str)) :param templates: TRAPpy events @@ -119,12 +122,13 @@ class ILinePlot(AbstractDataPlotter): same time. :type group: string - :param signals: A string of the type event_name:column to indicate - the value that needs to be plotted. You can add an additional - parameter to specify the color of the lin in rgb: - "event_name:column:color". The color is specified as a comma - separated list of rgb values, from 0 to 255 or from 0x0 to - 0xff. E.g. 0xff,0x0,0x0 is red and 100,40,32 is brown. + :param signals: When plotting traces (i.e. using ``Ftrace``, ``SysTrace`` et + al. for ``traces``), a string of the type event_name:column to indicate + the value that needs to be plotted. You can add an additional parameter + to specify the color of the line in rgb: "event_name:column:color". The + color is specified as a comma separated list of rgb values, from 0 to + 255 or from 0x0 to 0xff. E.g. 0xff,0x0,0x0 is red and 100,40,32 is + brown. .. note:: -- GitLab From 390b1aeb5921d7f72be473a0ddf08c1ea6ca7902 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Tue, 17 Jan 2017 15:44:06 +0000 Subject: [PATCH 8/9] ILinePlot: Move 'signals' next to 'column' in docstring These two params have equivalent roles for plotting traces and DataFrames respectively. Move them next to each other in the docstring to make it more likely that users will notice this symmetry and understand the API. --- trappy/plotter/ILinePlot.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/trappy/plotter/ILinePlot.py b/trappy/plotter/ILinePlot.py index e52f1a0..fb26d10 100644 --- a/trappy/plotter/ILinePlot.py +++ b/trappy/plotter/ILinePlot.py @@ -58,6 +58,23 @@ class ILinePlot(AbstractDataPlotter): plotted from ``traces[i]`` for each ``i``. :type column: (str, list(str)) + :param signals: When plotting traces (i.e. using ``Ftrace``, ``SysTrace`` et + al. for ``traces``), a string of the type event_name:column to indicate + the value that needs to be plotted. You can add an additional parameter + to specify the color of the line in rgb: "event_name:column:color". The + color is specified as a comma separated list of rgb values, from 0 to + 255 or from 0x0 to 0xff. E.g. 0xff,0x0,0x0 is red and 100,40,32 is + brown. + + .. note:: + + - Only one of `signals` or both `templates` and + `columns` should be specified + - Signals format won't work for :mod:`pandas.DataFrame` + input + + :type signals: str + :param templates: TRAPpy events .. note:: @@ -121,23 +138,6 @@ class ILinePlot(AbstractDataPlotter): you zoom on any plot in a group all plots will zoom at the same time. :type group: string - - :param signals: When plotting traces (i.e. using ``Ftrace``, ``SysTrace`` et - al. for ``traces``), a string of the type event_name:column to indicate - the value that needs to be plotted. You can add an additional parameter - to specify the color of the line in rgb: "event_name:column:color". The - color is specified as a comma separated list of rgb values, from 0 to - 255 or from 0x0 to 0xff. E.g. 0xff,0x0,0x0 is red and 100,40,32 is - brown. - - .. note:: - - - Only one of `signals` or both `templates` and - `columns` should be specified - - Signals format won't work for :mod:`pandas.DataFrame` - input - - :type signals: str """ def __init__(self, traces, templates=None, **kwargs): -- GitLab From 6a0aa9c0f0ef43e0b54fd9924acd0f651c5795fb Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Tue, 17 Jan 2017 15:41:38 +0000 Subject: [PATCH 9/9] plotter/Utils: Clarify normalize_list function - Rename `val` to `count`. This variable is a cadinality i.e. the length of a list. To me, `val` suggests an element of a list. - Add to docstring to explain intention of the function --- trappy/plotter/Utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/trappy/plotter/Utils.py b/trappy/plotter/Utils.py index 2a47580..344c981 100644 --- a/trappy/plotter/Utils.py +++ b/trappy/plotter/Utils.py @@ -21,13 +21,17 @@ import warnings from trappy.utils import listify -def normalize_list(val, lst): - """Normalize a unitary list""" +def normalize_list(count, lst): + """Normalize a unitary list + :param lst: list with single item + :param count: Length of returned list + :returns: List containing ``count`` instances of the item in ``list`` + """ if len(lst) != 1: raise RuntimeError("Cannot Normalize a non-unitary list") - return lst * val + return lst * count def decolonize(val): -- GitLab