Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.

[RFC] Some clarifications for plotting code #238

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions trappy/plotter/AbstractDataPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def _check_data(self):
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:
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:
Expand Down
15 changes: 10 additions & 5 deletions trappy/plotter/Constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -276,12 +276,17 @@ def _expand(self):
Len[columns] != 1
Len[templates] != 1
)

TODO is the following correct?
Permute(
Len[traces] != 1
Len[columns] = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct and should work when the same column is present in all the events (templates). I agree templates was a really bad name for the variable :(

Copy link
Contributor Author

@bjackman bjackman Feb 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I'll remove the "TODO" and amend. I've figured out what templates is (I think it's explained in another function) so perhaps I can add a comment for that too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, shouldn't templates have length 1 here? I.e. you have multiple traces; if they're DataFrames that all have a certain column then columns should have length 1, and if they're FTraces that all have a certain event then templates should have length 1?

Len[templates] != 1
)
"""
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")
Expand Down
45 changes: 27 additions & 18 deletions trappy/plotter/ILinePlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

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
Expand All @@ -46,10 +51,30 @@ 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 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::
Expand Down Expand Up @@ -113,22 +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: 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.

.. 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):
Expand Down
10 changes: 7 additions & 3 deletions trappy/plotter/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
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):
Expand Down