Code Monkey home page Code Monkey logo

cpp_ptb's Introduction

Documentation Status: stable DOI tests and coverage codecov All Contributors

CPP_PTB

This is the Crossmodal Perception and Plasticity lab (CPP) PsychToolBox (PTB) toolbox.

Those functions are mostly wrappers around some PTB functions to facilitate their use and their reuse (#DontRepeatYourself)

Documentation

All the documentation and installation information is accessible here.

Content

├── demos # quick demo of how to use some functions
├── docs # documentation
├── manualTests # all the tests that cannot be automated (yet)
├── src # actual code of the CPP_PTB
│   ├── aperture # function related to create apertur (circle, wedge, bar...)
│   ├── dot # functions to simplify the creations of RDK
│   ├── errors # all error functions
│   ├── fixation # to create fixation cross, dots
│   ├── keyboard # to collect responses, abort experiment...
│   ├── randomization # functions to help with trial randomization
│   └── utils # set of general functions
└── tests # all the tests that that can be run by github actions

Contributing

Feel free to open issues to report a bug and ask for improvements.

If you want to contribute, have a look at our contributing guidelines that are meant to guide you and help you get started. If something is not clear or you get stuck: it is more likely we did not do good enough a job at explaining things. So do not hesitate to open an issue, just to ask for clarification.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Remi Gau

💻 🎨 📖 🐛 📓 🤔 🚇 🚧 ⚠️ 💬

marcobarilari

💻 🎨 📖 🐛 📓 🤔

CerenB

💻 🎨 📖 👀 ⚠️ 🐛 📓 🤔

Fede F.

🤔 💻 🖋

iqrashahzad14

🐛 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

cpp_ptb's People

Contributors

allcontributors[bot] avatar cerenb avatar dependabot[bot] avatar iqrashahzad14 avatar marcobarilari avatar pre-commit-ci[bot] avatar remi-gau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp_ptb's Issues

miss_hit supports checking metrics too

Hi,

I am extremely delighted to see people use MISS_HIT :)

You might like to know that mh_metric can produce metrics (including McCabe cyclomatic complexity) and optionally enforce limits. This work also for MATLAB code embedded in Simulink models; and I plan to add support for Simulink models themselves. Special comments can be added to the code to justify exceeding limits, which also appear in the final report.

Let me know (by raising issues) if you want more features (e.g. different metrics or a different way to report e.g. json, ...)

Sandbox stand-alone function to develop ptb stimulation code

Hey geeks,

as you know I am working on the stimulation part of our experiment developing a grating motion. This is really preliminary stage and a lot of trial and error.

Developing it inside the experiment (with multiple levels of complexity e.g. CPP_PTB functions, design etc) it is just frustrating and time-consuming (starting the experiment requires a bit).

A solution I found helpful is to have a stand-alone function with a fixed part (e.g. to init PTB) and a playground part to develop your stimulation. The purpose is very simple: just develop your stimulation in a sandbox script, when ready add the needed vars on your setParameters.m function and the code for the stimulation in a separate function.

To have a look, see the annexed PR #23 . It comes with a cooked example from Peter Scarfe.. Do you think it could be of interest to this repo?

Of course, it is not commented either pretty or in line with our code style plus at the moment it is built to serve my purpose (not ready to developed auditory stimulation). Might need to hear from you if it is worth adding it here and spend time on it.

Open to any idea and to be dropped cause it might be not of general interest.

create function to initialize RNG seed - must work both for matlab (including "old" versions) AND octave

I had this function somewhere else but I think this is not ideal

function [] = setUpRand()
    % Set up the randomizers for uniform and normal distributions.
    % It is of great importance to do this before anything else!
    rand('state', sum(100, clock));
    randn('state', sum(100, clock));
end

@marcobarilari I think this is much more your area of expertise than mine. Can I assign you to this?

Having one function we can reuse across all projects would be super useful.

And also we actually need it for our localizers I think.

Improve `Add as a submodule` section

from #92

Example for submodule usage

So say you want to clone a repo that has some nested submodules, then you would type this to get the content of all the submodules at once (here with my experiment repo):

git clone --recurse-submodules https://github.com/user_name/yourExperiment.git

This would be the way to do it "by hand"

# clone the repo
git clone https://github.com/user_name/yourExperiment.git

# go into the directory
cd yourExperiment

# initialize and get the content of the first level of submodules  (CPP_PTB and CPP_BIDS)
git submodule init
git submodule update

# get the nested submodules JSONio and BIDS-matlab for CPP_BIDS
git submodule foreach --recursive 'git submodule init'
git submodule foreach --recursive 'git submodule update'

@marcobarilari
marcobarilari 8 days ago Member
in 3.2.1 you are describing how to clone a repo with the submodules and not how to use the submodules (and why?) in the repo of a new experiment (e.g. experiment/lib/submodule1 and add the folder to the path in the exp script)

As it is here might be a bit confusing. This example might be more helpful in the repo of an experiment with submodules (e.g. the localizers) to explain how to clone them

eyeTracker error from lab desktop computer

I copy/paste the error we encountered in LLN using the lab desktop computer and EyeLink

Eyelink already initialized!
Running experiment on a 'EYELINK CL 4.56 ' tracker.
Error in function Open: Usage error
Could not find *any* audio hardware on your system - or at least not with the provided deviceid, if any!
Error in function FillRect: Invalid Window (or Texture) Index provided:
It doesn't correspond to an open window or texture.
Did you close it accidentally via Screen('Close') or Screen('CloseAll') ?
EYELINK: WARNING! PsychEyelinkCallRuntime() Failed to call eyelink runtime
callback function PsychEyelinkDispatchCallback [rc = 1]!
EYELINK: WARNING! Make sure that function is on your Matlab/Octave path and properly initialized.
EYELINK: WARNING! May also be an error during execution of that function.
Type ple at command prompt for error messages.
EYELINK: WARNING! Auto-Disabling all callbacks to the runtime environment for safety reasons.
Eyelink: In PsychEyelink_get_input_key(): Error condition detected: Trying to send TERMINATE_KEY abort keycode!
Eyelink: In PsychEyelink_get_input_key(): Error condition detected: Trying to send TERMINATE_KEY abort keycode!
Error in function FillRect: Invalid Window (or Texture) Index provided:
It doesn't correspond to an open window or texture.
Did you close it accidentally via Screen('Close') or Screen('CloseAll') ?
Error using Screen
Usage:

Screen('FillRect', windowPtr [,color] [,rect] )

Error in eyeTracker (line 150)
Screen('FillRect', cfg.screen.win, [0 0 0]);

Error in visualLocTanslational (line 52)
[el] = eyeTracker('Calibration', cfg);

EyeTracker: use information from cfg to set up and save cfg.eyetracker on shutdown

from Remi #74

% Set calibration type.
Eyelink('command', 'calibration_type = HV5');

I think that we want to be able to define the calibration type from setParameters.

HV5: horizontal ; vertical ; 5 points
H3 for horizontal calibration at 3 positions
HV9 for horizontal and vertical calibration at 9 positions.
We need to see what calibration type eyelink offers by default.

https://docs.google.com/document/d/1eggzTCzSHG3AEKhtnEDbcdk-2avXN6I94X8aUPEBVsw/edit?disco=AAAAB8R3onE

there are things to add in the eytracking function (see cpp-lln-lab/CPP_BIDS#106)

  • to set parameters initialized by CPP_BIDS
  • to update the cfg after the setup and calibration of the eyetracker
  • to save a json when shutting down so all the details of cfg.eyetracker can be saved.

TODOs flags have been added in the relevant files

improve initPTB

  • refactor the window opening section (pass the window size as argument)

Easier alternative to `mpm` to manage this repo inside other projects

A not exhaustive list of alternatives (literally everything is coming up to my mind), please provide any comment and solutions. I would be also happy to suggest all of them in the read-me with user-case examples.

  • MatlabPackageManager
    pros: 'easy' to get and then forget about it,
    cons: does it work in octave? Would be better to download a specific version/commit, it can only be used with one specific version of the package (right?)

  • Submodules
    pros: in principle, downloading the experiment you have the whole package plus the benefit to stay updated and use version control of this dependency. Can probably handle a use case in which one uses different version on different projects (e.g. older and newer projects).
    cons: for pro users and not super clear how to use it at the moment.

  • Download a specific version and c/p it in a subfun folder
    pros: the easiest solution to share the code and 'installing' it on the stimulation computer (usually not the one used to develop the code).
    cons: extreme solution useful only at the very latest stage (i.e. one minute before acquiring your data); prone to be customized/modified (is it what we want?)

add a licence

PTB seems to use the MIT licence so I suggest we use the same

EyeTracker: `command` help section

from Remi #74

Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');
Eyelink('command', 'link_event_data = GAZE,GAZERES,HREF,AREA,VELOCITY');
Eyelink('command', 'link_event_filter = LEFT,RIGHT,FIXATION,BLINK,SACCADE,BUTTON');

We need to dig into the help section to see if that means we can set which eye to follow.

unit test for read and filter logfile

Actually, if you want to try writing a unit test, this function is perfect for it.

  • isntall the mox unit toolbox on your computer
  • create a tsv file with the some dummy content that the fucntion should read and filter (you can create and store it in a dummyData folder inside the tests directory.
  • write a unit test function in the tests folder (see below for a template)
function test_suite = test_readOutputFilter %#ok<*STOUT>
    try % assignment of 'localfunctions' is necessary in Matlab >= 2016
        test_functions = localfunctions(); %#ok<*NASGU>
    catch % no problem; early Matlab versions can use initTestSuite fine
    end
    initTestSuite;
end

function test_readOutputFilterBasic()

    %% set up
   cfg = ... % fill in
   filterHeader = ... % fill in
   filterContent  = ... % fill in

   outputFiltered = readOutputFilter(cfg, filterHeader, filterContent)

   %% test data
   expectedOutput = ... % create a structure that describes what output you expect

    %% test
    assertEqual(expectedOutput, outputFiltered); % make sure they match

end

Originally posted by @Remi-Gau in #75 (comment)

Screen SkipSyncTest option set

Would you consider to make your initPTB more flexible with :
Screen('Preference', 'SkipSyncTests', 1);
instead of what you have:
Screen('Preference', 'SkipSyncTests', 0);
With 0 option, most of the macbook pro users will not be able to run their experiment because PTB sync fails and it stops the execution of the whole script.

More info to test monitor flip delays and other bottlenecks that might mess up your experiment timing

From #30

@CerenB
related to these cfg.ifi and cfg.vbl : are they useful if experimenter wants to check the monitor delays? I wanted to test some hardware issues (adapters + which laptop to use). and was thinking flip interval could be a parameter to compare the hardwares.

@marcobarilari
This is a good question that tickles a long-standing curiosity. If you want we can dig, I think you can have this info from some PTB's messages and we can add a miniguide to it (e.g. the simplest would be a link in the readme referencing the specific page in the PTB website that, IMHO, is not easy to navigate). I'll open an issue on that.

EyeTracker: improve custom calibration hard coding

from Remi #74

Eyelink('command', 'calibration_samples = 6');
Eyelink('command', 'calibration_sequence = 0,1,2,3,4,5');
Eyelink('command', 'calibration_targets = %d,%d %d,%d %d,%d %d,%d %d,%d', ...
    640, 512, ... % width/2,height/2

We definitely want to get rid of that hard coding and be able to set that up from a setParameters file

unit tests

List of functions or sub functions that can already have their unit tests

  • degToPix
  • computeFOV
  • checkAbortGetResponse
  • initFixation
  • eccenLogSpeed
  • dot functions
  • compute dot density

EyeTracker: improve tags in the output

from Remi #74

Some things need to be added in the main scripts as.

Like in the visual localizers calls to:

Eyelink('Message', 'block_start');
Eyelink('Message', 'trial_start');
Eyelink('Message', 'block_end');

Having those in the output of the eyetracker will definitely help us parse the huge tsv we will get.

saveEventsFile warning

  1. Warning
    It seems to be passing this warning when there's nan. But I think I still have nans - as early Xmas decoration in my response collection array, somehow. Thus I have 13 (number of button pressed) error messages like this:
Warning: Missing some target data for this event. 
> In saveEventsFile>checkExtracolumns (line 240)
  In saveEventsFile>checklLogFile (line 166)
  In saveEventsFile (line 84)
  In fMRIMainExperiment (line 229) 
           onset: 199.7325
      trial_type: 'response'
        duration: 0
        key_name: 'space'
         pressed: 1
          fileID: []
    extraColumns: []
          target: NaN
  1. It does not separate the time of the date in the saving name:
    sub-001_ses-001_task-RhythmCategFT_run-001_events_date-202007272044.tsv previously it was:
    sub-001_ses-001_task-RhythmCategFT_run-001_events_date-20200727_2044.tsv
    Previous version was slightly easier for a human to read.

Add more doc about miss_hit in the readme

oh forgot to add/check with miss_hit.
Would it be nice to add that info (how to run in terminal, e.g. mh_style functionxx.m) into README file? Or it would be too confusing? ( I simply forgot the function name and had to go through the history in my terminal 👯 )

Originally posted by @CerenB in #48 (comment)

Remove hardcoded value for scaling of fMRI screen size

I don't think we want to hard code the 2/3 here. We might just add it to the Cfg structure because the changes to be made to the screen size might be different in different scanner.

if strcmpi(cfg.stimPosition,'scanner')
    cfg.winRect(1,4) = cfg.winRect(1,4)*2/3;
end

make alpha blending optional in initPTB

% Enable alpha-blending, set it to a blend equation useable for linear superposition with alpha-weighted source.
Screen('BlendFunction', cfg.win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

CPP_waitForTriggerDemo crashes

CPP_waitForTriggerDemo.m crashes, please see below:

>> waitForTrigger(cfg);
Will wait for triggers on the main keyboard device.
Waiting for trigger 
 Trigger 1 
Reference to non-existent field 'MRI'.

Error in waitForTrigger>pauseBetweenTriggers (line 74)
    if ~isempty(cfg.MRI.repetitionTime)

Error in waitForTrigger (line 46)
                    pauseBetweenTriggers(cfg);

getResponseDemo error

During the next 5 seconds we will collect responses on the following keys: 

ALL KEYS


Error using ListenChar (line 108)
Invalid listenFlag provided!  See "help ListenChar" for more information

Error in getResponse (line 69)
        ListenChar(-1);

Error in CPP_getResponseDemo (line 73)
getResponse('init', cfg, expParameters, 1);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.