code: def _threshold_weight_map(x, fraction):
      """threshold a positive map in order to retain a certain fraction of the
      total value"""
      sorted_x = -np.sort(-x)
      if fraction < sorted_x[0] / x.sum():
          return np.zeros_like(x)
  
      idx = np.where(np.cumsum(sorted_x) < fraction * x.sum())[0][-1]
      x[x < sorted_x[idx]] = 0
      return x
  
file_path: nipy/nipy/labs/spatial_models/structural_bfls.py
imports: import numpy
  from scipy import stats
label_desc: Use image node_id 1 for calling a global function with example usage: _threshold_weight_map(x, fraction) and returns: x, np