code: def test_butterworth(rng):
      n_features = 20000
      n_samples = 100
  
      sampling = 100
      low_pass = 30
      high_pass = 10
  
      # Compare output for different options.
      # single timeseries
      data = rng.standard_normal(size=n_samples)
      data_original = data.copy()
      out_single = nisignal.butterworth(
          data,
          sampling,
          low_pass=low_pass,
          high_pass=high_pass,
          copy=True,
      )
      np.testing.assert_almost_equal(data, data_original)
      nisignal.butterworth(
          data,
          sampling,
          low_pass=low_pass,
          high_pass=high_pass,
          copy=False,
      )
      np.testing.assert_almost_equal(out_single, data)
      np.testing.assert_(id(out_single) != id(data))
  
      # multiple timeseries
      data = rng.standard_normal(size=(n_samples, n_features))
      data[
          :, 0
      ] = data_original  # set first timeseries to previous data
      data_original = data.copy()
  
      out1 = nisignal.butterworth(
          data,
          sampling,
          low_pass=low_pass,
          high_pass=high_pass,
          copy=True,
      )
      np.testing.assert_almost_equal(data, data_original)
      np.testing.assert_(id(out1) != id(data_original))
  
      # check that multiple- and single-timeseries filtering do the same thing.
      np.testing.assert_almost_equal(out1[:, 0], out_single)
      nisignal.butterworth(
          data,
          sampling,
          low_pass=low_pass,
          high_pass=high_pass,
          copy=False,
      )
      np.testing.assert_almost_equal(out1, data)
  
      # Test nyquist frequency clipping, issue #482
      out1 = nisignal.butterworth(
          data, sampling, low_pass=50.0, copy=True
      )
      out2 = nisignal.butterworth(
          data,
          sampling,
          low_pass=80.0,
          copy=True,  # Greater than nyq frequency
      )
      np.testing.assert_almost_equal(out1, out2)
      np.testing.assert_(id(out1) != id(out2))
  
      # Test check for equal values in critical frequencies
      sampling = 1
      low_pass = 2
      high_pass = 1
      with pytest.warns(
          UserWarning,
          match=(
              "Signals are returned unfiltered because "
              "band-pass critical frequencies are equal. "
              "Please check that inputs for sampling_rate, "
              "low_pass, and high_pass are valid."
          ),
      ):
          out = nisignal.butterworth(
              data,
              sampling,
              low_pass=low_pass,
              high_pass=high_pass,
              copy=True,
          )
      assert (out == data).all()
  
      # Test check for frequency higher than allowed (>=Nyquist).
      # The frequency should be modified and the filter should be run.
      sampling = 1
      high_pass = 0.01
      low_pass = 0.5
      with pytest.warns(
          UserWarning,
          match="The frequency specified for the low pass filter is too high",
      ):
          out = nisignal.butterworth(
              data,
              sampling,
              low_pass=low_pass,
              high_pass=high_pass,
              copy=True,
          )
      assert not np.array_equal(data, out)
  
      # Test check for frequency lower than allowed (<0).
      # The frequency should be modified and the filter should be run.
      sampling = 1
      high_pass = -1
      low_pass = 0.4
      with pytest.warns(
          UserWarning,
          match="The frequency specified for the high pass filter is too low",
      ):
          out = nisignal.butterworth(
              data,
              sampling,
              low_pass=low_pass,
              high_pass=high_pass,
              copy=True,
          )
      assert not np.array_equal(data, out)
  
      # Test check for high-pass frequency higher than low-pass frequency.
      # An error should be raised.
      sampling = 1
      high_pass = 0.2
      low_pass = 0.1
      with pytest.raises(
          ValueError,
          match=(
              r"High pass cutoff frequency \([0-9.]+\) is greater than or "
              r"equal to low pass filter frequency \([0-9.]+\)\."
          ),
      ):
          nisignal.butterworth(
              data,
              sampling,
              low_pass=low_pass,
              high_pass=high_pass,
              copy=True,
          )
  
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 4 for calling a global function with example usage: test_butterworth(rng) without return types