dsa-helpers 0.1__py3-none-any.whl
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/__init__.py +5 -0
- dsa_helpers/girder_utils.py +120 -0
- dsa_helpers/login.py +40 -0
- dsa_helpers-0.1.dist-info/LICENSE +19 -0
- dsa_helpers-0.1.dist-info/METADATA +22 -0
- dsa_helpers-0.1.dist-info/RECORD +8 -0
- dsa_helpers-0.1.dist-info/WHEEL +5 -0
- dsa_helpers-0.1.dist-info/top_level.txt +1 -0
dsa_helpers/__init__.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Functions using the girder client.
|
|
2
|
+
from girder_client import GirderClient
|
|
3
|
+
import pickle
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_item_large_image_metadata(gc: GirderClient, item_id: str) -> dict:
|
|
8
|
+
"""Get large image metadata for an item.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
gc (girder_client.GirderClient): The authenticated girder client.
|
|
12
|
+
item_id (str): The item id.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
dict: The metadata of the large image item.
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
return gc.get(f"item/{item_id}/tiles")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_thumbnail(
|
|
22
|
+
gc: GirderClient,
|
|
23
|
+
item_id: str,
|
|
24
|
+
mag: float | None = None,
|
|
25
|
+
width: int | None = None,
|
|
26
|
+
height: int | None = None,
|
|
27
|
+
fill: int | tuple = (255, 255, 255),
|
|
28
|
+
) -> np.ndarray:
|
|
29
|
+
"""Get the thumbnail image by a specific magnification or shape. If mag is
|
|
30
|
+
not None, then width and height are ignored. Fill is only used when both
|
|
31
|
+
width and height are provided, to return the thumbnail at the exact shape.
|
|
32
|
+
DSA convention will fill the height of the image, centering the image and
|
|
33
|
+
filling the top and bottom of the image equally.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
gc (girder_client.GirderClient): The authenticated girder client.
|
|
37
|
+
item_id (str): The item id.
|
|
38
|
+
mag (float, optional): The magnification. Defaults to None.
|
|
39
|
+
width (int, optional): The width of the thumbnail. Defaults to None.
|
|
40
|
+
height (int, optional): The height of the thumbnail. Defaults to None.
|
|
41
|
+
fill (int | tuple, optional): The fill color. Defaults to (255, 255, 255).
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
np.ndarray: The thumbnail image.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
ValueError: If neither mag, width, nor height is provided.
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
if all([mag is None, width is None, height is None]):
|
|
51
|
+
raise ValueError("Either mag, width, or height must be provided.")
|
|
52
|
+
|
|
53
|
+
if mag is not None:
|
|
54
|
+
get_url = f"item/{item_id}/tiles/region?magnification{mag}"
|
|
55
|
+
else:
|
|
56
|
+
# Instead use width and height.
|
|
57
|
+
get_url = f"item/{item_id}/tiles/thumbnail?"
|
|
58
|
+
|
|
59
|
+
if width is not None and height is not None:
|
|
60
|
+
if isinstance(fill, (tuple, list)):
|
|
61
|
+
if len(fill) == 3:
|
|
62
|
+
fill = f"rgb({fill[0]},{fill[1]},{fill[2]})"
|
|
63
|
+
elif len(fill) == 4:
|
|
64
|
+
fill = f"rgba({fill[0]},{fill[1]},{fill[2]},{fill[3]})"
|
|
65
|
+
|
|
66
|
+
get_url += f"width={width}&height={height}&fill={fill}"
|
|
67
|
+
elif width is not None:
|
|
68
|
+
get_url += f"width={width}"
|
|
69
|
+
else:
|
|
70
|
+
get_url += f"height={height}"
|
|
71
|
+
|
|
72
|
+
get_url += "&encoding=pickle"
|
|
73
|
+
|
|
74
|
+
response = gc.get(get_url, jsonResp=False)
|
|
75
|
+
|
|
76
|
+
return pickle.loads(response.content)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def get_region(
|
|
80
|
+
gc: GirderClient,
|
|
81
|
+
item_id: str,
|
|
82
|
+
left: int,
|
|
83
|
+
top: int,
|
|
84
|
+
width: int,
|
|
85
|
+
height: int,
|
|
86
|
+
mag: float | None = None,
|
|
87
|
+
) -> np.ndarray:
|
|
88
|
+
"""Get a region of the image for an item. Note that the output image might
|
|
89
|
+
not be in the shape (width, height) if left + width or top + height exceeds
|
|
90
|
+
the image size. The output image will be the maximum size possible.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
gc (girder_client.GirderClient): The authenticated girder client.
|
|
94
|
+
item_id (str): The item id.
|
|
95
|
+
left (int): The left coordinate.
|
|
96
|
+
top (int): The top coordinate.
|
|
97
|
+
width (int): The width of the region.
|
|
98
|
+
height (int): The height of the region.
|
|
99
|
+
mag (float, optional): The magnification. Defaults to None which returns
|
|
100
|
+
the image at scan magnification. Using a mag lower than the scan
|
|
101
|
+
magnification will result in an ouptut image smaller than the
|
|
102
|
+
width and height. Similarly, using a mag higher than the scan
|
|
103
|
+
magnification will result in an output image larger than the width
|
|
104
|
+
and height.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
np.ndarray: The region of the image.
|
|
108
|
+
|
|
109
|
+
"""
|
|
110
|
+
get_url = (
|
|
111
|
+
f"item/{item_id}/tiles/region?left={left}&top={top}®ionWidth="
|
|
112
|
+
f"{width}®ionHeight={height}&encoding=pickle"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
if mag is not None:
|
|
116
|
+
get_url += f"&magnification={mag}"
|
|
117
|
+
|
|
118
|
+
response = gc.get(get_url, jsonResp=False)
|
|
119
|
+
|
|
120
|
+
return pickle.loads(response.content)
|
dsa_helpers/login.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
Raises:
|
|
24
|
+
ValueError: If neither login_or_email nor api_key is provided.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
if login_or_email is None and api_key is None:
|
|
28
|
+
raise ValueError("Either login_or_email or api_key must be provided.")
|
|
29
|
+
|
|
30
|
+
gc = GirderClient(apiUrl=api_url)
|
|
31
|
+
|
|
32
|
+
if api_key is None:
|
|
33
|
+
if password is None:
|
|
34
|
+
_ = gc.authenticate(username=login_or_email, interactive=True)
|
|
35
|
+
else:
|
|
36
|
+
_ = gc.authenticate(username=login_or_email, password=password)
|
|
37
|
+
else:
|
|
38
|
+
_ = gc.authenticate(apiKey=api_key)
|
|
39
|
+
|
|
40
|
+
return gc
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dsa_helpers
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Utility functions for working with the DSA girder client.
|
|
5
|
+
Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
|
|
6
|
+
Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
|
|
7
|
+
Project-URL: Repository, https://github.com/Gutman-Lab/dsa-python-utils
|
|
8
|
+
Keywords: dsa,girder,girder_client
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: girder-client ==3.2.3
|
|
15
|
+
Requires-Dist: numpy ==2.0.0
|
|
16
|
+
|
|
17
|
+
# Digital Slide Archive (DSA) Helpers
|
|
18
|
+
Digital Slide Archive Python utility library.
|
|
19
|
+
|
|
20
|
+
This library is available for installation through [Python Package Index (PyPI)](https://pypi.org/).
|
|
21
|
+
|
|
22
|
+
This library was tested using Python version 3.11.8 and uses the dependencies described in requirements.txt.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
dsa_helpers/__init__.py,sha256=xMnPN050W8KjVTg38p9xStBCGAjfBx8kD5TnbITBd9o,107
|
|
2
|
+
dsa_helpers/girder_utils.py,sha256=KJ5Mr5RbRa67rfeo6_FbAVv8jKDZmyco_0d3fdpY_t4,4067
|
|
3
|
+
dsa_helpers/login.py,sha256=etJ5NUKkKo8mw_x5bbUJU8E3XD4RTOZLjhYIJrfb2QQ,1275
|
|
4
|
+
dsa_helpers-0.1.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
|
5
|
+
dsa_helpers-0.1.dist-info/METADATA,sha256=51tQr3e2PaUgITkSLLDItXYN50sTB_UX2KOTVwkC72Y,884
|
|
6
|
+
dsa_helpers-0.1.dist-info/WHEEL,sha256=-oYQCr74JF3a37z2nRlQays_SX2MqOANoqVjBBAP2yE,91
|
|
7
|
+
dsa_helpers-0.1.dist-info/top_level.txt,sha256=BmAEDVvDa1MJlSUFHWzx73UKec3o1K6dFUd9tHwgHGo,12
|
|
8
|
+
dsa_helpers-0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dsa_helpers
|