File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -365,18 +365,19 @@ def find_all_second_peaks(corr, width = 2):
365365 ind = indexes [:, 0 ]
366366 x = indexes [:, 1 ]
367367 y = indexes [:, 2 ]
368- iini = x - width
369- ifin = x + width + 1
370- jini = y - width
371- jfin = y + width + 1
372- iini [iini < 0 ] = 0 # border checking
373- ifin [ifin > corr .shape [1 ]] = corr .shape [1 ]
374- jini [jini < 0 ] = 0
375- jfin [jfin > corr .shape [2 ]] = corr .shape [2 ]
376- # create a masked view of the corr
377- tmp = corr .view (np .ma .MaskedArray )
368+ iini = np .maximum (x - width , 0 )
369+ ifin = np .minimum (x + width + 1 , corr .shape [1 ])
370+ jini = np .maximum (y - width , 0 )
371+ jfin = np .minimum (y + width + 1 , corr .shape [2 ])
372+
373+ # Create a masked view of the corr - vectorized masking
374+ tmp = corr .copy () # Need copy to avoid modifying input
375+ # Create mask for each window efficiently
378376 for i in ind :
379- tmp [i , iini [i ]:ifin [i ], jini [i ]:jfin [i ]] = np .ma .masked
377+ tmp [i , iini [i ]:ifin [i ], jini [i ]:jfin [i ]] = np .nan
378+
379+ # Convert to masked array where nans are masked
380+ tmp = np .ma .masked_invalid (tmp )
380381 indexes , peaks = find_all_first_peaks (tmp )
381382 return indexes , peaks
382383
Original file line number Diff line number Diff line change @@ -226,9 +226,10 @@ def local_median_val(
226226 # f = np.ones((2*size+1, 2*size+1))
227227 # f[size,size] = 0
228228
229+ # Convert to regular array with nans for masked values - avoid extra copies
229230 if np .ma .is_masked (u ):
230- masked_u = np .where (~ u .mask , u . data , np . nan )
231- masked_v = np .where (~ v .mask , v . data , np . nan )
231+ masked_u = np .where (u .mask , np . nan , u . data )
232+ masked_v = np .where (v .mask , np . nan , v . data )
232233 else :
233234 masked_u = u
234235 masked_v = v
@@ -300,8 +301,8 @@ def local_norm_median_val(
300301
301302 """
302303 if np .ma .is_masked (u ):
303- masked_u = np .where (~ u .mask , u . data , np . nan )
304- masked_v = np .where (~ v .mask , v . data , np . nan )
304+ masked_u = np .where (u .mask , np . nan , u . data )
305+ masked_v = np .where (v .mask , np . nan , v . data )
305306 else :
306307 masked_u = u
307308 masked_v = v
You can’t perform that action at this time.
0 commit comments