Trial handler input list

Hello,

currently, we’re using the trial handler and experiment handler like this: see code

Now we want to integrate the following: randomly sample from a uniform distribution 80 times, round the values between 0 and 1, with 0 and 1 representing signal presence or not. then traverse this list as the trials.
I can’t figure out how to do this using the trial handler. Can someone help? Thanks!

triallist = [
        {"condition": "signal"},
        {"condition": "noise"}
        ]
...
exphandler = data.ExperimentHandler(name=expName, extraInfo=expinfo, saveWideText=True, dataFileName=filename)
for b in blocks:
    exphandler.addLoop(data.TrialHandler(triallist, nReps=ntrials, method='random', originPath=-1, extraInfo=expinfo) )
...
for trials in exphandler.loops:
    # traverse through trials
    for trial in trials:
...

Do you mean you want 40 trials with noise ranging from 0 to 1 and no signal and 40 with a signal? That would be easy to set up in a spreadsheet.

“Signal presence was randomly selected on each trial, under the constraint that it would occur on 50% of the trials within each block of 80 trials.”

This is what we’re trying to do. There is either noise + signal, or just noise (the noise is always the same).

So how about creating 80 rows in a spreadsheet with noise increasing from 0 to 1 in .025 increments (twice) and reading the spreadsheet into the trial handler in random order?

Yes, but is it possible to do this without a spreadsheet? I.e. inputting a python list to the trial handler?

You could easily set up the list using a for loop and appending a target present and a target absent row on each iteration.

exactly, the list could be set up with the below code for example. But then how do I give it to the trial handler? Could you show me some example code?

trials = np.round( np.rand.uniform(0, 1, 80) )

How about the following?

conditions=[]
for Idx in range (40):
    conditions.append({"noise": Idx*.025, "signal": 0})
    conditions.append({"noise": Idx*.025, "signal": 1})
trials = data.TrialHandler(trialList=conditions, 
    method='random', nReps=1)
exphandler.addLoop(trials)

Now I got it, thanks a lot!