|
fosanalysis
A framework to evaluate distributed fiber optic sensor data
|
Contains functions to shift a (partly) view of an array across the full array. More...
Functions | |
| list | determine_moving_parameters (np.array data_array, tuple radius, tuple start_pixel=None, tuple step_size=None) |
| Generate indices for a moving window and check the other parameters. | |
| moving (np.array data_array, tuple radius, tuple start_pixel=None, tuple step_size=None) | |
| Generates a symmetric moving window over an array. | |
| sliding (np.array data_array, radius) | |
| Generates a sliding window over an array. | |
| np.array | sliding_window_function (np.array arr, radius, fn, str pad_mode=None, *args, **kwargs) |
Applies the function fn to a sliding window over the array arr. | |
Contains functions to shift a (partly) view of an array across the full array.
| list fosanalysis.utils.windows.determine_moving_parameters | ( | np.array | data_array, |
| tuple | radius, | ||
| tuple | start_pixel = None, | ||
| tuple | step_size = None ) |
Generate indices for a moving window and check the other parameters.
| data_array | Array of data over which the window should move. |
| radius | Inradius of the window's rectangle. If radius is an int, all axes will use this radius and the window is a square. For non-square windows, pass a tuple with a radius for each dimension of data_array. Along an axis, the window has a width of \(2r + 1\) for each element \(r\) of radius. |
| start_pixel | Index of the first window's central pixel. If start_pixel is an int, it is used for all dimensions of data_array. To specify a custom starting element, pass a tuple with a step size for each dimension of data_array. If None, it defaults to radius, the moving window starts with a full slice. |
| step_size | Step size for estimation. If step_size is an int, it is used for all dimensions of data_array. If None, it defaults to \(2r + 1\) for each element \(r\) of radius, which is equivalent to a rolling window. |
(orig_index_lists, radius, start_pixel, step_size): | orig_index_lists | List of lists, containing the indices along each axis. |
| radius | A tuple, see above. |
| start_pixel | A tuple, see above. |
| step_size | A tuple, see above. |
Definition at line 158 of file windows.py.
| fosanalysis.utils.windows.moving | ( | np.array | data_array, |
| tuple | radius, | ||
| tuple | start_pixel = None, | ||
| tuple | step_size = None ) |
Generates a symmetric moving window over an array.
This function returns a generator that yields information about the window_center_orig, target_pixel, and the content of the window. Converts data_array to a Numpy array. Ensuring radius as a tuple. do this similar for stepsize and the start pixel (start pixel if not given equal to radius). Determine orig_index_lists based on array dimensions and provided indices. It generates combinations of indices. It iterates over combinations and yields window information.
| data_array | Array of data over which the window should move. |
| radius | Inradius of the window's rectangle. If radius is an int, all axes will use this radius and the window is a square. For non-square windows, pass a tuple with a radius for each dimension of data_array. Along an axis, the window has a width of \(2r + 1\) for each element \(r\) of radius. |
| start_pixel | Index of the first window's central pixel. If start_pixel is an int, it is used for all dimensions of data_array. To specify a custom starting element, pass a tuple with a step size for each dimension of data_array. If None, it defaults to radius, the moving window starts with a full slice. |
| step_size | Step size how far the window moves in one step. If step_size is an int, it is used for all dimensions of data_array. If None, it defaults to \(2r + 1\) for each element \(r\) of radius, which is equivalent to a rolling window. |
(orig_pixel, target_pixel, window_content). | orig_pixel | Index of the window's center in data_array. |
| target_pixel | Index of the entry in a new array, in which the aggregated result is to be stored. |
| window_content | A view of the data_array, around the orig_pixel. |
Definition at line 109 of file windows.py.
| fosanalysis.utils.windows.sliding | ( | np.array | data_array, |
| radius ) |
Generates a sliding window over an array.
This function returns a generator, hence, it should be use like:
In contrast to other function like numpy.lib.stride_tricks.sliding_window_view(), this window slides over each pixel, even in the margin areas of data_array. So, for each entry in data_array, a view to the window surrounding it is yielded. In the margins, the window contains fewer entries. Thus, boundary effects are to be expected, when using this function.
| data_array | Array of data, over which the window should slide. |
| radius | Inradius of the window, sets the window's widths. Along an axis, the window has a width of \((2r+1)\). It is expected to be an int or iterable. If radius is an integer, it is used for all axes. The window will contain (up to) \((2r+1)^2\) entries. To set different widths for axes, use an iterable, such as a tuple. This tuple's length has to match the dimension of data_array. |
(pixel, window) is yielded. | pixel | Index of the window's central pixel in data_array. |
| window | Sub-array view of the data_array centered around pixel. |
Definition at line 63 of file windows.py.
| np.array fosanalysis.utils.windows.sliding_window_function | ( | np.array | arr, |
| radius, | |||
| fn, | |||
| str | pad_mode = None, | ||
| * | args, | ||
| ** | kwargs ) |
Applies the function fn to a sliding window over the array arr.
radius to the edge of the array in each direction) are not reliable, as they suffer from boundary effects. This is caused by the sliding window only visit "complete" windows. In the margins, the values of the edge is repeated. The padding behavior can be changed with pad_mode. | arr | Array of data, over which the window should slide. |
| radius | Inradius of the window, sets the window's widths. Along an axis, the window has a width of \((2r+1)\). It is expected to be an int a tuple. If radius is an integer, it is used for all axes. The windows will contain \((2r+1)^n\) entries. To set indiviual widths along for each dimension, use a tuple. This tuple's length has to match the dimension of arr. |
| fn | A function object (type: callable), taking a np.array as input and returning a float. |
| pad_mode | Mode for padding the edges of the result array. Defaults to "edge", which repeats the result value on the edge. For more, options, see numpy.pad() |
| *args | Additional positional arguments; ignored. |
| **kwargs | Additional keyword arguments; ignored. |
np.array with the same shape as arr. Each entry is the result of applying fn to a window reaching radius into each direction. Definition at line 14 of file windows.py.