-
Notifications
You must be signed in to change notification settings - Fork 12
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
[WIP] nmlimport package: importing morphologies from nml file #17
Conversation
Hi @mstimberg I am writing test for
Can you think on any reason? Can float-point precision be behind it. |
Yes, it's very likely almost the same value. For these kind of comparisons, rather use |
Hi @mstimberg I have added tests and docstring. Please have a look. I haven't updated sphinx doc to auto import docstring as due to some reason sphinx is not working on my pc for this particular project.
I suspect it has to do something with the fact that I have Also, passing |
Mmm, that's odd, it should work with
You don't need to do anything to import the docstrings. The Could you convert your docstrings to the numpydoc format? I find it much more readable in the source code and it is what we are using in the rest of |
Hi @mstimberg I have updated the docstring. I tried the sphinx build command but it also throws same error. |
@mstimberg I have made conda recipe for libNeuroML, can you have a look and see if it is good to go. |
Hi @kapilkd13 , this is looking very good! Just some minor things to make it perfect:
|
@mstimberg I forgot to mention I have developed the test script we were talking about. Its in the last commit here |
No worries, I saw the commit :) |
@mstimberg I added function to generate proximal distance from parent and its working fine. But their is another issue, while validating we are checking if the proximal distance of a segment is matching to the distal of its parent but in some files their is
|
Hi, this is fine, we don't support these morphologies yet, anyway. I think the best thing would be to raise a |
Hi @mstimberg I added runtime dependencies to conda recipe. Should we push it now https://github.com/kapilkd13/staged-recipes/blob/libneuroml/recipes/libneuroml/meta.yaml |
It is looking good, but some of the tests fail for me when building/installing/testing the package locally. It seems to be an issue with the Oh, and I think you can remove vellamike from the maintainers, according to Padraig he left academia so I guess he's not particularly interested in maintaining the package. |
brian2tools/nmlimport/nml.py
Outdated
@@ -31,7 +31,7 @@ def validate_morphology(segments): | |||
for segment in segments: | |||
|
|||
if segment.parent is not None: | |||
if segment.parent.fraction_along != 1: | |||
if segment.parent.fraction_along not in [0,1]: |
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.
I don't think we correctly support fraction_along=0
, it would mean to connect to the proximal end of a segment.
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.
Currently I was checking if it is connected proximally here I guess we should remove it then :)
Hi @mstimberg how are you testing conda recipe locally, currently I am using
to
Is this the right approach? Also how did you pip installed specific version of jsonpickle with conda recipe. is pip allowed in meta file? |
Sorry, I should have been clearer about this. I don't do any change to the conda install -c conda-forge --use-local libneuroml Because of the |
@kapilkd13 I agree that the case fraction_along != 0 or 1 could be ignored, as it would complicate the conversion of the model to Brian & not produce correct electrical connectivity, but the case fraction_along = 0 should be fine: it explicitly states that the new segment is connected to the proximal point of the parent, and that should be fine to represent in Brian format. |
@pgleeson I agree that Brian does support it in principle. The reason why I told @kapilkd13 to ignore it for now is that the current approach for converting the NeuroML morphology to Brian is to first convert it into a point-based format like the one used by SWC, so that we can then use Brian's existing import facility for this representation. With that SWC-like format, we only have a simple "parent" link, so we cannot express the difference between a proximal and distal connection. |
Hi @mstimberg I tried few things to resolve |
Hi @kapilkd13 , I looked into this in quite a bit of detail and added my comments to the github issue you linked. The specific issue seems to be a problem in Note that during testing, I had to clear the database, otherwise it would not overwrite the incorrect JSON with the fixed version: >>> import pymongo
>>> client = pymongo.MongoClient('localhost', 27017)
>>> client.drop_database('mike_test_db3')
>>> client.drop_database('test_db_4') |
@mstimberg I saw you comment on that thread, you dived in the code base and got to the issue. That was awesome :) I will try your suggestion. I also want to ask if I should push segment group related commits on this branch only or should we get this merge and start our work on new branch. |
I'd say: until we have a |
Can you have another go at the conda-forge recipe with the updated version of |
@mstimberg I tried with new libneuroml version but I am still getting the error. I modified |
@mstimberg I have created a new branch for conda recipe. Here is a link to final recipe https://github.com/kapilkd13/staged-recipes/blob/add_libneuroml/recipes/libneuroml/meta.yaml |
Great, I can confirm that it works fine on my machine as well. Please go ahead and open the pull request for inclusion in conda-forge. |
Hi @mstimberg I was working on morphology function. I have a doubt, while reading a nml file how should we determine if the given set of segments belong to a section. What I am thinking is to create a tree of morphology object and perform DFS and consider link of segments that have only one children (ex. A--B--C--D) as one section. Should we do this for intermediate nodes also. I mean |
Yes, I'd consider the second to be the right choice, with A and B separate if A is named
Hope that makes sense? |
Hi @mstimberg I have pushed current development, moving towards class implementation and changing morphology generation method. Its pretty rough right now but it will be the basic structure for us. please have a look.
|
ah, I forgot to rebase my branch against master. Docs are building now, Thanks :) Please go ahead and review this PR. In the meantime I will look at the biophysical properties extracted from the file. |
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.
All looks very good in principle, I left quite a number of comments but these are mostly style issues that should be easy to fix.
brian2tools/nmlimport/helper.py
Outdated
from collections import defaultdict | ||
|
||
# Return segment type depending on proximal and distal diameter | ||
def get_segment_type(segment): |
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.
I think this function is not used anymore.
brian2tools/nmlimport/helper.py
Outdated
|
||
|
||
# Checks if distal of first segment connects with proximal of second segment | ||
def are_segments_joined(segment1, segment2): |
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.
As discussed, I don't think we need this check anymore ("unconnected" segments are fine).
brian2tools/nmlimport/helper.py
Outdated
|
||
|
||
# Shift coordinates for further processing | ||
def shift_coords(x): |
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.
Another function that is not used.
@@ -0,0 +1,349 @@ | |||
import neuroml.loaders as loaders |
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.
Purely cosmetic, but I prefer imports to be ordered/grouped (first standard library imports, then 3-rd party, then brian2
/brian2tools
), see http://brian2.readthedocs.io/en/stable/developer/guidelines/style.html
brian2tools/nmlimport/nml.py
Outdated
|
||
seg_parent = get_parent_segment(segment, segments) | ||
|
||
if not are_segments_joined(segment, seg_parent): |
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.
As mentioned in the helper file, it is now fine if segments are not joined.
docs_sphinx/user/nmlimport.rst
Outdated
morphology=nml_object.morphology_obj | ||
| | ||
|
||
- To obtain topology information. |
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.
Maybe this section could be shortened a bit. How about saying: "With this Morphology
object, you can use all of Brian's functions to get information about the cell:" and then having a long code block (with these interactive >>>
prompts). I don't think you need to say that morphology.area
gives you the area, etc.
docs_sphinx/user/nmlimport.rst
Outdated
Pyramidal cell's Morphology plot. | ||
|
||
|
||
- To get the resolved group ids of an nml `SegmentGroup`. This returns a |
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.
As discussed, I think it would be good to first show here a shortened version of the NeuroML file. I'd also add a little explanation of what a SegmentGroup
is. BTW: You should use two backticks, i.e. ``SegmentGroup``
because SegmentGroup
is not an object defined anywhere in the documentation.
docs_sphinx/user/nmlimport.rst
Outdated
[8, 6, 7], 'basal_gaba_input': [6], 'background_input': [7]} | ||
| | ||
|
||
- To get the information of all the child segments of a parent segment. This |
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.
Not sure we need this, you can also use the children information stored in Brian's morphology
docs_sphinx/user/nmlimport.rst
Outdated
</morphology> | ||
</cell> | ||
|
||
Handling FractionAlong value |
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.
I would rather explain this in the section title (e.g. "Handling sections not connected at the distal end")
docs_sphinx/user/nmlimport.rst
Outdated
</cell> | ||
|
||
Handling FractionAlong value | ||
-------------------------------- |
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.
Underline needs to have the same length as the title 😄
Hi @mstimberg , I have made the suggested changes. But due to some reason travis is failing for python2. It looks like there is some issue with |
There was a problem in the |
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.
Everything is looking very good, there are just a few more typos and missing NmlMorphology
->NMLMorphology
renames to correct (see my comments).
brian2tools/nmlimport/nml.py
Outdated
return doc | ||
|
||
|
||
def _is_heurestically_sep(self, section, seg_id): |
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.
"heurestically" --> "heuristically"
brian2tools/nmlimport/nml.py
Outdated
Returns | ||
------- | ||
bool | ||
Returns true if the given segment is not heurestically connected |
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.
same here
brian2tools/nmlimport/nml.py
Outdated
|
||
def __init__(self, file_obj, name_heuristic=True): | ||
""" | ||
Initializes NmlMorphology Class |
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.
Here and in a few other places: "NmlMorphology" --> "NMLMorphology"
brian2tools/tests/testScript.py
Outdated
@@ -0,0 +1,62 @@ | |||
import argparse | |||
import os, sys | |||
from brian2tools.nmlimport.nml import NmlMorphology |
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 is now broken I guess (NmlMorphology
--> NMLMorphology
)
docs_sphinx/user/nmlimport.rst
Outdated
|
||
.. code:: python | ||
|
||
from brian2tools.nmlimport.nml import NmlMorphology |
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.
NmlMorphology
--> NMLMorphology
(here and below in a few places)
Hi @mstimberg I was developing function to convert str values like
|
Ha, I completely forgot about this function, I thought we only had the conversion in the other direction! We need to test this function more thoroughly, but in principle it should do what we want. So indeed no need to write this function again. Maybe the best approach would be to have a new package in parallel to |
...and merged it is! This is already very useful as it is, looking forward to seeing even more features implemented 👍 |
This PR features current progress in implementing nmlimport package that allows importing morphologies from nml file.