コード例 #1
0
ファイル: usage.py プロジェクト: BackupTheBerlios/pybci
# Just to show that this is possible (it may save time if you set <saving_mode> to False and write the data after
# collecting it) we call the saving function from 'externally'.
# In the <get_data>-function it is implemented if you set <saving_mode> to True.

example_bci.save_data(example_blockfile, 'plain', example_datablock)   
example_blockfile.close()     # In this case we have to close the file manually.


# Now let's get a bit more data. Therefore...
# ...we choose a larger trigger and show a sign for 500 ms, this time by a triangle...
example_bci.trigger_sign('triangle', 0.7, 500)   

# ...and request data for the next 10 seconds, with a <security_mode>, that gives us a warning if the number
# of returned blocks is not equal to the read (that is, 'incoming') ones.
# Also, we are not sure what may happen during these 10 seconds, so we'll switch on the <supervision_mode>
# (although both modes are switched on by default, anyway) to get the data collection restarted for 10 seconds
# if the Brain Recorder is stopped while collecting the data.
# Please note that the order of the channels in the data array is the one the channels are listed
# in <channels>.

example_data = example_bci.get_data(10, security_mode = True, supervision_mode = True)


# For now we are done. To finish and be sure that the allocated memory is cleared up savely,
# we call the ending function. 
example_bci.end_bci()   




コード例 #2
0
sample_rate = 500

condition_means = N.zeros((len(conditions), numof_channels))

for num, condition in zip(range(len(conditions)), conditions):
    condition_data = N.zeros((trials, numof_channels, sample_rate * sec_per_trial))
    for trial in range(trials):  # For each trial in each condition...

        time.sleep(1)  # ...we'll wait a second...

        # ...then give a sign by means of a triangle for the beginning of the trial, that is, the data
        # collection...
        example_bci.trigger_sign("triangle", 0.5, 300)

        # ...and store the data, separated for each trial.
        condition_data[trial] = example_bci.get_data(sec_per_trial)

    print "Condition", condition, "done."

    # At last, we'll take the average of the respective condition, but keep
    # the channel structure.
    condition_data = N.mean(condition_data, axis=2)  # average over the samples
    condition_data = N.mean(condition_data, axis=0)  # average over the trials

    # The result is an array with the structure [condition][channels], with the
    # channel values averaged over all samples and trials of the respect condition.
    condition_means[num] = condition_data

# The next thing we'll do is to estimate the eye movement impact array with the
# collected data: