code: def test_cosine_score():
      """Test simulation metrics."""
      src = read_source_spaces(src_fname)
      vert1 = [src[0]["vertno"][0:1], []]
      vert2 = [src[0]["vertno"][1:2], []]
      data1 = np.ones((1, 2))
      data2 = data1.copy()
      stc_true = SourceEstimate(
          data1, vert1, 0, 0.002, subject="sample"
      )
      stc_est1 = SourceEstimate(
          data2, vert2, 0, 0.002, subject="sample"
      )
      stc_est2 = SourceEstimate(
          data2, vert1, 0, 0.002, subject="sample"
      )
  
      E_per_sample1 = cosine_score(stc_true, stc_est1)
      E_unique1 = cosine_score(stc_true, stc_est1, per_sample=False)
  
      E_per_sample2 = cosine_score(stc_true, stc_est2)
      E_unique2 = cosine_score(stc_true, stc_est2, per_sample=False)
  
      assert_allclose(E_per_sample1, np.zeros(2))
      assert_allclose(E_unique1, 0.0, atol=1e-08)
      assert_allclose(E_per_sample2, np.ones(2))
      assert_allclose(E_unique2, 1.0, atol=1e-08)
  
file_path: mne-python/mne/simulation/metrics/tests/test_metrics.py
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose
  from scipy.linalg import norm
  from mne import SourceEstimate, read_source_spaces
  from mne.datasets import testing
  from mne.simulation import metrics
  from mne.simulation.metrics import cosine_score, f1_score, peak_position_error, precision_score, recall_score, region_localization_error, roc_auc_score, spatial_deviation_error
label_desc: Use image node_id 2 for calling a global function with example usage: test_cosine_score() without return types