Skip to content

Commit

Permalink
fixed napari index
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinyamauchi authored and ambrosejcarr committed Dec 16, 2018
1 parent de62eef commit e5e2b6a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 32 deletions.
83 changes: 56 additions & 27 deletions notebooks/test_napari.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%gui qt5\n",
"\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -47,7 +46,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 102/102 [00:04<00:00, 21.95it/s]\n"
"100%|██████████| 102/102 [07:40<00:00, 5.67s/it]\n"
]
}
],
Expand All @@ -59,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -69,21 +68,10 @@
"/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/vispy/visuals/isocurve.py:22: UserWarning: VisPy is not yet compatible with matplotlib 2.2+\n",
" warnings.warn(\"VisPy is not yet compatible with matplotlib 2.2+\")\n"
]
},
{
"data": {
"text/plain": [
"(<napari_gui.elements._viewer.Viewer at 0x18513bba8>,\n",
" [<Indices.ROUND: 'r'>, <Indices.CH: 'c'>, <Indices.Z: 'z'>])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"primary_image.show_stack_napari({})"
"viewer, ind = primary_image.show_stack_napari({})"
]
},
{
Expand All @@ -96,16 +84,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"102it [00:00, 202.79it/s]\n",
"102it [00:00, 304.91it/s]\n",
"3it [00:00, 104.66it/s]\n"
"102it [00:00, 156.95it/s]\n",
"102it [00:00, 131.20it/s]\n",
"3it [00:00, 12.05it/s]\n"
]
},
{
Expand All @@ -114,7 +102,7 @@
"<starfish.ImageStack (r: 1, c: 3, z: 34, y: 2048, x: 2048)>"
]
},
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -146,25 +134,35 @@
"decoded = IntensityTable.load('allen_decoded')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Displaying spots on a 3D image volume\n",
"show_spots_napari() projects the provided background image (mirroring language from decoded spots - maybe we should rename) along the rnd and channel axes and overlays the spots as ring markers.\n",
"\n",
"Spot marker parameters (e.g., opacity, size, color) can be adjusted by double clicking the \"markers\" box in the right panel. They can also be toggled on/off by clicking the \"eye\" checkbox icon."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 34/34 [00:00<00:00, 106.80it/s]\n"
"100%|██████████| 34/34 [00:00<00:00, 105.84it/s]\n"
]
},
{
"data": {
"text/plain": [
"<napari_gui.elements._viewer.Viewer at 0x1859f1a20>"
"<napari_gui.elements._viewer.Viewer at 0x193d56ba8>"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -175,12 +173,43 @@
"starfish.plot.show_spots_napari(spots=decoded, background_image=primary_image)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Z projected images\n",
"show_spots_napari can also take images projected along the z axis and automatically project the decoded spots along the z axis.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1/1 [00:00<00:00, 56.97it/s]\n",
"100%|██████████| 1/1 [00:00<00:00, 128.56it/s]\n"
]
},
{
"data": {
"text/plain": [
"<napari_gui.elements._viewer.Viewer at 0x1916121d0>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mp = primary_image.max_proj(Indices.CH, Indices.ROUND, Indices.Z)\n",
"\n",
"starfish.plot.show_spots_napari(spots=decoded, background_image=mp)"
]
}
],
"metadata": {
Expand Down
24 changes: 19 additions & 5 deletions starfish/plot/show_spots_napari.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from numpy import array, zeros
from numpy import zeros, array

from starfish import IntensityTable
from starfish.types import Indices
Expand All @@ -9,16 +9,30 @@ def show_spots_napari(
background_image=None,
radius_multiplier=30):

c_r = list(zeros(len(spots.y.values)))
coords = array([spots.x.values, spots.y.values, c_r, c_r, spots.z.values]).T

mp = background_image.max_proj(Indices.CH, Indices.ROUND)

# Make the array of maker coordinates
# If the background image is z projected, also z project the coordinates
c_r = zeros(len(spots.y.values))
if mp.raw_shape[2] == 1:
coords = array([spots.x.values, spots.y.values, c_r, c_r, c_r]).T

else:
coords = array([spots.x.values, spots.y.values, c_r, c_r, spots.z.values]).T

# Create the Napari viewer with an image stack
viewer, axes = mp.show_stack_napari({})

# This initializes an index for the instantiated marker display
# Should be fixed in Napari in the future - KY
viewer._index = [0,0,0,0,0]

# Get the sizes
sizes = spots.radius.values * radius_multiplier

# Add the markers to the viewer
viewer.add_markers(coords, face_color='white', edge_color='white', symbol='ring', size=sizes)
viewer.add_markers(
coords=coords, face_color='white', edge_color='white',
symbol='ring', size=sizes)

return viewer

0 comments on commit e5e2b6a

Please sign in to comment.