{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tube segmentation" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/Users/thomasathey/Documents/mimlab/mouselight/env/lib/python3.8/site-packages/python_jsonschema_objects/__init__.py:50: UserWarning: Schema version http://json-schema.org/draft-04/schema not recognized. Some keywords and features may not be supported.\n warnings.warn(\n" ] } ], "source": [ "from brainlit.utils import session\n", "from brainlit.feature_extraction import *\n", "import napari" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "url = \"s3://open-neurodata/brainlit/brain1\"\n", "sess = session.NeuroglancerSession(url=url, url_segments=url + \"_segments\", mip=0)\n", "SEGLIST = [\n", " 101,\n", " 103,\n", " 106,\n", " 107,\n", " 109,\n", " 11,\n", " 111,\n", " 112,\n", " 115,\n", " 11,\n", " 12,\n", " 120,\n", " 124,\n", " 126,\n", " 127,\n", " 129,\n", " 13,\n", " 132,\n", " 133,\n", " 136,\n", " 137,\n", " 14,\n", " 140,\n", " 141,\n", " 142,\n", " 143,\n", " 144,\n", " 145,\n", " 146,\n", " 147,\n", " 149,\n", " 150,\n", "]\n", "SEGLIST = SEGLIST[:1]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "Downloading: 100%|██████████| 1/1 [00:00<00:00, 9.18it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/2 [00:00, ?it/s]\n", "Downloading: 0%| | 0/2 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/2 [00:00, ?it/s]\n", "Downloading: 0%| | 0/2 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n", "Downloading: 0%| | 0/1 [00:00, ?it/s]\n" ] } ], "source": [ "# %%capture\n", "nbr = NeighborhoodFeatures(\n", " url=url, radius=1, offset=[50, 50, 50], segment_url=url + \"_segments\"\n", ")\n", "nbr.fit(seg_ids=SEGLIST, num_verts=10, file_path=\"demo\", batch_size=10)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(20, 30)" ] }, "metadata": {}, "execution_count": 4 } ], "source": [ "import glob, feather\n", "\n", "feathers = glob.glob(\"*.feather\")\n", "\n", "\n", "for count, feather_file in enumerate(feathers):\n", " if count == 0:\n", " data = feather.read_dataframe(feather_file)\n", " else:\n", " df = feather.read_dataframe(feather_file)\n", " data = pd.concat([data, df])\n", "data.shape" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Segment Vertex Label 0 1 2 3 4 5 6 \\\n", "0 101 0 1 28778 30111 30120 28438 29909 30092 28315 \n", "1 101 0 0 12290 12090 12222 12340 12215 12376 12185 \n", "2 101 1 1 15429 16558 17587 15353 16662 17459 15462 \n", "3 101 1 0 12166 12290 12180 12162 12129 12124 12058 \n", "4 101 2 1 13005 12535 12333 12903 12660 12402 12846 \n", "\n", " ... 17 18 19 20 21 22 23 24 25 26 \n", "0 ... 28751 30383 30683 29420 29565 30769 29762 28865 29364 29687 \n", "1 ... 12208 12144 11845 12030 12682 12340 12336 12194 12383 12067 \n", "2 ... 18105 14926 16441 17088 15187 16712 17474 15401 16939 18366 \n", "3 ... 12297 12090 12038 12144 11959 11929 12116 12093 12298 12407 \n", "4 ... 12502 12388 12404 12471 12860 12526 12441 12951 12771 12571 \n", "\n", "[5 rows x 30 columns]" ], "text/html": "
\n | Segment | \nVertex | \nLabel | \n0 | \n1 | \n2 | \n3 | \n4 | \n5 | \n6 | \n... | \n17 | \n18 | \n19 | \n20 | \n21 | \n22 | \n23 | \n24 | \n25 | \n26 | \n
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n101 | \n0 | \n1 | \n28778 | \n30111 | \n30120 | \n28438 | \n29909 | \n30092 | \n28315 | \n... | \n28751 | \n30383 | \n30683 | \n29420 | \n29565 | \n30769 | \n29762 | \n28865 | \n29364 | \n29687 | \n
1 | \n101 | \n0 | \n0 | \n12290 | \n12090 | \n12222 | \n12340 | \n12215 | \n12376 | \n12185 | \n... | \n12208 | \n12144 | \n11845 | \n12030 | \n12682 | \n12340 | \n12336 | \n12194 | \n12383 | \n12067 | \n
2 | \n101 | \n1 | \n1 | \n15429 | \n16558 | \n17587 | \n15353 | \n16662 | \n17459 | \n15462 | \n... | \n18105 | \n14926 | \n16441 | \n17088 | \n15187 | \n16712 | \n17474 | \n15401 | \n16939 | \n18366 | \n
3 | \n101 | \n1 | \n0 | \n12166 | \n12290 | \n12180 | \n12162 | \n12129 | \n12124 | \n12058 | \n... | \n12297 | \n12090 | \n12038 | \n12144 | \n11959 | \n11929 | \n12116 | \n12093 | \n12298 | \n12407 | \n
4 | \n101 | \n2 | \n1 | \n13005 | \n12535 | \n12333 | \n12903 | \n12660 | \n12402 | \n12846 | \n... | \n12502 | \n12388 | \n12404 | \n12471 | \n12860 | \n12526 | \n12441 | \n12951 | \n12771 | \n12571 | \n
5 rows × 30 columns
\n