Skip to content

Commit 7d48954

Browse files
stesMMathisLab
andauthored
Improve documentation for local docs build (#70)
* Add dev tool for local docs build * Update contribution guide * Clarify local paths * Move assets copy * Revert docs build in makefile to old command * Update hippocampus.py - fix spelling errors * Update multiobjective.py - spelling error --------- Co-authored-by: Mackenzie Mathis <mathis@rowland.harvard.edu>
1 parent 7400fb9 commit 7d48954

5 files changed

Lines changed: 119 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ data/
66
experiments/sweeps
77
exports/
88
demo_notebooks/
9+
assets/
910

1011
# Binary files
1112
*.png

cebra/datasets/hippocampus.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
class SingleRatDataset(cebra.data.SingleSessionDataset):
7676
"""A single rat hippocampus tetrode recording while the rat navigates on a linear track.
7777
78-
Neural data is spike counts binned into 25ms time window and the continuous behavior label is position and the running driection (left, right) of a rat.
78+
Neural data is spike counts binned into 25ms time window and the continuous behavior label is position and the running direction (left, right) of a rat.
7979
The behavior label is structured as 3D array consists of position, right, and left.
8080
8181
Args:
@@ -152,7 +152,7 @@ def decode(self, x_train, y_train, x_test, y_test):
152152
class SingleRatTrialSplitDataset(SingleRatDataset):
153153
"""A single rat hippocampus tetrode recording while the rat navigates on a linear track with 3-fold splits.
154154
155-
Neural data is spike counts binned into 25ms time window and the behavior is position and the running driection (left, right) of a rat.
155+
Neural data is spike counts binned into 25ms time window and the behavior is position and the running direction (left, right) of a rat.
156156
The behavior label is structured as 3D array consists of position, right, and left.
157157
The neural and behavior recordings are parsed into trials (a round trip from one end of the track) and the trials are split into a train, valid and test set with k=3 nested cross validation.
158158
@@ -249,7 +249,7 @@ def _split(self, split, **kwargs):
249249
class SingleRatCorruptDataset(SingleRatDataset):
250250
"""A single rat hippocampus tetrode recording while the rat navigates on a linear track with a shuffled behavior label.
251251
252-
Neural data is spike counts binned into 25ms time window and the behavior is position and the running driection (left, right) of a rat.
252+
Neural data is spike counts binned into 25ms time window and the behavior is position and the running direction (left, right) of a rat.
253253
The behavior label is structured as 3D array consists of position, right, and left and it is shuffled in random orders.
254254
255255
Args:
@@ -273,7 +273,7 @@ class MultipleRatsTrialSplitDataset(cebra.data.DatasetCollection):
273273
"""4 rats hippocampus tetrode recording while the rat navigates on a linear track with 3-fold splits.
274274
275275
Neural and behavior recordings of 4 rats.
276-
For each rat, neural data is spike counts binned into 25ms time window and the behavior is position and the running driection (left, right) of a rat.
276+
For each rat, neural data is spike counts binned into 25ms time window and the behavior is position and the running direction (left, right) of a rat.
277277
The behavior label is structured as 3D array consists of position, right, and left.
278278
Neural and behavior recordings of each rat are parsed into trials (a round trip from one end of the track) and the trials are split into a train, valid and test set with k=3 nested cross validation.
279279

cebra/models/multiobjective.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Mode:
6767
6868
- ``OVERLAPPING``: When ``dimensions`` are set to `(x0, x1, ...)``, features will be
6969
extracted from ``0:x0, 0:x1, ...``.
70-
- ``SEPERATE``: Features are extracted from ``x0:x1, x1:x2, ...``
70+
- ``SEPARATE``: Features are extracted from ``x0:x1, x1:x2, ...``
7171
7272
"""
7373

docs/source/contributing.rst

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,45 @@ It will link the package to the local location, basically meaning any changes to
9999
Adding a Demo Jupyter Notebook
100100
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101101

102-
New demo notebooks should be placed in ``demo_notebooks/`` folder.
103-
Then the new notebook needs to be added to the Demo Notebooks ``toctree`` in ``demo_notebooks/README.rst``.
102+
The demo notebooks are organized in this repository: https://github.com/AdaptiveMotorControlLab/CEBRA-demos
103+
104+
To add a demo, open a PR in that repo which adds the notebooks plus a line to the ``nbgallery`` in the README
105+
file: https://github.com/AdaptiveMotorControlLab/CEBRA-demos/blob/main/README.rst
106+
104107
For that, extend the ``toctree`` (at the end of the file) using the following template:
105108

106-
.. code:: bash
109+
.. code:: rst
110+
111+
.. nbgallery::
112+
:maxdepth: 2
113+
114+
Encoding of space, hippocampus (CA1) <demo_notebooks/Demo_hippocampus.ipynb>
115+
Decoding movie features from (V1) visual cortex <demo_notebooks/Demo_Allen.ipynb>
116+
Forelimb dynamics, somatosensory (S1) <demo_notebooks/Demo_primate_reaching.ipynb>
117+
...
107118
108-
<notebook_title> <demo_notebooks/<notebook_name>.ipynb>
119+
Your Notebook title <demo_notebooks/<your notebook name>.ipynb>
109120
110-
**Example:**
121+
Thumbnails for the notebooks can be placed in this repository
122+
https://github.com/AdaptiveMotorControlLab/CEBRA-assets/tree/main/docs/source/_static/thumbnails
123+
124+
and then referenced in the documentation config:
125+
https://github.com/AdaptiveMotorControlLab/CEBRA/blob/bb9d55e5a533372cb011c3db322fbd9a1a5ea278/docs/source/conf.py#L203-L228
126+
127+
To build the docs and verify the demo notebooks, you can run
111128

112129
.. code:: bash
113130
114-
Rat hippocampus <demo_notebooks/Demo_hippocampus.ipynb>
131+
./tools/build_docs.sh
132+
133+
to build the full documentation, and render it on `http://127.0.0.1:8080` in your webbrowser to verify.
134+
135+
For local edits,
136+
- CEBRA-assets is checked out under the ``/assets/`` path
137+
- CEBRA-figures is checkout out under the ``/docs/source/cebra-figures/`` path
138+
- CEBRA-demos is checkout out under the ``/docs/source/demo_notebooks/`` path
139+
140+
You can edit files there, create branches, and re-run ``./tools/build_docs.sh`` for re-building the docs.
115141

116142

117143
Building the Python package (information for maintainers only)

tools/build_docs.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
# Locally build the documentation and display it in a webserver.
3+
4+
set -xe
5+
6+
git_checkout_or_pull() {
7+
local repo=$1
8+
local target_dir=$2
9+
# TODO(stes): theoretically we could also auto-update the repo,
10+
# I commented this out for now to avoid interference with local
11+
# dev/changes
12+
#if [ -d "$target_dir" ]; then
13+
# cd "$target_dir"
14+
# git pull --ff-only origin main
15+
# cd -
16+
#else
17+
if [ ! -d "$target_dir" ]; then
18+
git clone "$repo" "$target_dir"
19+
fi
20+
}
21+
22+
checkout_cebra_figures() {
23+
git_checkout_or_pull git@github.com:AdaptiveMotorControlLab/cebra-figures.git docs/source/cebra-figures
24+
}
25+
26+
checkout_assets() {
27+
git_checkout_or_pull git@github.com:AdaptiveMotorControlLab/cebra-assets.git assets
28+
}
29+
30+
checkout_cebra_demos() {
31+
git_checkout_or_pull git@github.com:AdaptiveMotorControlLab/cebra-demos.git docs/source/demo_notebooks
32+
}
33+
34+
setup_python() {
35+
python -m pip install --upgrade pip setuptools wheel
36+
sudo apt-get install -y pandoc
37+
pip install torch --extra-index-url=https://download.pytorch.org/whl/cpu
38+
pip install '.[docs]'
39+
}
40+
41+
build_docs() {
42+
cp -r assets/* .
43+
export SPHINXOPTS="-W --keep-going -n"
44+
(cd docs && PYTHONPATH=.. make page)
45+
}
46+
47+
serve() {
48+
python -m http.server 8080 --b 0.0.0.0 -d docs/build/html
49+
}
50+
51+
main() {
52+
build_docs
53+
serve
54+
}
55+
56+
if [[ "$1" == "--build" ]]; then
57+
main
58+
fi
59+
60+
docker build -t cebra-docs -f - . << "EOF"
61+
FROM python:3.9
62+
63+
RUN python -m pip install --upgrade pip setuptools wheel \
64+
&& apt-get update -y && apt-get install -y pandoc git
65+
66+
RUN pip install torch --extra-index-url=https://download.pytorch.org/whl/cpu \
67+
&& pip install 'cebra[docs]' && pip uninstall -y cebra
68+
69+
EOF
70+
71+
checkout_cebra_figures
72+
checkout_assets
73+
checkout_cebra_demos
74+
75+
docker run \
76+
-p 127.0.0.1:8080:8080 \
77+
-u $(id -u):$(id -g) \
78+
-v .:/app -w /app \
79+
--tmpfs /.config --tmpfs /.cache \
80+
-it cebra-docs \
81+
./tools/build_docs.sh --build

0 commit comments

Comments
 (0)