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

Method apply_gradient_compensation

mne/io/base.py:310–357  ·  view source on GitHub ↗

Apply CTF gradient compensation. .. warning:: The compensation matrices are stored with single precision, so repeatedly switching between different of compensation (e.g., 0->1->3->2) can increase numerical noise, especially if d

(self, grade, verbose=None)

Source from the content-addressed store, hash-verified

308
309 @verbose
310 def apply_gradient_compensation(self, grade, verbose=None):
311 """Apply CTF gradient compensation.
312
313 .. warning:: The compensation matrices are stored with single
314 precision, so repeatedly switching between different
315 of compensation (e.g., 0->1->3->2) can increase
316 numerical noise, especially if data are saved to
317 disk in between changing grades. It is thus best to
318 only use a single gradient compensation level in
319 final analyses.
320
321 Parameters
322 ----------
323 grade : int
324 CTF gradient compensation level.
325 %(verbose)s
326
327 Returns
328 -------
329 raw : instance of Raw
330 The modified Raw instance. Works in-place.
331 """
332 grade = int(grade)
333 current_comp = self.compensation_grade
334 if current_comp != grade:
335 if self.proj:
336 raise RuntimeError(
337 "Cannot change compensation on data where projectors have been "
338 "applied."
339 )
340 # Figure out what operator to use (varies depending on preload)
341 from_comp = current_comp if self.preload else self._read_comp_grade
342 comp = make_compensator(self.info, from_comp, grade)
343 logger.info(
344 "Compensator constructed to change %d -> %d", current_comp, grade
345 )
346 set_current_comp(self.info, grade)
347 # We might need to apply it to our data now
348 if self.preload:
349 logger.info("Applying compensator to loaded data")
350 lims = np.concatenate(
351 [np.arange(0, len(self.times), 10000), [len(self.times)]]
352 )
353 for start, stop in zip(lims[:-1], lims[1:]):
354 self._data[:, start:stop] = np.dot(comp, self._data[:, start:stop])
355 else:
356 self._comp = comp # store it for later use
357 return self
358
359 @property
360 def _dtype(self):

Callers 15

test_field_map_ctfFunction · 0.80
test_fine_cal_systemsFunction · 0.80
test_other_systemsFunction · 0.80
test_fine_calibrationFunction · 0.80
test_cross_talkFunction · 0.80
test_ica_ctfFunction · 0.80
test_ica_eegFunction · 0.80
test_compute_proj_ctfFunction · 0.80
test_compensation_applyFunction · 0.80
make_evokedFunction · 0.80

Calls 3

make_compensatorFunction · 0.85
set_current_compFunction · 0.85
infoMethod · 0.80

Tested by 15

test_field_map_ctfFunction · 0.64
test_fine_cal_systemsFunction · 0.64
test_other_systemsFunction · 0.64
test_fine_calibrationFunction · 0.64
test_cross_talkFunction · 0.64
test_ica_ctfFunction · 0.64
test_ica_eegFunction · 0.64
test_compute_proj_ctfFunction · 0.64
test_compensation_applyFunction · 0.64
make_evokedFunction · 0.64