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


Python filetools.fromFile函数代码示例

本文整理汇总了Python中psychopy.tools.filetools.fromFile函数的典型用法代码示例。如果您正苦于以下问题:Python fromFile函数的具体用法?Python fromFile怎么用?Python fromFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_pickle

    def test_pickle(self):
        _, path = mkstemp(dir=self.tmp_dir, suffix='.psydat')

        test_data = 'Test'
        with open(path, 'wb') as f:
            pickle.dump(test_data, f)

        assert test_data == fromFile(path)
开发者ID:dgfitch,项目名称:psychopy,代码行数:8,代码来源:test_filetools.py

示例2: test_multiKeyResponses

 def test_multiKeyResponses(self):
     dat = fromFile(os.path.join(fixturesPath,'multiKeypressTrialhandler.psydat'))
     #test csv output
     dat.saveAsText(pjoin(self.temp_dir, 'testMultiKeyTrials.csv'), appendFile=False)
     utils.compareTextFiles(pjoin(self.temp_dir, 'testMultiKeyTrials.csv'), pjoin(fixturesPath,'corrMultiKeyTrials.csv'))
     #test xlsx output
     dat.saveAsExcel(pjoin(self.temp_dir, 'testMultiKeyTrials.xlsx'), appendFile=False)
     utils.compareXlsxFiles(pjoin(self.temp_dir, 'testMultiKeyTrials.xlsx'), pjoin(fixturesPath,'corrMultiKeyTrials.xlsx'))
开发者ID:GentBinaku,项目名称:psychopy,代码行数:8,代码来源:test_TrialHandler.py

示例3: test_multiKeyResponses

    def test_multiKeyResponses(self):
        pytest.skip()  # temporarily; this test passed locally but not under travis, maybe PsychoPy version of the .psyexp??

        dat = fromFile(os.path.join(fixturesPath,'multiKeypressTrialhandler.psydat'))
        #test csv output
        dat.saveAsText(pjoin(self.temp_dir, 'testMultiKeyTrials.csv'), appendFile=False)
        utils.compareTextFiles(pjoin(self.temp_dir, 'testMultiKeyTrials.csv'), pjoin(fixturesPath,'corrMultiKeyTrials.csv'))
        #test xlsx output
        dat.saveAsExcel(pjoin(self.temp_dir, 'testMultiKeyTrials.xlsx'), appendFile=False)
        utils.compareXlsxFiles(pjoin(self.temp_dir, 'testMultiKeyTrials.xlsx'), pjoin(fixturesPath,'corrMultiKeyTrials.xlsx'))
开发者ID:9173860,项目名称:psychopy,代码行数:10,代码来源:test_TrialHandler.py

示例4: test_json_dump_and_reopen_file

    def test_json_dump_and_reopen_file(self):
        t = data.TrialHandler2(self.conditions, nReps=5)
        t.addData('foo', 'bar')
        t.__next__()

        _, path = mkstemp(dir=self.temp_dir, suffix='.json')
        t.saveAsJson(fileName=path, fileCollisionMethod='overwrite')
        t.origin = ''

        t_loaded = fromFile(path)
        assert t == t_loaded
开发者ID:dgfitch,项目名称:psychopy,代码行数:11,代码来源:test_TrialHandler2.py

示例5: test_json_with_encoding

    def test_json_with_encoding(self):
        _, path_0 = mkstemp(dir=self.tmp_dir, suffix='.json')
        _, path_1 = mkstemp(dir=self.tmp_dir, suffix='.json')
        encoding_0 = 'utf-8'
        encoding_1 = 'utf-8-sig'

        test_data = 'Test'

        if PY3:
            with open(path_0, 'w', encoding=encoding_0) as f:
                json.dump(test_data, f)
            with open(path_1, 'w', encoding=encoding_1) as f:
                json.dump(test_data, f)
        else:
            with codecs.open(path_0, 'w', encoding=encoding_0) as f:
                json.dump(test_data, f)
            with codecs.open(path_1, 'w', encoding=encoding_1) as f:
                json.dump(test_data, f)

        assert test_data == fromFile(path_0, encoding=encoding_0)
        assert test_data == fromFile(path_1, encoding=encoding_1)
开发者ID:dgfitch,项目名称:psychopy,代码行数:21,代码来源:test_filetools.py

示例6: test_json_dump_and_reopen_file

    def test_json_dump_and_reopen_file(self):
        s = data.StairHandler(5)
        s.addResponse(1)
        s.addOtherData('foo', 'bar')
        s.__next__()

        _, path = mkstemp(dir=self.tmp_dir, suffix='.json')
        s.saveAsJson(fileName=path, fileCollisionMethod='overwrite')
        s.origin = ''

        s_loaded = fromFile(path)
        assert s == s_loaded
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:12,代码来源:test_StairHandlers.py

示例7: test_cPickle

    def test_cPickle(self):
        if PY3:
            pytest.skip('Skipping cPickle test on Python 3')
        else:
            import cPickle

        _, path = mkstemp(dir=self.tmp_dir, suffix='.psydat')

        test_data = 'Test'
        with open(path, 'wb') as f:
            cPickle.dump(test_data, f)

        assert test_data == fromFile(path)
开发者ID:dgfitch,项目名称:psychopy,代码行数:13,代码来源:test_filetools.py

示例8: test_json_dump_and_reopen_file

    def test_json_dump_and_reopen_file(self):
        p = data.PsiHandler(nTrials=10, intensRange=[0.1, 10],
                            alphaRange=[0.1, 10], betaRange=[0.1, 3],
                            intensPrecision=1, alphaPrecision=1,
                            betaPrecision=0.5, delta=0.01)
        p.addResponse(1)
        p.addOtherData('foo', 'bar')
        p.__next__()

        _, path = mkstemp(dir=self.tmp_dir, suffix='.json')
        p.saveAsJson(fileName=path, fileCollisionMethod='overwrite')
        p.origin = ''

        p_loaded = fromFile(path)
        assert p == p_loaded
开发者ID:bergwiesel,项目名称:psychopy,代码行数:15,代码来源:test_StairHandlers.py

示例9: csvFromPsydat

    def csvFromPsydat(self, evt=None):
        from psychopy import gui
        from psychopy.tools.filetools import fromFile

        names = gui.fileOpenDlg(allowed='*.psydat',
                    prompt=_translate("Select .psydat file(s) to extract"))
        for name in names or []:
            filePsydat = os.path.abspath(name)
            print("psydat: {0}".format(filePsydat))

            exp = fromFile(filePsydat)
            if filePsydat.endswith('.psydat'):
                fileCsv = filePsydat[:-7]
            else:
                fileCsv = filePsydat
            fileCsv += '.csv'
            exp.saveAsWideText(fileCsv)
            print('   -->: {0}'.format(os.path.abspath(fileCsv)))
开发者ID:harmadillo,项目名称:psychopy,代码行数:18,代码来源:_psychopyApp.py

示例10: print

#!/usr/bin/env python2

"""utility for creating a .csv file from a .psydat file

edit the file name, then run the script
"""

import os
from psychopy.tools.filetools import fromFile

# EDIT THE NEXT LINE to be your .psydat file, with the correct path:
name = 'fileName.psydat'

file_psydat = os.path.abspath(name)
print("psydat: {0}".format(file_psydat))

# read in the experiment session from the psydat file:
exp = fromFile(file_psydat)

# write out the data in .csv format (comma-separated tabular text):
if file_psydat.endswith('.psydat'):
    file_csv = file_psydat[:-7]
else:
    file_csv = file_psydat
file_csv += '.csv'
exp.saveAsWideText(file_csv)

print('-> csv: {0}'.format(os.path.abspath(file_csv)))
开发者ID:DennisEckmeier,项目名称:psychopy,代码行数:28,代码来源:csvFromPsydat.py

示例11: fromFile

# ====================== #
# ===== PARAMETERS ===== #
# ====================== #
# Declare parameters
ITI_min = 1
ITI_range = 1
tone_freq = 880 # in Hz
tone_prob = 0.5 # probability that tone will be heard on a given trial
tone_startvol = 0.01

# ========================== #
# ===== SET UP STIMULI ===== #
# ========================== #
try:#try to get a previous parameters file
    expInfo = fromFile('lastThresholdParams.pickle')
except:#if not there then use a default set
    expInfo = {'subject':'abc', 'refOrientation':0}
dateStr = time.strftime("%b_%d_%H%M", time.localtime())#add the current time

#present a dialogue to change params
dlg = gui.DlgFromDict(expInfo, title='perceptual threshold staircase', fixed=['date'])
if dlg.OK:
    toFile('lastThresholdParams.pickle', expInfo)#save params to file for next time
else:
    core.quit()#the user hit cancel so exit

#make a text file to save data
fileName = 'GetThreshold-' + expInfo['subject'] + '-' + dateStr
dataFile = open(fileName+'.txt', 'w')
dataFile.write('isOn	Increment	correct\n')
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:30,代码来源:GetPerceptualThreshold.py

示例12: fromFile

probe1_string = "Where was your attention focused just before this?"
probe1_options = (
    "Completely on the task",
    "Mostly on the task",
    "Not sure",
    "Mostly on inward thoughts",
    "Completely on inward thoughts",
)
probe2_string = "How aware were you of where your attention was?"
probe2_options = ("Very aware", "Somewhat aware", "Neutral", "Somewhat unaware", "Very unaware")

# ========================== #
# ===== SET UP STIMULI ===== #
# ========================== #
try:  # try to get a previous parameters file
    expInfo = fromFile("lastSequenceLearningParams.pickle")
except:  # if not there then use a default set
    expInfo = {"subject": "abc", "session": "1"}
dateStr = time.strftime("%b_%d_%H%M", time.localtime())  # add the current time

# present a dialogue to change params
dlg = gui.DlgFromDict(expInfo, title="Sequence Learning task", fixed=["date"])
if dlg.OK:
    toFile("lastSequenceLearningParams.pickle", expInfo)  # save params to file for next time
else:
    core.quit()  # the user hit cancel so exit

# make a text file to save data
fileName = "SequenceLearning-" + expInfo["subject"] + "-" + expInfo["session"] + "-" + dateStr
dataFile = open(fileName + ".txt", "w")
dataFile.write("key	RT	AbsTime\n")
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:31,代码来源:SequenceLearningTask.py

示例13: fromFile

# probe_options.append(['Completely on the task','Mostly on the task','Not sure','Mostly on inward thoughts','Completely on inward thoughts'])
# probe_strings.append('How aware were you of where your attention was?')
# probe_options.append(['Very aware','Somewhat aware','Neutral','Somewhat unaware','Very unaware'])

# enumerate constants
arrowNames = ["Left", "Right"]

# randomize list of block lengths
if randomizeBlocks:
    np.random.shuffle(blockLengths)

# ========================== #
# ===== SET UP LOGGING ===== #
# ========================== #
try:  # try to get a previous parameters file
    expInfo = fromFile("lastFlankerParams.pickle")
    expInfo["session"] += 1  # automatically increment session number
except:  # if not there then use a default set
    expInfo = {"subject": "1", "session": 1}
dateStr = time.strftime("%b_%d_%H%M", time.localtime())  # add the current time

# present a dialogue to change params
dlg = gui.DlgFromDict(expInfo, title="Flanker task", fixed=["date"], order=["subject", "session"])
if dlg.OK:
    toFile("lastFlankerParams.pickle", expInfo)  # save params to file for next time
else:
    core.quit()  # the user hit cancel so exit

# make a log file to save parameter/event  data
fileName = "Flanker-%s-%d-%s" % (
    expInfo["subject"],
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:31,代码来源:FlankerTask.py

示例14: fromFile

# -*- coding: utf-8 -*-
"""Determine screen gamma using motion-nulling method 
of Ledgeway and Smith, 1994, Vision Research, 34, 2727–2740

Instructions: on each trial press the up/down cursor keys depending on 
the apparent direction of motion of the bars."""

from psychopy import visual, core, event, gui, data
from psychopy.tools.filetools import fromFile, toFile
from psychopy import filters
import numpy as num
import time

try:
    #try to load previous info
    info = fromFile('info_gamma.pickle')
    print info
except:
    #if no file use some defaults
    info={}
    info['lumModNoise']=0.5
    info['lumModLum']=0.1
    info['contrastModNoise']=1.0
    info['observer']=''
    info['highGamma']=3.0
    info['lowGamma']=0.8
    info['nTrials']=50
dlg = gui.DlgFromDict(info)
#save to a file for future use (ie storing as defaults)
if dlg.OK: 
    toFile('info_gamma.pickle',info)
开发者ID:Dagiba,项目名称:psychopy,代码行数:31,代码来源:gammaMotionNull.py

示例15: print

    newParamsFilename = dlgResult
    print("dlgResult: %s"%dlgResult)
    if newParamsFilename is None: # keep going, but don't save
        saveParams = False
        print("Didn't save params.")
    else:
        toFile(newParamsFilename, params)# save it!
        print("Saved params to %s."%newParamsFilename)
#    toFile(newParamsFilename, params)
#    print("saved params to %s."%newParamsFilename)

# ========================== #
# ===== SET UP LOGGING ===== #
# ========================== #
try:#try to get a previous parameters file
    expInfo = fromFile(expInfoFilename)
    expInfo['session'] +=1 # automatically increment session number
    expInfo['paramsFile'] = [expInfo['paramsFile'],'Load...']
except:#if not there then use a default set
    expInfo = {'subject':'1', 'session':1, 'skipPrompts':False, 'tSound':0.0, 'paramsFile':['DEFAULT','Load...']}
# overwrite if you just saved a new parameter set
if saveParams:
    expInfo['paramsFile'] = [newParamsFilename,'Load...']
dateStr = ts.strftime("%b_%d_%H%M", ts.localtime()) # add the current time

#present a dialogue to change params
dlg = gui.DlgFromDict(expInfo, title='Distraction task', order=['subject','session','skipPrompts','paramsFile'])
if not dlg.OK:
    core.quit()#the user hit cancel so exit

# find parameter file
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:31,代码来源:DistractionTask_serial_d6.py


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