MCPcopy
hub / github.com/mne-tools/mne-python / sum

Method sum

mne/time_frequency/csd.py:201–273  ·  view source on GitHub ↗

Calculate the sum CSD in the given frequency range(s). If the exact given frequencies are not available, the nearest frequencies will be chosen. Parameters ---------- fmin : float | list of float | None Lower bound of the frequency range in Hertz

(self, fmin=None, fmax=None)

Source from the content-addressed store, hash-verified

199 )
200
201 def sum(self, fmin=None, fmax=None):
202 """Calculate the sum CSD in the given frequency range(s).
203
204 If the exact given frequencies are not available, the nearest
205 frequencies will be chosen.
206
207 Parameters
208 ----------
209 fmin : float | list of float | None
210 Lower bound of the frequency range in Hertz. Defaults to the lowest
211 frequency available. When a list of frequencies is given, these are
212 used as the lower bounds (inclusive) of frequency bins and the sum
213 is taken for each bin.
214 fmax : float | list of float | None
215 Upper bound of the frequency range in Hertz. Defaults to the
216 highest frequency available. When a list of frequencies is given,
217 these are used as the upper bounds (inclusive) of frequency bins
218 and the sum is taken for each bin.
219
220 Returns
221 -------
222 csd : instance of CrossSpectralDensity
223 The CSD matrix, summed across the given frequency range(s).
224 """
225 if self._is_sum:
226 raise RuntimeError(
227 "This CSD matrix already represents a mean or sum across frequencies."
228 )
229
230 # Deal with the various ways in which fmin and fmax can be specified
231 if fmin is None and fmax is None:
232 fmin = [self.frequencies[0]]
233 fmax = [self.frequencies[-1]]
234 else:
235 if isinstance(fmin, numbers.Number):
236 fmin = [fmin]
237 if isinstance(fmax, numbers.Number):
238 fmax = [fmax]
239 if fmin is None:
240 fmin = [self.frequencies[0]] * len(fmax)
241 if fmax is None:
242 fmax = [self.frequencies[-1]] * len(fmin)
243
244 if any(fmin_ > fmax_ for fmin_, fmax_ in zip(fmin, fmax)):
245 raise ValueError(
246 "Some lower bounds are higher than the corresponding upper bounds."
247 )
248
249 # Find the index of the lower bound of each frequency bin
250 fmin_inds = [self._get_frequency_index(f) for f in fmin]
251 fmax_inds = [self._get_frequency_index(f) + 1 for f in fmax]
252
253 if len(fmin_inds) != len(fmax_inds):
254 raise ValueError("The length of fmin does not match the length of fmax.")
255
256 # Sum across each frequency bin
257 n_bins = len(fmin_inds)
258 new_data = np.zeros((self._data.shape[0], n_bins), dtype=self._data.dtype)

Callers 15

meanMethod · 0.95
_read_coil_def_fileFunction · 0.45
_prepare_for_forwardFunction · 0.45
compute_depth_priorFunction · 0.45
_fast_sphere_dot_r0Function · 0.45
_do_self_dotsFunction · 0.45
_do_cross_dotsFunction · 0.45
_do_surface_dotsFunction · 0.45
_lin_field_coeffFunction · 0.45
_do_lin_field_coeffFunction · 0.45

Calls 3

_get_frequency_indexMethod · 0.95
appendMethod · 0.45

Tested by 15

test_make_forward_dipoleFunction · 0.36
test_make_field_map_meegFunction · 0.36
test_apply_forwardFunction · 0.36
_check_snrFunction · 0.36
test_pos_semidef_invFunction · 0.36
test_sum_squaredFunction · 0.36
test_time_maskFunction · 0.36
test_freq_maskFunction · 0.36
test_pcaFunction · 0.36