dsa-helpers 0.4.dev4__tar.gz → 0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dsa_helpers-0.5/.gitignore +11 -0
- {dsa_helpers-0.4.dev4/dsa_helpers.egg-info → dsa_helpers-0.5}/PKG-INFO +3 -3
- dsa_helpers-0.5/dsa_helpers/__init__.py +16 -0
- dsa_helpers-0.5/dsa_helpers/dash/__init__.py +3 -0
- dsa_helpers-0.5/dsa_helpers/dash/dash_paperdragon_utils.py +76 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/image_utils.py +19 -10
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/datasets/utils.py +1 -1
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/metrics/binary_dice_coefficient_metric.py +4 -2
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/object_detection/__init__.py +1 -1
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5/dsa_helpers.egg-info}/PKG-INFO +3 -3
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers.egg-info/SOURCES.txt +1 -1
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers.egg-info/requires.txt +1 -1
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/pyproject.toml +3 -3
- dsa_helpers-0.5/requirements.txt +23 -0
- dsa_helpers-0.5/tests/test.ipynb +133 -0
- dsa_helpers-0.4.dev4/.gitignore +0 -11
- dsa_helpers-0.4.dev4/dsa_helpers/__init__.py +0 -8
- dsa_helpers-0.4.dev4/dsa_helpers/dash/__init__.py +0 -1
- dsa_helpers-0.4.dev4/dsa_helpers/login.py +0 -36
- dsa_helpers-0.4.dev4/requirements.txt +0 -15
- dsa_helpers-0.4.dev4/tests/test.ipynb +0 -79
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/LICENSE +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/README.md +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/app.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/dash/header.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/dash/header_callbacks.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/girder_utils.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/imread.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/imwrite.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/__init__.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/datasets/SegFormerSegmentationDataset.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/datasets/__init__.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/metrics/__init__.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/object_detection/get_pearce_roi_images.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/object_detection/tile_image.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/object_detection/utils.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/transforms/__init__.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/transforms/segformer_transforms.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/mongo_utils.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/utils.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers.egg-info/dependency_links.txt +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers.egg-info/top_level.txt +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/setup.cfg +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/tests/app/Dockerfile +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/tests/app/app.py +0 -0
- {dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/tests/docker-compose.yaml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dsa_helpers
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5
|
|
4
4
|
Summary: Utility functions for working with the DSA girder client.
|
|
5
5
|
Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
|
|
6
6
|
Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
|
|
@@ -8,7 +8,7 @@ Project-URL: Repository, https://github.com/Gutman-Lab/dsa-python-utils
|
|
|
8
8
|
Keywords: dsa,girder,girder_client
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: girder-client
|
|
@@ -22,9 +22,9 @@ Requires-Dist: dash
|
|
|
22
22
|
Requires-Dist: dash_bootstrap_components
|
|
23
23
|
Requires-Dist: shapely
|
|
24
24
|
Requires-Dist: geopandas
|
|
25
|
+
Requires-Dist: transformers[torch]
|
|
25
26
|
Requires-Dist: torch
|
|
26
27
|
Requires-Dist: datasets
|
|
27
|
-
Requires-Dist: transformers
|
|
28
28
|
Requires-Dist: torchvision
|
|
29
29
|
|
|
30
30
|
# Digital Slide Archive (DSA) Helpers
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Shadow imports.
|
|
2
|
+
from .imread import imread
|
|
3
|
+
from .imwrite import imwrite
|
|
4
|
+
from . import girder_utils, image_utils, dash, ml, mongo_utils, utils
|
|
5
|
+
|
|
6
|
+
# Modules that should be available.
|
|
7
|
+
__all__ = [
|
|
8
|
+
"girder_utils",
|
|
9
|
+
"image_utils",
|
|
10
|
+
"dash",
|
|
11
|
+
"ml",
|
|
12
|
+
"imread",
|
|
13
|
+
"imwrite",
|
|
14
|
+
"mongo_utils",
|
|
15
|
+
"utils",
|
|
16
|
+
]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
def format_ann_docs_for_paperjs(
|
|
2
|
+
geojson_ann_docs: list[dict], return_as_input_to_paper: bool = False
|
|
3
|
+
) -> list[dict]:
|
|
4
|
+
"""Format DSA annotations in the geojson format into a format that paperdragon
|
|
5
|
+
can read and show as polygons.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
geojson_ann_docs (list[dict]): A list of geojson annotation documents.
|
|
9
|
+
return_as_input_to_paper (bool): Whether to return the formatted documents as
|
|
10
|
+
input to paper. Defaults to False.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
list[dict]: A list of formatted annotation documents for paperjs. Note that
|
|
14
|
+
it will return an empty list if the documents could not be formatted.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
# NOTE: hard-coded to only do the first doc.
|
|
18
|
+
formatted_docs = []
|
|
19
|
+
|
|
20
|
+
# Loop through each annotation document.
|
|
21
|
+
for ann_doc in geojson_ann_docs:
|
|
22
|
+
# Grab the features of this document, contains the polygon info.
|
|
23
|
+
features_to_include = []
|
|
24
|
+
|
|
25
|
+
for feature in ann_doc["features"]:
|
|
26
|
+
geometry = feature["geometry"]
|
|
27
|
+
if geometry["type"] == "Polygon":
|
|
28
|
+
properties = feature["properties"]
|
|
29
|
+
properties["rescale"] = {"strokeWidth": properties["lineWidth"]}
|
|
30
|
+
properties["strokeColor"] = properties["lineColor"]
|
|
31
|
+
properties["source"] = "dsa"
|
|
32
|
+
|
|
33
|
+
# Paperjs only supports multipolygons.
|
|
34
|
+
geometry["type"] = "MultiPolygon"
|
|
35
|
+
|
|
36
|
+
coordinates = geometry["coordinates"]
|
|
37
|
+
|
|
38
|
+
adjusted_coordinates = [
|
|
39
|
+
[[[int(coord) for coord in point[:2]] for point in coordinates[0]]]
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
geometry["coordinates"] = adjusted_coordinates
|
|
43
|
+
|
|
44
|
+
features_to_include.append(feature)
|
|
45
|
+
|
|
46
|
+
if len(features_to_include):
|
|
47
|
+
formatted_docs.append(features_to_include)
|
|
48
|
+
|
|
49
|
+
if return_as_input_to_paper:
|
|
50
|
+
return get_input_to_paper_dict(formatted_docs)
|
|
51
|
+
|
|
52
|
+
return formatted_docs
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_input_to_paper_dict(formatted_docs: list[dict] | None = None) -> dict:
|
|
56
|
+
"""Get the input to paper dictionary.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
formatted_docs (list[dict]): A list of formatted annotation documents for paperjs.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
dict: The input to paper dictionary.
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
input_to_paper = [{"type": "clearItems"}]
|
|
66
|
+
|
|
67
|
+
if formatted_docs is not None and len(formatted_docs):
|
|
68
|
+
for doc in formatted_docs:
|
|
69
|
+
input_to_paper.append(
|
|
70
|
+
{
|
|
71
|
+
"type": "drawItems",
|
|
72
|
+
"itemList": doc,
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
return {"actions": input_to_paper}
|
|
@@ -13,6 +13,8 @@ def tile_image(
|
|
|
13
13
|
stride: int | None = None,
|
|
14
14
|
fill: int | tuple = (255, 255, 255),
|
|
15
15
|
prepend_name: str = "",
|
|
16
|
+
overwrite: bool = False,
|
|
17
|
+
grayscale: bool = False,
|
|
16
18
|
) -> pd.DataFrame:
|
|
17
19
|
"""Tile an image into smaller images.
|
|
18
20
|
|
|
@@ -25,6 +27,10 @@ def tile_image(
|
|
|
25
27
|
fill (int | tuple, optional): The fill value for tiles over the edges.
|
|
26
28
|
Defaults to (255, 255, 255).
|
|
27
29
|
prepend_name (str, optional): A string to prepend to the tile names.
|
|
30
|
+
overwrite (bool, optional): Whether to overwrite existing images.
|
|
31
|
+
Defaults to False.
|
|
32
|
+
grayscale (bool, optional): Whether to save images as grayscale instead
|
|
33
|
+
of the default RGB. Defaults to False.
|
|
28
34
|
|
|
29
35
|
Returns:
|
|
30
36
|
pandas.DataFrame: A DataFrame with the tile locations.
|
|
@@ -38,9 +44,7 @@ def tile_image(
|
|
|
38
44
|
|
|
39
45
|
# Pad the image to avoid tiles not of the right size.
|
|
40
46
|
save_loc = Path(save_loc)
|
|
41
|
-
|
|
42
|
-
if not save_loc.exists():
|
|
43
|
-
save_loc.mkdir(parents=True)
|
|
47
|
+
save_loc.mkdir(parents=True, exist_ok=True)
|
|
44
48
|
|
|
45
49
|
if stride is None:
|
|
46
50
|
stride = tile_size
|
|
@@ -49,17 +53,22 @@ def tile_image(
|
|
|
49
53
|
|
|
50
54
|
xys = [(x, y) for x in range(0, w, stride) for y in range(0, h, stride)]
|
|
51
55
|
|
|
56
|
+
if prepend_name:
|
|
57
|
+
prepend_name += "_"
|
|
58
|
+
|
|
52
59
|
for xy in xys:
|
|
60
|
+
# Get the top left and bottom right coordinates of the tile.
|
|
53
61
|
x, y = xy
|
|
54
|
-
# Get the tile from the image.
|
|
55
|
-
tile_img = img[x : x + tile_size, y : y + tile_size]
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
# Filepath for saving tile.
|
|
64
|
+
save_fp = save_loc / f"{prepend_name}x{x}y{y}tilesize{tile_size}.png"
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
if not save_fp.is_file() or overwrite:
|
|
67
|
+
# Get the tile from the image.
|
|
68
|
+
tile_img = img[y : y + tile_size, x : x + tile_size]
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
imwrite(save_fp, tile_img, grayscale=grayscale)
|
|
62
71
|
|
|
63
|
-
|
|
72
|
+
df_data.append([save_fp, x, y, tile_size])
|
|
64
73
|
|
|
65
|
-
return
|
|
74
|
+
return pd.DataFrame(df_data, columns=["fp", "x", "y", "tile_size"])
|
{dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/metrics/binary_dice_coefficient_metric.py
RENAMED
|
@@ -7,7 +7,8 @@ def binary_dice_coefficient_metric(eval_pred):
|
|
|
7
7
|
with torch.no_grad():
|
|
8
8
|
logits, labels = eval_pred # assumed both are numpy
|
|
9
9
|
|
|
10
|
-
logits_tensor = torch.from_numpy(logits)
|
|
10
|
+
logits_tensor = torch.from_numpy(logits).cpu()
|
|
11
|
+
labels_tensor = torch.from_numpy(labels).cpu()
|
|
11
12
|
|
|
12
13
|
# Scale the logits to the size of the label.
|
|
13
14
|
logits_tensor = nn.functional.interpolate(
|
|
@@ -17,6 +18,7 @@ def binary_dice_coefficient_metric(eval_pred):
|
|
|
17
18
|
align_corners=False,
|
|
18
19
|
).argmax(dim=1)
|
|
19
20
|
|
|
20
|
-
pred_labels = logits_tensor.detach().
|
|
21
|
+
pred_labels = logits_tensor.detach().numpy()
|
|
22
|
+
labels = labels_tensor.numpy()
|
|
21
23
|
|
|
22
24
|
return {"dice_coefficient": binary_dice_coefficient(pred_labels, labels)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dsa_helpers
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5
|
|
4
4
|
Summary: Utility functions for working with the DSA girder client.
|
|
5
5
|
Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
|
|
6
6
|
Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
|
|
@@ -8,7 +8,7 @@ Project-URL: Repository, https://github.com/Gutman-Lab/dsa-python-utils
|
|
|
8
8
|
Keywords: dsa,girder,girder_client
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: girder-client
|
|
@@ -22,9 +22,9 @@ Requires-Dist: dash
|
|
|
22
22
|
Requires-Dist: dash_bootstrap_components
|
|
23
23
|
Requires-Dist: shapely
|
|
24
24
|
Requires-Dist: geopandas
|
|
25
|
+
Requires-Dist: transformers[torch]
|
|
25
26
|
Requires-Dist: torch
|
|
26
27
|
Requires-Dist: datasets
|
|
27
|
-
Requires-Dist: transformers
|
|
28
28
|
Requires-Dist: torchvision
|
|
29
29
|
|
|
30
30
|
# Digital Slide Archive (DSA) Helpers
|
|
@@ -9,7 +9,6 @@ dsa_helpers/girder_utils.py
|
|
|
9
9
|
dsa_helpers/image_utils.py
|
|
10
10
|
dsa_helpers/imread.py
|
|
11
11
|
dsa_helpers/imwrite.py
|
|
12
|
-
dsa_helpers/login.py
|
|
13
12
|
dsa_helpers/mongo_utils.py
|
|
14
13
|
dsa_helpers/utils.py
|
|
15
14
|
dsa_helpers.egg-info/PKG-INFO
|
|
@@ -18,6 +17,7 @@ dsa_helpers.egg-info/dependency_links.txt
|
|
|
18
17
|
dsa_helpers.egg-info/requires.txt
|
|
19
18
|
dsa_helpers.egg-info/top_level.txt
|
|
20
19
|
dsa_helpers/dash/__init__.py
|
|
20
|
+
dsa_helpers/dash/dash_paperdragon_utils.py
|
|
21
21
|
dsa_helpers/dash/header.py
|
|
22
22
|
dsa_helpers/dash/header_callbacks.py
|
|
23
23
|
dsa_helpers/ml/__init__.py
|
|
@@ -15,9 +15,9 @@ dependencies = [
|
|
|
15
15
|
'dash_bootstrap_components',
|
|
16
16
|
'shapely',
|
|
17
17
|
'geopandas',
|
|
18
|
+
"transformers[torch]",
|
|
18
19
|
"torch",
|
|
19
20
|
"datasets",
|
|
20
|
-
"transformers",
|
|
21
21
|
"torchvision"
|
|
22
22
|
]
|
|
23
23
|
name = "dsa_helpers"
|
|
@@ -29,13 +29,13 @@ maintainers = [
|
|
|
29
29
|
]
|
|
30
30
|
description = "Utility functions for working with the DSA girder client."
|
|
31
31
|
readme = "README.md"
|
|
32
|
-
requires-python = ">=3.
|
|
32
|
+
requires-python = ">=3.8"
|
|
33
33
|
classifiers = [
|
|
34
34
|
"Programming Language :: Python :: 3",
|
|
35
35
|
"License :: OSI Approved :: MIT License",
|
|
36
36
|
]
|
|
37
37
|
keywords = ["dsa", "girder", "girder_client"]
|
|
38
|
-
version = "v0.
|
|
38
|
+
version = "v0.5"
|
|
39
39
|
|
|
40
40
|
[project.urls]
|
|
41
41
|
Repository = "https://github.com/Gutman-Lab/dsa-python-utils"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# For developing the package locally.
|
|
2
|
+
build
|
|
3
|
+
twine
|
|
4
|
+
|
|
5
|
+
# For tests.
|
|
6
|
+
matplotlib
|
|
7
|
+
jupyter
|
|
8
|
+
|
|
9
|
+
# Mirrored requirements from pyproject.toml
|
|
10
|
+
girder-client
|
|
11
|
+
numpy
|
|
12
|
+
setuptools
|
|
13
|
+
opencv-python
|
|
14
|
+
pandas
|
|
15
|
+
pymongo
|
|
16
|
+
pillow
|
|
17
|
+
dash
|
|
18
|
+
dash_bootstrap_components
|
|
19
|
+
python-dotenv
|
|
20
|
+
transformers[torch]
|
|
21
|
+
torch
|
|
22
|
+
datasets
|
|
23
|
+
torchvision
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "markdown",
|
|
5
|
+
"metadata": {},
|
|
6
|
+
"source": [
|
|
7
|
+
"# Tests\n",
|
|
8
|
+
"Test different functions of the library."
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"cell_type": "code",
|
|
13
|
+
"execution_count": 16,
|
|
14
|
+
"metadata": {},
|
|
15
|
+
"outputs": [],
|
|
16
|
+
"source": [
|
|
17
|
+
"# Import the library.\n",
|
|
18
|
+
"import dsa_helpers as dh\n",
|
|
19
|
+
"from pathlib import Path\n",
|
|
20
|
+
"import matplotlib.pyplot as plt\n",
|
|
21
|
+
"from shutil import rmtree"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"cell_type": "code",
|
|
26
|
+
"execution_count": 12,
|
|
27
|
+
"metadata": {},
|
|
28
|
+
"outputs": [],
|
|
29
|
+
"source": [
|
|
30
|
+
"# Constants\n",
|
|
31
|
+
"DATA_DIR = \"data\"\n",
|
|
32
|
+
"DSA_API_URL = \"https://computablebrain.emory.edu/api/v1\"\n",
|
|
33
|
+
"DSA_WSI_ITEM_ID = \"670fd3e2897872a4bba54097\"\n",
|
|
34
|
+
"THUMBNAIL_MAG = 2.0\n",
|
|
35
|
+
"TILE_SIZE = 512"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"cell_type": "code",
|
|
40
|
+
"execution_count": 3,
|
|
41
|
+
"metadata": {},
|
|
42
|
+
"outputs": [],
|
|
43
|
+
"source": [
|
|
44
|
+
"# Authenticate girder client.\n",
|
|
45
|
+
"gc = dh.girder_utils.login(DSA_API_URL)"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"cell_type": "code",
|
|
50
|
+
"execution_count": 18,
|
|
51
|
+
"metadata": {},
|
|
52
|
+
"outputs": [],
|
|
53
|
+
"source": [
|
|
54
|
+
"# Clean up the data directory.\n",
|
|
55
|
+
"rmtree(DATA_DIR, ignore_errors=True)"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"cell_type": "markdown",
|
|
60
|
+
"metadata": {},
|
|
61
|
+
"source": [
|
|
62
|
+
"## 1.1. Get thumbnail at specified magnification."
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"cell_type": "code",
|
|
67
|
+
"execution_count": null,
|
|
68
|
+
"metadata": {},
|
|
69
|
+
"outputs": [],
|
|
70
|
+
"source": [
|
|
71
|
+
"# Read a sample thumbnail from the DSA.\n",
|
|
72
|
+
"thumbnail_img = dh.girder_utils.get_thumbnail(\n",
|
|
73
|
+
" gc, \n",
|
|
74
|
+
" DSA_WSI_ITEM_ID,\n",
|
|
75
|
+
" mag=THUMBNAIL_MAG\n",
|
|
76
|
+
")[:, :, :3]\n",
|
|
77
|
+
"\n",
|
|
78
|
+
"plt.imshow(thumbnail_img)\n",
|
|
79
|
+
"plt.title(f'Thumbnail Image (mag={THUMBNAIL_MAG})')\n",
|
|
80
|
+
"plt.show()"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"cell_type": "markdown",
|
|
85
|
+
"metadata": {},
|
|
86
|
+
"source": [
|
|
87
|
+
"## 1.2. Tile thumbnail from numpy array."
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"cell_type": "code",
|
|
92
|
+
"execution_count": null,
|
|
93
|
+
"metadata": {},
|
|
94
|
+
"outputs": [],
|
|
95
|
+
"source": [
|
|
96
|
+
"# Create location to save tiles.\n",
|
|
97
|
+
"save_dir = Path(DATA_DIR) / \"thumbnail_tile_images\"\n",
|
|
98
|
+
"\n",
|
|
99
|
+
"# Tile the image.\n",
|
|
100
|
+
"tiles_df = dh.image_utils.tile_image(\n",
|
|
101
|
+
" thumbnail_img,\n",
|
|
102
|
+
" save_dir, \n",
|
|
103
|
+
" tile_size=TILE_SIZE,\n",
|
|
104
|
+
" fill=(114, 114, 114),\n",
|
|
105
|
+
" prepend_name=\"thumbnail\",\n",
|
|
106
|
+
")\n",
|
|
107
|
+
"\n",
|
|
108
|
+
"tiles_df.head()"
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"metadata": {
|
|
113
|
+
"kernelspec": {
|
|
114
|
+
"display_name": "env",
|
|
115
|
+
"language": "python",
|
|
116
|
+
"name": "python3"
|
|
117
|
+
},
|
|
118
|
+
"language_info": {
|
|
119
|
+
"codemirror_mode": {
|
|
120
|
+
"name": "ipython",
|
|
121
|
+
"version": 3
|
|
122
|
+
},
|
|
123
|
+
"file_extension": ".py",
|
|
124
|
+
"mimetype": "text/x-python",
|
|
125
|
+
"name": "python",
|
|
126
|
+
"nbconvert_exporter": "python",
|
|
127
|
+
"pygments_lexer": "ipython3",
|
|
128
|
+
"version": "3.12.3"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"nbformat": 4,
|
|
132
|
+
"nbformat_minor": 2
|
|
133
|
+
}
|
dsa_helpers-0.4.dev4/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from . import header
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Login / authenticate function for the girder client.
|
|
2
|
-
from girder_client import GirderClient
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def login(
|
|
6
|
-
api_url: str,
|
|
7
|
-
login_or_email: str | None = None,
|
|
8
|
-
password: str | None = None,
|
|
9
|
-
api_key: str | None = None,
|
|
10
|
-
) -> GirderClient:
|
|
11
|
-
"""Authenticate a girder client with the given credentials or interactively
|
|
12
|
-
if none is given.
|
|
13
|
-
|
|
14
|
-
Args:
|
|
15
|
-
api_url (str): The DSA girder API url.
|
|
16
|
-
login_or_email (str | None): The login or email. Defaults to None.
|
|
17
|
-
password (str | None): Password for login / email. Defaults to None.
|
|
18
|
-
api_key (str | None): The api key to authenticate with. Defaults to None.
|
|
19
|
-
|
|
20
|
-
Returns:
|
|
21
|
-
girder_client.GirderClient: The authenticated girder client.
|
|
22
|
-
|
|
23
|
-
"""
|
|
24
|
-
gc = GirderClient(apiUrl=api_url)
|
|
25
|
-
|
|
26
|
-
if api_key is None:
|
|
27
|
-
if login_or_email is None:
|
|
28
|
-
_ = gc.authenticate(interactive=True)
|
|
29
|
-
elif password is None:
|
|
30
|
-
_ = gc.authenticate(username=login_or_email, interactive=True)
|
|
31
|
-
else:
|
|
32
|
-
_ = gc.authenticate(username=login_or_email, password=password)
|
|
33
|
-
else:
|
|
34
|
-
_ = gc.authenticate(apiKey=api_key)
|
|
35
|
-
|
|
36
|
-
return gc
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"cells": [
|
|
3
|
-
{
|
|
4
|
-
"cell_type": "markdown",
|
|
5
|
-
"metadata": {},
|
|
6
|
-
"source": [
|
|
7
|
-
"# Test Python Package Build"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"cell_type": "code",
|
|
12
|
-
"execution_count": 1,
|
|
13
|
-
"metadata": {},
|
|
14
|
-
"outputs": [],
|
|
15
|
-
"source": [
|
|
16
|
-
"# Import all modules.\n",
|
|
17
|
-
"from dsa_helpers import *"
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"cell_type": "markdown",
|
|
22
|
-
"metadata": {},
|
|
23
|
-
"source": [
|
|
24
|
-
"#### Authenticate girder client."
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"cell_type": "code",
|
|
29
|
-
"execution_count": 3,
|
|
30
|
-
"metadata": {},
|
|
31
|
-
"outputs": [],
|
|
32
|
-
"source": [
|
|
33
|
-
"gc = girder_utils.login(\"\")"
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"cell_type": "markdown",
|
|
38
|
-
"metadata": {},
|
|
39
|
-
"source": [
|
|
40
|
-
"#### Get DSA items recursively"
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"cell_type": "code",
|
|
45
|
-
"execution_count": null,
|
|
46
|
-
"metadata": {},
|
|
47
|
-
"outputs": [],
|
|
48
|
-
"source": [
|
|
49
|
-
"# Get items from a folder.\n",
|
|
50
|
-
"items = girder_utils.get_items(gc, \"\")\n",
|
|
51
|
-
"print(f\"Got {len(items)} items from folder.\")\n",
|
|
52
|
-
"\n",
|
|
53
|
-
"items = girder_utils.get_items(gc, \"\")\n",
|
|
54
|
-
"print(f\"Got {len(items)} items from collection.\")"
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
],
|
|
58
|
-
"metadata": {
|
|
59
|
-
"kernelspec": {
|
|
60
|
-
"display_name": "env",
|
|
61
|
-
"language": "python",
|
|
62
|
-
"name": "python3"
|
|
63
|
-
},
|
|
64
|
-
"language_info": {
|
|
65
|
-
"codemirror_mode": {
|
|
66
|
-
"name": "ipython",
|
|
67
|
-
"version": 3
|
|
68
|
-
},
|
|
69
|
-
"file_extension": ".py",
|
|
70
|
-
"mimetype": "text/x-python",
|
|
71
|
-
"name": "python",
|
|
72
|
-
"nbconvert_exporter": "python",
|
|
73
|
-
"pygments_lexer": "ipython3",
|
|
74
|
-
"version": "3.12.3"
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
"nbformat": 4,
|
|
78
|
-
"nbformat_minor": 2
|
|
79
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/datasets/SegFormerSegmentationDataset.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dsa_helpers-0.4.dev4 → dsa_helpers-0.5}/dsa_helpers/ml/object_detection/get_pearce_roi_images.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|