|
| 1 | +# %% |
| 2 | +import tempfile |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import torch |
| 6 | + |
| 7 | +from stamp.cache import download_file |
| 8 | +from stamp.heatmaps import heatmaps_ |
| 9 | + |
| 10 | +# %% |
| 11 | + |
| 12 | + |
| 13 | +def test_heatmap_integration(): |
| 14 | + example_chekpoint_path = download_file( |
| 15 | + url="https://github.com/KatherLab/STAMP/releases/download/2.0.0-dev8/example-model.ckpt", |
| 16 | + file_name="example-model.ckpt", |
| 17 | + sha256sum="a71dffd4b5fdb82acd5f84064880efd3382e200b07e5a008cb53e03197b6de56", |
| 18 | + ) |
| 19 | + example_slide_path = download_file( |
| 20 | + url="https://github.com/KatherLab/STAMP/releases/download/2.0.0.dev14/TCGA-G4-6625-01Z-00-DX1.0fa26667-2581-4f96-a891-d78dbc3299b4.svs", |
| 21 | + file_name="TCGA-G4-6625-01Z-00-DX1.0fa26667-2581-4f96-a891-d78dbc3299b4.svs", |
| 22 | + sha256sum="9b7d2b0294524351bf29229c656cc886af028cb9e7463882289fac43c1347525", |
| 23 | + ) |
| 24 | + example_feature_path = download_file( |
| 25 | + url="https://github.com/KatherLab/STAMP/releases/download/2.0.0.dev14/TCGA-G4-6625-01Z-00-DX1.0fa26667-2581-4f96-a891-d78dbc3299b4-mahmood-uni.h5", |
| 26 | + file_name="TCGA-G4-6625-01Z-00-DX1.0fa26667-2581-4f96-a891-d78dbc3299b4-mahmood-uni.h5", |
| 27 | + sha256sum="13b1390241e73a3969915d3d01c5c64f1b7c68318a685d8e3bf851067162f0bc", |
| 28 | + ) |
| 29 | + with tempfile.TemporaryDirectory(prefix="stamp_test_heatmaps_") as tmp_dir: |
| 30 | + dir = Path(tmp_dir) |
| 31 | + wsi_dir = dir / "wsis" |
| 32 | + wsi_dir.mkdir() |
| 33 | + (wsi_dir / "slide.svs").symlink_to(example_slide_path) |
| 34 | + feature_dir = dir / "feats" |
| 35 | + feature_dir.mkdir() |
| 36 | + (feature_dir / "slide.h5").symlink_to(example_feature_path) |
| 37 | + |
| 38 | + heatmaps_( |
| 39 | + feature_dir=feature_dir, |
| 40 | + wsi_dir=wsi_dir, |
| 41 | + checkpoint_path=example_chekpoint_path, |
| 42 | + output_dir=dir / "output", |
| 43 | + slide_paths=None, |
| 44 | + device="cuda" if torch.cuda.is_available() else "cpu", |
| 45 | + topk=5, |
| 46 | + bottomk=5, |
| 47 | + ) |
0 commit comments