ngio.common API documentation¶
ngio.common
¶
Common classes and functions that are used across the package.
Dimensions
¶
Dimension metadata.
Create a Dimension object from a Zarr array.
Parameters:
-
shape
(tuple[int, ...]
) –The shape of the Zarr array.
-
axes_mapper
(AxesMapper
) –The axes mapper object.
Source code in ngio/common/_dimensions.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
get
¶
Return the dimension of the given axis name.
Parameters:
-
axis_name
(str
) –The name of the axis (either canonical or non-canonical).
-
default
(int | None
, default:None
) –The default value to return if the axis does not exist. If None, an error is raised.
Source code in ngio/common/_dimensions.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
has_axis
¶
Return whether the axis exists.
Source code in ngio/common/_dimensions.py
59 60 61 62 63 64 |
|
AbstractTransform
¶
Abstract base class for a generic transform.
transform_numpy
¶
Transform a numpy array.
Source code in ngio/common/_io_transforms.py
12 13 14 |
|
transform_dask
¶
transform_dask(array: Array) -> Array
Transform a dask array.
Source code in ngio/common/_io_transforms.py
16 17 18 |
|
transform_delayed
¶
transform_delayed(array: Delayed) -> Delayed
Transform a delayed dask array.
Source code in ngio/common/_io_transforms.py
20 21 22 |
|
TransformProtocol
¶
Bases: Protocol
Protocol numpy, dask, or delayed array transforms.
transform_numpy
¶
Transform a numpy array.
Source code in ngio/common/_io_transforms.py
28 29 30 |
|
transform_dask
¶
transform_dask(array: Array) -> Array
Transform a dask array.
Source code in ngio/common/_io_transforms.py
32 33 34 |
|
transform_delayed
¶
transform_delayed(array: Delayed) -> Delayed
Transform a delayed dask array.
Source code in ngio/common/_io_transforms.py
36 37 38 |
|
Roi
¶
Bases: BaseModel
Region of interest (ROI) metadata.
unit
class-attribute
instance-attribute
¶
unit: SpaceUnits | str | None = Field(
DefaultSpaceUnit, repr=False
)
to_pixel_roi
¶
to_pixel_roi(
pixel_size: PixelSize, dimensions: Dimensions
) -> RoiPixels
Convert to raster coordinates.
Source code in ngio/common/_roi.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
zoom
¶
Zoom the ROI by a factor.
Parameters:
-
zoom_factor
(float
, default:1
) –The zoom factor. If the zoom factor is less than 1 the ROI will be zoomed in. If the zoom factor is greater than 1 the ROI will be zoomed out. If the zoom factor is 1 the ROI will not be changed.
Source code in ngio/common/_roi.py
69 70 71 72 73 74 75 76 77 78 |
|
RoiPixels
¶
Bases: BaseModel
Region of interest (ROI) metadata.
to_roi
¶
Convert to world coordinates.
Source code in ngio/common/_roi.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
to_slices
¶
Return the slices for the ROI.
Source code in ngio/common/_roi.py
112 113 114 115 116 117 118 119 |
|
get_as_dask
¶
get_as_dask(
array: Array,
*,
dimensions: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
) -> Array
Source code in ngio/common/_array_io_pipe.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
get_as_delayed
¶
get_as_delayed(
array: Array,
*,
dimensions: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
) -> Delayed
Source code in ngio/common/_array_io_pipe.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
get_as_numpy
¶
get_as_numpy(
array: Array,
*,
dimensions: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
) -> ndarray
Source code in ngio/common/_array_io_pipe.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
get_masked_as_dask
¶
get_masked_as_dask(
array: Array,
label_array: Array,
label: int,
*,
dimensions_array: Dimensions,
dimensions_label: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
) -> Array
Source code in ngio/common/_array_io_pipe.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
|
get_masked_as_numpy
¶
get_masked_as_numpy(
array: Array,
label_array: Array,
label: int,
*,
dimensions_array: Dimensions,
dimensions_label: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
) -> ndarray
Source code in ngio/common/_array_io_pipe.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
|
set_dask
¶
set_dask(
array: Array,
patch: Array,
*,
dimensions: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
)
Source code in ngio/common/_array_io_pipe.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
set_dask_masked
¶
set_dask_masked(
array: Array,
label_array: Array,
label: int,
patch: Array,
*,
dimensions_array: Dimensions,
dimensions_label: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
)
Source code in ngio/common/_array_io_pipe.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
|
set_delayed
¶
set_delayed(
array: Array,
patch: ndarray | Delayed,
*,
dimensions: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
)
Source code in ngio/common/_array_io_pipe.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
set_numpy
¶
set_numpy(
array: Array,
patch: ndarray,
*,
dimensions: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
)
Source code in ngio/common/_array_io_pipe.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
set_numpy_masked
¶
set_numpy_masked(
array: Array,
label_array: Array,
label: int,
patch: ndarray,
*,
dimensions_array: Dimensions,
dimensions_label: Dimensions,
axes_order: Collection[str] | None = None,
transforms: Collection[TransformProtocol] | None = None,
**slice_kwargs: slice | int | Iterable[int],
)
Source code in ngio/common/_array_io_pipe.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|
compute_masking_roi
¶
Compute a ROIs for each label in a segmentation.
This function expects a 2D or 3D segmentation array. And this function expects the axes order to be 'zyx' or 'yx'. Other axes orders are not supported.
Source code in ngio/common/_masking_roi.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
consolidate_pyramid
¶
consolidate_pyramid(
source: Array,
targets: list[Array],
order: Literal[0, 1, 2] = 1,
mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None
Consolidate the Zarr array.
Source code in ngio/common/_pyramid.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
init_empty_pyramid
¶
init_empty_pyramid(
store: StoreOrGroup,
paths: list[str],
ref_shape: Collection[int],
scaling_factors: Collection[float],
chunks: Collection[int] | None = None,
dtype: str = "uint16",
mode: AccessModeLiteral = "a",
) -> None
Source code in ngio/common/_pyramid.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
on_disk_zoom
¶
on_disk_zoom(
source: Array,
target: Array,
order: Literal[0, 1, 2] = 1,
mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None
Apply a zoom operation from a source zarr array to a target zarr array.
Parameters:
-
source
(Array
) –The source array to zoom.
-
target
(Array
) –The target array to save the zoomed result to.
-
order
(Literal[0, 1, 2]
, default:1
) –The order of interpolation. Defaults to 1.
-
mode
(Literal['dask', 'numpy', 'coarsen']
, default:'dask'
) –The mode to use. Defaults to "dask".
Source code in ngio/common/_pyramid.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
roi_to_slice_kwargs
¶
roi_to_slice_kwargs(
roi: Roi | RoiPixels,
dimensions: Dimensions,
pixel_size: PixelSize | None = None,
**slice_kwargs: slice | int | Iterable[int],
) -> dict[str, slice | int | Iterable[int]]
Convert a WorldCooROI to slice_kwargs.
Source code in ngio/common/_roi.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
concatenate_image_tables
¶
concatenate_image_tables(
images: Collection[OmeZarrContainer],
extras: Collection[dict[str, str]],
name: str,
index_key: str | None = None,
strict: bool = True,
mode: Literal["eager", "lazy"] = "eager",
) -> Table
Concatenate tables from different images into a single table.
Parameters:
-
images
(Collection[OmeZarrContainer]
) –A collection of images.
-
extras
(Collection[dict[str, str]]
) –A collection of extras dictionaries for each image. this will be added as columns to the table, and will be concatenated with the table index to create a new index.
-
name
(str
) –The name of the table to concatenate.
-
index_key
(str | None
, default:None
) –The key to use for the index of the concatenated table.
-
strict
(bool
, default:True
) –If True, raise an error if the table is not found in the image.
-
mode
(Literal['eager', 'lazy']
, default:'eager'
) –The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.
Source code in ngio/common/_table_ops.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
concatenate_image_tables_as
¶
concatenate_image_tables_as(
images: Collection[OmeZarrContainer],
extras: Collection[dict[str, str]],
name: str,
table_cls: type[TableType],
index_key: str | None = None,
strict: bool = True,
mode: Literal["eager", "lazy"] = "eager",
) -> TableType
Concatenate tables from different images into a single table.
Parameters:
-
images
(Collection[OmeZarrContainer]
) –A collection of images.
-
extras
(Collection[dict[str, str]]
) –A collection of extras dictionaries for each image. this will be added as columns to the table, and will be concatenated with the table index to create a new index.
-
name
(str
) –The name of the table to concatenate.
-
table_cls
(type[TableType]
) –The output will be casted to this class, if the new table_cls is compatible with the table_cls of the input tables.
-
index_key
(str | None
, default:None
) –The key to use for the index of the concatenated table.
-
strict
(bool
, default:True
) –If True, raise an error if the table is not found in the image.
-
mode
(Literal['eager', 'lazy']
, default:'eager'
) –The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.
Source code in ngio/common/_table_ops.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
concatenate_image_tables_as_async
async
¶
concatenate_image_tables_as_async(
images: Collection[OmeZarrContainer],
extras: Collection[dict[str, str]],
name: str,
table_cls: type[TableType],
index_key: str | None = None,
strict: bool = True,
mode: Literal["eager", "lazy"] = "eager",
) -> TableType
Concatenate tables from different images into a single table.
Parameters:
-
images
(Collection[OmeZarrContainer]
) –A collection of images.
-
extras
(Collection[dict[str, str]]
) –A collection of extras dictionaries for each image. this will be added as columns to the table, and will be concatenated with the table index to create a new index.
-
name
(str
) –The name of the table to concatenate.
-
table_cls
(type[TableType]
) –The output will be casted to this class, if the new table_cls is compatible with the table_cls of the input tables.
-
index_key
(str | None
, default:None
) –The key to use for the index of the concatenated table.
-
strict
(bool
, default:True
) –If True, raise an error if the table is not found in the image.
-
mode
(Literal['eager', 'lazy']
, default:'eager'
) –The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.
Source code in ngio/common/_table_ops.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
concatenate_image_tables_async
async
¶
concatenate_image_tables_async(
images: Collection[OmeZarrContainer],
extras: Collection[dict[str, str]],
name: str,
index_key: str | None = None,
strict: bool = True,
mode: Literal["eager", "lazy"] = "eager",
) -> Table
Concatenate tables from different images into a single table.
Parameters:
-
images
(Collection[OmeZarrContainer]
) –A collection of images.
-
extras
(Collection[dict[str, str]]
) –A collection of extras dictionaries for each image. this will be added as columns to the table, and will be concatenated with the table index to create a new index.
-
name
(str
) –The name of the table to concatenate.
-
index_key
(str | None
, default:None
) –The key to use for the index of the concatenated table.
-
strict
(bool
, default:True
) –If True, raise an error if the table is not found in the image.
-
mode
(Literal['eager', 'lazy']
, default:'eager'
) –The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.
Source code in ngio/common/_table_ops.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
conctatenate_tables
¶
conctatenate_tables(
tables: Collection[TableWithExtras],
mode: Literal["eager", "lazy"] = "eager",
index_key: str | None = None,
table_cls: type[TableType] | None = None,
) -> Table
Concatenate tables from different plates into a single table.
Source code in ngio/common/_table_ops.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
list_image_tables
¶
list_image_tables(
images: Collection[OmeZarrContainer],
filter_types: str | None = None,
mode: Literal["common", "all"] = "common",
) -> list[str]
List all table names in the images.
Parameters:
-
images
(Collection[OmeZarrContainer]
) –A collection of images.
-
filter_types
(str | None
, default:None
) –The type of tables to filter. If None, return all tables. Defaults to None.
-
mode
(Literal['common', 'all']
, default:'common'
) –Whether to return only common tables between all images or all tables. Defaults to "common".
Source code in ngio/common/_table_ops.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
list_image_tables_async
async
¶
list_image_tables_async(
images: Collection[OmeZarrContainer],
filter_types: str | None = None,
mode: Literal["common", "all"] = "common",
) -> list[str]
List all image tables in the image asynchronously.
Parameters:
-
images
(Collection[OmeZarrContainer]
) –A collection of images.
-
filter_types
(str | None
, default:None
) –The type of tables to filter. If None, return all tables. Defaults to None.
-
mode
(Literal['common', 'all']
, default:'common'
) –Whether to return only common tables between all images or all tables. Defaults to "common".
Source code in ngio/common/_table_ops.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
dask_zoom
¶
dask_zoom(
source_array: Array,
scale: tuple[int, ...] | None = None,
target_shape: tuple[int, ...] | None = None,
order: Literal[0, 1, 2] = 1,
) -> Array
Dask implementation of zooming an array.
Only one of scale or target_shape must be provided.
Parameters:
-
source_array
(Array
) –The source array to zoom.
-
scale
(tuple[int, ...] | None
, default:None
) –The scale factor to zoom by.
-
target_shape
((tuple[int, ...], None)
, default:None
) –The target shape to zoom to.
-
order
(Literal[0, 1, 2]
, default:1
) –The order of interpolation. Defaults to 1.
Returns:
-
Array
–da.Array: The zoomed array.
Source code in ngio/common/_zoom.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
numpy_zoom
¶
numpy_zoom(
source_array: ndarray,
scale: tuple[int, ...] | None = None,
target_shape: tuple[int, ...] | None = None,
order: Literal[0, 1, 2] = 1,
) -> ndarray
Numpy implementation of zooming an array.
Only one of scale or target_shape must be provided.
Parameters:
-
source_array
(ndarray
) –The source array to zoom.
-
scale
(tuple[int, ...] | None
, default:None
) –The scale factor to zoom by.
-
target_shape
((tuple[int, ...], None)
, default:None
) –The target shape to zoom to.
-
order
(Literal[0, 1, 2]
, default:1
) –The order of interpolation. Defaults to 1.
Returns:
-
ndarray
–np.ndarray: The zoomed array
Source code in ngio/common/_zoom.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|