Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Sep 15, 2024
1 parent 2f49427 commit 6dda361
Show file tree
Hide file tree
Showing 54 changed files with 334 additions and 1,877 deletions.
11 changes: 7 additions & 4 deletions src/lazyslide/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Efficient and Scalable Whole Slide Image (WSI) processing library."""
__version__ = "0.1.0"

from wsi_data import open_wsi
import lazyslide.pp as pp
import lazyslide.tl as tl
import lazyslide.pl as pl
from . import preprocess as pp
from . import tools as tl
from . import plotting as pl
from . import models as models

# Re-export
from wsidata import open_wsi, agg_wsi
4 changes: 2 additions & 2 deletions src/lazyslide/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def feature(
wsi = zs.open_wsi(slide, backed_file=output)
print(f"Read slide file {slide}")
print(f"Extract features using model {model}")
zs.tl.feature_extraction(wsi, model, slide_encoder=slide_encoder, device=device)
zs.tl.feature_extraction(wsi, model, slide_agg=slide_encoder, device=device)
wsi.save()
print(f"Write to {wsi.sdata.path}")

Expand All @@ -136,7 +136,7 @@ def agg_wsi(
slide_table: Path = Argument(..., help="The slide table file"),
output: Optional[str] = OUTPUT,
):
from wsi_data import agg_wsi
from wsidata import agg_wsi

print(f"Read slide table {slide_table}")
slides_table = pd.read_csv(slide_table)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple

ScoreResult = namedtuple("Score", ["scores", "qc"])
ScoreResult = namedtuple("ScoreResult", ["scores", "qc"])


class ScorerBase:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/lazyslide/utils.py → src/lazyslide/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from rich.console import Console

console = Console()


def get_torch_device():
"""Automatically get the torch device"""
import torch
Expand Down Expand Up @@ -27,6 +32,7 @@ def default_pbar(disable=False):
TaskProgressColumn(),
TimeRemainingColumn(compact=True, elapsed_when_finished=True),
disable=disable,
console=console,
)


Expand Down
9 changes: 0 additions & 9 deletions src/lazyslide/data/__init__.py

This file was deleted.

135 changes: 0 additions & 135 deletions src/lazyslide/data/datasets.py

This file was deleted.

92 changes: 0 additions & 92 deletions src/lazyslide/data/prepare.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/lazyslide/pl/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions src/lazyslide/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._api import tissue, tiles
from ._report import qc_summary
34 changes: 20 additions & 14 deletions src/lazyslide/pl/api.py → src/lazyslide/plotting/_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib.pyplot as plt

from wsi_data import WSIData
from .viewer import SlideViewer
from wsidata import WSIData
from ._viewer import SlideViewer
from .._const import Key


Expand All @@ -14,6 +14,7 @@ def tissue(
show_contours=True,
show_origin=True,
show_id=True,
show_bbox=None,
render_size=1000,
scale_bar=True,
ax=None,
Expand Down Expand Up @@ -51,9 +52,9 @@ def tissue(
:context: close-figs
>>> import lazyslide as zs
>>> wsi = zs.WSI("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> zs.pp.find_tissue(wsi)
>>> zs.pl.tissue(wsi)
>>> wsi = zs.open_wsi("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> zs.preprocess.find_tissue(wsi)
>>> zs.plotting.tissue(wsi)
"""
if ax is None:
Expand All @@ -71,8 +72,10 @@ def tissue(
slide.add_origin(ax=ax)
if show_id:
slide.add_tissue_id(ax=ax)
if show_contours:
slide.add_contours_holes(ax=ax)
if show_bbox is None:
show_bbox = True
if show_contours or show_bbox:
slide.add_contours_holes(ax=ax, show_bbox=show_bbox, show_shape=show_contours)
slide.add_title(title, ax=ax)


Expand All @@ -91,6 +94,7 @@ def tiles(
show_contours=True,
show_origin=True,
show_id=False,
show_bbox=None,
render_size=1000,
alpha=0.9,
marker="o",
Expand Down Expand Up @@ -172,11 +176,11 @@ def tiles(
:context: close-figs
>>> import lazyslide as zs
>>> wsi = zs.WSI("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> zs.pp.find_tissue(wsi)
>>> zs.pp.tiles(wsi, 256, mpp=0.5)
>>> zs.pp.tiles_qc(wsi, scorers=["contrast"])
>>> zs.pl.tiles(wsi, tissue_id=0, show_grid=True, color='contrast')
>>> wsi = zs.open_wsi("https://github.com/camicroscope/Distro/raw/master/images/sample.svs")
>>> zs.preprocess.find_tissue(wsi)
>>> zs.preprocess.tiles(wsi, 256, mpp=0.5)
>>> zs.preprocess.tiles_qc(wsi, scorers=["contrast"])
>>> zs.plotting.tiles(wsi, tissue_id=0, show_grid=True, color='contrast')
"""
if ax is None:
Expand All @@ -196,8 +200,10 @@ def tiles(
slide.add_origin(ax=ax)
if show_id:
slide.add_tissue_id(ax=ax)
if show_contours:
slide.add_contours_holes(ax=ax)
if show_bbox is None:
show_bbox = True
if show_contours or show_bbox:
slide.add_contours_holes(ax=ax, show_bbox=show_bbox, show_shape=show_contours)
if show_point:
slide.add_points(
feature_key=feature_key,
Expand Down
Loading

0 comments on commit 6dda361

Please sign in to comment.