当前位置: 首页>>代码示例>>Python>>正文


Python Raw.close方法代码示例

本文整理汇总了Python中mne.io.Raw.close方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.close方法的具体用法?Python Raw.close怎么用?Python Raw.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mne.io.Raw的用法示例。


在下文中一共展示了Raw.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ica_additional

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import close [as 别名]
def test_ica_additional():
    """Test additional ICA functionality"""
    tempdir = _TempDir()
    stop2 = 500
    raw = Raw(raw_fname).crop(1.5, stop, False)
    raw.load_data()
    picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
                       eog=False, exclude='bads')
    test_cov = read_cov(test_cov_name)
    events = read_events(event_name)
    picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
                       eog=False, exclude='bads')
    epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
                    baseline=(None, 0), preload=True)
    # test if n_components=None works
    with warnings.catch_warnings(record=True):
        ica = ICA(n_components=None,
                  max_pca_components=None,
                  n_pca_components=None, random_state=0)
        ica.fit(epochs, picks=picks, decim=3)
    # for testing eog functionality
    picks2 = pick_types(raw.info, meg=True, stim=False, ecg=False,
                        eog=True, exclude='bads')
    epochs_eog = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks2,
                        baseline=(None, 0), preload=True)

    test_cov2 = test_cov.copy()
    ica = ICA(noise_cov=test_cov2, n_components=3, max_pca_components=4,
              n_pca_components=4)
    assert_true(ica.info is None)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks[:5])
    assert_true(isinstance(ica.info, Info))
    assert_true(ica.n_components_ < 5)

    ica = ICA(n_components=3, max_pca_components=4,
              n_pca_components=4)
    assert_raises(RuntimeError, ica.save, '')
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=[1, 2, 3, 4, 5], start=start, stop=stop2)

    # test corrmap
    ica2 = ica.copy()
    corrmap([ica, ica2], (0, 0), threshold='auto', label='blinks', plot=True,
            ch_type="mag")
    corrmap([ica, ica2], (0, 0), threshold=2, plot=False, show=False)
    assert_true(ica.labels_["blinks"] == ica2.labels_["blinks"])
    assert_true(0 in ica.labels_["blinks"])
    plt.close('all')

    # test warnings on bad filenames
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        ica_badname = op.join(op.dirname(tempdir), 'test-bad-name.fif.gz')
        ica.save(ica_badname)
        read_ica(ica_badname)
    assert_naming(w, 'test_ica.py', 2)

    # test decim
    ica = ICA(n_components=3, max_pca_components=4,
              n_pca_components=4)
    raw_ = raw.copy()
    for _ in range(3):
        raw_.append(raw_)
    n_samples = raw_._data.shape[1]
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=None, decim=3)
    assert_true(raw_._data.shape[1], n_samples)

    # test expl var
    ica = ICA(n_components=1.0, max_pca_components=4,
              n_pca_components=4)
    with warnings.catch_warnings(record=True):
        ica.fit(raw, picks=None, decim=3)
    assert_true(ica.n_components_ == 4)

    # epochs extraction from raw fit
    assert_raises(RuntimeError, ica.get_sources, epochs)
    # test reading and writing
    test_ica_fname = op.join(op.dirname(tempdir), 'test-ica.fif')
    for cov in (None, test_cov):
        ica = ICA(noise_cov=cov, n_components=2, max_pca_components=4,
                  n_pca_components=4)
        with warnings.catch_warnings(record=True):  # ICA does not converge
            ica.fit(raw, picks=picks, start=start, stop=stop2)
        sources = ica.get_sources(epochs).get_data()
        assert_true(ica.mixing_matrix_.shape == (2, 2))
        assert_true(ica.unmixing_matrix_.shape == (2, 2))
        assert_true(ica.pca_components_.shape == (4, len(picks)))
        assert_true(sources.shape[1] == ica.n_components_)

        for exclude in [[], [0]]:
            ica.exclude = [0]
            ica.labels_ = {'foo': [0]}
            ica.save(test_ica_fname)
            ica_read = read_ica(test_ica_fname)
            assert_true(ica.exclude == ica_read.exclude)
            assert_equal(ica.labels_, ica_read.labels_)
            ica.exclude = []
            ica.apply(raw, exclude=[1])
#.........这里部分代码省略.........
开发者ID:mdclarke,项目名称:mne-python,代码行数:103,代码来源:test_ica.py

示例2: build_maxfilter_cmd

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import close [as 别名]
    def build_maxfilter_cmd(self, in_fname, out_fname, origin='0 0 40',
                            frame='head', bad=None, autobad='off', skip=None,
                            force=False, st=False, st_buflen=16.0,
                            st_corr=0.96, trans=None, movecomp=False,
                            headpos=False, hp=None, hpistep=None,
                            hpisubt=None, hpicons=True, linefreq=None,
                            cal=None, ctc=None, mx_args='',
                            maxfilter_bin='/neuro/bin/util/maxfilter',
                            logfile=None):

        """Build a NeuroMag MaxFilter command for later execution.

        See the Maxfilter manual for details on the different options!

        Things to implement
        * check that cal-file matches date in infile!
        * check that maxfilter binary is OK

        Parameters
        ----------
        in_fname : str
            Input file name
        out_fname : str
            Output file name
        maxfilter_bin : str
            Full path to the maxfilter-executable
        logfile : str
            Full path to the output logfile
        force : bool
            Overwrite existing output (default: False)
        origin : array-like or str
            Head origin in mm. If None it will be estimated from headshape
            points.
        frame : str ('device' or 'head')
            Coordinate frame for head center
        bad : str, list (or None)
            List of static bad channels. Can be a list with channel names, or a
            string with channels (with or without the preceding 'MEG')
        autobad : string ('on', 'off', 'n')
            Sets automated bad channel detection on or off
        skip : string or a list of float-tuples (or None)
            Skips raw data sequences, time intervals pairs in sec,
            e.g.: 0 30 120 150
        force : bool
            Ignore program warnings
        st : bool
            Apply the time-domain SSS extension (tSSS)
        st_buflen : float
            tSSS buffer length in sec (disabled if st is False)
        st_corr : float
            tSSS subspace correlation limit (disabled if st is False)
        movecomp : bool (or 'inter')
            Estimates and compensates head movements in continuous raw data.
        trans : str(filename or 'default') (or None)
            Transforms the data into the coil definitions of in_fname,
            or into the default frame. If None, and movecomp is True,
            data will be movement compensated to initial head position.
        headpos : bool
            Estimates and stores head position parameters, but does not
            compensate movements
        hp : string (or None)
            Stores head position data in an ascii file
        hpistep : float (or None)
            Sets head position update interval in ms
        hpisubt : str('amp', 'base', 'off') (or None)
            Subtracts hpi signals: sine amplitudes, amp + baseline, or switch
            off
        hpicons : bool
            Check initial consistency isotrak vs hpifit
        linefreq : int (50, 60) (or None)
            Sets the basic line interference frequency (50 or 60 Hz)
            (None: do not use line filter)
        cal : str
            Path to calibration file
        ctc : str
            Path to Cross-talk compensation file
        mx_args : str
            Additional command line arguments to pass to MaxFilter
        """
        # determine the head origin if necessary
        if origin is None:
            self.logger.info('Estimating head origin from headshape points..')
            raw = Raw(in_fname, preload=False)
            with warnings.filterwarnings('error', category=RuntimeWarning):
                r, o_head, o_dev = fit_sphere_to_headshape(raw.info,
                                                           dig_kind='auto',
                                                           units='m')
            raw.close()

            self.logger.info('Fitted sphere: r = {.1f} mm'.format(r))
            self.logger.info('Origin head coordinates: {.1f} {.1f} {.1f} mm'.
                             format(o_head[0], o_head[1], o_head[2]))
            self.logger.info('Origin device coordinates: {.1f} {.1f} {.1f} mm'.
                             format(o_dev[0], o_dev[1], o_dev[2]))

            self.logger.info('[done]')
            if frame == 'head':
                origin = o_head
            elif frame == 'device':
                origin = o_dev
#.........这里部分代码省略.........
开发者ID:sarathykousik,项目名称:stormdb-python,代码行数:103,代码来源:process.py

示例3: build_maxfilter_cmd

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import close [as 别名]

#.........这里部分代码省略.........
    verbose : bool, str, int, or None
        If not None, override default verbose level (see mne.verbose).


    Returns
    -------
    origin: string
        Head origin in selected coordinate frame
    """

    if verbose:
        log_level=logging.INFO
    else:
        log_level=logging.ERROR
    logger.setLevel(log_level)

    # check for possible maxfilter bugs
    if mv_trans is not None and movecomp:
        _mxwarn("Don't use '-trans' with head-movement compensation "
                "'-movecomp'")

#    if autobad != 'off' and (mv_headpos or mv_comp):
#        _mxwarn("Don't use '-autobad' with head-position estimation "
#                "'-headpos' or movement compensation '-movecomp'")

#    if st and autobad != 'off':
#        _mxwarn("Don't use '-autobad' with '-st' option")

    # determine the head origin if necessary
    if origin is None:
        logger.info('Estimating head origin from headshape points..')
        raw = Raw(in_fname)
        r, o_head, o_dev = fit_sphere_to_headshape(raw.info, ylim=0.070) # Note: this is not standard MNE...
        raw.close()
        logger.info('[done]')
        if frame == 'head':
            origin = o_head
        elif frame == 'device':
            origin = o_dev
        else:
            RuntimeError('invalid frame for origin')

    # format command
    if origin is False:
        cmd = (maxfilter_bin + ' -f %s -o %s -v '
                % (in_fname, out_fname))
    else:
        if not isinstance(origin, basestring):
            origin = '%0.1f %0.1f %0.1f' % (origin[0], origin[1], origin[2])

        cmd = (maxfilter_bin + ' -f %s -o %s -frame %s -origin %s -v '
                % (in_fname, out_fname, frame, origin))

    if bad is not None:
        # format the channels
        if not isinstance(bad, list):
            bad = bad.split()
        bad = map(str, bad)
        bad_logic = [ch[3:] if ch.startswith('MEG') else ch for ch in bad]
        bad_str = ' '.join(bad_logic)

        cmd += '-bad %s ' % bad_str

    cmd += '-autobad %s ' % autobad

    if skip is not None:
开发者ID:christellegans,项目名称:pipelines,代码行数:70,代码来源:maxfilter_cfin.py

示例4: len

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import close [as 别名]
                mfp["input_file"] = raw_fname

                if len(session_input_files) > 1:
                    output_name_base = output_folder + "/" + session + "-" + fnum_raw
                else:
                    output_name_base = output_folder + "/" + session

                if not "empt" in session.lower():  #### TYPO IN ONE SESSION NAME: emptRy!!
                    # change this to test existence of initial HPI measurement...
                    mfp["output_file"] = output_name_base + mf_fname_suffix + ".fif"
                    mfp["mv_hp"] = output_name_base + mf_fname_suffix + ".pos"
                    mfp["logfile"] = output_name_base + mf_fname_suffix + ".log"
                    if radius_head is None:  # only needed once per study (same HPI digs)
                        raw = Raw(raw_fname)
                        radius_head, origin_head, origin_devive = fit_sphere_to_headshape(raw.info, verbose=VERBOSE)
                        raw.close()
                    mfp["origin_head"] = origin_head
                    mfp["radius_head"] = radius_head

                else:
                    mfp["output_file"] = output_name_base + mf_fname_suffix + ".fif"
                    mfp["mv_hp"] = None
                    mfp["logfile"] = output_name_base + mf_fname_suffix + ".log"
                    mfp["movecomp"] = False
                    mfp["hpicons"] = False
                    mfp["origin_head"] = False  # Must be False, if None, will try to estimate it!
                    mfp["radius_head"] = False

                # Since both session_input and session_output_files are lists, they
                # will now remain ordered 1-to-1
                session_output_files.append(mfp["output_file"])
开发者ID:christellegans,项目名称:pipelines,代码行数:33,代码来源:maxfilter_demo.py


注:本文中的mne.io.Raw.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。