NeuroML / NeuroML2

This repository hosts the NeuroML 2 Schema, the ComponentType definitions in LEMS and the core documentation of NeuroML2.
https://docs.neuroml.org
GNU Lesser General Public License v3.0
50 stars 24 forks source link

pynml-channelanalysis xyz.channel.nml giving error #203

Closed vsrivas closed 1 year ago

vsrivas commented 1 year ago

I am trying to analyze the channel dynamics as given in https://docs.neuroml.org/Userdocs/SingleCompartmentHHExample.html. I am getting error

File ["<ipython-input-23-a4d75f53f6e0>"](https://localhost:8080/#), line 1
    pynml-channelanalysis Kdrfast.channel.nml
                          ^
SyntaxError: invalid syntax

The .nml channel file is in the present working directory. I am working on google colab.

Thanks for any help.

sanjayankur31 commented 1 year ago

Hi @vsrivas . pynml-channelanalysis is a command that needs to be run in a terminal. It's not Python code. So, are you running this in the terminal on Collab (requires one to pay for Collab pro from what I see) or are you trying to run it in a Python cell? If you're trying to run this in a cell, you need to precede the command with a ! as you do to install packages and so on :

!pip install pyneuroml[analysis]
!pynml-channelanalysis ...

You can also use the new Open Source Brain platform here where you can create private workspaces to work in---you'll have access to jupyter lab there which includes a terminal etc. Do note that it's still in beta and under development, though :)

https://docs.opensourcebrain.org/OSBv2/Overview.html

vsrivas commented 1 year ago

Hi @sanjayankur31 : Thanks for walking me through the steps. I am able to run the program but the figure is not visible. I get this message on colab: _pyNeuroML >>> INFO - Loading NeuroML2 file: /content/ca1/NeuroML2/channels/HCNolm.channel.nml pyNeuroML >>> INFO - Loading NeuroML2 file: /content/ca1/NeuroML2/channels/HCNolm.channel.nml pyNeuroML >>> INFO - Loading NeuroML2 file: /content/ca1/NeuroML2/channels/HCNolm.channel.nml pyNeuroML >>> INFO - Loading LEMS file: /content/LEMS_Test_HCNolm.xml and running with jNeuroML pyNeuroML >>> INFO - Executing: (java -Xmx400M -Djava.awt.headless=true -jar "/usr/local/lib/python3.8/dist-packages/pyneuroml/lib/jNeuroML-0.12.0-jar-with-dependencies.jar" "/content/LEMS_Test_HCNolm.xml" -nogui -I '') in directory: . pyNeuroML >>> INFO - Command completed successfully! Figure(640x480) Figure(640x480)__

I do not know what am I missing. Thanks for your help.

pgleeson commented 1 year ago

@vsrivas Have a look at section 1.3 of this notebook: =https://github.com/NeuroML/Documentation/blob/pg_updates/source/Userdocs/NML2_examples/NeuroML-DB.ipynb.

It shows how to call the channelanalysis function from inside the python notebook and how to display the plots.

sanjayankur31 commented 1 year ago

The pynml-channelanalysis command runs and opens the generated plots in a matplotlib window. That's what the Figure.. bits are showing. Adding this to the top of your notebook may show them in the notebook too:

%matplotlib notebook

See https://medium.com/@Med1um1/using-matplotlib-in-jupyter-notebooks-comparing-methods-and-some-tips-python-c38e85b40ba1

vsrivas commented 1 year ago

@sanjayankur31 @pgleeson : I managed to get the plots using the github link. Now I want to customize the plots (removing grids, changing plot color, modifying axis labels etc). I understand that I have to use matplotlib customization to modify these plots but clueless about how to proceed after:

run(channel_files=[chan_fname1, chan_fname2, chan_fname3])
# plots are generated

Please advise.

sanjayankur31 commented 1 year ago

There's no direct way of customising the plots---these functions are meant to provide a quick way of analysing the channels so users can get quick plots to compare etc. The analyses save all the data they generates in .dat files, so your best bet is to read those and plot as you wish?

In a cell in your jupyter notebook, try:

!ls *.dat

You should see lots of *.dat files, like this:

$ ls *.dat
Kv3_1.m.inf.lems.dat  Kv3_1.m.tau.lems.dat  Kv3_1.rampV.lems.dat

So you should be able to read these files using numpy etc. and plot them as you wish. There are also some helper plotting functions here:

https://pyneuroml.readthedocs.io/en/development/pyneuroml.plot.html

If you want to modify the analysis etc., you can look at the sources here:

https://github.com/NeuroML/pyNeuroML/blob/master/pyneuroml/analysis/NML2ChannelAnalysis.py

vsrivas commented 1 year ago

@sanjayankur31 @pgleeson : Thanks for your valuable guidance in using NeuroML.

sanjayankur31 commented 1 year ago

No worries @vsrivas , we're always here to help. Please open more issues as required. If you also see anything that you feel should be included in our documentation and so on, please do let us know and we'll add it.