-
Notifications
You must be signed in to change notification settings - Fork 3
branch: models_igr: graph display + record selection #6
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
6fe2e9a
d5df424
2ddc41c
e5fe31f
4fb520f
7758ed8
06fc25d
3ed9930
c8fb1e2
597409e
cf742d9
ef7ae7f
79f38d8
34a7336
387e21a
f2d346e
8411e81
2ca9dec
be385e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,11 +1,9 @@ | ||||||
| from nrn import Segment, Section | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this concept of recording with labels should be moved to separated class which inherits from |
||||||
| from collections import defaultdict | ||||||
|
|
||||||
| import matplotlib.pyplot as plt | ||||||
| import numpy as np | ||||||
| import pandas as pd | ||||||
| from neuron import h | ||||||
| import matplotlib.pyplot as plt | ||||||
|
|
||||||
| from neuronpp.core.hocwrappers.seg import Seg | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -39,7 +37,8 @@ def __init__(self, elements, variables='v'): | |||||
| try: | ||||||
| s = getattr(elem.hoc, "_ref_%s" % var) | ||||||
| except AttributeError: | ||||||
| raise AttributeError("there is no attribute of %s. Maybe you forgot to append loc param for sections?" % var) | ||||||
| raise AttributeError( | ||||||
| "there is no attribute of %s. Maybe you forgot to append loc param for sections?" % var) | ||||||
|
|
||||||
| rec = h.Vector().record(s) | ||||||
| self.recs[var].append((name, rec)) | ||||||
|
|
@@ -84,16 +83,19 @@ def _plot_static(self, position=None): | |||||
| for i, (name, rec) in enumerate(section_recs): | ||||||
| rec_np = rec.as_numpy() | ||||||
| if np.max(np.isnan(rec_np)): | ||||||
| raise ValueError("Vector recorded for variable: '%s' and segment: '%s' contains nan values." % (var_name, name)) | ||||||
| raise ValueError( | ||||||
| "Vector recorded for variable: '%s' and segment: '%s' contains nan values." % (var_name, name)) | ||||||
|
|
||||||
| if position is not "merge": | ||||||
| ax = self._get_subplot(fig=fig, var_name=var_name, position=position, row_len=len(section_recs), index=i + 1) | ||||||
| ax = self._get_subplot(fig=fig, var_name=var_name, position=position, row_len=len(section_recs), | ||||||
| index=i + 1) | ||||||
| ax.set_title("Variable: %s" % var_name) | ||||||
| ax.plot(self.t, rec, label=name) | ||||||
| ax.set(xlabel='t (ms)', ylabel=var_name) | ||||||
| ax.legend() | ||||||
|
|
||||||
| def _plot_animate(self, steps=10000, y_lim=None, position=None): | ||||||
| def _plot_animate(self, steps=10000, y_lim=None, position=None, true_class=None, pred_class=None, stepsize=None, | ||||||
| dt=None): | ||||||
|
||||||
| """ | ||||||
| Call each time you want to redraw plot. | ||||||
|
|
||||||
|
|
@@ -125,13 +127,14 @@ def _plot_animate(self, steps=10000, y_lim=None, position=None): | |||||
| if position == 'merge': | ||||||
| ax = fig.add_subplot(1, 1, 1) | ||||||
| else: | ||||||
| ax = self._get_subplot(fig=fig, var_name=var_name, position=position, row_len=len(section_recs), index=i + 1) | ||||||
| ax = self._get_subplot(fig=fig, var_name=var_name, position=position, row_len=len(section_recs), | ||||||
| index=i + 1) | ||||||
|
|
||||||
| if y_lim: | ||||||
| ax.set_ylim(y_lim[0], y_lim[1]) | ||||||
| line, = ax.plot([], lw=1) | ||||||
| ax.set_title("Variable: %s" % var_name) | ||||||
| ax.set_ylabel(var_name) | ||||||
| # ax.set_title("Variable: %s" % var_name) | ||||||
| ax.set_ylabel("{}_{}".format(var_name, i)) | ||||||
| ax.set_xlabel("t (ms)") | ||||||
| ax.legend() | ||||||
|
|
||||||
|
|
@@ -143,17 +146,42 @@ def _plot_animate(self, steps=10000, y_lim=None, position=None): | |||||
|
|
||||||
| ax.set_xlim(t.min(), t.max()) | ||||||
| if y_lim is None: | ||||||
| ax.set_ylim(r.min()-(np.abs(r.min()*0.05)), r.max()+(np.abs(r.max()*0.05))) | ||||||
| ax.set_ylim(r.min() - (np.abs(r.min() * 0.05)), r.max() + (np.abs(r.max() * 0.05))) | ||||||
|
|
||||||
| # update data | ||||||
| line.set_data(t, r) | ||||||
|
|
||||||
| # info draw triangles for true and predicted classes | ||||||
|
||||||
| true_x, true_y, pred_x, pred_y = self._class_tcks(label=i, true_class=true_class, pred_class=pred_class, | ||||||
|
||||||
| t=t, r=r, stepsize=stepsize, dt=dt) | ||||||
| ax.scatter(true_x, true_y, c="orange", marker="^", alpha=0.95) | ||||||
| ax.scatter(pred_x, pred_y, c="magenta", marker="v", alpha=0.95) | ||||||
|
|
||||||
| # info join plots by removing labels and ticks from subplots that are not on the edge | ||||||
| for key in self.axs: | ||||||
| for ax in self.axs[key]: | ||||||
| ax[0].label_outer() | ||||||
| fig.subplots_adjust(left=0.09, bottom=0.075, right=0.99, top=0.98, wspace=None, hspace=0.00) | ||||||
| fig.canvas.draw() | ||||||
| fig.canvas.flush_events() | ||||||
|
|
||||||
| if create_fig: | ||||||
| plt.show(block=False) | ||||||
|
|
||||||
| def _class_tcks(self, label, true_class, pred_class, t, r, stepsize, dt): | ||||||
|
||||||
| def _class_tcks(self, label, true_class, pred_class, t, r, stepsize, dt): | |
| def _draw_true_predicted_class_marks(self, label, true_class, pred_class, t, r, stepsize, dt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works for me
ziemowit-s marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to find better true_y (position of lower triangle) and red_y (position of upper one). All goes well as long as the motor neurone are activated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was original idea how to present plot but now I think it was bad idea to manually shift it like this. But it maybe as it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem w linii 95 z rzeczywistym przesunięciem polega na znalezieniu nazwy warstwy poprzedzającej. Jeśli jest nią 'hid_1' to wtedy może być przez