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

Fixes 491: updates recording to handle individual cells as PopulationView #492

Closed
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
10 changes: 9 additions & 1 deletion pyNN/common/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,11 @@ def write_data(self, io, variables='all', gather=True, clear=False, annotations=
file as metadata.
"""
logger.debug("Population %s is writing %s to %s [gather=%s, clear=%s]" % (self.label, variables, io, gather, clear))
# ignoring the method parameter 'annotations', and using class attribute 'self.annotations'
# seems ok as this method parameter does not seem to be used within pynn currently.
# TODO: decide whether this method parameter needs to be retained.
Copy link
Contributor Author

@appukuttan-shailesh appukuttan-shailesh Jun 27, 2017

Choose a reason for hiding this comment

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

@apdavison : Does this method require to accept 'annotations' as an input parameter? From a quick grep in the pynn directory, it appeared as if none of the function calls pass this parameter to the method.

self.recorder.write(variables, io, gather, self._record_filter, clear=clear,
annotations=annotations)
annotations=self.annotations)

def get_data(self, variables='all', gather=True, clear=False):
"""
Expand Down Expand Up @@ -828,6 +831,7 @@ def __init__(self, parent, selector, label=None):
self.local_cells = self.all_cells[self._mask_local]
self.first_id = numpy.min(self.all_cells) # only works if we assume all_cells is sorted, otherwise could use min()
self.last_id = numpy.max(self.all_cells)
self.annotations = {}
self.recorder = self.parent.recorder
self._record_filter = self.all_cells

Expand Down Expand Up @@ -909,6 +913,9 @@ def index_in_grandparent(self, indices):
else:
return indices_in_parent

def annotate(self, **annotations):
self.annotations.update(annotations)

def describe(self, template='populationview_default.txt', engine='default'):
"""
Returns a human-readable description of the population view.
Expand All @@ -923,6 +930,7 @@ def describe(self, template='populationview_default.txt', engine='default'):
"parent": self.parent.label,
"mask": self.mask,
"size": self.size}
context.update(self.annotations)
return descriptions.render(engine, template, context)


Expand Down
6 changes: 5 additions & 1 deletion pyNN/common/procedural_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def record(variables, source, filename, sampling_interval=None, annotations=None
# would actually like to be able to record to an array and choose later
# whether to write to a file.
if not isinstance(source, (BasePopulation, Assembly)):
source = source.parent
if isinstance(source, (IDMixin)):
source = source.as_view()
else:
# not sure when this would be used; retaining earlier code
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apdavison : do you see any scenario where this would be used? should we remove it?

source = source.parent
source.record(variables, to_file=filename, sampling_interval=sampling_interval)
if annotations:
source.annotate(**annotations)
Expand Down