Concatenate raw instances as if they were continuous. .. note:: Boundaries of the raw files are annotated bad. If you wish to use the data as continuous recording, you can remove the boundary annotations after concatenation (see :meth:`m
(self, raws, preload=None)
| 2127 | |
| 2128 | @fill_doc |
| 2129 | def append(self, raws, preload=None): |
| 2130 | """Concatenate raw instances as if they were continuous. |
| 2131 | |
| 2132 | .. note:: Boundaries of the raw files are annotated bad. If you wish to |
| 2133 | use the data as continuous recording, you can remove the |
| 2134 | boundary annotations after concatenation (see |
| 2135 | :meth:`mne.Annotations.delete`). |
| 2136 | |
| 2137 | Parameters |
| 2138 | ---------- |
| 2139 | raws : list, or Raw instance |
| 2140 | List of Raw instances to concatenate to the current instance |
| 2141 | (in order), or a single raw instance to concatenate. |
| 2142 | %(preload_concatenate)s |
| 2143 | """ |
| 2144 | if not isinstance(raws, list): |
| 2145 | raws = [raws] |
| 2146 | |
| 2147 | # make sure the raws are compatible |
| 2148 | all_raws = [self] |
| 2149 | all_raws += raws |
| 2150 | _check_raw_compatibility(all_raws) |
| 2151 | |
| 2152 | # deal with preloading data first (while files are separate) |
| 2153 | all_preloaded = self.preload and all(r.preload for r in raws) |
| 2154 | if preload is None: |
| 2155 | if all_preloaded: |
| 2156 | preload = True |
| 2157 | else: |
| 2158 | preload = False |
| 2159 | |
| 2160 | if preload is False: |
| 2161 | if self.preload: |
| 2162 | self._data = None |
| 2163 | self.preload = False |
| 2164 | else: |
| 2165 | # do the concatenation ourselves since preload might be a string |
| 2166 | nchan = self.info["nchan"] |
| 2167 | c_ns = np.cumsum([rr.n_times for rr in ([self] + raws)]) |
| 2168 | nsamp = c_ns[-1] |
| 2169 | |
| 2170 | if not self.preload: |
| 2171 | this_data = self._read_segment() |
| 2172 | else: |
| 2173 | this_data = self._data |
| 2174 | |
| 2175 | # allocate the buffer |
| 2176 | _data = _allocate_data(preload, (nchan, nsamp), this_data.dtype) |
| 2177 | _data[:, 0 : c_ns[0]] = this_data |
| 2178 | |
| 2179 | for ri in range(len(raws)): |
| 2180 | if not raws[ri].preload: |
| 2181 | # read the data directly into the buffer |
| 2182 | data_buffer = _data[:, c_ns[ri] : c_ns[ri + 1]] |
| 2183 | raws[ri]._read_segment(data_buffer=data_buffer) |
| 2184 | else: |
| 2185 | _data[:, c_ns[ri] : c_ns[ri + 1]] = raws[ri]._data |
| 2186 | self._data = _data |