本文整理汇总了Python中psychopy.tools.filetools.fromFile函数的典型用法代码示例。如果您正苦于以下问题:Python fromFile函数的具体用法?Python fromFile怎么用?Python fromFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: list
# get list of possible non-target letters
#nontargets = list(set(['a','b','c','d','e','f','g','h','i','j'])-set(targetLetter)) # get all the letters a-j that aren't targetLetter.
nontargets = list(set(['b','c','d','e','f','g','j','k','l','m'])-set(targetLetter)) # a, h, and i are said kind of strangely by the bot.
# randomize list of block lengths
if randomizeBlocks:
np.random.shuffle(blockLengths)
# ========================== #
# ===== SET UP LOGGING ===== #
# ========================== #
try:#try to get a previous parameters file
expInfo = fromFile('lastAudSartParams.pickle')
expInfo['session'] +=1 # automatically increment session number
except:#if not there then use a default set
expInfo = {'subject':'1', 'session':1, 'target letter':targetLetter}
dateStr = time.strftime("%b_%d_%H%M", time.localtime())#add the current time
#present a dialogue to change params
dlg = gui.DlgFromDict(expInfo, title='Numerical SART task', fixed=['date'], order=['subject','session','target letter'])
if dlg.OK:
toFile('lastAudSartParams.pickle', expInfo)#save params to file for next time
else:
core.quit()#the user hit cancel so exit
# get volume from dialogue
targetLetter = expInfo['target letter']
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:28,代码来源:AuditorySartTask.py
示例17: fromFile
from psychopy import core, gui, data
from psychopy.tools.filetools import fromFile, toFile
import numpy, random, os, serial, pygame
from math import *
from am_arduino import *
## -- get input from experimenter --
parameterFile = 'lastParams-tactvis.pickle'
try:
exptInfo = fromFile(parameterFile) # previous values
except: # default values
exptInfo = {'01. Participant Code':'P00',
'02. Stimulation site':'right hand',
'03. Session number':1,
'04. Conditioning':['incongruent','congruent','off'],
'05. Conditioning time (sec)':5,
'06. Top-up time (sec)':5,
'07. Number of trials':10,
'08. Conditioning motors (1-6)':'1,2,3,4,5,6',
'09. Conditioning lights (1-6)':'1,2,3,4,5,6',
'10. Conditioning reversed motors (1-6)':'3,4',
'11. Test motors (1-6)':'3,4',
'12. Test lights (1-6)':'',
'13. ISOI (ms)':100,
'14. Duration (ms)':100,
'15. Use GO button':True,
'16. Folder for saving data':'Conditioning-Data',
'17. Device orientation (0 or 1)':0,
'18. Arduino serial port':'/dev/cu.usbmodem1421',
'19. Print arduino messages':False}
exptInfo['20. Date and time']= data.getDateStr(format='%Y-%m-%d_%H-%M-%S') #add the current time
开发者ID:SDAMcIntyre,项目名称:Apparent-Motion-Arduino,代码行数:31,代码来源:Experiment_TactVis-conditioning.py
示例18: files
# save parameters
if saveParams:
dlgResult = gui.fileSaveDlg(prompt='Save Params...',initFilePath = os.getcwd() + '/Params', initFileName = newParamsFilename,
allowed="PICKLE files (.pickle)|.pickle|All files (.*)|")
newParamsFilename = dlgResult
if newParamsFilename is None: # keep going, but don't save
saveParams = False
else:
toFile(newParamsFilename, params) # save it!
# ========================== #
# ===== SET UP LOGGING ===== #
# ========================== #
scriptName = os.path.basename(__file__)
try: # try to get a previous parameters file
expInfo = fromFile('%s-lastExpInfo.pickle'%scriptName)
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,
'paramsFile':['DEFAULT','Load...']}
# overwrite params struct if you just saved a new parameter set
if saveParams:
expInfo['paramsFile'] = [newParamsFilename,'Load...']
#present a dialogue to change select params
dlg = gui.DlgFromDict(expInfo, title=scriptName, order=['subject','session','skipPrompts','paramsFile'])
if not dlg.OK:
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:31,代码来源:SampleExperiment_d1.py
示例19: 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 LOGGING ===== #
# ========================== #
try: # try to get a previous parameters file
expInfo = fromFile("lastSartParams.pickle")
expInfo["session"] += 1 # automatically increment session number
except: # if not there then use a default set
expInfo = {"subject": "1", "session": 1, "target digit": 3}
dateStr = time.strftime("%b_%d_%H%M", time.localtime()) # add the current time
# present a dialogue to change params
dlg = gui.DlgFromDict(
expInfo, title="Numerical SART task", fixed=["date"], order=["subject", "session", "target digit"]
)
if dlg.OK:
toFile("lastSartParams.pickle", expInfo) # save params to file for next time
else:
core.quit() # the user hit cancel so exit
# get volume from dialogue
开发者ID:djangraw,项目名称:PsychoPyParadigms,代码行数:31,代码来源:NumericalSartTask.py
示例20: fromFile
#!/usr/bin/env python2
"""measure your JND in orientation using a staircase method"""
from psychopy import core, visual, gui, data, event
from psychopy.tools.filetools import fromFile, toFile
import time, numpy
try:#try to get a previous parameters file
expInfo = fromFile('lastParams.pickle')
except:#if not there then use a default set
expInfo = {'observer':'jwp', '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='simple JND Exp', fixed=['date'])
if dlg.OK:
toFile('lastParams.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 = expInfo['observer'] + dateStr
dataFile = open(fileName+'.txt', 'w')
dataFile.write('targetSide oriIncrement correct\n')
#create window and stimuli
globalClock = core.Clock()#to keep track of time
trialClock = core.Clock()#to keep track of time
win = visual.Window([800,600],allowGUI=False, monitor='testMonitor', units='deg')
foil = visual.GratingStim(win, sf=1, size=4, mask='gauss', ori=expInfo['refOrientation'])
target = visual.GratingStim(win, sf=1, size=4, mask='gauss', ori=expInfo['refOrientation'])
开发者ID:natsn,项目名称:psychopy,代码行数:31,代码来源:JND_staircase_exp.py
注:本文中的psychopy.tools.filetools.fromFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论