dsa-helpers 1.1.1.dev0__tar.gz → 1.1.2.dev0__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.
Files changed (51) hide show
  1. {dsa_helpers-1.1.1.dev0/dsa_helpers.egg-info → dsa_helpers-1.1.2.dev0}/PKG-INFO +1 -1
  2. dsa_helpers-1.1.2.dev0/dev.py +41 -0
  3. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/__init__.py +1 -1
  4. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/girder_utils.py +10 -0
  5. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/image_utils.py +28 -0
  6. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/tiling.py +15 -3
  7. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0/dsa_helpers.egg-info}/PKG-INFO +1 -1
  8. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers.egg-info/SOURCES.txt +1 -0
  9. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/pyproject.toml +1 -1
  10. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/.gitignore +0 -0
  11. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/.readthedocs.yaml +0 -0
  12. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/LICENSE +0 -0
  13. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/README.md +0 -0
  14. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/app.py +0 -0
  15. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/docs/requirements.txt +0 -0
  16. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/docs/source/conf.py +0 -0
  17. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/docs/source/index.rst +0 -0
  18. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/cli_utils.py +0 -0
  19. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/dash/__init__.py +0 -0
  20. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/dash/dash_paperdragon_utils.py +0 -0
  21. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/dash/header.py +0 -0
  22. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/dash/header_callbacks.py +0 -0
  23. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/gpd_utils.py +0 -0
  24. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/imread.py +0 -0
  25. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/imwrite.py +0 -0
  26. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/__init__.py +0 -0
  27. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/callbacks.py +0 -0
  28. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/datasets/SegFormerSegmentationDataset.py +0 -0
  29. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/datasets/__init__.py +0 -0
  30. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/datasets/utils.py +0 -0
  31. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/evaluate.py +0 -0
  32. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/metrics.py +0 -0
  33. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/object_detection/__init__.py +0 -0
  34. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/object_detection/get_pearce_roi_images.py +0 -0
  35. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/object_detection/tile_image.py +0 -0
  36. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/object_detection/utils.py +0 -0
  37. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/segformer_semantic_segmentation/__init__.py +0 -0
  38. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/segformer_semantic_segmentation/inference.py +0 -0
  39. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/transforms/__init__.py +0 -0
  40. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/ml/transforms/segformer_transforms.py +0 -0
  41. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/mongo_utils.py +0 -0
  42. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/tile_utils.py +0 -0
  43. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers/utils.py +0 -0
  44. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers.egg-info/dependency_links.txt +0 -0
  45. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers.egg-info/requires.txt +0 -0
  46. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/dsa_helpers.egg-info/top_level.txt +0 -0
  47. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/setup.cfg +0 -0
  48. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/tests/app/Dockerfile +0 -0
  49. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/tests/app/app.py +0 -0
  50. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/tests/docker-compose.yaml +0 -0
  51. {dsa_helpers-1.1.1.dev0 → dsa_helpers-1.1.2.dev0}/tests/test.ipynb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsa_helpers
3
- Version: 1.1.1.dev0
3
+ Version: 1.1.2.dev0
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>
@@ -0,0 +1,41 @@
1
+ """Script to develop functions for the library."""
2
+
3
+ from argparse import ArgumentParser
4
+ from dsa_helpers.girder_utils import (
5
+ login,
6
+ post_annotation,
7
+ remove_overlapping_annotations,
8
+ )
9
+
10
+
11
+ def parse_args():
12
+ parser = ArgumentParser()
13
+ parser.add_argument(
14
+ "--api-token", type=str, default=None, help="Girder API token"
15
+ )
16
+ parser.add_argument(
17
+ "--api-url", type=str, default=None, help="Girder API URL"
18
+ )
19
+ return parser.parse_args()
20
+
21
+
22
+ def main(args):
23
+ gc = login(args.api_url, api_key=args.api_token)
24
+
25
+ # Get an annotation document.
26
+ doc = gc.get("annotation/...")
27
+
28
+ annotation = remove_overlapping_annotations(
29
+ doc["annotation"], ["Gray Matter", "White Matter", "Leptomeninges"]
30
+ )
31
+
32
+ # Push the new doc.
33
+ annotation["name"] = "temp"
34
+
35
+ response = post_annotation(gc, "...", annotation)
36
+
37
+ print(response)
38
+
39
+
40
+ if __name__ == "__main__":
41
+ main(parse_args())
@@ -3,7 +3,7 @@ from .imread import imread
3
3
  from .imwrite import imwrite
4
4
 
5
5
  # Version of the dsa-helpers package
6
- __version__ = "1.1.1.dev0"
6
+ __version__ = "1.1.2.dev0"
7
7
 
8
8
  # To avoid slow downs, do not allow from dsa_helpers import * to import anything.
9
9
  __all__ = []
@@ -1,6 +1,16 @@
1
1
  """Module for working with the girder client, or related to girder
2
2
  documents, such as annotation documents.
3
3
 
4
+ Functions:
5
+ - login: Authenticate a girder client with the given credentials or interactively
6
+ - get_item_large_image_metadata: Get large image metadata for an item
7
+ - get_thumbnail: Get the thumbnail image by a specific magnification or shape
8
+ - get_region: Get image region from DSA
9
+ - get_element_contours: Get the contours of an element, regardless of the type
10
+ - get_roi_images: Get regions of interest (ROIs) as images from DSA annotations
11
+ - post_annotation: Post a new annotation to the DSA
12
+ - remove_overlapping_annotations: Remove overlapping regions from elements
13
+
4
14
  """
5
15
 
6
16
  from girder_client import GirderClient, HttpError
@@ -100,3 +100,31 @@ def label_mask_to_polygons(
100
100
  polygons.append([polygon, int(label)])
101
101
 
102
102
  return polygons
103
+
104
+
105
+ def convert_label_mask_to_rgb(
106
+ mask: np.ndarray, int2rgb: dict, alpha: bool = False
107
+ ) -> np.ndarray:
108
+ """
109
+ Convert a label mask to an RGB mask.
110
+
111
+ Args:
112
+ mask: Label mask to convert.
113
+ int2rgb: Dictionary mapping integer labels to RGB colors. If
114
+ passing alpha as True, then pass RGBA colors.
115
+ alpha: Whether to include the alpha channel in the RGB mask.
116
+
117
+ Returns:
118
+ (np.ndarray): RGB(A) mask.
119
+
120
+ """
121
+ # Create a new RGB mask of the same size as the label mask.
122
+ rgb_mask = np.zeros(
123
+ (mask.shape[0], mask.shape[1], 4 if alpha else 3), dtype=np.uint8
124
+ )
125
+
126
+ # Loop through the label mask.
127
+ for label, rgb in int2rgb.items():
128
+ rgb_mask[mask == label] = rgb
129
+
130
+ return rgb_mask
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Functions for tiling images.
3
3
 
4
- This module contains functions used to tile large images, usually for
4
+ This module contains functions used to tile large images, usually for
5
5
  use in developing deep learning models.
6
6
 
7
7
  """
@@ -29,12 +29,20 @@ def _proccess_tile_with_masks_from_dsa_annotations(
29
29
  mask_dir,
30
30
  background_idx,
31
31
  edge_thr,
32
+ ignore_existing,
32
33
  ):
33
34
  # Calculate the x and y in tile magnification.
34
35
  x_mag = int(x * sf)
35
36
  y_mag = int(y * sf)
36
37
 
38
+ # Format the filepath to save the tile.
37
39
  fn = f"{prepend_name}x{x_mag}y{y_mag}.png"
40
+ img_fp = img_dir / fn
41
+ mask_fp = mask_dir / fn
42
+
43
+ # Ignore existing tiles.
44
+ if ignore_existing and img_fp.is_file() and mask_fp.is_file():
45
+ return str(img_fp), x_mag, y_mag
38
46
 
39
47
  # Get the tile.
40
48
  tile_img = ts.getRegion(
@@ -98,9 +106,8 @@ def _proccess_tile_with_masks_from_dsa_annotations(
98
106
  tile_mask[label_mask == 1] = idx
99
107
 
100
108
  # Save the image and mask.
101
- img_fp = img_dir / fn
102
109
  imwrite(img_fp, tile_img)
103
- imwrite(mask_dir / fn, tile_mask, grayscale=True)
110
+ imwrite(mask_fp, tile_mask, grayscale=True)
104
111
 
105
112
  return str(img_fp), x_mag, y_mag
106
113
 
@@ -117,6 +124,7 @@ def tile_wsi_with_masks_from_dsa_annotations(
117
124
  nproc: int = 1,
118
125
  background_idx: int = 0,
119
126
  edge_thr: float = 0.25,
127
+ ignore_existing: bool = False,
120
128
  ) -> list[str]:
121
129
  """Tile a WSI with semantic segmentation label masks created from
122
130
  DSA annotations. DSA annotation class labels for elements are
@@ -146,6 +154,9 @@ def tile_wsi_with_masks_from_dsa_annotations(
146
154
  the tile is padded background then it is ignored. If the
147
155
  amount of tile in WSI / amount of tile padded is less than
148
156
  this threshold, the tile is ignored. Defaults to 0.25.
157
+ ignore_existing (bool, optional): Whether to ignore existing
158
+ tiles. If False, tiles will not be created if they already
159
+ exist. Defaults to False.
149
160
 
150
161
  Returns:
151
162
  list[str]: A list of tuples: (tile file path, x, y coordinates
@@ -256,6 +267,7 @@ def tile_wsi_with_masks_from_dsa_annotations(
256
267
  mask_dir,
257
268
  background_idx,
258
269
  edge_thr,
270
+ ignore_existing,
259
271
  ),
260
272
  )
261
273
  for xy in xys
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsa_helpers
3
- Version: 1.1.1.dev0
3
+ Version: 1.1.2.dev0
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>
@@ -3,6 +3,7 @@
3
3
  LICENSE
4
4
  README.md
5
5
  app.py
6
+ dev.py
6
7
  pyproject.toml
7
8
  docs/requirements.txt
8
9
  docs/source/conf.py
@@ -36,7 +36,7 @@ classifiers = [
36
36
  "License :: OSI Approved :: MIT License",
37
37
  ]
38
38
  keywords = ["dsa", "girder", "girder_client"]
39
- version = "v1.1.1.dev0"
39
+ version = "v1.1.2.dev0"
40
40
 
41
41
  [project.urls]
42
42
  Repository = "https://github.com/Gutman-Lab/dsa-python-utils"