Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Pass plot notebooks by melonora · Pull Request #91 · scverse/spatialdata-tutorials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 702 additions & 55 deletions notebooks/examples/aggregation.ipynb

Large diffs are not rendered by default.

205 changes: 159 additions & 46 deletions notebooks/examples/napari_rois.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,37 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"id": "a7943409-b7aa-428b-8fe3-14c76dd2c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script type=\"application/javascript\" id=\"jupyter_black\">\n",
" (function() {\n",
" if (window.IPython === undefined) {\n",
" return\n",
" }\n",
" var msg = \"WARNING: it looks like you might have loaded \" +\n",
" \"jupyter_black in a non-lab notebook with \" +\n",
" \"`is_lab=True`. Please double check, and if \" +\n",
" \"loading with `%load_ext` please review the README!\"\n",
" console.log(msg)\n",
" alert(msg)\n",
" })()\n",
" </script>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.164303700Z",
"start_time": "2024-04-02T17:30:49.133239Z"
}
],
},
"outputs": [],
"source": [
"%load_ext jupyter_black"
"# %load_ext jupyter_black"
]
},
{
Expand All@@ -61,8 +39,8 @@
"id": "1ca349bd",
"metadata": {
"ExecuteTime": {
"end_time": "2023-04-10T21:55:24.852734Z",
"start_time": "2023-04-10T21:55:20.519549Z"
"end_time": "2024-04-02T17:30:49.186373200Z",
"start_time": "2024-04-02T17:30:49.167303100Z"
},
"collapsed": false,
"jupyter": {
Expand DownExpand Up@@ -104,6 +82,10 @@
"execution_count": 3,
"id": "d981654b-bfe2-453c-906c-b1b386a83078",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.406164500Z",
"start_time": "2024-04-02T17:30:49.186373200Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -163,6 +145,10 @@
"execution_count": 4,
"id": "849a6fcc-5f73-4080-8a55-984b6385de6e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.423674900Z",
"start_time": "2024-04-02T17:30:49.408164700Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -206,6 +192,10 @@
"execution_count": 5,
"id": "b16e7554-0f38-439d-9b46-e3fc651d1ee2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.442675Z",
"start_time": "2024-04-02T17:30:49.422674300Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -255,6 +245,10 @@
"execution_count": 6,
"id": "7eb48cd4-8093-4262-885b-16229a3ec51f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.456674400Z",
"start_time": "2024-04-02T17:30:49.438678200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -328,6 +322,10 @@
"execution_count": 7,
"id": "920ad9a0-a9e9-42f6-8dcf-cbd1d2e268df",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.492776400Z",
"start_time": "2024-04-02T17:30:49.453675900Z"
},
"tags": []
},
"outputs": [
Expand All@@ -354,6 +352,10 @@
"execution_count": 8,
"id": "f3928c32-45b4-4aae-bbae-5f7dba3df33d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.507777600Z",
"start_time": "2024-04-02T17:30:49.469674900Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -424,6 +426,10 @@
"execution_count": 9,
"id": "eec065cf-1de3-4a28-985d-4d0f30adc710",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.512779900Z",
"start_time": "2024-04-02T17:30:49.485734800Z"
},
"tags": []
},
"outputs": [],
Expand DownExpand Up@@ -455,6 +461,10 @@
"execution_count": 10,
"id": "265725f6-a143-41e0-8438-9585f4cee09e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.561824Z",
"start_time": "2024-04-02T17:30:49.500776600Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -497,6 +507,10 @@
"execution_count": 11,
"id": "07cb973d-4dc4-476d-956b-e73de5ca2f56",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.518777200Z"
},
"tags": []
},
"outputs": [
Expand DownExpand Up@@ -553,7 +567,12 @@
"cell_type": "code",
"execution_count": 12,
"id": "e7e88143-14e1-4210-9b8f-f282ebb93fdd",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.563825Z",
"start_time": "2024-04-02T17:30:49.535779800Z"
}
},
"outputs": [],
"source": [
"# we rounded the coordinates to make it less verbose here in the notebook\n",
Expand DownExpand Up@@ -592,7 +611,12 @@
"cell_type": "code",
"execution_count": 13,
"id": "a39af193-ecc9-4f2b-9fe3-a21aa6e3612b",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:49.565821600Z",
"start_time": "2024-04-02T17:30:49.547776500Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -641,7 +665,12 @@
"cell_type": "code",
"execution_count": 14,
"id": "7fbd77aa-9e6b-4597-b924-2f86eeb924bb",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:30:50.149186700Z",
"start_time": "2024-04-02T17:30:49.563825Z"
}
},
"outputs": [
{
"name": "stderr",
Expand DownExpand Up@@ -671,7 +700,12 @@
"cell_type": "code",
"execution_count": 15,
"id": "cbd6d2d5-b5b6-4b60-899c-7c79b77e55e4",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:36:13.430881600Z",
"start_time": "2024-04-02T17:36:13.415878Z"
}
},
"outputs": [
{
"data": {
Expand DownExpand Up@@ -702,6 +736,69 @@
"filtered_tables"
]
},
{
"cell_type": "markdown",
"id": "b259322b39d43b07",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Note that polygon_query only returns a table in case of the table annotating an element in the \n",
"resulting queried `SpatialData` object. Other tables are filtered out. Should you want to keep \n",
"tables that are not annotating any elements in the resulting `SpatialData` object, a parameter \n",
"`filter_tables` set to `False` can be passed on to the `polygon_query` function. Which region(s) or \n",
"elements a table annotates can be retrieved as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7c35473723cb95f3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-02T17:33:16.943803100Z",
"start_time": "2024-04-02T17:33:16.928757900Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CytAssist_FFPE_Human_Breast_Cancer\n"
]
}
],
"source": [
"from spatialdata import SpatialData\n",
"\n",
"# Note that we could also do visium_sdata.get_annotated regions here. This is just meant to show we\n",
"# can also get annotated regions from a table outside a Spatialdata object.\n",
"print(SpatialData.get_annotated_regions(visium_sdata[\"table\"]))"
]
},
{
"cell_type": "markdown",
"id": "632783dbf2e93b4b",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"It can be that a table is annotating an element but is still not returned after the polygon query. \n",
"The reason in that case is that the resulting table didn't contain any rows annotating elements in \n",
"the result of the query."
]
},
{
"cell_type": "markdown",
"id": "974e2a73-3296-405b-b57a-3d5199563d10",
Expand All@@ -712,9 +809,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "e60b1ccb-58a6-4c04-929f-58bfa612fc30",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.181187Z"
}
},
"outputs": [],
"source": [
"# it's important for the index to be unique\n",
Expand All@@ -723,9 +824,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "c8152e43-31db-46e5-a01a-5983960f1910",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.182187500Z"
}
},
"outputs": [],
"source": [
"categories = [\"unassigned\"] + list(filtered_tables.keys())\n",
Expand All@@ -740,9 +845,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "460d8932-f73c-4b04-9121-17e2d28779e7",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.183187300Z"
}
},
"outputs": [
{
"data": {
Expand All@@ -755,7 +864,7 @@
"Name: count, dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All@@ -774,16 +883,20 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "28ebf11b-b070-4b7a-8651-02affa387b6c",
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2024-04-02T17:30:50.184187400Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:651: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
"/Users/macbook/embl/projects/basel/spatialdata-plot/src/spatialdata_plot/pl/utils.py:692: FutureWarning: The default value of 'ignore' for the `na_action` parameter in pandas.Categorical.map is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning\n",
" color_vector = color_source_vector.map(color_map)\n"
]
},
Expand Down
Loading