Skip to content

Commit c33ae7f

Browse files
authored
Merge pull request #92 from Remi-Gau/remi-doc
update DOC and add tests
2 parents a402b14 + e7e1cff commit c33ae7f

32 files changed

+773
-251
lines changed

README.md

Lines changed: 70 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![](https://img.shields.io/badge/Octave-CI-blue?logo=Octave&logoColor=white)](https://github.com/cpp-lln-lab/CPP_PTB/actions)
2-
![](https://github.com/cpp-lln-lab/CPP_PTB/workflows/CI/badge.svg)
2+
![](https://github.com/cpp-lln-lab/CPP_PTB/workflows/CI/badge.svg)
33

44
[![Build Status](https://travis-ci.com/cpp-lln-lab/CPP_PTB.svg?branch=master)](https://travis-ci.com/cpp-lln-lab/CPP_PTB)
55

@@ -11,33 +11,30 @@
1111

1212
# CPP_PTB
1313

14-
<!-- vscode-markdown-toc -->
15-
* 1. [Requirements](#Requirements)
16-
* 2. [Code guidestyle](#Codeguidestyle)
17-
* 3. [How to install](#Howtoinstall)
18-
* 3.1. [Download with git](#Downloadwithgit)
19-
* 3.2. [Add as a submodule](#Addasasubmodule)
20-
* 3.2.1. [Example for submodule usage](#Exampleforsubmoduleusage)
21-
* 3.3. [Direct download](#Directdownload)
22-
* 4. [Setting up keyboards](#Settingupkeyboards)
23-
* 5. [Structure](#Structure)
24-
* 6. [Annexes](#Annexes)
25-
* 6.1. [Experiment template [ WIP ]](#ExperimenttemplateWIP)
26-
* 6.2. [devSandbox (stand-alone)](#devSandboxstand-alone)
27-
* 7. [Contributors ✨](#Contributors)
28-
29-
<!-- vscode-markdown-toc-config
30-
numbering=true
31-
autoSave=true
32-
/vscode-markdown-toc-config -->
33-
<!-- /vscode-markdown-toc -->
14+
<!-- TOC -->
15+
16+
- [CPP_PTB](#cpp_ptb)
17+
- [Requirements](#requirements)
18+
- [Documentation](#documentation)
19+
- [Content](#content)
20+
- [How to install](#how-to-install)
21+
- [Download with git](#download-with-git)
22+
- [Add as a submodule](#add-as-a-submodule)
23+
- [Example for submodule usage](#example-for-submodule-usage)
24+
- [Direct download](#direct-download)
25+
- [Add CPP_PTB globally to the matlab path](#add-cpp_ptb-globally-to-the-matlab-path)
26+
- [Code style guide](#code-style-guide)
27+
- [Unit tests](#unit-tests)
28+
- [Contributors ✨](#contributors-)
29+
30+
<!-- /TOC -->
3431

3532

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

38-
Those functions are mostly wrappers around some PTB functions to facilitate their use and to have a codebase to facilitate their reuse.
35+
Those functions are mostly wrappers around some PTB functions to facilitate their use and their reuse (#DontRepeatYourself)
3936

40-
## 1. <a name='Requirements'></a>Requirements
37+
## Requirements
4138

4239
Make sure that the following toolboxes are installed and added to the matlab / octave path.
4340

@@ -47,58 +44,65 @@ For instructions see the following links:
4744
|----------------------------------------------------------|--------------|
4845
| [PsychToolBox](http://psychtoolbox.org/) | >=3.0.14 |
4946
| [Matlab](https://www.mathworks.com/products/matlab.html) | >=2015b |
50-
| or [octave](https://www.gnu.org/software/octave/) | 4.? |
47+
| or [Octave](https://www.gnu.org/software/octave/) | 4.? |
5148

52-
The exact version required for this to work but it is known to work with:
49+
Tested:
5350
- matlab 2015b or octave 4.2.2 and PTB 3.0.14.
5451

55-
## 2. <a name='Codeguidestyle'></a>Code guidestyle
52+
## Documentation
5653

57-
We use the `camelCase` to more easily differentiates our functions from the ones from PTB that use a `PascalCase`.
58-
We use the following regular expression for function names: `[a-z]+(([A-Z]|[0-9]){1}[a-z]+)*`.
54+
All the documentation is accessible [here](./docs/00_index.md).
5955

60-
We keep the McCabe complexity as reported by the [check_my_code function](https://github.com/Remi-Gau/check_my_code) below 15.
56+
## Content
6157

62-
We use the [MISS_HIT linter](https://florianschanda.github.io/miss_hit/style_checker.html) to automatically fix some linting issues. The code style and quality is also checked during the continuous integration.
58+
```bash
59+
├── demos # quick demo of how to use some functions
60+
├── dev # templates for experiment (will be moved out soon)
61+
├── docs # documentation
62+
├── manualTests # all the tests that cannot be automated (yet)
63+
├── src # actual code of the CPP_PTB
64+
│ ├── aperture # function related to create apertur (circle, wedge, bar...)
65+
│ ├── dot # functions to simplify the creations of RDK
66+
│ ├── errors # all error functions
67+
│ ├── fixation # to create fixation cross, dots
68+
│ ├── keyboard # to collect responses, abort experiment...
69+
│ ├── randomization # functions to help with trial randomization
70+
│ └── utils # set of general functions
71+
└── tests # all the tests that that can be run by github actions
72+
```
6373

64-
## 3. <a name='Howtoinstall'></a>How to install
74+
## How to install
6575

66-
### 3.1. <a name='Downloadwithgit'></a>Download with git
76+
### Download with git
6777

6878
``` bash
6979
cd fullpath_to_directory_where_to_install
7080
# use git to download the code
7181
git clone https://github.com/cpp-lln-lab/CPP_PTB.git
7282
# move into the folder you have just created
7383
cd CPP_PTB
74-
# add the src folder to the matlab path and save the path
75-
matlab -nojvm -nosplash -r "addpath(fullfile(pwd)); savepath ();"
7684
```
7785

78-
Then get the latest commit:
86+
Then get the latest commit to stay up to date:
7987
```bash
8088
# from the directory where you downloaded the code
8189
git pull origin master
8290
```
8391

8492
To work with a specific version, create a branch at a specific version tag number
8593
```bash
86-
# creating and checking out a branch that will be calle version1 at the version tag v0.0.1
87-
git checkout -b version1 v0.0.1
94+
# creating and checking out a branch that will be called version1 at the version tag v1.0.0
95+
git checkout -b version1 v1.0.0
8896
```
8997

90-
### 3.2. <a name='Addasasubmodule'></a>Add as a submodule
98+
### Add as a submodule
9199

92100
Add it as a submodule in the repo you are working on.
93101

94102
``` bash
95103
cd fullpath_to_directory_where_to_install
96104
# use git to download the code
97105
git submodule add https://github.com/cpp-lln-lab/CPP_PTB.git
98-
# move into the folder you have just created
99-
cd CPP_PTB
100-
# add the src folder to the matlab path and save the path
101-
matlab -nojvm -nosplash -r "addpath(fullfile(pwd))"
102106
```
103107

104108
To get the latest commit you then need to update the submodule with the information
@@ -109,7 +113,7 @@ git submodule update --remote --merge
109113

110114
Remember that updates to submodules need to be committed as well.
111115

112-
#### 3.2.1. <a name='Exampleforsubmoduleusage'></a>Example for submodule usage
116+
#### Example for submodule usage
113117

114118
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):
115119
``` bash
@@ -133,7 +137,7 @@ git submodule foreach --recursive 'git submodule init'
133137
git submodule foreach --recursive 'git submodule update'
134138
```
135139

136-
### 3.3. <a name='Directdownload'></a>Direct download
140+
### Direct download
137141

138142
Download the code. Unzip. And add to the matlab path.
139143

@@ -145,112 +149,41 @@ Or take the latest commit (NOT RECOMMENDED):
145149

146150
https://github.com/cpp-lln-lab/CPP_PTB/archive/master.zip
147151

148-
## 4. <a name='Settingupkeyboards'></a>Setting up keyboards
149-
150-
To select a specific keyboard to be used by the experimenter or the participant, you need to know
151-
the value assigned by PTB to each keyboard device.
152+
### Add CPP_PTB globally to the matlab path
152153

153-
To know this copy-paste this on the command window:
154+
This is NOT RECOMMENDED as this might create conflicts if you use different versions of CPP_PTB as sub-modules.
154155

155-
``` matlab
156-
[keyboardNumbers, keyboardNames] = GetKeyboardIndices;
156+
Also note that this might not work at all if you have not set a command line alias to start Matlab from a terminal window by just typing `matlab`. :wink:
157157

158-
disp(keyboardNumbers);
159-
disp(keyboardNames);
158+
```bash
159+
# from within the CPP_PTB folder
160+
matlab -nojvm -nosplash -r "addpath(genpath(fullfile(pwd, 'src'))); savepath(); path(); exit();"
160161
```
161162

162-
You can then assign a specific device number to the main keyboard or the response box in the `cfg` structure
163-
164-
- `cfg.keyboard.responseBox` would be the device number of the device used by the participant to give his/her
165-
response: like the button box in the scanner or a separate keyboard for a behavioral experiment
166-
- `cfg.keyboard.keyboard` would be the device number of the keyboard on which the experimenter will type or
167-
press the keys necessary to start or abort the experiment.
168-
169-
`cfg.keyboard.responseBox` and `cfg.keyboard.keyboard` can be different or the same.
170-
171-
Using empty vectors (ie `[]`) or a negative value for those means that you will let PTB find and use the default device.
172-
173-
## 5. <a name='Structure'></a>Structure
174-
175-
The `cfg` structure is where most of the information about your experiment will be defined.
176-
177-
Below we try to outline what it contains.
178-
179-
```matlab
180-
181-
cfg.testingDevice = 'pc';
182-
183-
% cfg.color
184-
cfg.keyboard.keyboard = [];
185-
cfg.keyboard.responseBox = [];
186-
cfg.keyboard.responseKey = {};
187-
cfg.keyboard.escapeKey = 'ESCAPE';
188-
189-
% cfg.debug
190-
cfg.debug.do = true;
191-
cfg.debug.transpWin = true;
192-
cfg.debug.smallWin = true;
193-
194-
% cfg.text
195-
cfg.text.font
196-
cfg.text.size
197-
cfg.text.style
198-
199-
% cfg.color
200-
cfg.color.background
201-
202-
% cfg.screen
203-
cfg.screen.monitorWidth
204-
cfg.screen.monitorDistance
205-
cfg.screen.idx
206-
cfg.screen.win
207-
cfg.screen.winRect
208-
cfg.screen.winWidth
209-
cfg.screen.winHeight
210-
cfg.screen.center
211-
cfg.screen.FOV
212-
cfg.screen.ppd
213-
cfg.screen.ifi
214-
cfg.screen.monRefresh
215-
216-
% cfg.audio
217-
cfg.audio.do
218-
cfg.audio.pahandle
219-
cfg.audio.devIdx
220-
cfg.audio.playbackMode
221-
cfg.audio.requestedLatency
222-
cfg.audio.fs
223-
cfg.audio.channels
224-
cfg.audio.initVolume
225-
cfg.audio.pushSize
226-
cfg.audio.requestOffsetTime
227-
cfg.audio.reqsSampleOffset
228-
229-
% cfg.mri
230-
cfg.mri.repetitionTime
231-
cfg.mri.triggerNb
232-
cfg.mri.triggerKey
233-
```
163+
## Code style guide
164+
165+
We use the `camelCase` to more easily differentiates our functions from the ones from PTB that use a `PascalCase`.
234166

235-
## 6. <a name='Annexes'></a>Annexes
167+
In practice, we use the following regular expression for function names: `[a-z]+(([A-Z]|[0-9]){1}[a-z]+)*`.
236168

237-
### 6.1. <a name='ExperimenttemplateWIP'></a>Experiment template [ WIP ]
169+
> Regular expressions look scary but are SUPER useful to sort through filenames:
170+
> - A quick [intro to regular expression](https://www.rexegg.com/)
171+
> - And many websites allow you to "design and test" your regular expression:
172+
> - [regexr](https://regexr.com/)
173+
> - [regexper](https://regexper.com/#%5Ba-z%5D%2B%28%28%5BA-Z%5D%7C%5B0-9%5D%29%7B1%7D%5Ba-z%5D%2B%29)
174+
> - ...
238175
239-
### 6.2. <a name='devSandboxstand-alone'></a>devSandbox (stand-alone)
176+
We keep the McCabe complexity below 15 as reported by the [check_my_code function](https://github.com/Remi-Gau/check_my_code) or the [MISS_HIT code checker](https://florianschanda.github.io/miss_hit). A couple of code quality metrics are also checked automatically by MISS_HIT (avoiding functions with too many nested `if` blocks).
240177

241-
This script is a stand-alone function that can be useful as a sandbox to develop the PTB audio/visual stimulation of your experiment. No input/output required.
178+
We use the [MISS_HIT linter](https://florianschanda.github.io/miss_hit/style_checker.html) to automatically fix some linting issues.
242179

243-
Here, a tutorial from https://peterscarfe.com/contrastgratingdemo.html is provided for illustrative purpose (notice that some variable names are updated to our code style). For your use, you will delete that part.
180+
The code style and quality is also checked during the [continuous integration](./.travis.yml).
244181

245-
It is composed of two parts:
246-
- a fixed structure that will initialize and close PTB in 'debug mode'
247-
(`PsychDebugWindowConfiguration`, `SkipSyncTests`)
248-
- the actual sandbox where to set your dynamic variables (the stimulation
249-
parameters) and the 'playground' where to develop the stimulation code
182+
## Unit tests
250183

251-
When you are happy with it, ideally you will move the vars in `setParameters.m` and the stimulation code in a separate function in `my-experiment-folder/subfun`. The code style and variable names are the same used in `cpp-lln-lab/CPP_PTB` github repo, therefore it should be easy to move everything in your experiment scripts (see the template that is annexed in `cpp-lln-lab/CPP_PTB`).
184+
Unit tests are run with the mox unit toolbox and automated with github action on Octave.
252185

253-
## 7. <a name='Contributors'></a>Contributors ✨
186+
## Contributors ✨
254187

255188
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
256189

0 commit comments

Comments
 (0)