本文整理汇总了Python中psychopy.data.importConditions函数的典型用法代码示例。如果您正苦于以下问题:Python importConditions函数的具体用法?Python importConditions怎么用?Python importConditions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了importConditions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]
示例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]
示例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)
示例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
示例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'))
示例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()
示例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)
示例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']
示例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
示例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=",")
示例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
示例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
示例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
示例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']
)
示例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()