Skip to content

Commit

Permalink
Modified examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AirMicrodot committed May 15, 2019
1 parent b011b24 commit 02b5207
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
14 changes: 14 additions & 0 deletions diagnostics/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def __init__(self, data, t0=0, name="", fs=1):
"correct_negatives": lambda x: x - min(x * (x < 0)),
}
self._reprconfig = {"threshold": 10, "separator": ", "}
self._type = "TimeSerie"
return

@property
def data(self):
Expand Down Expand Up @@ -602,6 +604,8 @@ def __init__(self, *args, **kwargs):
if self.data.dtype != np.bool:
raise ValueError("data is not of dtype 'bool'")

self._type = "BooleanTimeSerie"

@property
def data(self):
return self._data
Expand Down Expand Up @@ -687,6 +691,9 @@ def __init__(self, data, t, name="", shrink=False):
self.data = data
self.t = t
self.name = name

self._type = "StateChangeArray"

return

def __repr__(self):
Expand Down Expand Up @@ -1076,6 +1083,9 @@ def __init__(self, *args, **kwargs):
if self.data.dtype != np.bool:
raise ValueError("data is not of dtype 'bool'")

self._type = "BooleanStateChangeArray"
return

def __repr__(self):
return "BooleanStateChangeArray({}, t={}, name={})".format(
np.array2string(self.data, **self._reprconfig),
Expand Down Expand Up @@ -1106,6 +1116,8 @@ def __init__(self, t0, te, name=""):
raise ValueError("te can't be before t0!")
self.te = te
self.name = name
self._type = "Report"


def __repr__(self):
return "Report(t0={}, te={}, name={})".format(
Expand Down Expand Up @@ -1172,6 +1184,8 @@ def __init__(self, value, t=0, name="", validity=1):
self.t = t
self.name = name
self.validity = validity
self._type = "Report"


@property
def state(self):
Expand Down
5 changes: 5 additions & 0 deletions diagnostics/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
def plot(*args, **kwargs):

fig = kwargs.pop("figure", plt.figure())
set_title = kwargs.pop("set_title", False)
align_x = kwargs.pop("align", kwargs.pop("align_x", False))
as_dt = kwargs.get("as_dt", False)
cmap = kwargs.get("cmap", plt.get_cmap("tab10"))

lines = [a.line(color=cmap(idx), **kwargs) for idx, a in enumerate(args)]
titles = [a._type for a in args]
if align_x:
lims = [
min([l.get_xdata()[0] for l in lines]),
Expand All @@ -20,6 +22,9 @@ def plot(*args, **kwargs):
ax.add_line(line)
ax.autoscale()
ax.legend()
if set_title:
ax.set_title(titles[idx])
ax.set_xlabel("Time")
if as_dt:
ax.xaxis_date()
fig.autofmt_xdate()
Expand Down

0 comments on commit 02b5207

Please sign in to comment.