Skip to content

Commit af77e5f

Browse files
Merge pull request #208 from NeuralEnsemble/feat-list-params
Feat: add method to list parameters of a component object
2 parents 41597db + 656f32e commit af77e5f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

neuroml/nml/generatedssupersuper.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,30 @@ def info(self, show_contents=False, return_format="string"):
468468
print(info_str)
469469
return info_str
470470

471+
def get_parameters(self):
472+
"""Get parameters for this component
473+
474+
This returns a subset of the results of the `info()` method, limiting
475+
the results to the parameters only.
476+
477+
.. versionadded:: 0.6.6
478+
479+
:returns: dictionary with parameter names as keys, and parameter values
480+
as values
481+
:rtype: dict[str, str]
482+
483+
"""
484+
info = self.info(show_contents="all", return_format="dict")
485+
parameters = {}
486+
for member, memberinfo in info.items():
487+
if (
488+
memberinfo["type"].startswith("Nml2Quantity_")
489+
or memberinfo["type"] == "NmlId"
490+
):
491+
parameters[member] = memberinfo["members"]
492+
493+
return parameters
494+
471495
def validate(self, recursive=False):
472496
"""Validate the component.
473497

neuroml/test/test_nml.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,21 @@ def test_adding_any(self):
870870
print(annotation_text)
871871
self.assertEqual("<Annotation>some_string</Annotation>", annotation_text)
872872

873+
def test_parameter_listing(self):
874+
"""Test listing component parameters"""
875+
params = {
876+
"id": "test_cell",
877+
"thresh": "10mV",
878+
"leak_reversal": "10mV",
879+
"reset": "0mV",
880+
"C": "10 F",
881+
"leak_conductance": "10 nS",
882+
}
883+
cell = component_factory("IafCell", **params) # type: neuroml.Cell
884+
received_parameters = cell.get_parameters()
885+
self.assertDictEqual(params, received_parameters)
886+
print(received_parameters)
887+
873888

874889
if __name__ == "__main__":
875890
ta = TestNML()

0 commit comments

Comments
 (0)