diff --git a/notebooks/test_napari.ipynb b/notebooks/test_napari.ipynb index b2c099fad..6b23862fc 100644 --- a/notebooks/test_napari.ipynb +++ b/notebooks/test_napari.ipynb @@ -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" ] } ], @@ -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" ] } @@ -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" ] }, { @@ -102,7 +102,7 @@ "" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -126,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -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": [ - "" + "" ] }, - "execution_count": 6, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -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": [ - "" + "" ] }, - "execution_count": 5, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -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": { @@ -228,7 +245,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/starfish/plot/show_spots_napari.py b/starfish/plot/show_spots_napari.py index 2a5344c3e..5df4d5138 100644 --- a/starfish/plot/show_spots_napari.py +++ b/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