| Conditions | 9 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from __future__ import division |
||
| 15 | def inspect(self): |
||
| 16 | provenance = super(FifFile, self).inspect() |
||
| 17 | """ try: |
||
| 18 | img = self.libs.mne.io.Raw(self.path, allow_maxshield=True) |
||
| 19 | except ValueError: |
||
| 20 | pass |
||
| 21 | else: |
||
| 22 | inspect file |
||
| 23 | Return |
||
| 24 | """ |
||
| 25 | ftypes = { |
||
| 26 | 'cov': self.libs.mne.read_cov, |
||
| 27 | 'epo': self.libs.mne.read_epochs, |
||
| 28 | 'ave': self.libs.mne.read_evokeds, |
||
| 29 | 'raw': partial(self.libs.mne.io.read_raw_fif, allow_maxshield=True), |
||
| 30 | } |
||
| 31 | oldLevel = logging.getLogger('mne').getEffectiveLevel() |
||
| 32 | logging.getLogger('mne').setLevel(logging.ERROR) |
||
| 33 | for ftype, readfif in ftypes.items(): |
||
| 34 | try: |
||
| 35 | img = readfif(self.path) |
||
| 36 | if img == []: |
||
| 37 | continue |
||
| 38 | break |
||
| 39 | except ValueError: |
||
| 40 | continue |
||
| 41 | else: |
||
| 42 | ftype = 'other' |
||
| 43 | logging.getLogger('mne').setLevel(oldLevel) |
||
| 44 | |||
| 45 | if ftype == 'raw': |
||
| 46 | sub = img.info['subject_info'] |
||
| 47 | if sub is not None: |
||
| 48 | provenance['subject'] = sub['first_name']+' '+sub['last_name'] |
||
| 49 | provenance['project'] = img.info['proj_name'] |
||
| 50 | acqTS = img.info['meas_date'][0] |
||
| 51 | provenance['acquired'] = datetime.fromtimestamp(acqTS) |
||
| 52 | T = img.last_samp - img.first_samp + 1 |
||
| 53 | provenance['dimensions'] = [img.info['nchan'], T] |
||
| 54 | provenance['sampling-frequency'] = img.info['sfreq'] |
||
| 55 | provenance['duration'] = T/img.info['sfreq'] |
||
| 56 | |||
| 57 | if ftype == 'epo': |
||
| 58 | provenance['lowpass'] = img.info['lowpass'] |
||
| 59 | provenance['highpass'] = img.info['highpass'] |
||
| 60 | provenance['bad-channels'] = img.info['bads'] |
||
| 61 | provenance['dimensions'] = [img.events.shape[0], img.times.shape[0]] |
||
| 62 | |||
| 63 | if ftype == 'ave': |
||
| 64 | nEvokeds = len(img) |
||
| 65 | provenance['dimensions'] = [nEvokeds] + list(img[0].data.shape) |
||
| 66 | |||
| 67 | provenance['fif-type'] = ftype |
||
| 68 | provenance['modality'] = 'MEG' |
||
| 69 | return provenance |
||
| 70 | |||
| 85 |