Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds napari screenshot to quickstart #1910

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ help-docs:

### REQUIREMENTS #############################################
#
GENERATED_REQUIREMENT_FILES=starfish/REQUIREMENTS-STRICT.txt requirements/REQUIREMENTS-CI.txt requirements/REQUIREMENTS-NAPARI-CI.txt
SOURCE_REQUIREMENT_FILES=REQUIREMENTS.txt requirements/REQUIREMENTS-CI.txt.in requirements/REQUIREMENTS-NAPARI-CI.txt.in
GENERATED_REQUIREMENT_FILES=starfish/REQUIREMENTS-STRICT.txt requirements/REQUIREMENTS-CI.txt requirements/REQUIREMENTS-NAPARI-CI.txt requirements/REQUIREMENTS-DOCS.txt
SOURCE_REQUIREMENT_FILES=REQUIREMENTS.txt requirements/REQUIREMENTS-CI.txt.in requirements/REQUIREMENTS-NAPARI-CI.txt.in requirements/REQUIREMENTS-DOCS.txt.in

# This rule pins the requirements with the minimal set of changes required to satisfy the
# requirements. This is typically run when a new requirement is added, and we want to
Expand Down
6 changes: 5 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
'download_section_examples': False,
'default_thumb_file': f'{dir_}/_static/design/logo-solo.png',
'min_reported_time': 10,
'first_notebook_cell': ("# This cell is added by sphinx-gallery\n"
"# It can be customized to whatever you like\n"
"%matplotlib inline\n"
"%gui qt"),

}

Expand Down Expand Up @@ -157,7 +161,7 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
def setup(app):
app.add_stylesheet("my-styles.css")
app.add_css_file("my-styles.css")

html_theme_options = {
'navbar_title': " ",
Expand Down
6 changes: 5 additions & 1 deletion examples/data_loading/plot_loading_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@
# can optionally specify a set of cropping parameters. To demonstrate how those work, we'll slice
# out a 100 pixel square from the :code:`(200, 140)` pixel :py:class:`.FieldOfView`:

from starfish import display

image = fov.get_image("primary", x=slice(0, 100), y=slice(0, 100))
image

display(stack=image)

###################################################################################################
# Calling :py:meth:`.FieldOfView.get_image` localizes the data and produces an
# :py:class:`.ImageStack`, a 5-d tensor and *starfish*'s main in-memory image storage and
# processing class.
# processing class.
17 changes: 7 additions & 10 deletions examples/quick_start/plot_quick_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@
# the dimension slider to compare channels 1 and 3 of round 1 (zero-based indexing),
# you can already see which cells express mouse ACTB and which cells express human ACTB.
#
# .. code-block:: python
#
# from starfish import display
#
# %gui qt
# viewer = display(imgs)
# viewer.layers[0].name = "raw stack" # rename the layer
from starfish import display

viewer = display(imgs)
viewer.layers[0].name = "raw stack" # rename the layer
viewer

####################################################################################################
# **View codebook**
Expand Down Expand Up @@ -260,9 +258,8 @@ def make_expression_matrix(masks, decoded):
# and segmented cells (:py:class:`.BinaryMaskCollection`) as layers in napari to verify the
# results.
#
# .. code-block:: python
#
# display(stack=registered_imgs, spots=decoded, masks=masks, viewer=viewer)

display(stack=registered_imgs, spots=decoded, masks=masks, viewer=viewer)

####################################################################################################
# **View decoded spots as a table**
Expand Down
2 changes: 1 addition & 1 deletion readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ build:
python:
version: 3.6
install:
- requirements: requirements/REQUIREMENTS-CI.txt
- requirements: requirements/REQUIREMENTS-DOCS.txt
- method: pip
path: .
141 changes: 141 additions & 0 deletions requirements/REQUIREMENTS-DOCS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# You should not edit this file directly. Instead, you should edit one of the following files (requirements/REQUIREMENTS-DOCS.txt.in) and run make requirements/REQUIREMENTS-DOCS.txt
alabaster==0.7.12
appdirs==1.4.4
appnope==0.1.2
argon2-cffi==20.1.0
async-generator==1.10
attrs==20.3.0
Babel==2.9.0
backcall==0.2.0
bleach==3.3.0
boto3==1.17.10
botocore==1.20.10
cached-property==1.5.2
cachey==0.2.1
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==7.1.2
cycler==0.10.0
dask==2021.2.0
dataclasses==0.6
decorator==4.4.2
defusedxml==0.6.0
diskcache==5.2.1
docutils==0.16
entrypoints==0.3
freetype-py==2.2.0
h5py==3.1.0
HeapDict==1.0.1
idna==2.10
imageio==2.9.0
imagesize==1.2.0
importlib-metadata==3.4.0
iniconfig==1.1.1
ipykernel==5.4.3
ipython==7.16.1
ipython-genutils==0.2.0
ipywidgets==7.6.3
jedi==0.18.0
Jinja2==2.11.3
jmespath==0.10.0
joblib==1.0.1
jsonschema==3.2.0
jupyter-client==6.1.11
jupyter-core==4.7.1
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.0
kiwisolver==1.3.1
m2r2==0.2.7
MarkupSafe==1.1.1
matplotlib==3.3.4
mistune==0.8.4
mpmath==1.2.1
napari==0.3.8
napari-plugin-engine==0.1.9
napari-svg==0.1.4
nbclient==0.5.2
nbconvert==6.0.7
nbformat==5.1.2
nest-asyncio==1.5.1
networkx==2.5
notebook==6.2.0
numpy==1.19.5
numpydoc==1.1.0
packaging==20.9
pandas==1.1.5
pandocfilters==1.4.3
parso==0.8.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow==8.1.0
pluggy==0.13.1
prometheus-client==0.9.0
prompt-toolkit==3.0.16
psutil==5.8.0
ptyprocess==0.7.0
py==1.10.0
pycparser==2.20
Pygments==2.8.0
PyOpenGL==3.1.5
pyparsing==2.4.7
PyQt5==5.14.2
PyQt5-sip==12.8.1
pyrsistent==0.17.3
pytest==6.2.2
pytest-qt==3.3.0
python-dateutil==2.8.0
pytz==2021.1
PyWavelets==1.1.1
PyYAML==5.4.1
pyzmq==22.0.3
qtconsole==5.0.2
QtPy==1.9.0
read-roi==1.6.0
regional==1.1.2
requests==2.25.1
s3transfer==0.3.4
scikit-image==0.15.0
scikit-learn==0.24.1
scipy==1.5.4
seaborn==0.11.1
semantic-version==2.8.5
Send2Trash==1.5.0
setuptools==40.6.2
showit==1.1.4
six==1.15.0
slicedimage==4.1.1
snowballstemmer==2.1.0
Sphinx==3.5.1
sphinx-autodoc-typehints==1.11.1
sphinx-bootstrap-theme==0.7.1
sphinx-gallery==0.8.2
sphinx-rtd-theme==0.5.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-programoutput==0.16
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sympy==1.5.1
terminado==0.9.2
testpath==0.4.4
threadpoolctl==2.1.0
tifffile==2020.9.3
toml==0.10.2
toolz==0.11.1
tornado==6.1
tqdm==4.56.2
trackpy==0.4.2
traitlets==4.3.3
typing-extensions==3.7.4.3
urllib3==1.26.3
validators==0.18.2
vispy==0.6.6
wcwidth==0.2.5
webencodings==0.5.1
widgetsnbextension==3.5.1
wrapt==1.12.1
xarray==0.16.2
zipp==3.4.0
11 changes: 11 additions & 0 deletions requirements/REQUIREMENTS-DOCS.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
napari >= 0.3.4
PyQt5==5.14.2
pytest-qt
sphinx
sphinx_autodoc_typehints
sphinx_bootstrap_theme
sphinxcontrib-programoutput
sphinx-gallery
sphinx_rtd_theme
m2r2
seaborn
30 changes: 28 additions & 2 deletions starfish/core/_display.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import __main__
import base64
import warnings
from collections import OrderedDict
from io import BytesIO
from typing import Iterable, List, Optional, Set, Tuple, Union

import numpy as np
Expand All @@ -13,9 +15,33 @@
from starfish.core.types import Axes, Features

try:
from napari import Viewer
from napari import Viewer as NapariViewer

class Viewer(NapariViewer):

def _get_png(self):
from imageio import imsave

image = self.screenshot(canvas_only=False)
with BytesIO() as file_obj:
imsave(file_obj, image, format='png')
file_obj.seek(0)
png = file_obj.read()
return png

def _repr_html_(self):

png = self._get_png()
data = base64.b64encode(png).decode('utf-8')

return (
"<div>"
f"<img class='screenshot' src='data:image/png;base64, {data}' />"
"</div>"
)

except ImportError:
Viewer = None
Viewer = None # type: ignore


NAPARI_VERSION = "0.3.4" # when changing this, update docs in display
Expand Down