Skip to content

Commit c207c5b

Browse files
committed
start tutorial
1 parent b19fb78 commit c207c5b

File tree

9 files changed

+132
-7
lines changed

9 files changed

+132
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ htmlcov/
44

55
tests/analysis/generated/
66
tests/analysis/output/
7+
tests/tutorial/output/

docs/gridgen/bin/parameters.html

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ <h1 class="title">Module <code>gridgen.bin.parameters</code></h1>
511511
return parameters
512512

513513

514-
if __name__ == &#39;__main__&#39;:
515-
514+
def main():
516515
md = [
517516
&#39;## Parameters&#39;,
518517
&#39;&#39;,
@@ -525,7 +524,11 @@ <h1 class="title">Module <code>gridgen.bin.parameters</code></h1>
525524
parameters_file = PKG_PATH / &#39;docs&#39; / &#39;parameters.md&#39;
526525

527526
with parameters_file.open(&#39;w&#39;) as f:
528-
f.write(&#39;\n&#39;.join(md))</code></pre>
527+
f.write(&#39;\n&#39;.join(md))
528+
529+
530+
if __name__ == &#39;__main__&#39;:
531+
main()</code></pre>
529532
</details>
530533
</section>
531534
<section>
@@ -642,6 +645,31 @@ <h2 id="returns">Returns</h2>
642645
return out</code></pre>
643646
</details>
644647
</dd>
648+
<dt id="gridgen.bin.parameters.main"><code class="name flex">
649+
<span>def <span class="ident">main</span></span>(<span>)</span>
650+
</code></dt>
651+
<dd>
652+
<div class="desc"></div>
653+
<details class="source">
654+
<summary>
655+
<span>Expand source code</span>
656+
</summary>
657+
<pre><code class="python">def main():
658+
md = [
659+
&#39;## Parameters&#39;,
660+
&#39;&#39;,
661+
&#39;Parameters should be saved as a `json` file.&#39;,
662+
&#39;You can pass the parameters with the command `gridgen parameters.json func` where `func` is one of the possible functions (`grid2d`, `ecog`, `fit` etc).&#39;,
663+
&#39;You can also use the command `gridgen parameters.json parameters` to generate a template `parameters.json` file.&#39;,
664+
&#39;&#39;,
665+
]
666+
md = md + help_template(TEMPLATE)
667+
parameters_file = PKG_PATH / &#39;docs&#39; / &#39;parameters.md&#39;
668+
669+
with parameters_file.open(&#39;w&#39;) as f:
670+
f.write(&#39;\n&#39;.join(md))</code></pre>
671+
</details>
672+
</dd>
645673
<dt id="gridgen.bin.parameters.parse_parameters"><code class="name flex">
646674
<span>def <span class="ident">parse_parameters</span></span>(<span>parameters, function, output_dir=None)</span>
647675
</code></dt>
@@ -788,9 +816,10 @@ <h1>Index</h1>
788816
</ul>
789817
</li>
790818
<li><h3><a href="#header-functions">Functions</a></h3>
791-
<ul class="">
819+
<ul class="two-column">
792820
<li><code><a title="gridgen.bin.parameters.convert_to_path" href="#gridgen.bin.parameters.convert_to_path">convert_to_path</a></code></li>
793821
<li><code><a title="gridgen.bin.parameters.help_template" href="#gridgen.bin.parameters.help_template">help_template</a></code></li>
822+
<li><code><a title="gridgen.bin.parameters.main" href="#gridgen.bin.parameters.main">main</a></code></li>
794823
<li><code><a title="gridgen.bin.parameters.parse_parameters" href="#gridgen.bin.parameters.parse_parameters">parse_parameters</a></code></li>
795824
<li><code><a title="gridgen.bin.parameters.prepare_template" href="#gridgen.bin.parameters.prepare_template">prepare_template</a></code></li>
796825
<li><code><a title="gridgen.bin.parameters.validate_template" href="#gridgen.bin.parameters.validate_template">validate_template</a></code></li>

docs/img/grid2d.png

5.63 KB
Loading

docs/tutorial.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Tutorial
2+
**gridgen** consists of some functions (commands) that allow you to:
3+
- create the 2d grid (`grid2d`)
4+
- compute the power spectral density (PSD) at each electrode (`ecog`)
5+
- create the 3d grid (`grid3d`)
6+
- fit the 3d grid onto the surface, by fitting the ecog values (`fit`)
7+
- compare the results (`matlab`)
8+
9+
In addition, you need to pass the parameters for your analysis.
10+
Parameters are structured in a json format.
11+
A description of the parameters can be found in [Parameters](parameters.md).
12+
13+
You can also generate an template `json` file with all the necessary parameters with the command:
14+
15+
```bash
16+
gridgen parameters.json parameters
17+
```
18+
19+
Then you need to populate the values in parameters.
20+
Note that each command requires different set of parameters. f.e.
21+
22+
```bash
23+
gridgen parameters.json grid2d
24+
```
25+
26+
only requires the parameter `grid2d` while the command:
27+
28+
```bash
29+
gridgen parameters.json grid3d
30+
```
31+
32+
requires the parameters `grid3d`, `mri`, `initial` (and possibly `morphology` and `functional`).
33+
This information is described in [Parameters](parameters.md) and `gridgen` will throw an error if the parametes are not complete.
34+
35+
## grid2d
36+
The first step is to create a 2d grid.
37+
This grid will only give us the electrode labels and no additional information (so, no information about electrode spacing).
38+
You can create a grid with the parameters (called `parameters.json`):
39+
40+
```json
41+
{
42+
"grid2d": {
43+
"n_rows": 4,
44+
"n_columns": 3,
45+
"direction": "TBLR",
46+
"chan_pattern": "chan{}"
47+
}
48+
}
49+
```
50+
51+
By convention, the wires are at the bottom.
52+
`chan_pattern` is used to generate the channel labels.
53+
`chan{}` will create `chan1`, `chan2`, `chan3` and `chan{:03d}` will create `chan001`, `chan002`, `chan003` (see [Python string formatting](https://docs.python.org/3/library/string.html#formatspec)).
54+
55+
```bash
56+
gridgen parameters.json grid2d
57+
```
58+
59+
which will create a file called `grid2d_labels.tsv` like this:
60+
61+
![grid2d_labels.tsv](img/grid2d.png)
62+
63+

gridgen/bin/parameters.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,7 @@ def parse_parameters(parameters, function, output_dir=None):
485485
return parameters
486486

487487

488-
if __name__ == '__main__':
489-
488+
def main():
490489
md = [
491490
'## Parameters',
492491
'',
@@ -500,3 +499,7 @@ def parse_parameters(parameters, function, output_dir=None):
500499

501500
with parameters_file.open('w') as f:
502501
f.write('\n'.join(md))
502+
503+
504+
if __name__ == '__main__':
505+
main()

tests/paths.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
TEST_PATH = Path(__file__).resolve().parent
55
ANALYSIS_PATH = TEST_PATH / 'analysis'
66
DATA_PATH = ANALYSIS_PATH / 'data'
7+
TUTORIAL_PATH = TEST_PATH / 'tutorial'
78

89
SMOOTH_FILE = DATA_PATH / 'lh_smooth.pial'
910
PIAL_FILE = DATA_PATH / 'lh.pial'

tests/test_command.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from gridgen.bin.command import main, _JSONEncoder_path
22
from gridgen.bin.parameters import REQUIRED
3+
from gridgen.bin.parameters import main as main_parameters
34
from json import dump
5+
46
from .paths import OUTPUT_PATH, ECOG_FILE, T1_FILE, SMOOTH_FILE, PIAL_FILE, FUNC_FILE
57

68
EXAMPLES = {
79
"grid2d": {
810
"n_rows": 3,
911
"n_columns": 2,
10-
"direction": "TBLR",
12+
"direction": "RLBT",
1113
"chan_pattern": "chan{}"
1214
},
1315
"ecog": {
@@ -67,3 +69,7 @@ def test_cmd():
6769
dump(params, f, indent=2, cls=_JSONEncoder_path)
6870

6971
main([str(param_json), cmd])
72+
73+
74+
def test_help():
75+
main_parameters()

tests/test_tutorial.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .paths import TUTORIAL_PATH
2+
from gridgen.bin.command import main
3+
4+
5+
output = str(TUTORIAL_PATH / 'output')
6+
7+
def test_grid2d():
8+
param_json = TUTORIAL_PATH / 'grid2d.json'
9+
main([
10+
str(param_json),
11+
'--output_dir',
12+
str(output),
13+
'grid2d'
14+
])

tests/tutorial/grid2d.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"grid2d": {
3+
"n_rows": 4,
4+
"n_columns": 3,
5+
"direction": "TBLR",
6+
"chan_pattern": "chan{}"
7+
}
8+
}

0 commit comments

Comments
 (0)