code: def test_high_variance_confounds():
      # C and F order might take different paths in the function. Check that the
      # result is identical.
      n_features = 1001
      length = 20
      n_confounds = 5
      seriesC, _, _ = generate_signals(
          n_features=n_features, length=length, order="C"
      )
      seriesF, _, _ = generate_signals(
          n_features=n_features, length=length, order="F"
      )
  
      np.testing.assert_almost_equal(seriesC, seriesF, decimal=13)
      outC = nisignal.high_variance_confounds(
          seriesC, n_confounds=n_confounds, detrend=False
      )
      outF = nisignal.high_variance_confounds(
          seriesF, n_confounds=n_confounds, detrend=False
      )
      np.testing.assert_almost_equal(outC, outF, decimal=13)
  
      # Result must not be influenced by global scaling
      seriesG = 2 * seriesC
      outG = nisignal.high_variance_confounds(
          seriesG, n_confounds=n_confounds, detrend=False
      )
      np.testing.assert_almost_equal(outC, outG, decimal=13)
      assert outG.shape == (length, n_confounds)
  
      # Changing percentile changes the result
      seriesG = seriesC
      outG = nisignal.high_variance_confounds(
          seriesG,
          percentile=1.0,
          n_confounds=n_confounds,
          detrend=False,
      )
      with pytest.raises(AssertionError):
          np.testing.assert_almost_equal(outC, outG, decimal=13)
      assert outG.shape == (length, n_confounds)
  
      # Check shape of output
      out = nisignal.high_variance_confounds(
          seriesG, n_confounds=7, detrend=False
      )
      assert out.shape == (length, 7)
  
      # Adding a trend and detrending should give same results as with no trend.
      seriesG = seriesC
      trends = generate_trends(n_features=n_features, length=length)
      seriesGt = seriesG + trends
  
      outG = nisignal.high_variance_confounds(
          seriesG, detrend=False, n_confounds=n_confounds
      )
      outGt = nisignal.high_variance_confounds(
          seriesGt, detrend=True, n_confounds=n_confounds
      )
      # Since sign flips could occur, we look at the absolute values of the
      # covariance, rather than the absolute difference, and compare this to
      # the identity matrix
      np.testing.assert_almost_equal(
          np.abs(outG.T.dot(outG)),
          np.identity(outG.shape[1]),
          decimal=13,
      )
      # Control for sign flips by taking the min of both possibilities
      np.testing.assert_almost_equal(
          np.min(
              np.abs(np.dstack([outG - outGt, outG + outGt])), axis=2
          ),
          np.zeros(outG.shape),
      )
  
      # Control robustness to NaNs
      seriesG[:, 0] = 0
      out1 = nisignal.high_variance_confounds(
          seriesG, n_confounds=n_confounds
      )
      seriesG[:, 0] = np.nan
      out2 = nisignal.high_variance_confounds(
          seriesG, n_confounds=n_confounds
      )
      np.testing.assert_almost_equal(out1, out2, decimal=13)
  
imports: import os.path
  import numpy
  import pytest
  import scipy.signal
  from pandas import read_csv
  from nilearn import signal
  from nilearn.conftest import _rng
  from nilearn.signal import clean
label_desc: Use image node_id 17 for calling a global function with example usage: test_high_variance_confounds() without return types