code: def annotate_muscle_zscore(
      raw,
      threshold=4,
      ch_type=None,
      min_length_good=0.1,
      filter_freq=(110, 140),
      n_jobs=None,
      verbose=None,
  ):
      """Create annotations for segments that likely contain muscle artifacts.
  
      Detects data segments containing activity in the frequency range given by
      ``filter_freq`` whose envelope magnitude exceeds the specified z-score
      threshold, when summed across channels and divided by ``sqrt(n_channels)``.
      False-positive transient peaks are prevented by low-pass filtering the
      resulting z-score time series at 4 Hz. Only operates on a single channel
      type, if ``ch_type`` is ``None`` it will select the first type in the list
      ``mag``, ``grad``, ``eeg``.
      See :footcite:`Muthukumaraswamy2013` for background on choosing
      ``filter_freq`` and ``threshold``.
  
      Parameters
      ----------
      raw : instance of Raw
          Data to estimate segments with muscle artifacts.
      threshold : float
          The threshold in z-scores for marking segments as containing muscle
          activity artifacts.
      ch_type : 'mag' | 'grad' | 'eeg' | None
          The type of sensors to use. If ``None`` it will take the first type in
          ``mag``, ``grad``, ``eeg``.
      min_length_good : float | None
          The shortest allowed duration of "good data" (in seconds) between
          adjacent annotations; shorter segments will be incorporated into the
          surrounding annotations.``None`` is equivalent to ``0``.
          Default is ``0.1``.
      filter_freq : array-like, shape (2,)
          The lower and upper frequencies of the band-pass filter.
          Default is ``(110, 140)``.
      %(n_jobs)s
      %(verbose)s
  
      Returns
      -------
      annot : mne.Annotations
          Periods with muscle artifacts annotated as BAD_muscle.
      scores_muscle : array
          Z-score values averaged across channels for each sample.
  
      References
      ----------
      .. footbibliography::
      """
      raw_copy = raw.copy()
  
      if ch_type is None:
          raw_ch_type = raw_copy.get_channel_types()
          if "mag" in raw_ch_type:
              ch_type = "mag"
          elif "grad" in raw_ch_type:
              ch_type = "grad"
          elif "eeg" in raw_ch_type:
              ch_type = "eeg"
          else:
              raise ValueError(
                  "No M/EEG channel types found, please specify a"
                  " ch_type or provide M/EEG sensor data"
              )
          logger.info(
              "Using %s sensors for muscle artifact detection"
              % (ch_type)
          )
  
      if ch_type in ("mag", "grad"):
          raw_copy.pick(ch_type)
      else:
          ch_type = {"meg": False, ch_type: True}
          raw_copy.pick(**ch_type)
  
      raw_copy.filter(
          filter_freq[0],
          filter_freq[1],
          fir_design="firwin",
          pad="reflect_limited",
          n_jobs=n_jobs,
      )
      raw_copy.apply_hilbert(envelope=True, n_jobs=n_jobs)
  
      data = raw_copy.get_data(reject_by_annotation="NaN")
      nan_mask = ~np.isnan(data[0])
      sfreq = raw_copy.info["sfreq"]
  
      art_scores = zscore(data[:, nan_mask], axis=1)
      art_scores = art_scores.sum(axis=0) / np.sqrt(art_scores.shape[0])
      art_scores = filter_data(art_scores, sfreq, None, 4)
  
      scores_muscle = np.zeros(data.shape[1])
      scores_muscle[nan_mask] = art_scores
  
      art_mask = scores_muscle > threshold
      # return muscle scores with NaNs
      scores_muscle[~nan_mask] = np.nan
  
      # remove artifact free periods shorter than min_length_good
      min_length_good = (
          0 if min_length_good is None else min_length_good
      )
      min_samps = min_length_good * sfreq
      comps, num_comps = label(art_mask == 0)
      for com in range(1, num_comps + 1):
          l_idx = np.nonzero(comps == com)[0]
          if len(l_idx) < min_samps:
              art_mask[l_idx] = True
  
      annot = _annotations_from_mask(
          raw_copy.times,
          art_mask,
          "BAD_muscle",
          orig_time=raw.info["meas_date"],
      )
      _adjust_onset_meas_date(annot, raw)
      return annot, scores_muscle
  
file_path: mne-python/mne/preprocessing/artifact_detection.py
imports: import numpy
  from scipy.ndimage import distance_transform_edt, label
  from scipy.signal import find_peaks
  from scipy.stats import zscore
  from ..annotations import Annotations, _adjust_onset_meas_date, _annotations_starts_stops, annotations_from_events
  from ..filter import filter_data
  from ..io.base import BaseRaw
  from ..transforms import Transform, _angle_between_quats, _average_quats, _quat_to_affine, apply_trans, quat_to_rot
  from ..utils import _mask_to_onsets_offsets, _pl, _validate_type, logger, verbose
label_desc: Use image node_id 1 for calling a global function with example usage: annotate_muscle_zscore(raw, threshold, ch_type, min_length_good, filter_freq, n_jobs, verbose) and returns: annot,  scores_muscle