67
+
+ Source code in src/xarray_multiscale/chunks.py
+ 67
68
69
70
@@ -754,8 +748,8 @@
array = array.rechunk(new_chunks)
return array
|
-
-
+
+
@@ -763,7 +757,7 @@
-
+
diff --git a/api/multiscale/index.html b/api/multiscale/index.html
index 870652f..cc10bc7 100644
--- a/api/multiscale/index.html
+++ b/api/multiscale/index.html
@@ -556,12 +556,11 @@ multiscale
-
+
-
-
+
@@ -574,110 +573,99 @@ multiscale
-
- multiscale
+ multiscale
- multiscale(
- array,
- reduction,
- scale_factors,
- preserve_dtype=True,
- chunks="preserve",
- chained=True,
- namer=_default_namer,
- **kwargs
-)
+multiscale(array, reduction, scale_factors, preserve_dtype=True, chunks='preserve', chained=True, namer=_default_namer, **kwargs)
-
-
- Generate a coordinate-aware multiscale representation of an array.
+
+ Generate a coordinate-aware multiscale representation of an array.
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- Array-like, e.g. Numpy array, Dask array
- |
-
-
- The array to be downscaled.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- reduction |
-
- callable
- |
-
-
- A function that aggregates chunks of data over windows.
+ |
+
+
+ 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 xarray_multiscale.reducers.WindowedReducer for the expected
signature of this callable.
-
- |
-
- required
- |
-
-
- scale_factors |
-
- int or sequence of ints
- |
-
-
- The desired downscaling factors, one for each axis, or a single
+
+ |
+
+ 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
+
+ |
+
+ 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.
+
+ |
+
+ 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 chunks is set to "preserve" (the default), then chunk sizes will
decrease with each level of downsampling. Otherwise, this argument is
passed to xarray_multiscale.chunks.normalize_chunks .
@@ -686,20 +674,20 @@
producing a list of arrays with the same chunk size.
Note that rechunking can be computationally expensive
for arrays with many chunks.
-
- |
-
- 'preserve'
- |
-
-
- chained |
-
- bool
- |
-
-
- If True (default), the nth downscaled array is generated by
+
+ |
+
+ '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 scale_factors . This means that the nth
downscaled array directly depends on the n-1th downscaled array.
@@ -710,76 +698,74 @@
(i.e., the input array) with the scale_factors raised to the nth
power. This means that the nth downscaled array directly depends
on the input array.
-
- |
-
- True
- |
-
-
- namer |
-
- callable, defaults to `_default_namer`
- |
-
-
- A function for naming the output arrays. This function should take an integer
+
+ |
+
+ 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
- |
-
+
+
+
+ _default_namer
+ |
+
+
+ **kwargs |
+
+ Any
+ |
+
+
+ Additional keyword arguments that will be passed to the reduction function.
+
+ |
+
+ {}
+ |
+
+
+
+
+
+ Returns:
+
+
- **kwargs |
-
- Any
- |
-
-
- Additional keyword arguments that will be passed to the reduction function.
-
- |
-
- {}
- |
+Name | Type |
+ Description |
-
-
-
-
-
- Returns:
-
-
-
-Name | Type |
- Description |
-
-
-
-
-result |
- list[DataArray]
- |
-
-
- The first element of this list is the input array, converted to an
+
+
+
+result |
+ list[DataArray]
+ |
+
+
+ The first element of this list is the input array, converted to an
xarray.DataArray . Each subsequent element of the list is
the result of downsampling the previous element of the list.
The coords attributes of these DataArrays track the changing
offset and scale induced by the downsampling operation.
-
- |
-
-
- |
-
+
+
+
+
+
- Examples:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale import multiscale
>>> from xarray_multiscale.reducers import windowed_mean
@@ -793,9 +779,9 @@
* dim_0 (dim_0) float64 0.5 2.5]
-
- Source code in src/xarray_multiscale/multiscale.py
- 31
+
+ Source code in src/xarray_multiscale/multiscale.py
+ 31
32
33
34
@@ -1019,31 +1005,29 @@
return result
|
-
-
+
+
-
-
- to_dataarray
+ to_dataarray
to_dataarray(array, name=None)
-
-
+
+
Convert the input to an xarray.DataArray if it is not already one.
-
- Source code in src/xarray_multiscale/multiscale.py
- 145
+
+ Source code in src/xarray_multiscale/multiscale.py
+ 145
146
147
148
@@ -1085,31 +1069,29 @@
result = xarray.DataArray(data=data, coords=coords, dims=dims, attrs=attrs, name=name)
return result
|
-
-
+
+
-
-
- downscale_dask
+ downscale_dask
downscale_dask(array, reduction, scale_factors, **kwargs)
-
-
+
+
Downscale a dask array.
-
- Source code in src/xarray_multiscale/multiscale.py
- 168
+
+ Source code in src/xarray_multiscale/multiscale.py
+ 168
169
170
171
@@ -1163,31 +1145,29 @@
graph = HighLevelGraph.from_collections(name, dsk, dependencies=[array])
return Array(graph, name, chunks, meta=meta)
|
-
-
+
+
-
-
- downscale_coords
+ downscale_coords
downscale_coords(array, scale_factors)
-
-
+
+
Downscale coordinates by taking the windowed mean of each coordinate array.
-
- Source code in src/xarray_multiscale/multiscale.py
- 215
+
+ Source code in src/xarray_multiscale/multiscale.py
+ 215
216
217
218
@@ -1215,26 +1195,24 @@
new_coords[coord_name] = coord.coarsen(coarsening_dims).mean()
return new_coords
|
-
-
+
+
-
-
- downsampling_depth
+ downsampling_depth
downsampling_depth(shape, scale_factors)
-
-
+
+
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.
@@ -1243,52 +1221,50 @@ If all scale_factors are 1, this function returns 0.
-
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- shape |
-
- Sequence[int]
- |
-
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- scale_factors |
-
- Sequence[int]
- |
-
-
- Downsampling factors.
-
- |
-
- required
- |
-
-
-
-
+
+
+
+ shape |
+
+ Sequence[int]
+ |
+
+
+ |
+
+ required
+ |
+
+
+ scale_factors |
+
+ Sequence[int]
+ |
+
+
+ Downsampling factors.
+
+ |
+
+ required
+ |
+
+
+
- Examples:
+ Examples:
>>> downsampling_depth((8,), (2,))
3
>>> downsampling_depth((8,2), (2,2))
@@ -1297,9 +1273,9 @@ 2
-
- Source code in src/xarray_multiscale/multiscale.py
- 231
+
+ Source code in src/xarray_multiscale/multiscale.py
+ 231
232
233
234
@@ -1389,8 +1365,8 @@ result = min(depths.astype("int"))
return result
|
-
-
+
+
@@ -1398,7 +1374,7 @@
-
+
diff --git a/api/reducers/index.html b/api/reducers/index.html
index 03d5c3c..bf6b9ed 100644
--- a/api/reducers/index.html
+++ b/api/reducers/index.html
@@ -610,12 +610,11 @@ reducers
-
+
-
-
+
@@ -628,95 +627,91 @@ reducers
-
- reshape_windowed
+ reshape_windowed
reshape_windowed(array, window_size)
-
-
+
+
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 |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be reshaped. The array must have a reshape method.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window size. The length of window_size must match the
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be reshaped. The array must have a reshape method.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window size. The length of window_size must match the
dimensionality of array .
-
- |
-
- required
- |
-
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
+
+
+
+ required
+ |
+
+
+
+
+
+ Returns:
+
+
-
- The input array reshaped with extra dimensions.
- |
-
-
- E.g., for an array with shape (10, 2) ,
+ Type |
+ Description |
+ |
+
+
+
+
+ The input array reshaped with extra dimensions.
+ |
+
+
+ E.g., for an array with shape (10, 2) ,
reshape_windowed(array, (2, 2)) returns
output with shape (5, 2, 1, 2) .
-
- |
-
-
-
-
+
+
+
+
+
- Examples:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import reshape_windowed
>>> data = np.arange(12).reshape(3, 4)
@@ -725,9 +720,9 @@
(3, 1, 2, 2)
-
- Source code in src/xarray_multiscale/reducers.py
- 24
+
+ Source code in src/xarray_multiscale/reducers.py
+ 24
25
26
27
@@ -807,115 +802,112 @@
new_shape += (s // f, f)
return array.reshape(new_shape)
|
-
-
+
+
-
-
- windowed_mean
+ windowed_mean
windowed_mean(array, window_size, **kwargs)
-
-
- Compute the windowed mean of an array.
+
+ Compute the windowed mean of an array.
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled. The array must have
+ Name |
+ Type |
+ Description |
+ Default |
+ |
+
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled. The array must have
reshape and mean methods that obey the
np.reshape and np.mean APIs.
-
- |
-
- required
- |
-
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window to use for aggregations. The array is partitioned into
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window to use for aggregations. The array is partitioned into
non-overlapping regions with size equal to window_size , and the
values in each window are aggregated to generate the result.
-
- |
-
- required
- |
-
+
+
+
+ required
+ |
+
+
+ **kwargs |
+
+ Any
+ |
+
+
+ Extra keyword arguments passed to array.mean
+
+ |
+
+ {}
+ |
+
+
+
+
+
+ Returns:
+
+
- **kwargs |
-
- Any
- |
-
-
- Extra keyword arguments passed to array.mean
-
- |
-
- {}
- |
+ Type |
+ Description |
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
-
-
- Array - like
- |
-
-
- The result of the windowed mean. The length of each axis of this array
+
+
+
+
+ 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 array.mean given the kwargs (if any) passed to it.
-
- |
-
-
- |
+
+
+
+
+
+
Notes
@@ -926,8 +918,7 @@
implementation of the array reshaping routine.
-
- Examples:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import windowed_mean
>>> data = np.arange(16).reshape(4, 4)
@@ -936,9 +927,9 @@
[10.5, 12.5]])
-
- Source code in src/xarray_multiscale/reducers.py
- 66
+
+ Source code in src/xarray_multiscale/reducers.py
+ 66
67
68
69
@@ -1036,114 +1027,111 @@
result: npt.NDArray[Any] = reshaped.mean(axis=tuple(range(1, reshaped.ndim, 2)), **kwargs)
return result
|
-
-
+
+
-
-
- windowed_max
+ windowed_max
windowed_max(array, window_size, **kwargs)
-
-
- Compute the windowed maximum of an array.
+
+ Compute the windowed maximum of an array.
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled. The array must have reshape and
-max methods.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window to use for aggregations. The array is partitioned into
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled. The array must have reshape and
+max methods.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window to use for aggregations. The array is partitioned into
non-overlapping regions with size equal to window_size , and the
values in each window are aggregated to generate the result.
-
- |
-
- required
- |
-
+
+
+
+ required
+ |
+
+
+ **kwargs |
+
+ Any
+ |
+
+
+ Extra keyword arguments passed to array.mean
+
+ |
+
+ {}
+ |
+
+
+
+
+
+ Returns:
+
+
- **kwargs |
-
- Any
- |
-
-
- Extra keyword arguments passed to array.mean
-
- |
-
- {}
- |
+ Type |
+ Description |
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
-
-
- Array - like
- |
-
-
- The result of the windowed max. The length of each axis of this array
+
+
+
+
+ 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.
-
- |
-
-
- |
+
+
+
+
+
+
Notes
@@ -1154,8 +1142,7 @@
the implementation of the array reshaping routine.
-
- Examples:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import windowed_mean
>>> data = np.arange(16).reshape(4, 4)
@@ -1164,9 +1151,9 @@
[13, 15]])
-
- Source code in src/xarray_multiscale/reducers.py
- 117
+
+ Source code in src/xarray_multiscale/reducers.py
+ 117
118
119
120
@@ -1262,114 +1249,111 @@
result: npt.NDArray[Any] = reshaped.max(axis=tuple(range(1, reshaped.ndim, 2)), **kwargs)
return result
|
-
-
+
+
-
-
- windowed_min
+ windowed_min
windowed_min(array, window_size, **kwargs)
-
-
- Compute the windowed minimum of an array.
+
+ Compute the windowed minimum of an array.
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled. The array must have reshape and
-min methods.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window to use for aggregations. The array is partitioned into
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled. The array must have reshape and
+min methods.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window to use for aggregations. The array is partitioned into
non-overlapping regions with size equal to window_size , and the
values in each window are aggregated to generate the result.
-
- |
-
- required
- |
-
+
+
+
+ required
+ |
+
+
+ **kwargs |
+
+ Any
+ |
+
+
+ Extra keyword arguments passed to array.mean
+
+ |
+
+ {}
+ |
+
+
+
+
+
+ Returns:
+
+
- **kwargs |
-
- Any
- |
-
-
- Extra keyword arguments passed to array.mean
-
- |
-
- {}
- |
+ Type |
+ Description |
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
-
-
- Array - like
- |
-
-
- The result of the windowed min. The length of each axis of this array
+
+
+
+
+ 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.
-
- |
-
-
- |
+
+
+
+
+
+
Notes
@@ -1380,8 +1364,7 @@
for the implementation of the array reshaping routine.
-
- Examples:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import windowed_mean
>>> data = np.arange(16).reshape(4, 4)
@@ -1390,9 +1373,9 @@
[8, 10]])
-
- Source code in src/xarray_multiscale/reducers.py
- 167
+
+ Source code in src/xarray_multiscale/reducers.py
+ 167
168
169
170
@@ -1488,66 +1471,63 @@
result: npt.NDArray[Any] = reshaped.min(axis=tuple(range(1, reshaped.ndim, 2)), **kwargs)
return result
|
-
-
+
+
-
-
- windowed_mode
+ windowed_mode
windowed_mode(array, window_size)
-
-
+
+
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 |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled. The array must have a reshape
-method.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window to use for aggregation. The array is partitioned into
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled. The array must have a reshape
+method.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window to use for aggregation. The array is partitioned into
non-overlapping regions with size equal to window_size , and the
values in each window are aggregated to generate the result.
If the product of the elements of window_size is 16 or less, then
@@ -1555,43 +1535,41 @@
windowed_mode_scipy is used. This is a speculative cutoff based
on the documentation of the countless algorithm used in
windowed_mode_countless which was created by William Silversmith.
-
- |
-
- required
- |
-
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
+
+
+
+ required
+ |
+
+
+
+
+
+ Returns:
+
+
-
- Numpy array
- |
-
-
- The result of the windowed mode. The length of each axis of this array
-will be a fraction of the input.
-
- |
+ 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:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import windowed_mode
>>> data = np.arange(16).reshape(4, 4)
@@ -1600,9 +1578,9 @@
[ 8, 10]])
-
- Source code in src/xarray_multiscale/reducers.py
- 217
+
+ Source code in src/xarray_multiscale/reducers.py
+ 217
218
219
220
@@ -1686,108 +1664,104 @@
else:
return windowed_mode_scipy(array, window_size)
|
-
-
+
+
-
-
- windowed_mode_scipy
+ windowed_mode_scipy
windowed_mode_scipy(array, window_size)
-
-
+
+
Compute the windowed mode of an array using scipy.stats.mode.
Input will be coerced to a numpy array.
-
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled. The array must have a reshape
-method.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window to use for aggregation. The array is partitioned into
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled. The array must have a reshape
+method.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window to use for aggregation. The array is partitioned into
non-overlapping regions with size equal to window_size , and the
values in each window are aggregated to generate the result.
-
- |
-
- required
- |
-
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
+
+
+
+ required
+ |
+
+
+
+
+
+ Returns:
+
+
-
- Numpy array
- |
-
-
- The result of the windowed mode. The length of each axis of this array
-will be a fraction of the input.
-
- |
+ 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.
+
+ |
+
+
+
+
Notes
This function wraps scipy.stats.mode .
-
- Examples:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import windowed_mode
>>> data = np.arange(16).reshape(4, 4)
@@ -1796,9 +1770,9 @@
[ 8, 10]])
-
- Source code in src/xarray_multiscale/reducers.py
- 261
+
+ Source code in src/xarray_multiscale/reducers.py
+ 261
262
263
264
@@ -1880,26 +1854,24 @@
result: npt.NDArray[Any] = mode(collapsed, axis=collapsed.ndim - 1, keepdims=False).mode
return result
|
-
-
+
+
-
-
- windowed_mode_countless
+ windowed_mode_countless
windowed_mode_countless(array, window_size)
-
-
+
+
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
@@ -1915,53 +1887,52 @@ Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window size. The length of window_size must match the
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window size. The length of window_size must match the
dimensionality of array .
-
- |
-
- required
- |
-
-
-
-
-
- Source code in src/xarray_multiscale/reducers.py
-
+
+
+ Source code in src/xarray_multiscale/reducers.py
+ 312
313
314
315
@@ -2099,123 +2070,118 @@
return final_result
|
-
-
+
+
-
-
- windowed_rank
+ windowed_rank
windowed_rank(array, window_size, rank=-1)
-
-
+
+
Compute the windowed rank order filter of an array.
Input will be coerced to a numpy array.
-
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- NDArray[Any]
- |
-
-
- The array to be downscaled. The array must have a reshape
-method.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- window_size |
-
- tuple[int, ...]
- |
-
-
- The window to use for aggregation. The array is partitioned into
+ |
+
+
+ array |
+
+ NDArray[Any]
+ |
+
+
+ The array to be downscaled. The array must have a reshape
+method.
+
+ |
+
+ required
+ |
+
+
+ window_size |
+
+ tuple[int, ...]
+ |
+
+
+ The window to use for aggregation. The array is partitioned into
non-overlapping regions with size equal to window_size , and the
values in each window are sorted to generate the result.
-
- |
-
- required
- |
-
-
- rank |
-
- int
- |
-
-
- The index to take from the sorted values in each window. If non-negative, then
+
+ |
+
+ 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 window_size minus one,
(inclusive).
Rank may be negative, in which case it denotes an index relative to the end of the sorted
values following normal python indexing rules.
E.g., when rank is -1 (the default), this takes the maxmum value of each window.
-
- |
-
- -1
- |
-
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
+
+
+
+ -1
+ |
+
+
+
+
+
+ Returns:
+
+
-
- Numpy array
- |
-
-
- The result of the windowed rank filter. The length of each axis of this array
-will be a fraction of the input.
-
- |
+ 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:
+ Examples:
>>> import numpy as np
>>> from xarray_multiscale.reducers import windowed_rank
>>> data = np.arange(16).reshape(4, 4)
@@ -2224,9 +2190,9 @@
[12 14]])
-
- Source code in src/xarray_multiscale/reducers.py
- 383
+
+ Source code in src/xarray_multiscale/reducers.py
+ 383
384
385
386
@@ -2336,8 +2302,8 @@
result: npt.NDArray[Any] = np.take(np.sort(collapsed, axis=-1), rank, axis=-1)
return result
|
-
-
+
+
@@ -2345,7 +2311,7 @@
-
+
diff --git a/api/util/index.html b/api/util/index.html
index 4a1a98e..19f447b 100644
--- a/api/util/index.html
+++ b/api/util/index.html
@@ -500,12 +500,11 @@ util
-
+
-
-
+
@@ -518,94 +517,91 @@ util
-
- adjust_shape
+ adjust_shape
adjust_shape(array, scale_factors)
-
-
+
+
Pad or crop array such that its new dimensions are evenly
divisible by a set of integers.
-
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
+Parameters:
+
+
- array |
-
- ndarray
- |
-
-
- Array that will be padded.
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
- scale_factors |
-
- Sequence of ints
- |
-
-
- The output array is guaranteed to have dimensions that are each
+ |
+
+
+ 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 |
-
-
-
+
+
+
+ required
+ |
+
+
+
+
+
+ Returns:
+
+
-
- DataArray
- |
-
-
-
-
- |
+ Type |
+ Description |
-
-
-
-
- Source code in src/xarray_multiscale/util.py
- 8
+
+
+
+
+ DataArray
+ |
+
+
+
+
+ |
+
+
+ |
+
+
+ Source code in src/xarray_multiscale/util.py
+ 8
9
10
11
@@ -657,99 +653,95 @@
result = array.isel({d: slice(s) for d, s in zip(array.dims, new_shape)})
return result
|
-
-
+
+
-
-
- logn
+ logn
-
-
- Compute the logarithm of x base n.
+
+ Compute the logarithm of x base n.
- Parameters:
-
-
-
- Name |
- Type |
- Description |
- Default |
-
-
-
-
- x |
-
- float or int.
- |
-
-
-
-
- |
-
- required
- |
-
+Parameters:
+
+
- n |
-
- ArrayLike
- |
-
-
-
-
- |
-
- required
- |
+ Name |
+ Type |
+ Description |
+ Default |
-
-
-
-
-
- Returns:
-
-
-
- Type |
- Description |
-
-
-
+
+
+
+ x |
+
+ float or int.
+ |
+
+
+
+
+ |
+
+ required
+ |
+
+
+ n |
+
+ ArrayLike
+ |
+
+
+
+
+ |
+
+ required
+ |
+
+
+
+
+
+ Returns:
+
+
-
- float
- |
-
-
- np.log(x) / np.log(n)
-
- |
+ Type |
+ Description |
-
-
-
-
- Source code in src/xarray_multiscale/util.py
- 36
+
+
+
+
+ float
+ |
+
+
+ np.log(x) / np.log(n)
+
+ |
+
+
+ |
+
+
+ Source code in src/xarray_multiscale/util.py
+ 36
37
38
39
@@ -783,8 +775,8 @@
result: npt.NDArray[np.float64] = np.log(x) / np.log(n)
return result
|
-
-
+
+
@@ -792,7 +784,7 @@
-
+
diff --git a/assets/_mkdocstrings.css b/assets/_mkdocstrings.css
index 57a23e1..85449ec 100644
--- a/assets/_mkdocstrings.css
+++ b/assets/_mkdocstrings.css
@@ -26,6 +26,11 @@
float: right;
}
+/* Backward-compatibility: docstring section titles in bold. */
+.doc-section-title {
+ font-weight: bold;
+}
+
/* Symbols in Navigation and ToC. */
:root,
[data-md-color-scheme="default"] {
diff --git a/index.html b/index.html
index fc1632d..35d3a90 100644
--- a/index.html
+++ b/index.html
@@ -648,7 +648,7 @@ Coordinates matter when y
| |
Another way of thinking about this is that if you downsample an arbitrarily large image to a single value, then the only sensible place to localize that value is at the center of the image. Thus, incrementally downsampling slightly shifts the downsampled image toward that point.
-Why should you care? If you work with images where the coordinates matter (for example, images recorded from scientific instruments), then you should care about keeping track of those coordinates. Tools like numpy or scikit-image make it very easy to ignore the coordinates of your image. These tools model images as simple arrays, and from the array perspective data[0,0] and downsampled_data[0,0] lie on the same position in space because they take the same array index. However, downsampled_data[0,0] is almost certainly shifted relative to data[0,0] . Coordinate-blind tools like scikit-image force your to track the coordinates on your own, which is a recipe for mistakes. This is the value of xarray . By explicitly modelling coordinates alongside data values, xarray ensures that you never lose track of where your data comes from, which is why xarray-multiscale uses it.
+Why should you care? If you work with images where the coordinates matter (for example, images recorded from scientific instruments), then you should care about keeping track of those coordinates. Tools like numpy or scikit-image make it very easy to ignore the coordinates of your image. These tools model images as simple arrays, and from the array perspective data[0,0] and downsampled_data[0,0] lie on the same position in space because they take the same array index. However, downsampled_data[0,0] is almost certainly shifted relative to data[0,0] . Coordinate-blind tools like scikit-image force you to track the coordinates on your own, which is a recipe for mistakes. This is the value of xarray . By explicitly modelling coordinates alongside data values, xarray ensures that you never lose track of where your data comes from, which is why xarray-multiscale uses it.
Who needs this
The library xarray already supports basic downsampling routines via the DataArray.coarsen API. So if you use xarray and just need to compute a windowed mean, then you may not need xarray-multiscale at all. But the DataArray.coarsen API does not
allow users to provide their own downsampling functions; If you need something like windowed mode downsampling, or something you wrote yourself, then xarray-multiscale should be useful to you.
diff --git a/sitemap.xml b/sitemap.xml
index d84af4b..98f71f3 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -2,27 +2,27 @@
https://janeliascicomp.github.io/xarray-multiscale/
- 2024-07-24
+ 2024-07-25
daily
https://janeliascicomp.github.io/xarray-multiscale/api/chunks/
- 2024-07-24
+ 2024-07-25
daily
https://janeliascicomp.github.io/xarray-multiscale/api/multiscale/
- 2024-07-24
+ 2024-07-25
daily
https://janeliascicomp.github.io/xarray-multiscale/api/reducers/
- 2024-07-24
+ 2024-07-25
daily
https://janeliascicomp.github.io/xarray-multiscale/api/util/
- 2024-07-24
+ 2024-07-25
daily
\ No newline at end of file
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
index 1f7af11..5ed3746 100644
Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ
|
|
|
|
|
|
|
|
|
|
|
|
|