brainglobe / brainrender

a python based software for visualization of neuroanatomical and morphological data.
https://brainglobe.info/documentation/brainrender/index.html
BSD 3-Clause "New" or "Revised" License
541 stars 77 forks source link

URL of streamlines may be failure #93

Closed MyNameIsMoney closed 4 years ago

MyNameIsMoney commented 4 years ago

Hi, I am a new user of brainrender. When I run the example file streamlines.py and tractography.py, there is an ERROR that "Could not download streamlines for region CA1", and I visit the URL, there is ERROR 404. Is something wrong of my internet or the URL has been changed? However, I can run the example file brain_region.py successfully. Looking forward your reply. Thanks.

FedeClaudi commented 4 years ago

Hi,

Thanks for getting in touch, let's see if we can fix this.

Running streamlines.py works fine for me:

image

Could you give me some more details about your set up please? So that I can try and replicate the error.

Thank you, Federico

MyNameIsMoney commented 4 years ago

Hi, these are the details : python version is 3.7.7 brainrender version is 0.4.0.0 OS is windows10 I install brainrender in a conda vertual environment, and I use command pip install brainrender,when Iinstalled it, there are some error: ERROR: allensdk 2.1.0 has requirement numpy<1.19.0,>=1.15.4, but you'll have numpy 1.19.0 which is incompatible. ERROR: allensdk 2.1.0 has requirement pandas<=0.25.3,>=0.25.1, but you'll have pandas 1.0.5 which is incompatible. ERROR: allensdk 2.1.0 has requirement scikit-image<0.17.0,>=0.14.0, but you'll have scikit-image 0.17.2 which is incompatible. So, I reinstalled these packages in the vertual packages : numpy==1.18.5 , pandas==0.25.3, ipython==7.14.0 Then, I ran streamlines.py, when I ran filepaths, data = scene.atlas.download_streamlines_for_region("CA1"), I couldn't download the file from URL, there was an error: Could not download streamlines for region CA1, and the following code could't run correctly. Looking forward your reply, thanks.

FedeClaudi commented 4 years ago

Hi,

Thanks for all the details, that helps.

I'm not sure exactly what's causing the error here. Could you please copy/paste the entire error message you get when you run the code? That might give more clues :)

MyNameIsMoney commented 4 years ago

Hi, this is the information appear on my cmd windows when I run the streamlines.py:

settings: screenshots are set to have transparent backgroundset the parameter "SCREENSHOT_TRANSPARENT_BACKGROUND" to false if you would prefer a not transparent background
  0%|                                                                                            | 0/6 [00:00<?, ?it/s]No internet connection available.
  0%|                                                                                            | 0/6 [00:10<?, ?it/s]
Could not download streamlines for region CA1
Traceback (most recent call last):
  File "streamlines.py", line 19, in <module>
    scene.add_streamlines(data, color="darkseagreen", show_injection_site=False)
  File "D:\anaconda\envs\brain3D\lib\site-packages\brainrender\scene.py", line 505, in add_streamlines
    return self.atlas.add_streamlines(self, *args,  **kwargs)
  File "D:\anaconda\envs\brain3D\lib\site-packages\brainrender\atlases\aba.py", line 801, in add_streamlines
    if isinstance(sl_file[0], (str, pd.DataFrame)): # we have a list of files to add
IndexError: list index out of range
FedeClaudi commented 4 years ago

mmm, thanks. I can't replicate the error on my machine, so I will have to need you to try something for me.

Can you try running this code and let me know what the outcome is?

from brainrender.scene import Scene
import pandas as pd
from brainrender.Utils.ABA.aba_utils import experiments_source_search, download_streamlines

scene = brainrender.scene.Scene()
region_experiments = experiments_source_search(scene.atlas.mca, 'CA1')
download_streamlines(region_experiments.id.values, streamlines_folder=scene.atlas.streamlines_cache)

thanks

MyNameIsMoney commented 4 years ago

Hello. When I ran the code at first time , there was an error means that cold not found the module brainrender.Utils.ABA.aba_utils, then I downloaded the code zip from https://github.com/BrancoLab/BrainRender, and replace the brainrender folder in my vertual environment with the folder I have downloaded. After this, I ran the code again and the error is:

0%|          | 0/6 [00:10<?, ?it/s]
Traceback (most recent call last):
  File "D:/PyCharmProject/brain3Dtest/debugTest.py", line 7, in <module>
    download_streamlines(region_experiments.id.values, streamlines_folder=scene.atlas.streamlines_cache)
  File "D:\anaconda\envs\brain3D\lib\site-packages\brainrender\Utils\ABA\aba_utils.py", line 148, in download_streamlines
    response = request(url)
  File "D:\anaconda\envs\brain3D\lib\site-packages\brainrender\Utils\webqueries.py", line 18, in request
    raise ConnectionError("You need to have an internet connection to send requests.")
ConnectionError: You need to have an internet connection to send requests.

In addition, I followed the way mentioned on the homepage to install brainrender(create an ventural environment with anaconda, pip install brainrender). Are there something wrong when I install the package? Is there any other way to install brainrender? I really want to experience this amazing strong software. Thanks.

FedeClaudi commented 4 years ago

Hi,

Let me give you some instructions on how to install brainrender if we still have problems after that we can figure out what the problem is.

  1. Create a new anaconda environment conda create -n br python==3.7 [in anaconda prompt]
  2. activate: conda activate br
  3. install brainrender pip install brainrender

You might get some error/warning messages while installing, but you can safely ignore them.

Once this is done, you can try runnning streamlines.py and the code I've sent you above for testing. Let me know how it goes!

MyNameIsMoney commented 4 years ago

Hi, I have reinstalled the brainrender following your instuction, and do nothing else. I could successfully ran brain_region.py, labelled_cells.py, . When I ran colored_neurons,there are errors

No internet connection available.
Traceback (most recent call last):
  File "colored_neurons.py", line 25, in <module>
    neurons_metadata = mlapi.fetch_neurons_metadata(filterby='soma', filter_regions=['MOs'])
  File "D:\anaconda\envs\br\lib\site-packages\morphapi\api\mouselight.py", line 282, in fetch_neurons_metadata
    res = post_mouselight(url, query=query)["searchNeurons"]
  File "D:\anaconda\envs\br\lib\site-packages\morphapi\utils\webqueries.py", line 78, in post_mouselight
    "You need an internet connection for API queries, sorry."
ConnectionError: You need an internet connection for API queries, sorry.

When I ran mouselight.py, there are errors:

No internet connection available.
Traceback (most recent call last):
  File "mouselight.py", line 22, in <module>
    neurons_metadata = mlapi.fetch_neurons_metadata(filterby='soma', filter_regions=['MOs'])
  File "D:\anaconda\envs\br\lib\site-packages\morphapi\api\mouselight.py", line 282, in fetch_neurons_metadata
    res = post_mouselight(url, query=query)["searchNeurons"]
  File "D:\anaconda\envs\br\lib\site-packages\morphapi\utils\webqueries.py", line 78, in post_mouselight
    "You need an internet connection for API queries, sorry."
ConnectionError: You need an internet connection for API queries, sorry.

When I ran streamlines.py, there are errors:

Could not download streamlines for region CA1
Traceback (most recent call last):
  File "streamlines.py", line 20, in <module>
    scene.add_streamlines(data, color="darkseagreen", show_injection_site=False)
  File "D:\anaconda\envs\br\lib\site-packages\brainrender\scene.py", line 505, in add_streamlines
    return self.atlas.add_streamlines(self, *args,  **kwargs)
  File "D:\anaconda\envs\br\lib\site-packages\brainrender\atlases\aba.py", line 801, in add_streamlines
    if isinstance(sl_file[0], (str, pd.DataFrame)): # we have a list of files to add
IndexError: list index out of range

When I ran tracetography.py, there are errors:

Traceback (most recent call last):
  File "tractography.py", line 15, in <module>
    p0 = scene.atlas.get_region_CenterOfMass("ZI")
  File "D:\anaconda\envs\br\lib\site-packages\brainrender\atlases\aba.py", line 164, in get_region_CenterOfMass
    if self.root is None:
AttributeError: 'ABA' object has no attribute 'root'

When I ran the code you gave me:

from brainrender.scene import Scene
import pandas as pd
from brainrender.Utils.ABA.aba_utils import experiments_source_search, download_streamlines

scene = brainrender.scene.Scene()
region_experiments = experiments_source_search(scene.atlas.mca, 'CA1')
download_streamlines(region_experiments.id.values, streamlines_folder=scene.atlas.streamlines_cache)

there are errors:

Traceback (most recent call last):
  File "debugTest.py", line 3, in <module>
    from brainrender.Utils.ABA.aba_utils import experiments_source_search, download_streamlines
ModuleNotFoundError: No module named 'brainrender.Utils.ABA.aba_utils'

Thanks.

FedeClaudi commented 4 years ago

Lot's of errors.. let's see what's going on.


ConnectionError: You need an internet connection for API queries, sorry. -> as the error message suggests, you get this error if you try to send a web request but no internet connection is found. Is the computer you're using to run this code connected (I assume so, but worth checking)?

If it is, could you try the following (and let me know what happens):

import requests
requests.get('http://www.google.com/', timeout=5)

If there's something wrong with your internet connection, then you will also fail to download streamlines data. This would also explain the error in streamlines.py.


for the debug code, could you try to replace line 3 with:

from brainrender.Utils.ABA.aba_utils import parse_streamline, download_streamlines, experiments_source_search
MyNameIsMoney commented 4 years ago

when I tried:

import requests
requests.get('http://www.google.com/', timeout=5)

there are errors:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    requests.get('http://www.google.com', timeout = 5)
  File "D:\anaconda\envs\br\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "D:\anaconda\envs\br\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\anaconda\envs\br\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\anaconda\envs\br\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "D:\anaconda\envs\br\lib\site-packages\requests\adapters.py", line 504, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='www.google.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x000001E017ABB828>, 'Connection to www.google.com timed out. (connect timeout=5)'))

when I change the debug code, there are errors:

Traceback (most recent call last):
  File "debugTest.py", line 3, in <module>
    from brainrender.Utils.ABA.aba_utils import parse_streamline, download_streamlines, experiments_source_search
ModuleNotFoundError: No module named 'brainrender.Utils.ABA.aba_utils'

There may be the limited of my internet, I could visit google correctly using VPN, but I couldn't ping it successfully. Could you tell where to download the data? Maybe I can download the data manually. Thanks.

FedeClaudi commented 4 years ago

Yeah the timeout for webqueries is set to 5s, so if you have limited internet that might be causing the problem.. You might be able to download the data manually, but it's not trivial. In particular I don't know the URLs for any of the brain atlas data, the download is handled in brainrender using their python sdk but I don't know what happens behind the scenes.

I could help you find the streamlines data though, that you can download manually.

MyNameIsMoney commented 4 years ago

Thank you very much, I need the data of CA1, LSr and AIP, if it is convenient for you to find this data, please contact me. Thanks again.

FedeClaudi commented 4 years ago

Step1 download streamlines

Okay, so the URL pattern to download the streamlines is:

https://neuroinformatics.nl/HBP/allen-connectivity-viewer/json/streamlines_{}.json.gz

where your replace {} with the experiment ID that you're interested in. To find the exp. id you can use the allen SDK to find the experiment that targeted the brain region you're interested in: https://github.com/BrancoLab/BrainRender/blob/a929a7889af72f1d0c70e4f9320f71ac7e51155f/brainrender/Utils/ABA/aba_utils.py#L62

You should also be able to use the Allen Brain Atlas online tools to find the ids of experiments you're interested in.

Step2 extract

In step 1 you've downloaded a .json for each experiment. This contains the streamlines info. You need to uncompress this and then you'll have to save the .json in the folder that brainrender uses to store streamlines data.

In your home directory you should have a folder called .brainrender (you might have to show hidden folders). In it you go to Data>Streamlines and you can copy the .json there.

Step3 render

To render, you can use:

filepaths = ['path/to/first/file.json', 'path/to/second/file.json', ...]
scene.add_streamlines(filepaths)

I think this should work, but I haven't tested it. Let me know how it goes.

MyNameIsMoney commented 4 years ago

Thanks for your patient. But I can't visit the url :https://neuroinformatics.nl/HBP/allen-connectivity-viewer/json/streamlines_122642490.json.gz or https://neuroinformatics.nl/HBP/allen-connectivity-viewer/json/streamlines_{122642490}.json.gz , the page is 404 not found. But I could down a streamlines_122642490.json in page https://neuroinformatics.nl/HBP/allen-connectivity-viewer/streamline-downloader.html, I don't know whether the data is right and how to rewrite the code. After I download the streamlines_122642490.json, I could draw it like this: image

FedeClaudi commented 4 years ago

oh okay, then yes you can use the streamline-downloader instead, that's probably easier. Glad it's working now!

MyNameIsMoney commented 4 years ago

Thank you very much!