multiscale
multiscale #
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.
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
|
**kwargs |
Any
|
Additional keyword arguments that will be passed to the reduction function. |
{}
|
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]
Source code in 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 139 140 141 142 |
|
to_dataarray #
Convert the input to an xarray.DataArray
if it is not already one.
Source code in src/xarray_multiscale/multiscale.py
downscale_dask #
Downscale a dask array.
Source code in src/xarray_multiscale/multiscale.py
downscale_coords #
Downscale coordinates by taking the windowed mean of each coordinate array.
Source code in src/xarray_multiscale/multiscale.py
downsampling_depth #
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