Skip to content

Commit a631828

Browse files
authored
refactor process and bump version (#30)
a Hail Mary-commit, counting on it working, we need CI!
1 parent 3f0e110 commit a631828

File tree

6 files changed

+87
-70
lines changed

6 files changed

+87
-70
lines changed

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def run(self):
2020

2121
setup(
2222
name = "stormdb",
23-
version = "0.4b",
23+
version = "0.5",
2424
author = "Christopher Bailey",
2525
author_email = "[email protected]",
26-
description = ("Access to StormDb @ CFIN"),
26+
description = ("Tools for accessing StormDb @ CFIN"),
2727
license = "BSD",
2828
keywords = "code",
29-
url = "https://github.com/cfin-tools/stormdb.git",
29+
url = "https://github.com/meeg-cfin/stormdb-python.git",
3030
packages=['stormdb'],
3131
scripts=['bin/submit_to_cluster'],
3232
long_description=read('README.md'),

stormdb/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""
2-
STORM database access
2+
STORM database access and cluster processing tools.
33
"""
44

5-
__VERSION__= '0.3git'
6-
7-
#import .access
5+
__VERSION__ = '0.5'

stormdb/process/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Tools for processing data on hyades-cluster."""
2+
3+
# Authors: Christopher Bailey <[email protected]>
4+
# Mads Jensen <[email protected]>
5+
#
6+
# License: BSD (3-clause)
7+
8+
from .maxfilter import Maxfilter
9+
from .mne_python import MNEPython

stormdb/process/base.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
=========================
3+
Helpers for process-tools.
4+
=========================
5+
"""
6+
7+
import os
8+
9+
10+
def check_destination_writable(dest):
11+
try:
12+
open(dest, 'w')
13+
except IOError:
14+
return False
15+
else:
16+
os.remove(dest)
17+
return True
18+
19+
20+
def check_source_readable(source):
21+
try:
22+
fid = open(source, 'r')
23+
except IOError:
24+
return False
25+
else:
26+
fid.close()
27+
return True
Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
=========================
3-
Classes to process data on hyades cluster
3+
Classes related to Maxfilter
44
55
Credits:
66
Several functions are modified versions from those in mne-python
@@ -11,54 +11,14 @@
1111
# Author: Chris Bailey <[email protected]>
1212
#
1313
# License: BSD (3-clause)
14-
import os
1514
import warnings
16-
import inspect
1715
import numpy as np
1816

1917
from mne.io import Raw
2018
from mne.bem import fit_sphere_to_headshape
2119

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
6222

6323

6424
class Maxfilter(ClusterBatch):
@@ -360,23 +320,3 @@ def __init__(self, proj_name, bad=[], verbose=True):
360320
# uniq_bads = [b for b in new_bads if b not in self.bad]
361321
# self.info['bad'] = uniq_bads
362322
# 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

stormdb/process/mne_python.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import inspect
2+
3+
from .base import check_destination_writable, check_source_readable
4+
from ..cluster import ClusterBatch
5+
6+
7+
class MNEPython(ClusterBatch):
8+
"""Clusterised mne-python commands.
9+
"""
10+
def __init__(self, proj_name, bad=[], verbose=True):
11+
super(MNEPython, self).__init__(proj_name)
12+
13+
self.info = dict(bad=bad, io_mapping=[])
14+
15+
def parse_arguments(self, func):
16+
# argspec = inspect.getargspec(Raw.filter)
17+
argspec = inspect.getargspec(func)
18+
n_pos = len(argspec.args) - len(argspec.defaults)
19+
args = argspec.args[1:n_pos] # drop self
20+
kwargs = {key: val for key, val in zip(argspec.args[n_pos:],
21+
argspec.defaults)}
22+
return(args, kwargs)
23+
24+
def raw_filter(self, in_fname, out_fname, l_freq, h_freq, **kwargs):
25+
if not check_source_readable(in_fname):
26+
raise IOError('Input file {0} not readable!'.format(in_fname))
27+
if not check_destination_writable(out_fname):
28+
raise IOError('Output file {0} not writable!'.format(out_fname))
29+
30+
script = ("from mne.io import read_raw_fif;"
31+
"raw = read_raw_fif('{in_fname:s}', preload=True);"
32+
"raw.filter({l_freq}, {h_freq}{kwargs:});"
33+
"raw.save('{out_fname:s}')")
34+
filtargs = ', '.join("{!s}={!r}".format(key, val) for
35+
(key, val) in kwargs.items())
36+
filtargs = ', ' + filtargs if len(kwargs) > 0 else filtargs
37+
cmd = "python -c \""
38+
cmd += script.format(in_fname=in_fname, out_fname=out_fname,
39+
l_freq=l_freq, h_freq=h_freq, kwargs=filtargs)
40+
cmd += "\""
41+
42+
self.add_job(cmd, n_threads=1, job_name='mne.raw.filter')
43+
self.info['io_mapping'] += [dict(input=in_fname, output=out_fname)]

0 commit comments

Comments
 (0)