code: def dispersion_ranking_NN(self, nnm, num_norm_avg=50):
          self.knn_avg(nnm)
          D_avg = self.adata.layers['X_knn_avg']
          mu, var = sf.mean_variance_axis(D_avg, axis=0)
          dispersions = np.zeros(var.size)
          dispersions[mu > 0] = var[mu > 0] / mu[mu > 0]
          self.adata.var['spatial_dispersions'] = dispersions.copy()
          ma = np.sort(dispersions)[-num_norm_avg:].mean()
          dispersions[dispersions >= ma] = ma
          weights = ((dispersions / dispersions.max())**0.5).flatten()
          self.adata.var['weights'] = weights
          return weights