lib5c.algorithms.donut_filters module¶
-
lib5c.algorithms.donut_filters.
apply_filter
(obs_matrix, exp_matrix, footprint, max_percent=0.2, min_exp=0.1)[source]¶ Computes a corrected expected value by applying a footprint to observed and expected matrix.
- Parameters
exp_matrix (obs_matrix,) – The square, symmetric matrices of observed and expected counts, respectively.
footprint (np.ndarray) – The footprint to convolve. Should contain 1’s at positions included in the footprint and 0’s everywhere else.
max_percent (float) – If the proportion of nan’s in the footprint for a pixel is greater than this value, the corrected expected at that point will be set to nan.
min_exp (float) – If the sum of entries in
exp_matrix
under the footprint for a particular pixel is less than this value, set the output at this pixel to nan to avoid numerical instability related to division by small numbers.
- Returns
The corrected expected value.
- Return type
np.ndarray
-
lib5c.algorithms.donut_filters.
donut_filt
(obs_matrix, exp_matrix, p, w, max_percent=0.2, min_exp=0.1)[source]¶ Computes the full donut filter.
- Parameters
exp_matrix (obs_matrix,) – The square, symmetric matrices of observed and expected counts, respectively.
w (p,) – The inner and outer radii of the donut, respectively.
max_percent (float) – If the proportion of nan’s in the footprint for a pixel is greater than this value, the corrected expected at that point will be set to nan.
min_exp (float) – If the sum of entries in
exp_matrix
under the footprint for a particular pixel is less than this value, set the output at this pixel to nan to avoid numerical instability related to division by small numbers.
- Returns
The corrected expected value.
- Return type
np.ndarray
-
lib5c.algorithms.donut_filters.
lower_left_filt
(obs_matrix, exp_matrix, p, w, max_percent=0.2, min_exp=0.1)[source]¶ Computes the lower left donut filter.
- Parameters
exp_matrix (obs_matrix,) – The square, symmetric matrices of observed and expected counts, respectively.
w (p,) – The inner and outer radii of the donut, respectively.
max_percent (float) – If the proportion of nan’s in the footprint for a pixel is greater than this value, the corrected expected at that point will be set to nan.
min_exp (float) – If the sum of entries in
exp_matrix
under the footprint for a particular pixel is less than this value, set the output at this pixel to nan to avoid numerical instability related to division by small numbers.
- Returns
The corrected expected value.
- Return type
np.ndarray
Examples
>>> import numpy as np >>> from lib5c.algorithms.donut_filters import lower_left_filt >>> from lib5c.algorithms.expected import empirical_binned >>> from lib5c.algorithms.expected import make_expected_matrix_from_list >>> obs = np.array([[10, 4, 1], ... [ 4, 8, 6], ... [ 1, 6, 12]]).astype(float) >>> exp = make_expected_matrix_from_list( ... empirical_binned(obs, log_transform=False)) >>> exp array([[10., 5., 1.], [ 5., 10., 5.], [ 1., 5., 10.]]) >>> lower_left_filt(obs, exp, 0, 1, max_percent=0.0, min_exp=0.0) array([[ nan, 4. , 0.8], [ 4. , 10. , 6. ], [ 0.8, 6. , nan]])