<commit_before># Authors: <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

import copy
import os
import os.path as op

import numpy as np

from ..constants import FIFF
from ..open import fiff_open, _fiff_get_fid, _get_next_fname
from ..meas_info import read_meas_info
from ..tree import dir_tree_find
from ..tag import read_tag, read_tag_info
from ..base import (BaseRaw, _RawShell, _check_raw_compatibility,
                    _check_maxshield)
from ..utils import _mult_cal_one

from ...annotations import (Annotations, _combine_annotations,
                            _read_annotations_fif)

from ...event import AcqParserFIF
from ...utils import check_fname, logger, verbose, warn


class Raw(BaseRaw):
    """Raw data in FIF format.

    Parameters
    ----------
    fname : str
        The raw file to load. For files that have automatically been split,
        the split part will be automatically loaded. Filenames should end
        with raw.fif, raw.fif.gz, raw_sss.fif, raw_sss.fif.gz,
        raw_tsss.fif or raw_tsss.fif.gz.
    allow_maxshield : bool | str (default False)
        If True, allow loading of data that has been recorded with internal
        active compensation (MaxShield). Data recorded with MaxShield should
        generally not be loaded directly, but should first be processed using
        SSS/tSSS to remove the compensation signals that may also affect brain
        activity. Can also be "yes" to load without eliciting a warning.
    preload : bool or str (default False)
        Preload data into memory for data manipulation and faster indexing.
        If True, the data will be preloaded into memory (fast, requires
        large amount of memory). If preload is a string, preload is the
        file name of a memory-mapped file which is used to store the data
        on the hard drive (slower, requires less memory).
    verbose : bool, str, int, or None
        If not None, override default verbose level (see :func:`mne.verbose`
        and :ref:`Logging documentation <tut_logging>` for more).

    Attributes
    ----------
    info : dict
        :class:`Measurement info <mne.Info>`.
    ch_names : list of string
        List of channels' names.
    n_times : int
        Total number of time points in the raw file.
    times :  ndarray
        Time vector in seconds. Starts from 0, independently of `first_samp`
        value. Time interval between consecutive time samples is equal to the
        inverse of the sampling frequency.
    preload : bool
        Indicates whether raw data are in memory.
    verbose : bool, str, int, or None
        See above.

    """

    @verbose
    def __init__(self, fname, allow_maxshield=False, preload=False,
                 verbose=None):  # noqa: D102
        fnames = [op.realpath(fname)]
        del fname
        split_fnames = []

        raws = []
        for ii, fname in enumerate(fnames):
            do_check_fname = fname not in split_fnames
            raw, next_fname, buffer_size_sec = \
                self._read_raw_file(fname, allow_maxshield,
                                    preload, do_check_fname)
            raws.append(raw)
            if next_fname is not None:
                if not op.exists(next_fname):
                    warn('Split raw file detected but next file %s does not '
                         'exist.' % next_fname)
                    continue
                # process this file next
                fnames.insert(ii + 1, next_fname)
                split_fnames.append(next_fname)

        _check_raw_compatibility(raws)
        super(Raw, self).__init__(
            copy.deepcopy(raws[0].info), False,
            [r.first_samp for r in raws], [r.last_samp for r in raws],
            [r.filename for r in raws], [r._raw_extras for r in raws],
            raws[0].orig_format, None, buffer_size_sec=buffer_size_sec,
            verbose=verbose)

        # combine annotations
        self.set_annotations(raws[0].annotations, False)
        if any([r.annotations for r in raws[1:]]):
            n_samples = np.sum(self._last_samps - self._first_samps + 1)
            for r in raws:
                annotations = _combine_annotations(
                    self.annotations, r.annotations,
                    n_samples, self.first_samp, r.first_samp,
                    r.info['sfreq'], self.info['meas_date'])
                self.set_annotations(annotations, False)<commit_msg>FIX don't delete fname (#5747)<commit_after># Authors: <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#          <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

import copy
import os
import os.path as op

import numpy as np

from ..constants import FIFF
from ..open import fiff_open, _fiff_get_fid, _get_next_fname
from ..meas_info import read_meas_info
from ..tree import dir_tree_find
from ..tag import read_tag, read_tag_info
from ..base import (BaseRaw, _RawShell, _check_raw_compatibility,
                    _check_maxshield)
from ..utils import _mult_cal_one

from ...annotations import (Annotations, _combine_annotations,
                            _read_annotations_fif)

from ...event import AcqParserFIF
from ...utils import check_fname, logger, verbose, warn


class Raw(BaseRaw):
    """Raw data in FIF format.

    Parameters
    ----------
    fname : str
        The raw file to load. For files that have automatically been split,
        the split part will be automatically loaded. Filenames should end
        with raw.fif, raw.fif.gz, raw_sss.fif, raw_sss.fif.gz,
        raw_tsss.fif or raw_tsss.fif.gz.
    allow_maxshield : bool | str (default False)
        If True, allow loading of data that has been recorded with internal
        active compensation (MaxShield). Data recorded with MaxShield should
        generally not be loaded directly, but should first be processed using
        SSS/tSSS to remove the compensation signals that may also affect brain
        activity. Can also be "yes" to load without eliciting a warning.
    preload : bool or str (default False)
        Preload data into memory for data manipulation and faster indexing.
        If True, the data will be preloaded into memory (fast, requires
        large amount of memory). If preload is a string, preload is the
        file name of a memory-mapped file which is used to store the data
        on the hard drive (slower, requires less memory).
    verbose : bool, str, int, or None
        If not None, override default verbose level (see :func:`mne.verbose`
        and :ref:`Logging documentation <tut_logging>` for more).

    Attributes
    ----------
    info : dict
        :class:`Measurement info <mne.Info>`.
    ch_names : list of string
        List of channels' names.
    n_times : int
        Total number of time points in the raw file.
    times :  ndarray
        Time vector in seconds. Starts from 0, independently of `first_samp`
        value. Time interval between consecutive time samples is equal to the
        inverse of the sampling frequency.
    preload : bool
        Indicates whether raw data are in memory.
    verbose : bool, str, int, or None
        See above.

    """

    @verbose
    def __init__(self, fname, allow_maxshield=False, preload=False,
                 verbose=None):  # noqa: D102
        fnames = [op.realpath(fname)]
        split_fnames = []

        raws = []
        for ii, this_fname in enumerate(fnames):
            do_check_fname = this_fname not in split_fnames
            raw, next_fname, buffer_size_sec = \
                self._read_raw_file(this_fname, allow_maxshield,
                                    preload, do_check_fname)
            raws.append(raw)
            if next_fname is not None:
                if not op.exists(next_fname):
                    warn('Split raw file detected but next file %s does not '
                         'exist.' % next_fname)
                    continue
                # process this file next
                fnames.insert(ii + 1, next_fname)
                split_fnames.append(next_fname)

        _check_raw_compatibility(raws)
        super(Raw, self).__init__(
            copy.deepcopy(raws[0].info), False,
            [r.first_samp for r in raws], [r.last_samp for r in raws],
            [r.filename for r in raws], [r._raw_extras for r in raws],
            raws[0].orig_format, None, buffer_size_sec=buffer_size_sec,
            verbose=verbose)

        # combine annotations
        self.set_annotations(raws[0].annotations, False)
        if any([r.annotations for r in raws[1:]]):
            n_samples = np.sum(self._last_samps - self._first_samps + 1)
            for r in raws:
                annotations = _combine_annotations(
                    self.annotations, r.annotations,
                    n_samples, self.first_samp, r.first_samp,
                    r.info['sfreq'], self.info['meas_date'])
                self.set_annotations(annotations, False)
{'fraction_non_alphanumeric': 0.08106326889279437, 'fraction_numerical': 0.0028558875219683658, 'mean_word_length': 2.129941560673771, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6467091', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2538, 'n_words': 895}