Skip to content

Commit

Permalink
Make IntensityTable and ImageStack mandatory, adjust code to pass lin…
Browse files Browse the repository at this point in the history
…t & mypy, add docstring
  • Loading branch information
ambrosejcarr committed Dec 16, 2018
1 parent e5e2b6a commit fd18a0f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 54 deletions.
59 changes: 38 additions & 21 deletions notebooks/test_napari.ipynb
Expand Up @@ -46,7 +46,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 102/102 [07:40<00:00, 5.67s/it]\n"
"100%|██████████| 102/102 [00:03<00:00, 26.80it/s]\n"
]
}
],
Expand All @@ -58,14 +58,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/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",
"/Users/ambrosecarr/projects/spacetx/starfish/.venv/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"
]
}
Expand All @@ -84,16 +84,16 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"102it [00:00, 156.95it/s]\n",
"102it [00:00, 131.20it/s]\n",
"3it [00:00, 12.05it/s]\n"
"102it [00:00, 487.57it/s]\n",
"102it [00:00, 576.99it/s]\n",
"3it [00:00, 64.72it/s]\n"
]
},
{
Expand All @@ -102,7 +102,7 @@
"<starfish.ImageStack (r: 1, c: 3, z: 34, y: 2048, x: 2048)>"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -126,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -146,23 +146,33 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 34/34 [00:00<00:00, 105.84it/s]\n"
"100%|██████████| 34/34 [00:00<00:00, 214.03it/s]\n"
]
},
{
"data": {
"text/plain": [
"<napari_gui.elements._viewer.Viewer at 0x193d56ba8>"
"<napari_gui.elements._viewer.Viewer at 0x1992e52e8>"
]
},
"execution_count": 6,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -183,24 +193,24 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"metadata": {},
"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"
"100%|██████████| 1/1 [00:00<00:00, 99.96it/s]\n",
"100%|██████████| 1/1 [00:00<00:00, 168.60it/s]\n"
]
},
{
"data": {
"text/plain": [
"<napari_gui.elements._viewer.Viewer at 0x1916121d0>"
"<napari_gui.elements._viewer.Viewer at 0x1931da4e0>"
]
},
"execution_count": 5,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -210,13 +220,20 @@
"\n",
"starfish.plot.show_spots_napari(spots=decoded, background_image=mp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "starfish",
"language": "python",
"name": "python3"
"name": "starfish"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -228,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.5"
}
},
"nbformat": 4,
Expand Down
77 changes: 44 additions & 33 deletions starfish/plot/show_spots_napari.py
@@ -1,38 +1,49 @@
from numpy import zeros, array
from numpy import array, zeros

from starfish import IntensityTable
from starfish import ImageStack, IntensityTable
from starfish.types import Indices


def show_spots_napari(
spots: IntensityTable=None,
background_image=None,
radius_multiplier=30):

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=coords, face_color='white', edge_color='white',
symbol='ring', size=sizes)

return viewer
spots: IntensityTable, background_image: ImageStack, radius_multiplier: int=30
) -> None:
"""Display detected spots on a background image using Napari
Parameters
----------
spots : IntensityTable
IntensityTable containing spot information. Will be projected to match the coordinates of
the background image, if provided.
background_image : ImageStack
ImageStack containing data to display spots on top of.
radius_multiplier : int
Multiplies the radius of the displayed spots (default 30)
"""

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=coords, face_color='white', edge_color='white', symbol='ring', size=sizes
)

return viewer

0 comments on commit fd18a0f

Please sign in to comment.