|
1 | 1 | """ |
2 | 2 | ========================= |
3 | | -Classes to process data on hyades cluster |
| 3 | +Classes related to Maxfilter |
4 | 4 |
|
5 | 5 | Credits: |
6 | 6 | Several functions are modified versions from those in mne-python |
|
11 | 11 | # Author: Chris Bailey <[email protected]> |
12 | 12 | # |
13 | 13 | # License: BSD (3-clause) |
14 | | -import os |
15 | 14 | import warnings |
16 | | -import inspect |
17 | 15 | import numpy as np |
18 | 16 |
|
19 | 17 | from mne.io import Raw |
20 | 18 | from mne.bem import fit_sphere_to_headshape |
21 | 19 |
|
22 | | -from .cluster import ClusterBatch |
23 | | - |
24 | | - |
25 | | -class MNEPython(ClusterBatch): |
26 | | - """ Foo |
27 | | - """ |
28 | | - def __init__(self, proj_name, bad=[], verbose=True): |
29 | | - super(MNEPython, self).__init__(proj_name) |
30 | | - |
31 | | - self.info = dict(bad=bad, io_mapping=[]) |
32 | | - |
33 | | - def parse_arguments(self, func): |
34 | | - # argspec = inspect.getargspec(Raw.filter) |
35 | | - argspec = inspect.getargspec(func) |
36 | | - n_pos = len(argspec.args) - len(argspec.defaults) |
37 | | - args = argspec.args[1:n_pos] # drop self |
38 | | - kwargs = {key: val for key, val in zip(argspec.args[n_pos:], |
39 | | - argspec.defaults)} |
40 | | - return(args, kwargs) |
41 | | - |
42 | | - def raw_filter(self, in_fname, out_fname, l_freq, h_freq, **kwargs): |
43 | | - if not check_source_readable(in_fname): |
44 | | - raise IOError('Input file {0} not readable!'.format(in_fname)) |
45 | | - if not check_destination_writable(out_fname): |
46 | | - raise IOError('Output file {0} not writable!'.format(out_fname)) |
47 | | - |
48 | | - script = ("from mne.io import read_raw_fif;" |
49 | | - "raw = read_raw_fif('{in_fname:s}', preload=True);" |
50 | | - "raw.filter({l_freq}, {h_freq}{kwargs:});" |
51 | | - "raw.save('{out_fname:s}')") |
52 | | - filtargs = ', '.join("{!s}={!r}".format(key, val) for |
53 | | - (key, val) in kwargs.items()) |
54 | | - filtargs = ', ' + filtargs if len(kwargs) > 0 else filtargs |
55 | | - cmd = "python -c \"" |
56 | | - cmd += script.format(in_fname=in_fname, out_fname=out_fname, |
57 | | - l_freq=l_freq, h_freq=h_freq, kwargs=filtargs) |
58 | | - cmd += "\"" |
59 | | - |
60 | | - self.add_job(cmd, n_threads=1, job_name='mne.raw.filter') |
61 | | - self.info['io_mapping'] += [dict(input=in_fname, output=out_fname)] |
| 20 | +from .base import check_destination_writable, check_source_readable |
| 21 | +from ..cluster import ClusterBatch |
62 | 22 |
|
63 | 23 |
|
64 | 24 | class Maxfilter(ClusterBatch): |
@@ -360,23 +320,3 @@ def __init__(self, proj_name, bad=[], verbose=True): |
360 | 320 | # uniq_bads = [b for b in new_bads if b not in self.bad] |
361 | 321 | # self.info['bad'] = uniq_bads |
362 | 322 | # self.logger.info('Maxfilter object bad channel list updated') |
363 | | - |
364 | | - |
365 | | -def check_destination_writable(dest): |
366 | | - try: |
367 | | - open(dest, 'w') |
368 | | - except IOError: |
369 | | - return False |
370 | | - else: |
371 | | - os.remove(dest) |
372 | | - return True |
373 | | - |
374 | | - |
375 | | -def check_source_readable(source): |
376 | | - try: |
377 | | - fid = open(source, 'r') |
378 | | - except IOError: |
379 | | - return False |
380 | | - else: |
381 | | - fid.close() |
382 | | - return True |
0 commit comments