@@ -101,37 +101,33 @@ def _normalize_fit_radial_intensity(radii, polynomial, normalization_radius):
101
101
)
102
102
103
103
def _select_rank_method (method ):
104
- # For now, we have more than one option for ranking the values
105
104
def _percentile_ranks_scipy (arr ):
106
105
from scipy import stats
107
106
108
- return stats .rankdata (arr , method = "average" ) / len (arr )
107
+ mask = ~ np .isnan (arr )
108
+ ranks = np .full (arr .shape , np .nan )
109
+ ranks [mask ] = stats .rankdata (arr [mask ], method = "average" ) / np .sum (mask )
110
+ return ranks
109
111
110
112
def _percentile_ranks_numpy (arr ):
113
+ ranks = arr .copy ()
111
114
sorted_indices = np .argsort (arr )
112
- ranks = np .empty_like (sorted_indices )
113
- ranks [sorted_indices ] = np .arange (1 , len (arr ) + 1 )
114
- return ranks / float (len (arr ))
115
-
116
- def _percentile_ranks_numpy_inplace (arr ):
117
- sorted_indices = np .argsort (arr )
118
- arr [sorted_indices ] = np .arange (1 , len (arr ) + 1 )
119
- return arr / float (len (arr ))
115
+ sorted_indices = sorted_indices [~ np .isnan (arr [sorted_indices ])]
116
+ ranks [sorted_indices ] = np .arange (1 , len (sorted_indices ) + 1 )
117
+ return ranks / float (len (sorted_indices ))
120
118
121
119
def _pass_without_filtering (arr ):
122
120
return arr
123
121
124
122
method = method .lower ()
125
- if method == "inplace" :
126
- ranking_func = _percentile_ranks_numpy_inplace
127
- elif method == "numpy" :
123
+ if method == "numpy" :
128
124
ranking_func = _percentile_ranks_numpy
129
125
elif method == "scipy" :
130
126
ranking_func = _percentile_ranks_scipy
131
127
elif method == "none" :
132
128
ranking_func = _pass_without_filtering
133
129
else :
134
- msg = f"{ method } is invalid. Allowed values are 'inplace', ' numpy', 'scipy', or 'none'"
130
+ msg = f"{ method } is invalid. Allowed values are 'numpy', 'scipy', or 'none'"
135
131
raise NotImplementedError (msg )
136
132
return ranking_func
137
133
0 commit comments