diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..3305824 --- /dev/null +++ b/404.html @@ -0,0 +1,429 @@ + + + +
+ + + + + + + + + + + + + + + + + + +Given an xarray.DataArray
, normalize a chunk size against that array.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ DataArray
+ |
+
+
+
+ An |
+ + required + | +
chunk_size |
+
+ str | int | Sequence[int] | dict[Hashable, int]
+ |
+
+
+
+ A specification of a chunk size. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ dict[Hashable, int]
+ |
+
+
+
+ An xarray-compatible specification of chunk sizes. + |
+
src/xarray_multiscale/chunks.py
Ensure that all chunks of a dask array are divisible by scale_factors, rechunking the array +if necessary.
+ +src/xarray_multiscale/chunks.py
multiscale(
+ array,
+ reduction,
+ scale_factors,
+ preserve_dtype=True,
+ chunks="preserve",
+ chained=True,
+ namer=_default_namer,
+)
+
Generate a coordinate-aware multiscale representation of an array.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ Array-like, e.g. Numpy array, Dask array
+ |
+
+
+
+ The array to be downscaled. + |
+ + required + | +
reduction |
+
+ callable
+ |
+
+
+
+ A function that aggregates chunks of data over windows.
+See |
+ + required + | +
scale_factors |
+
+ int or sequence of ints
+ |
+
+
+
+ The desired downscaling factors, one for each axis, or a single +value for all axes. + |
+ + required + | +
preserve_dtype |
+
+ bool
+ |
+
+
+
+ If True, output arrays are all cast to the same data type as the +input array. If False, output arrays will have data type determined +by the output of the reduction function. + |
+
+ True
+ |
+
chunks |
+
+ sequence or dict of ints, or the string "preserve" (default)
+ |
+
+
+
+ Set the chunking of the output arrays. Applies only to dask arrays.
+If Otherwise, this keyword argument will be passed to the
+ |
+
+ 'preserve'
+ |
+
chained |
+
+ bool
+ |
+
+
+
+ If True (default), the nth downscaled array is generated by
+applying the reduction function on the n-1th downscaled array with
+the user-supplied If False, the nth downscaled array is generated by applying the
+reduction function on the 0th downscaled array
+(i.e., the input array) with the |
+
+ True
+ |
+
namer |
+
+ callable, defaults to `_default_namer`
+ |
+
+
+
+ A function for naming the output arrays. This function should take an integer +index and return a string. The default function simply prepends the string +representation of the integer with the character "s". + |
+
+ _default_namer
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
result |
+ list[DataArray]
+ |
+
+
+
+ The first element of this list is the input array, converted to an
+ The |
+
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale import multiscale
+>>> from xarray_multiscale.reducers import windowed_mean
+>>> multiscale(np.arange(4), windowed_mean, 2)
+[<xarray.DataArray (dim_0: 4)>
+array([0, 1, 2, 3])
+Coordinates:
+ * dim_0 (dim_0) float64 0.0 1.0 2.0 3.0, <xarray.DataArray (dim_0: 2)>
+array([0, 2])
+Coordinates:
+ * dim_0 (dim_0) float64 0.5 2.5]
+
src/xarray_multiscale/multiscale.py
31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 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 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 |
|
Convert the input to an xarray.DataArray
if it is not already one.
src/xarray_multiscale/multiscale.py
Downscale a dask array.
+ +src/xarray_multiscale/multiscale.py
Downscale coordinates by taking the windowed mean of each coordinate array.
+ +src/xarray_multiscale/multiscale.py
For a shape and a sequence of scale factors, calculate the +number of downsampling operations that must be performed to produce +a downsampled shape with at least one singleton value.
+If any element of scale_factors
is greater than the
+corresponding shape, this function returns 0.
If all scale_factors
are 1, this function returns 0.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
shape |
+
+ Sequence[int]
+ |
+
+
+
+ An array shape. + |
+ + required + | +
scale_factors |
+
+ Sequence[int]
+ |
+
+
+
+ Downsampling factors. + |
+ + required + | +
Examples:
+>>> downsampling_depth((8,), (2,))
+3
+>>> downsampling_depth((8,2), (2,2))
+1
+>>> downsampling_depth((7,), (2,))
+2
+
src/xarray_multiscale/multiscale.py
Reshape an array to support windowed operations. New
+dimensions will be added to the array, one for each element of
+window_size
.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be reshaped. The array must have a |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window size. The length of |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ The input array reshaped with extra dimensions.
+ |
+
+
+
+ E.g., for an |
+
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import reshape_windowed
+>>> data = np.arange(12).reshape(3, 4)
+>>> reshaped = reshape_windowed(data, (1, 2))
+>>> reshaped.shape
+(3, 1, 2, 2)
+
src/xarray_multiscale/reducers.py
Compute the windowed mean of an array.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. The array must have
+ |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window to use for aggregations. The array is partitioned into
+non-overlapping regions with size equal to |
+ + required + | +
**kwargs |
+
+ Any
+ |
+
+
+
+ Extra keyword arguments passed to |
+
+ {}
+ |
+
Returns:
+Type | +Description | +
---|---|
+ Array - like
+ |
+
+
+
+ The result of the windowed mean. The length of each axis of this array
+will be a fraction of the input. The datatype is determined by the
+behavior of |
+
This function works by first reshaping the array to have an extra
+axis per element of window_size
, then computing the
+mean along those extra axes.
See xarray_multiscale.reductions.reshape_windowed
for the
+implementation of the array reshaping routine.
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import windowed_mean
+>>> data = np.arange(16).reshape(4, 4)
+>>> windowed_mean(data, (2, 2))
+array([[ 2.5, 4.5],
+ [10.5, 12.5]])
+
src/xarray_multiscale/reducers.py
Compute the windowed maximum of an array.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. The array must have |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window to use for aggregations. The array is partitioned into
+non-overlapping regions with size equal to |
+ + required + | +
**kwargs |
+
+ Any
+ |
+
+
+
+ Extra keyword arguments passed to |
+
+ {}
+ |
+
Returns:
+Type | +Description | +
---|---|
+ Array - like
+ |
+
+
+
+ The result of the windowed max. The length of each axis of this array +will be a fraction of the input. The datatype of the return value will +will be the same as the input. + |
+
This function works by first reshaping the array to have an extra
+axis per element of window_size
, then computing the
+max along those extra axes.
See xarray_multiscale.reductions.reshape_windowed
for
+the implementation of the array reshaping routine.
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import windowed_mean
+>>> data = np.arange(16).reshape(4, 4)
+>>> windowed_max(data, (2, 2))
+array([[ 5, 7],
+ [13, 15]])
+
src/xarray_multiscale/reducers.py
Compute the windowed minimum of an array.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. The array must have |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window to use for aggregations. The array is partitioned into
+non-overlapping regions with size equal to |
+ + required + | +
**kwargs |
+
+ Any
+ |
+
+
+
+ Extra keyword arguments passed to |
+
+ {}
+ |
+
Returns:
+Type | +Description | +
---|---|
+ Array - like
+ |
+
+
+
+ The result of the windowed min. The length of each axis of this array +will be a fraction of the input. The datatype of the return value will +will be the same as the input. + |
+
This function works by first reshaping the array to have an extra
+axis per element of window_size
, then computing the
+min along those extra axes.
See xarray_multiscale.reductions.reshape_windowed
+for the implementation of the array reshaping routine.
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import windowed_mean
+>>> data = np.arange(16).reshape(4, 4)
+>>> windowed_min(data, (2, 2))
+array([[0, 2],
+ [8, 10]])
+
src/xarray_multiscale/reducers.py
Compute the windowed mode of an array using either
+windowed_mode_countess
or windowed_mode_scipy
+Input will be coerced to a numpy array.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. The array must have a |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window to use for aggregation. The array is partitioned into
+non-overlapping regions with size equal to |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Numpy array
+ |
+
+
+
+ The result of the windowed mode. The length of each axis of this array +will be a fraction of the input. + |
+
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import windowed_mode
+>>> data = np.arange(16).reshape(4, 4)
+>>> windowed_mode(data, (2, 2))
+array([[ 0, 2],
+ [ 8, 10]])
+
src/xarray_multiscale/reducers.py
Compute the windowed mode of an array using scipy.stats.mode. +Input will be coerced to a numpy array.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. The array must have a |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window to use for aggregation. The array is partitioned into
+non-overlapping regions with size equal to |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Numpy array
+ |
+
+
+
+ The result of the windowed mode. The length of each axis of this array +will be a fraction of the input. + |
+
This function wraps scipy.stats.mode
.
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import windowed_mode
+>>> data = np.arange(16).reshape(4, 4)
+>>> windowed_mode(data, (2, 2))
+array([[ 0, 2],
+ [ 8, 10]])
+
src/xarray_multiscale/reducers.py
countless downsamples labeled images (segmentations) +by finding the mode using vectorized instructions. +It is ill advised to use this O(2^N-1) time algorithm +and O(NCN/2) space for N > about 16 tops. +This means it's useful for the following kinds of downsampling. +This could be implemented for higher performance in +C/Cython more simply, but at least this is easily +portable. +2x2x1 (N=4), 2x2x2 (N=8), 4x4x1 (N=16), 3x2x1 (N=6) +and various other configurations of a similar nature. +c.f. https://medium.com/@willsilversmith/countless-3d-vectorized-2x-downsampling-of-labeled-volume-images-using-python-and-numpy-59d686c2f75
+This function has been modified from the original +to avoid mutation of the input argument.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. + |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window size. The length of |
+ + required + | +
src/xarray_multiscale/reducers.py
312 +313 +314 +315 +316 +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 +348 +349 +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 |
|
Compute the windowed rank order filter of an array. +Input will be coerced to a numpy array.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ NDArray[Any]
+ |
+
+
+
+ The array to be downscaled. The array must have a |
+ + required + | +
window_size |
+
+ tuple[int, ...]
+ |
+
+
+
+ The window to use for aggregation. The array is partitioned into
+non-overlapping regions with size equal to |
+ + required + | +
rank |
+
+ int
+ |
+
+
+
+ The index to take from the sorted values in each window. If non-negative, then
+rank must be between 0 and the product of the elements of |
+
+ -1
+ |
+
Returns:
+Type | +Description | +
---|---|
+ Numpy array
+ |
+
+
+
+ The result of the windowed rank filter. The length of each axis of this array +will be a fraction of the input. + |
+
Examples:
+>>> import numpy as np
+>>> from xarray_multiscale.reducers import windowed_rank
+>>> data = np.arange(16).reshape(4, 4)
+>>> windowed_rank(data, (2, 2), -2)
+array([[ 4 6]
+ [12 14]])
+
src/xarray_multiscale/reducers.py
Pad or crop array such that its new dimensions are evenly +divisible by a set of integers.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
array |
+
+ ndarray
+ |
+
+
+
+ Array that will be padded. + |
+ + required + | +
scale_factors |
+
+ Sequence of ints
+ |
+
+
+
+ The output array is guaranteed to have dimensions that are each +evenly divisible by the corresponding scale factor, and chunks +that are smaller than or equal to the scale factor +(if the array has chunks) + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ DataArray
+ |
+
+
+
+
+ |
+
src/xarray_multiscale/util.py
Compute the logarithm of x base n.
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
x |
+
+ float or int.
+ |
+
+
+
+
+ |
+ + required + | +
n |
+
+ ArrayLike
+ |
+
+
+
+
+ |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ float
+ |
+
+
+
+ np.log(x) / np.log(n) + |
+
src/xarray_multiscale/util.py