Skip to content

How to use dataset.open_remote() to download public datasets on WebKnoosos? #1389

@Mariosz2

Description

@Mariosz2

I want to download the public dataset j0256 from WebKnoossos. First, I tried using Dataset.open_remote() and directly used https://webknossos.org/datasets/Zebra%20finch%20HVC%20j0256-5c051f59010000b538527270/view#6301,7121,1330,0,1 as dataset_name_or_url.

import webknossos as wk

def main() -> None:
    layers = ["color"]
    mags = [wk.Mag(1)]

    # Set the bounding box which should be downloaded
    bbox = wk.BoundingBox([50, 50, 50], [150, 150, 150])

    # Download the dataset
    with wk.webknossos_context(token='xxxxxx'):
        ds = wk.Dataset.open_remote('https://webknossos.org/datasets/Zebra%20finch%20HVC%20j0256-5c051f59010000b538527270/view#6301,7121,1330,0,1'
        ).download(
            bbox=bbox,
            layers=layers,
            mags=mags,
        )
    # Check that the layer was downloaded
    print(f"Layers: {ds.layers}")

if __name__ == "__main__":
    main()

However, there was an error:

❯python -u "/Users/mario_sz/Desktop/datasetproc/test.py"
Traceback (most recent call last):
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/client/api_client/_abstract_api_client.py", line 214, in _assert_good_response response.raise_for_status()
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/httpx/_models.py", line 749, in raise_for_status raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://webknossos.org/api/v7/datasets/Zebra%20finch%20HVC%20j0256-5c051f59010000b538527270/view#6301,7121,1330,0,1' For more information check: https://httpstatuses.com/404

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/mario_sz/Desktop/datasetproc/test.py", line 31, in <module>
main()
File "/Users/mario_sz/Desktop/datasetproc/test.py", line 19, in main
ds = wk.Dataset.open_remote('https://webknossos.org/datasets/Zebra%20finch%20HVC%20j0256-5c051f59010000b538527270/view#6301,7121,1330,0,1')
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/dataset/dataset.py", line 498, in open_remote api_dataset_info = wk_context.api_client.dataset_info(
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/client/api_client/wk_api_client.py", line 71, in dataset_info return self._get_json(route, ApiDataset, query={"sharingToken": sharing_token})
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/client/api_client/_abstract_api_client.py", line 36, in _get_json response = self._get(route, query)
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/client/api_client/_abstract_api_client.py", line 111, in _get return self._request("GET", route, query, timeout_seconds=timeout_seconds)
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/client/api_client/_abstract_api_client.py", line 180, in _request self._assert_good_response(response)
File "/opt/anaconda3/envs/py39/lib/python3.8/site-packages/webknossos/client/api_client/_abstract_api_client.py", line 216, in _assert_good_response raise UnexpectedStatusError(response) from e
webknossos.client.api_client.errors.UnexpectedStatusError: An error occurred while making a GET request to the URL https://webknossos.org/api/v7/datasets/Zebra%20finch%20HVC%20j0256-5c051f59010000b538527270/view#6301,7121,1330,0,1. If this is unexpected, please double-check your WEBKNOSSOS URL and credentials.
If the error persists, it might be caused by a version mismatch of the python client and the WEBKNOSSOS server API version.
See https://github.com/scalableminds/webknossos-libs/releases for current releases.
Got response status 404 with body: {"messages":[{"error":"Couldn't find the requested resource."}]}

Then I also attempted to use the example in the WEBKNOSSOS Documentation at https://docs.webknossos.org/webknossos-py/examples/download_image_data.html, but I found that the wk.RemoteDataset.open function no longer has the dataset_name_or_url parameter.
If someone could answer my question, I would be extremely grateful!

Python version: 3.11
Webknossos version: 3.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions