本文整理汇总了Python中psychopy.data.importConditions函数的典型用法代码示例。如果您正苦于以下问题:Python importConditions函数的具体用法?Python importConditions怎么用?Python importConditions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了importConditions函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_TrialTypeImport
def test_TrialTypeImport():
fromCSV = data.importConditions(os.path.join(fixturesPath, 'trialTypes.csv'))
fromXLSX = data.importConditions(os.path.join(fixturesPath, 'trialTypes.xlsx'))
for trialN, trialCSV in enumerate(fromCSV):
trialXLSX = fromXLSX[trialN]
assert trialXLSX.keys()==trialCSV.keys()
for header in trialCSV.keys():
if trialXLSX[header] != trialCSV[header]:
print(header, trialCSV[header], trialXLSX[header])
assert trialXLSX[header] == trialCSV[header]
开发者ID:jeremygray,项目名称:psychopy,代码行数:11,代码来源:test_Xlsx.py
示例2: test_TrialTypeImport
def test_TrialTypeImport():
fromCSV = data.importConditions(os.path.join(thisDir, 'trialTypes.csv'))
fromXLSX = data.importConditions(os.path.join(thisDir, 'trialTypes.xlsx'))
for trialN, trialCSV in enumerate(fromCSV):
trialXLSX = fromXLSX[trialN]
assert trialXLSX.keys()==trialCSV.keys()
for header in trialCSV.keys():
if trialXLSX[header]==None and numpy.isnan(trialCSV[header]):
trialCSV[header]=None#this is ok
if trialXLSX[header] != trialCSV[header]:
print header, trialCSV[header], trialXLSX[header]
assert trialXLSX[header] == trialCSV[header]
开发者ID:RSharman,项目名称:psychopy,代码行数:13,代码来源:test_Xlsx.py
示例3: test_loopBlocks
def test_loopBlocks(self):
"""An experiment file with made-up params and routines to see whether
future versions of experiments will get loaded.
"""
#load the test experiment (with a stims loop, trials loop and blocks loop)
expfile = path.join(self.exp.prefsPaths['tests'], 'data', 'testLoopsBlocks.psyexp')
self.exp.loadFromXML(expfile) # reload the edited file
#alter the settings so the data goes to our tmp dir
datafileBase = os.path.join(self.tmp_dir, 'testLoopsBlocks')
self.exp.settings.params['Data filename'].val = repr(datafileBase)
#write the script from the experiment
script = self.exp.writeScript(expPath=expfile)
py_file = os.path.join(self.tmp_dir, 'testLoopBlocks.py')
# save it
f = codecs.open(py_file, 'w', 'utf-8')
f.write(script.getvalue().replace("core.quit()", "pass"))
f.write("del thisExp\n") #garbage collect the experiment so files are auto-saved
f.close()
#run the file (and make sure we return to this location afterwards)
wd = os.getcwd()
execfile(py_file)
os.chdir(wd)
#load the data
dat = data.importConditions(datafileBase+".csv")
assert len(dat)==8 # because 4 'blocks' with 2 trials each (3 stims per trial)
开发者ID:Lx37,项目名称:psychopy,代码行数:25,代码来源:test_Experiment.py
示例4: findPathsInFile
def findPathsInFile(filePath):
"""Recursively search a conditions file (xlsx or csv)
extracting valid file paths in any param/cond
:param filePath: str to a potential file path (rel or abs)
:return: list of dicts{'rel','abs'} of valid file paths
"""
paths = []
# does it look at all like an excel file?
if (not isinstance(filePath, basestring)
or filePath[-4:] not in ['.csv', 'xlsx']):
return paths
thisFile = getPaths(filePath)
# does it exist?
if not thisFile:
return paths
# this file itself is valid so add to resources if not already
if thisFile not in paths:
paths.append(thisFile)
conds = data.importConditions(thisFile['abs']) # load the abs path
for thisCond in conds: # thisCond is a dict
for param, val in list(thisCond.items()):
if isinstance(val, basestring) and len(val):
subFile = getPaths(val)
else:
subFile = None
if subFile:
paths.append(subFile)
# if it's a possible conditions file then recursive
if thisFile['abs'][-4:] in ["xlsx", ".csv"]:
contained = findPathsInFile(subFile['abs'])
paths.extend(contained)
return paths
开发者ID:flipphillips,项目名称:psychopy,代码行数:33,代码来源:_experiment.py
示例5: test_TrialHandlerAndXLSX
def test_TrialHandlerAndXLSX(self):
"""Currently tests the contents of xslx file against known good example
"""
conds = data.importConditions(os.path.join(fixturesPath,
'trialTypes.xlsx'))
trials = data.TrialHandler(trialList=conds,
seed=self.random_seed,
nReps=2, autoLog=False)
responses = [1,1,None,3,2,3, 1,3,2,2,1,1]
rts = [0.1,0.1,None,0.3,0.2,0.3, 0.1,0.3,0.2,0.2,0.1,0.1]
for trialN, trial in enumerate(trials):
if responses[trialN] is None:
continue
trials.addData('resp', responses[trialN])
trials.addData('rt',rts[trialN])
trials.saveAsExcel(self.name)# '.xlsx' should be added automatically
trials.saveAsText(self.name, delim=',')# '.xlsx' added automatically
trials.saveAsWideText(os.path.join(self.temp_dir,'actualXlsx'))
# Make sure the file is there
assert os.path.isfile(self.fullName)
#compare with known good file
utils.compareXlsxFiles(self.fullName,
os.path.join(fixturesPath,'corrXlsx.xlsx'))
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:26,代码来源:test_xlsx.py
示例6: test_quest
def test_quest(self):
conditions = data.importConditions(
os.path.join(fixturesPath, 'multiStairConds.xlsx'))
stairs = data.MultiStairHandler(
stairType='quest', conditions=conditions, method='random',
nTrials=20, name='QuestStairs', autoLog=False)
exp = data.ExperimentHandler(
name='testExp', savePickle=True, saveWideText=True,
dataFileName=os.path.join(self.temp_dir, 'multiQuestExperiment'),
autoLog=False)
rng = np.random.RandomState(seed=self.random_seed)
exp.addLoop(stairs)
for intensity, condition in stairs:
# make data that will cause different stairs to finish different
# times
if rng.rand() > condition['startVal']:
corr = 1
else:
corr = 0
stairs.addData(corr)
stairs.saveAsExcel(os.path.join(self.temp_dir, 'multiQuestOut'))
# contains more info
stairs.saveAsPickle(os.path.join(self.temp_dir, 'multiQuestOut'))
exp.close()
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:27,代码来源:test_MultiStairHandler.py
示例7: testTrialHandlerAndXLSX
def testTrialHandlerAndXLSX(self):
conds = data.importConditions(os.path.join(thisDir, 'trialTypes.xlsx'))
trials = data.TrialHandler(trialList=conds, seed=100, nReps=2)
responses=[1,1,2,3,2,3, 1,3,2,2,1,1]
rts=numpy.array(responses)/10.0
for trialN, trial in enumerate(trials):
trials.addData('resp', responses[trialN])
trials.addData('rt',rts[trialN])
trials.saveAsExcel(self.name)
# Make sure the file is there
assert os.path.isfile(self.fullName)
expBook = load_workbook(os.path.join(thisDir,'corrXlsx.xlsx'))
actBook = load_workbook(self.fullName)
for wsN, expWS in enumerate(expBook.worksheets):
actWS = actBook.worksheets[wsN]
for key, expVal in expWS._cells.items():
actVal = actWS._cells[key]
try:
# convert to float if possible and compare with a reasonable
# (default) precision
expVal.value = float(expVal.value)
nose.tools.assert_almost_equals(expVal.value,
float(actVal.value))
except:
# otherwise do precise comparison
nose.tools.assert_equal(expVal.value, actVal.value)
开发者ID:jsalva,项目名称:psychopy,代码行数:28,代码来源:testXlsx.py
示例8: test_ImportCondsUnicode
def test_ImportCondsUnicode():
if not data.haveXlrd:
# open pyxl thinks the right-to-left file has blanks in header
pytest.skip("We know this fails with openpyxl")
fromXLSX = data.importConditions(os.path.join(fixturesPath,
'right_to_left_unidcode.xlsx'))
assert u'\u05d2\u05d9\u05dc' in fromXLSX[0]['question']
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:8,代码来源:test_xlsx.py
示例9: openTrialHandler
def openTrialHandler(xlsx_source):
exp_conditions = importConditions(xlsx_source)
trials = TrialHandler(exp_conditions, 1)
# Inform the ioDataStore that the experiment is using a
# TrialHandler. The ioDataStore will create a table
# which can be used to record the actual trial variable values (DV or IV)
# in the order run / collected.
#
io.createTrialHandlerRecordTable(trials)
return trials
开发者ID:dgfitch,项目名称:psychopy,代码行数:11,代码来源:iohub_demo.py
示例10: exposurePhase
def exposurePhase(self, condFile = None, reps = 1):
# test has rating, exposure has break
self.generateDisplay()
self.conditionsFile = data.importConditions('conditions/'+condFile)
self.trials = data.TrialHandler(self.conditionsFile, method = 'sequential', nReps = reps, extraInfo = EXP_INFO)
for trial in self.trials :
thisSequence = [trial.A]
for item in thisSequence:
self.playSound(whichSound='sounds/'+str(item)+'.wav', ISI = 0.50)
# core.wait(0) # uncomment to add silence between trials (in addition to ISI after each sound) replace 0 with amount of time
if event.getKeys(['escape']): core.quit()
self.trials.saveAsWideText(thisPhase+'datafile.csv', delim=",")
开发者ID:kschuler,项目名称:guide,代码行数:12,代码来源:experiment.py
示例11: findPathsInFile
def findPathsInFile(filePath):
"""Recursively search a conditions file (xlsx or csv)
extracting valid file paths in any param/cond
:param filePath: str to a potential file path (rel or abs)
:return: list of dicts{'rel','abs'} of valid file paths
"""
# Clean up filePath that cannot be eval'd
if '$' in filePath:
try:
filePath = filePath.strip('$')
filePath = eval(filePath)
except NameError:
# List files in director and get condition files
if 'xlsx' in filePath or 'xls' in filePath or 'csv' in filePath:
# Get all xlsx and csv files
expPath = self.expPath
if 'html' in self.expPath: # Get resources from parent directory i.e, original exp path
expPath = self.expPath.split('html')[0]
fileList = (
[getPaths(condFile) for condFile in os.listdir(expPath)
if len(condFile.split('.')) > 1
and condFile.split('.')[1] in ['xlsx', 'xls', 'csv']])
return fileList
paths = []
# does it look at all like an excel file?
if (not isinstance(filePath, basestring)
or not os.path.splitext(filePath)[1] in ['.csv', '.xlsx',
'.xls']):
return paths
thisFile = getPaths(filePath)
# does it exist?
if not thisFile:
return paths
# this file itself is valid so add to resources if not already
if thisFile not in paths:
paths.append(thisFile)
conds = data.importConditions(thisFile['abs']) # load the abs path
for thisCond in conds: # thisCond is a dict
for param, val in list(thisCond.items()):
if isinstance(val, basestring) and len(val):
subFile = getPaths(val)
else:
subFile = None
if subFile:
paths.append(subFile)
# if it's a possible conditions file then recursive
if thisFile['abs'][-4:] in ["xlsx", ".xls", ".csv"]:
contained = findPathsInFile(subFile['abs'])
paths.extend(contained)
return paths
开发者ID:hoechenberger,项目名称:psychopy,代码行数:52,代码来源:_experiment.py
示例12: test_quest
def test_quest(self):
conditions = data.importConditions(
pjoin(TESTSDATA_PATH, 'multiStairConds.xlsx'))
stairs = data.MultiStairHandler(stairType='quest', conditions=conditions,
method='random', nTrials=5)
for intensity,condition in stairs:
#make data that will cause different stairs to finish different times
if random()>condition['startVal']:
corr=1
else:corr=0
stairs.addData(corr)
stairs.saveAsExcel(pjoin(self.temp_dir, 'multiQuestOut'))
stairs.saveAsPickle(pjoin(self.temp_dir, 'multiQuestOut'))#contains more info
开发者ID:RSharman,项目名称:psychopy,代码行数:13,代码来源:test_TrialHandler.py
示例13: test_TrialTypeImport
def test_TrialTypeImport():
def checkEachtrial(fromCSV, fromXLSX):
for trialN, trialCSV in enumerate(fromCSV):
trialXLSX = fromXLSX[trialN]
assert list(trialXLSX.keys()) == list(trialCSV.keys())
for header in trialCSV:
if trialXLSX[header] != trialCSV[header]:
print(header, trialCSV[header], trialXLSX[header])
assert trialXLSX[header] == trialCSV[header]
fromCSV = data.importConditions(os.path.join(fixturesPath,
'trialTypes.csv'))
# use pandas/xlrd once
fromXLSX = data.importConditions(os.path.join(fixturesPath,
'trialTypes.xlsx'))
checkEachtrial(fromCSV, fromXLSX)
# then pretend it doesn't exist to force use of openpyxl
haveXlrd = data.haveXlrd
data.haveXlrd = False
fromXLSX = data.importConditions(os.path.join(fixturesPath,
'trialTypes.xlsx'))
checkEachtrial(fromCSV, fromXLSX)
data.haveXlrd = haveXlrd # return to what it was
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:23,代码来源:test_xlsx.py
示例14: __init__
def __init__(self,win,info):
self.boards = [] #Empty board array
self.reverseImage = 'images/card-back.png'
self.win = win
self.boardData = data.importConditions('expdata.xlsx') #Read in data file
self.trials = data.TrialHandler(trialList=self.boardData, nReps=1, method="sequential")
#Now create the experimentHandler
self.thisExp = data.ExperimentHandler(
name= "Card pair game",
version =1,
extraInfo = info, #the info we created earlier
dataFileName = "data/" + info['participant'] + "_" + info['session'] + "_part2_"+ info['dateStr']
)
开发者ID:uokpsytech,项目名称:psychopy_training,代码行数:14,代码来源:exp_core.py
示例15: removeComponent
def removeComponent(self, component, compID):
"""Remove either a Routine or a Loop from the Flow
"""
flow = self.frame.exp.flow
if component.getType() == 'Routine':
# check whether this will cause a collapsed loop
# prev and next elements on flow are a loop init/end
prevIsLoop = nextIsLoop = False
if compID > 0: # there is at least one preceding
prevIsLoop = (flow[compID - 1]).getType() == 'LoopInitiator'
if len(flow) > (compID + 1): # there is at least one more compon
nextIsLoop = (flow[compID + 1]).getType() == 'LoopTerminator'
if prevIsLoop and nextIsLoop:
# because flow[compID+1] is a terminator
loop = flow[compID + 1].loop
msg = _translate('The "%s" Loop is about to be deleted as '
'well (by collapsing). OK to proceed?')
title = _translate('Impending Loop collapse')
warnDlg = dialogs.MessageDialog(
parent=self.frame, message=msg % loop.params['name'],
type='Warning', title=title)
resp = warnDlg.ShowModal()
if resp in [wx.ID_CANCEL, wx.ID_NO]:
return # abort
elif resp == wx.ID_YES:
# make recursive calls to this same method until success
# remove the loop first
self.removeComponent(loop, compID)
# because the loop has been removed ID is now one less
self.removeComponent(component, compID - 1)
return # have done the removal in final successful call
# remove name from namespace only if it's a loop;
# loops exist only in the flow
elif 'conditionsFile' in component.params:
conditionsFile = component.params['conditionsFile'].val
if conditionsFile and conditionsFile not in ['None', '']:
try:
trialList, fieldNames = data.importConditions(
conditionsFile, returnFieldNames=True)
for fname in fieldNames:
self.frame.exp.namespace.remove(fname)
except Exception:
msg = ("Conditions file %s couldn't be found so names not"
" removed from namespace")
logging.debug(msg % conditionsFile)
self.frame.exp.namespace.remove(component.params['name'].val)
# perform the actual removal
flow.removeComponent(component, id=compID)
self.draw()
开发者ID:dgfitch,项目名称:psychopy,代码行数:49,代码来源:flow.py
示例16: testPhase
def testPhase(self, condFile = None, reps = 1):
# test has rating, exposure has break
self.generateDisplay()
self.conditionsFile = data.importConditions('conditions/'+condFile)
self.trials = data.TrialHandler(self.conditionsFile, method = 'sequential', nReps = reps, extraInfo = EXP_INFO)
for trial in self.trials :
# fix filter NA for future
thisSequence = [trial.A]
for item in thisSequence:
self.playSound(whichSound='sounds/'+str(item)+'.wav', ISI = 0.50)
if thisPhase == 'test':
rating = self.collectRating()
self.trials.addData('rating', rating)
if event.getKeys(['escape']): core.quit()
self.trials.saveAsWideText(thisPhase+'datafile.csv', delim=",")
开发者ID:kschuler,项目名称:guide,代码行数:15,代码来源:experiment.py
示例17: test_simple
def test_simple(self):
conditions = data.importConditions(
pjoin(fixturesPath, 'multiStairConds.xlsx'))
stairs = data.MultiStairHandler(stairType='simple', conditions=conditions,
method='random', nTrials=20, name='simpleStairs', autoLog=False)
exp = data.ExperimentHandler(name='testExp',
savePickle=True,
saveWideText=True,
dataFileName=pjoin(self.temp_dir, 'multiStairExperiment'), autoLog=False)
exp.addLoop(stairs)
for intensity,condition in stairs:
#make data that will cause different stairs to finish different times
if random()>condition['startVal']:
corr=1
else:corr=0
stairs.addData(corr)
stairs.saveAsExcel(pjoin(self.temp_dir, 'multiStairOut'))
stairs.saveAsPickle(pjoin(self.temp_dir, 'multiStairOut'))#contains more info
开发者ID:9173860,项目名称:psychopy,代码行数:18,代码来源:test_TrialHandler.py
示例18: exec
if thisCycleLoop != None:
for paramName in thisCycleLoop.keys():
exec(paramName + '= thisCycleLoop.' + paramName)
for thisCycleLoop in CycleLoop:
currentLoop = CycleLoop
# print "LOOP COUNT (Cycle No): ", currentLoop
# abbreviate parameter names if possible (e.g. rgb = thisCycleLoop.rgb)
if thisCycleLoop != None:
for paramName in thisCycleLoop.keys():
exec(paramName + '= thisCycleLoop.' + paramName)
# LOOP for IRREGULAR TARGETS
irregularTargets = data.TrialHandler(nReps=4, method=u'random',
extraInfo=expInfo, originPath=None,
trialList=data.importConditions('Oddballs_irregular_WavFilesCalib.csv'),
seed=None, name='irregularTargets')
# NOTE now how there are only 4 repetitions (nReps) of the irregularTargets,
# whereas you might assume 8 to be the correct number, but now as we define
# the deviant-deviant interval differently so that the deviant can be preceded by
# 2-6 or 8-12 standard tones and during 8 consecutive tones there might be two deviants
# for example the each block now consists of 16 tones in contrast to 8 tones per block
# of the regular condition (see below), see the Fig. 1 of Jongsma et al. (2013) for graphical
# representation
thisExp.addLoop(irregularTargets) # add the loop to the experiment
thisIrregularTarget = irregularTargets.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisIrregularTarget.rgb)
if thisIrregularTarget != None:
for paramName in thisIrregularTarget.keys():
exec(paramName + '= thisIrregularTarget.' + paramName)
开发者ID:LightingResearchCenter,项目名称:learningOddball,代码行数:31,代码来源:Oddball_Calib.py
示例19: hasattr
for thisComponent in instrComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if key_resp_3.keys in ['', [], None]: # No response was made
key_resp_3.keys=None
# store data for thisExp (ExperimentHandler)
thisExp.addData('key_resp_3.keys',key_resp_3.keys)
if key_resp_3.keys != None: # we had a response
thisExp.addData('key_resp_3.rt', key_resp_3.rt)
thisExp.nextEntry()
# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=1, method='random',
extraInfo=expInfo, originPath=u'/Users/aaron/Documents/GitHub/NCIL-SOC-2015/PsychoPy/stroop.psyexp',
trialList=data.importConditions(u'psychopy_playing_conditions.xlsx'),
seed=666, name='trials')
thisExp.addLoop(trials) # add the loop to the experiment
thisTrial = trials.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
for thisTrial in trials:
currentLoop = trials
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
开发者ID:FrancescoUsai,项目名称:NCIL-SOC-2015,代码行数:30,代码来源:stroop_lastrun.py
示例20: hasattr
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=1, method='random',
extraInfo=expInfo, originPath=None,
trialList=data.importConditions('mainTrials.csv'),
seed=None, name='trials')
thisExp.addLoop(trials) # add the loop to the experiment
thisTrial = trials.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
for thisTrial in trials:
currentLoop = trials
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
开发者ID:awellis,项目名称:MovingBall,代码行数:30,代码来源:CircularMotion.py
注:本文中的psychopy.data.importConditions函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论