Skip to content

Commit

Permalink
add examples to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
eabila committed Sep 17, 2024
1 parent f21a559 commit ef5a586
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions lazyslide/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ def tissue_contours(
key : str, default: "tissue"
The tissue key.
as_array : bool, default: False
Return the contour as an array.
If False, the contour is returned as a shapely geometry.
Returns the contour as an array.
If False, the contour is returned as a shapely geometry object.
shuffle : bool, default: False
If True, return tissue contour in random order.
Examples
--------
>>> import lazyslide as zs
>>> wsi = zs.WSI("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> for tissue_contour in zs.get.tissue_contours(wsi):
... print(tissue_contour.tissue_id, tissue_contour.contour)
"""
if f"{key}_contours" not in wsi.sdata.shapes:
raise ValueError(f"Contour {key}_contours not found.")
Expand Down Expand Up @@ -78,7 +86,7 @@ def tissue_images(
tissue_key : str, default: "tissue"
The tissue key.
level : int, default: 0
The level to extract the tissue images.
The level to extract the tissue images from.
mask_bg : bool | int, default: False
Mask the background with the given value.
If False, the background is not masked.
Expand All @@ -87,6 +95,15 @@ def tissue_images(
color_norm : str, {"macenko", "reinhard"}, default: None
Color normalization method.
Examples
--------
>>> import matplotlib.pyplot as plt
>>> import lazyslide as zs
>>> wsi = zs.WSI("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> for tissue_image in zs.get.tissue_images(wsi):
... plt.imshow()
"""

level_downsample = wsi.metadata.level_downsample[level]
Expand Down Expand Up @@ -212,7 +229,13 @@ def tile_images(


def pyramids(wsi):
"""Return a dataframe with the pyramid levels"""
"""Return a dataframe with the pyramid levels
Parameters
----------
wsi : WSI
The whole-slide image object
"""
heights, widths = zip(*wsi.metadata.level_shape)
return pd.DataFrame(
{
Expand All @@ -229,7 +252,24 @@ def features_anndata(
tile_key="tiles",
feature_key=None,
):
"""Convert the WSI to an AnnData object"""
"""Convert the WSI to an AnnData object
Parameters
----------
wsi : WSI
The whole-slide image object.
tile_key : str, default: "tiles"
The tile key.
feature_key : str, default: None
The feature key pointing to the numeric tile features.
Examples
--------
>>> import lazyslide as zs
>>> wsi = zs.WSI("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> adata = zs.get.features_anndata(wsi)
"""
return wsi.get_features(feature_key, tile_key=tile_key)


Expand Down

0 comments on commit ef5a586

Please sign in to comment.