Skip to content

Commit

Permalink
ENH: add _get_argvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed Oct 31, 2018
1 parent fcb641b commit 2de3292
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 13 deletions.
3 changes: 2 additions & 1 deletion mne/io/array/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from ..base import BaseRaw
from ...utils import verbose, logger, _validate_type
from ...utils import verbose, logger, _validate_type, _get_argvalues


class RawArray(BaseRaw):
Expand Down Expand Up @@ -68,6 +68,7 @@ def __init__(self, data, info, first_samp=0, verbose=None): # noqa: D102
super(RawArray, self).__init__(info, data,
first_samps=(int(first_samp),),
dtype=dtype, verbose=verbose)
self._init_kwargs = _get_argvalues()
logger.info(' Range : %d ... %d = %9.3f ... %9.3f secs' % (
self.first_samp, self.last_samp,
float(self.first_samp) / info['sfreq'],
Expand Down
3 changes: 2 additions & 1 deletion mne/io/artemis123/artemis123.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import calendar

from .utils import _load_mne_locs, _read_pos
from ...utils import logger, warn, verbose
from ...utils import logger, warn, verbose, _get_argvalues
from ..utils import _read_segments_file
from ..base import BaseRaw
from ..meas_info import _empty_info, _make_dig_points
Expand Down Expand Up @@ -338,6 +338,7 @@ def __init__(self, input_fname, preload=False, verbose=None,
info, preload, filenames=[input_fname], raw_extras=[header_info],
last_samps=last_samps, orig_format=np.float32,
verbose=verbose)
self._init_kwargs = _get_argvalues()
self.info['hpi_results'] = []

if add_head_trans:
Expand Down
3 changes: 2 additions & 1 deletion mne/io/brainvision/brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import numpy as np

from ...utils import verbose, logger, warn
from ...utils import verbose, logger, warn, _get_argvalues
from ..constants import FIFF
from ..meas_info import _empty_info
from ..base import BaseRaw, _check_update_montage
Expand Down Expand Up @@ -145,6 +145,7 @@ def __init__(self, vhdr_fname, montage=None,
info, last_samps=[n_samples - 1], filenames=[data_filename],
orig_format=fmt, preload=preload, verbose=verbose,
raw_extras=[offsets])
self._init_kwargs = _get_argvalues()

# Get annotations from vmrk file
annots = read_annotations_brainvision(mrk_fname, info['sfreq'])
Expand Down
3 changes: 2 additions & 1 deletion mne/io/bti/bti.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np

from ...utils import logger, verbose, sum_squared
from ...utils import logger, verbose, sum_squared, _get_argvalues
from ...transforms import (combine_transforms, invert_transform, apply_trans,
Transform)
from ..constants import FIFF
Expand Down Expand Up @@ -1045,6 +1045,7 @@ def __init__(self, pdf_fname, config_fname='config',
super(RawBTi, self).__init__(
info, preload, filenames=[pdf_fname], raw_extras=[bti_info],
last_samps=[bti_info['total_slices'] - 1], verbose=verbose)
self._init_kwargs = _get_argvalues()

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
"""Read a segment of data from a file."""
Expand Down
3 changes: 2 additions & 1 deletion mne/io/cnt/cnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import numpy as np

from ...utils import warn, verbose
from ...utils import warn, verbose, _get_argvalues
from ...channels.layout import _topo_to_sphere
from ..constants import FIFF
from ..utils import _mult_cal_one, _find_channels, _create_chs
Expand Down Expand Up @@ -365,6 +365,7 @@ def __init__(self, input_fname, montage, eog=(), misc=(), ecg=(), emg=(),
info, preload, filenames=[input_fname], raw_extras=[cnt_info],
last_samps=last_samps, orig_format='int',
verbose=verbose)
self._init_kwargs = _get_argvalues()

@verbose
def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
Expand Down
3 changes: 2 additions & 1 deletion mne/io/ctf/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import numpy as np

from ...utils import verbose, logger, _clean_names
from ...utils import verbose, logger, _clean_names, _get_argvalues
from ...externals.six import string_types

from ..base import BaseRaw
Expand Down Expand Up @@ -151,6 +151,7 @@ def __init__(self, directory, system_clock='truncate', preload=False,
last_samps=last_samps, filenames=fnames,
raw_extras=raw_extras, orig_format='int',
buffer_size_sec=buffer_size_sec, verbose=verbose)
self._init_kwargs = _get_argvalues()

# Add bad segments as Annotations (correct for start time)
start_time = -res4['pre_trig_pts'] / float(info['sfreq'])
Expand Down
3 changes: 2 additions & 1 deletion mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..constants import FIFF
from ...filter import resample
from ...externals.six.moves import zip
from ...utils import copy_function_doc_to_method_doc
from ...utils import copy_function_doc_to_method_doc, _get_argvalues
from ...annotations import Annotations, events_from_annotations


Expand Down Expand Up @@ -197,6 +197,7 @@ def __init__(self, input_fname, montage, eog=None, misc=None,
super(RawEDF, self).__init__(
info, preload, filenames=[input_fname], raw_extras=[edf_info],
last_samps=last_samps, orig_format='int', verbose=verbose)
self._init_kwargs = _get_argvalues()

@verbose
def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
Expand Down
3 changes: 2 additions & 1 deletion mne/io/eeglab/eeglab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..constants import FIFF, Bunch
from ..meas_info import _empty_info, create_info
from ..base import BaseRaw, _check_update_montage
from ...utils import logger, verbose, warn
from ...utils import logger, verbose, warn, _get_argvalues
from ...channels.montage import Montage
from ...epochs import BaseEpochs
from ...event import read_events
Expand Down Expand Up @@ -390,6 +390,7 @@ def __init__(self, input_fname, montage, eog=(), event_id=None,
info, data, filenames=[input_fname], last_samps=last_samps,
orig_format='double', verbose=verbose)

self._init_kwargs = _get_argvalues()
# create event_ch from annotations
annot = read_annotations_eeglab(input_fname)
self.set_annotations(annot)
Expand Down
3 changes: 2 additions & 1 deletion mne/io/egi/egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..utils import _read_segments_file, _create_chs
from ..meas_info import _empty_info
from ..constants import FIFF
from ...utils import verbose, logger, warn
from ...utils import verbose, logger, warn, _get_argvalues


def _read_header(fid):
Expand Down Expand Up @@ -270,6 +270,7 @@ def __init__(self, input_fname, montage=None, eog=None, misc=None,
info, preload, orig_format=egi_info['orig_format'],
filenames=[input_fname], last_samps=[egi_info['n_samples'] - 1],
raw_extras=[egi_info], verbose=verbose)
self._init_kwargs = _get_argvalues()

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
"""Read a segment of data from a file."""
Expand Down
3 changes: 2 additions & 1 deletion mne/io/eximia/eximia.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..base import BaseRaw
from ..utils import _read_segments_file, _file_size
from ..meas_info import create_info
from ...utils import logger, verbose, warn
from ...utils import logger, verbose, warn, _get_argvalues


def read_raw_eximia(fname, preload=False, verbose=None):
Expand Down Expand Up @@ -86,6 +86,7 @@ def __init__(self, fname, preload=False, verbose=None):
super(RawEximia, self).__init__(
info, preload=preload, last_samps=(n_samples - 1,),
filenames=[fname], orig_format='short')
self._init_kwargs = _get_argvalues()

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
"""Read a chunk of raw data."""
Expand Down
3 changes: 2 additions & 1 deletion mne/io/fiff/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
_read_annotations)

from ...event import AcqParserFIF
from ...utils import check_fname, logger, verbose, warn
from ...utils import check_fname, logger, verbose, warn, _get_argvalues


class Raw(BaseRaw):
Expand Down Expand Up @@ -103,6 +103,7 @@ def __init__(self, fname, allow_maxshield=False, preload=False,
[r.filename for r in raws], [r._raw_extras for r in raws],
raws[0].orig_format, None, buffer_size_sec=buffer_size_sec,
verbose=verbose)
self._init_kwargs = _get_argvalues()

# combine annotations
self.set_annotations(raws[0].annotations, False)
Expand Down
3 changes: 2 additions & 1 deletion mne/io/kit/kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from ..pick import pick_types
from ...coreg import fit_matched_points, _decimate_points
from ...utils import verbose, logger, warn
from ...utils import verbose, logger, warn, _get_argvalues
from ...transforms import (apply_trans, als_ras_trans,
get_ras_to_neuromag_trans, Transform)
from ..base import BaseRaw
Expand Down Expand Up @@ -122,6 +122,7 @@ def __init__(self, input_fname, mrk=None, elp=None, hsp=None, stim='>',
super(RawKIT, self).__init__(
info, preload, last_samps=last_samps, filenames=[input_fname],
raw_extras=self._raw_extras, verbose=verbose)
self._init_kwargs = _get_argvalues()

if isinstance(mrk, list):
mrk = [read_mrk(marker) if isinstance(marker, string_types)
Expand Down
3 changes: 2 additions & 1 deletion mne/io/nicolet/nicolet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import datetime
import calendar

from ...utils import logger
from ...utils import logger, _get_argvalues
from ..utils import _read_segments_file, _find_channels, _create_chs
from ..base import BaseRaw, _check_update_montage
from ..meas_info import _empty_info
Expand Down Expand Up @@ -179,6 +179,7 @@ def __init__(self, input_fname, ch_type, montage=None, eog=(), ecg=(),
info, preload, filenames=[input_fname], raw_extras=[header_info],
last_samps=last_samps, orig_format='int',
verbose=verbose)
self._init_kwargs = _get_argvalues()

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
"""Read a chunk of raw data."""
Expand Down
11 changes: 11 additions & 0 deletions mne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ def nottest(f):
# RANDOM UTILITIES


def _get_argvalues():
"""Return all arguments (except self) and values of calling function."""
frame = inspect.stack()[1][0]
args, _, _, values = inspect.getargvalues(frame)
params = dict()
for arg in args:
params[arg] = values[arg]
params.pop('self', None)
return params


def _ensure_int(x, name='unknown', must_be='an int'):
"""Ensure a variable is an integer."""
# This is preferred over numbers.Integral, see:
Expand Down

0 comments on commit 2de3292

Please sign in to comment.