From c0301c0382501dccb8c04ec1abcc584a91b59d9a Mon Sep 17 00:00:00 2001 From: Kushaan Gupta Date: Sat, 12 Oct 2024 00:35:14 -0400 Subject: [PATCH 1/4] use README as landing page --- .github/workflows/ci.yml | 2 +- .github/workflows/deploy-docs.yml | 2 +- README.md | 18 +++++++++--------- docs/index.md | 2 +- mkdocs.yml | 6 +++++- pyproject.toml | 1 + 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ac7258..9c6e26c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: neuro_py CI +name: CI on: push: diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 3e7e18a..f2590a6 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -1,4 +1,4 @@ -name: Deploy docs +name: Docs on: [push, pull_request] jobs: build: diff --git a/README.md b/README.md index 34b6106..af85736 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,19 @@ Analysis of neuroelectrophysiology data in Python. +| | | +|---------|--------------------------------------------------------------------| +| CI/CD | [![CI - Test](https://github.com/ryanharvey1/neuro_py/actions/workflows/ci.yml/badge.svg)](https://github.com/ryanharvey1/neuro_py/actions/workflows/ci.yml) [![Docs](https://github.com/ryanharvey1/neuro_py/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/ryanharvey1/neuro_py/actions/workflows/deploy-docs.yml) | +| Package | [![PyPI - Version](https://img.shields.io/pypi/v/neuro-analysis-py.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/neuro-analysis-py.svg?logo=python&label=Python&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/neuro-analysis-py?color=blue&label=Installs&logo=pypi&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) | +| Repository | [![GitHub - Stars](https://img.shields.io/github/stars/ryanharvey1/neuro_py?logo=github&label=Stars)]() [![GitHub - Forks](https://img.shields.io/github/forks/ryanharvey1/neuro_py?logo=github&label=Forks)]() [![Downloads](https://pepy.tech/badge/neuro-analysis-py)](https://pepy.tech/project/neuro-analysis-py) [![GitHub - Issues](https://img.shields.io/github/issues/ryanharvey1/neuro_py?logo=github&label=Issues&logoColor=gold)]() [![Commits](https://img.shields.io/github/last-commit/ryanharvey1/neuro_py)]() [![Contributors](https://img.shields.io/github/contributors/ryanharvey1/neuro_py)]() | +| Meta | [![GitHub - License](https://img.shields.io/github/license/ryanharvey1/neuro_py?logo=github&label=License&logoColor=gold)](LICENSE) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![docstring - numpydoc](https://img.shields.io/badge/docstring-numpydoc-blue)](https://numpydoc.readthedocs.io/en/latest/format.html) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) | + + Overview ======== neuro_py is a Python package for analysis of neuroelectrophysiology data. It is built on top of the [nelpy](https://github.com/nelpy/nelpy) package, which provides core data objects. neuro_py provides a set of functions for analysis of freely moving electrophysiology, including behavior tracking utilities, neural ensemble detection, peri-event analyses, robust batch analysis tools, and more. -Tutorials are [here](https://github.com/ryanharvey1/neuro_py/tree/master/tutorials) and more will be added. +Tutorials are [here](https://github.com/ryanharvey1/neuro_py/tree/main/tutorials) and more will be added. ## Installation @@ -57,11 +65,3 @@ Please make sure to update tests as appropriate. - [@ryanharvey1](https://www.github.com/ryanharvey1) - [@lolaBerkowitz](https://www.github.com/lolaBerkowitz) - [@kushaangupta](https://github.com/kushaangupta) - - -## License - -neuro_py is distributed under the MIT license. See the [LICENSE](https://github.com/neuro_py/neuro_py/blob/master/LICENSE) file for details. - - - diff --git a/docs/index.md b/docs/index.md index 9469503..75687bc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1 @@ -# neuro-py +{% include-markdown "../README.md" %} diff --git a/mkdocs.yml b/mkdocs.yml index 67c648b..35adaee 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -66,7 +66,11 @@ plugins: python: options: docstring_style: numpy - +- include-markdown: # https://github.com/mondeja/mkdocs-include-markdown-plugin + opening_tag: "{%" + closing_tag: "%}" + rewrite_relative_urls: true + heading_offset: 1 nav: - Home: index.md diff --git a/pyproject.toml b/pyproject.toml index 236c399..7152ea3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ dependencies = [ "mkdocs-gen-files>=0.5.0", "mkdocs-literate-nav>=0.6.1", "mkdocs-section-index>=0.3.9", + "mkdocs-include-markdown-plugin>=6.2.2", ] [project.urls] From 9958f21c884ce3fa8e24a20630f3dcb96723b908 Mon Sep 17 00:00:00 2001 From: Kushaan Gupta Date: Sat, 12 Oct 2024 21:19:14 -0400 Subject: [PATCH 2/4] add inter fonts & tweak README --- README.md | 2 +- docs/stylesheets/extra.css | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af85736..39ee5c8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Analysis of neuroelectrophysiology data in Python. |---------|--------------------------------------------------------------------| | CI/CD | [![CI - Test](https://github.com/ryanharvey1/neuro_py/actions/workflows/ci.yml/badge.svg)](https://github.com/ryanharvey1/neuro_py/actions/workflows/ci.yml) [![Docs](https://github.com/ryanharvey1/neuro_py/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/ryanharvey1/neuro_py/actions/workflows/deploy-docs.yml) | | Package | [![PyPI - Version](https://img.shields.io/pypi/v/neuro-analysis-py.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/neuro-analysis-py.svg?logo=python&label=Python&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/neuro-analysis-py?color=blue&label=Installs&logo=pypi&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) | -| Repository | [![GitHub - Stars](https://img.shields.io/github/stars/ryanharvey1/neuro_py?logo=github&label=Stars)]() [![GitHub - Forks](https://img.shields.io/github/forks/ryanharvey1/neuro_py?logo=github&label=Forks)]() [![Downloads](https://pepy.tech/badge/neuro-analysis-py)](https://pepy.tech/project/neuro-analysis-py) [![GitHub - Issues](https://img.shields.io/github/issues/ryanharvey1/neuro_py?logo=github&label=Issues&logoColor=gold)]() [![Commits](https://img.shields.io/github/last-commit/ryanharvey1/neuro_py)]() [![Contributors](https://img.shields.io/github/contributors/ryanharvey1/neuro_py)]() | +| Repository | [![GitHub - Issues](https://img.shields.io/github/issues/ryanharvey1/neuro_py?logo=github&label=Issues&logoColor=gold)]() [![Commits](https://img.shields.io/github/last-commit/ryanharvey1/neuro_py)]() [![Contributors](https://img.shields.io/github/contributors/ryanharvey1/neuro_py)]() [![Downloads](https://pepy.tech/badge/neuro-analysis-py)](https://pepy.tech/project/neuro-analysis-py) | | Meta | [![GitHub - License](https://img.shields.io/github/license/ryanharvey1/neuro_py?logo=github&label=License&logoColor=gold)](LICENSE) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![docstring - numpydoc](https://img.shields.io/badge/docstring-numpydoc-blue)](https://numpydoc.readthedocs.io/en/latest/format.html) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) | diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index bd3304b..3f66a0f 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -1,3 +1,16 @@ +@import url('https://rsms.me/inter/inter.css'); +* { + font-family: 'Inter', sans-serif; +} +h1, h2, h3, h4, h5, h6 { + font-weight: 700 !important; +} +pre * { font-family: monospace; } + +p { + text-align: justify; +} + :root { --md-code-font: "Roboto Mono"; --md-default-fg-color: #111; From 8306fb5048e93e7b073a9345ad6decd09107799d Mon Sep 17 00:00:00 2001 From: Kushaan Gupta Date: Sun, 13 Oct 2024 00:25:29 -0400 Subject: [PATCH 3/4] Render ipython notebooks for docs --- README.md | 8 +- docs/copy_tutorials.py | 45 +++ docs/index.md | 7 + docs/stylesheets/extra.css | 6 + mkdocs.yml | 18 +- pyproject.toml | 1 + tutorials/batch_analysis.ipynb | 79 ++++-- ...utorial.ipynb => explained_variance.ipynb} | 58 ++-- tutorials/reactivation.ipynb | 55 ++-- ...l_map_tutorial.ipynb => spatial_map.ipynb} | 258 +++++++++++++----- 10 files changed, 397 insertions(+), 138 deletions(-) create mode 100644 docs/copy_tutorials.py rename tutorials/{explained_variance_tutorial.ipynb => explained_variance.ipynb} (99%) rename tutorials/{spatial_map_tutorial.ipynb => spatial_map.ipynb} (99%) diff --git a/README.md b/README.md index 39ee5c8..61bc74b 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ Analysis of neuroelectrophysiology data in Python. | CI/CD | [![CI - Test](https://github.com/ryanharvey1/neuro_py/actions/workflows/ci.yml/badge.svg)](https://github.com/ryanharvey1/neuro_py/actions/workflows/ci.yml) [![Docs](https://github.com/ryanharvey1/neuro_py/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/ryanharvey1/neuro_py/actions/workflows/deploy-docs.yml) | | Package | [![PyPI - Version](https://img.shields.io/pypi/v/neuro-analysis-py.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/neuro-analysis-py.svg?logo=python&label=Python&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/neuro-analysis-py?color=blue&label=Installs&logo=pypi&logoColor=gold)](https://pypi.org/project/neuro-analysis-py/) | | Repository | [![GitHub - Issues](https://img.shields.io/github/issues/ryanharvey1/neuro_py?logo=github&label=Issues&logoColor=gold)]() [![Commits](https://img.shields.io/github/last-commit/ryanharvey1/neuro_py)]() [![Contributors](https://img.shields.io/github/contributors/ryanharvey1/neuro_py)]() [![Downloads](https://pepy.tech/badge/neuro-analysis-py)](https://pepy.tech/project/neuro-analysis-py) | -| Meta | [![GitHub - License](https://img.shields.io/github/license/ryanharvey1/neuro_py?logo=github&label=License&logoColor=gold)](LICENSE) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![docstring - numpydoc](https://img.shields.io/badge/docstring-numpydoc-blue)](https://numpydoc.readthedocs.io/en/latest/format.html) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) | +| Metadata | [![GitHub - License](https://img.shields.io/github/license/ryanharvey1/neuro_py?logo=github&label=License&logoColor=gold)](LICENSE) [![code style - black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![docstring - numpydoc](https://img.shields.io/badge/docstring-numpydoc-blue)](https://numpydoc.readthedocs.io/en/latest/format.html) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) | Overview ======== -neuro_py is a Python package for analysis of neuroelectrophysiology data. It is built on top of the [nelpy](https://github.com/nelpy/nelpy) package, which provides core data objects. neuro_py provides a set of functions for analysis of freely moving electrophysiology, including behavior tracking utilities, neural ensemble detection, peri-event analyses, robust batch analysis tools, and more. +`neuro_py` is a Python package for analysis of neuroelectrophysiology data. It is built on top of the [nelpy](https://github.com/nelpy/nelpy) package, which provides core data objects. `neuro_py` provides a set of functions for analysis of freely moving electrophysiology, including behavior tracking utilities, neural ensemble detection, peri-event analyses, robust batch analysis tools, and more. Tutorials are [here](https://github.com/ryanharvey1/neuro_py/tree/main/tutorials) and more will be added. @@ -40,13 +40,13 @@ pip install -e . --force-reinstall --no-cache-dir ## Usage ```python -import neuro_py as neuro +import neuro_py as npy ``` ## Dependencies -For ease of use, this package uses nelpy core data objects. See [nelpy](https://github.com/nelpy/nelpy) +For ease of use, this package uses `nelpy` core data objects. See [nelpy](https://github.com/nelpy/nelpy) ## Testing diff --git a/docs/copy_tutorials.py b/docs/copy_tutorials.py new file mode 100644 index 0000000..6f085c0 --- /dev/null +++ b/docs/copy_tutorials.py @@ -0,0 +1,45 @@ +"""Examples copying utility function.""" + +from pathlib import Path + +import mkdocs_gen_files + +EXAMPLES_DIRECTORY_PATH = Path("tutorials") + + +def write_file(file_path: Path) -> None: + """ + Copies file from examples directory into mkdocs scope. + + Args: + file_path (Path): Current file path. + """ + root_path = file_path.relative_to(".") + print(f"Copying {root_path} file to {root_path}") + with root_path.open("rb") as src, mkdocs_gen_files.open(root_path, "wb") as dst: + dst.write(src.read()) + + +banned_directories = [ + "cache", + "files", + "example_files", + "__pycache__", + "lightning_logs", +] +banned_extensions = [".pbf", ".parquet", ".json", ".geojson", ".pt"] +for i in EXAMPLES_DIRECTORY_PATH.glob("**/*"): + if i.is_file(): + should_copy = True + for banned_extension in banned_extensions: + if banned_extension in i.suffixes: + should_copy = False + break + + for banned_directory in banned_directories: + if banned_directory in i.parts: + should_copy = False + break + + if should_copy: + write_file(i) diff --git a/docs/index.md b/docs/index.md index 75687bc..a0de414 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1,8 @@ + + {% include-markdown "../README.md" %} diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index 3f66a0f..6772573 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -11,6 +11,12 @@ p { text-align: justify; } +.md-nav__link--active { + background-color: var(--md-code-bg-color); + border-radius: 0.2em; + padding: 0.2em; +} + :root { --md-code-font: "Roboto Mono"; --md-default-fg-color: #111; diff --git a/mkdocs.yml b/mkdocs.yml index 35adaee..0b1cba6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -8,9 +8,6 @@ extra_css: theme: name: "material" - font: - text: Roboto - code: Roboto Mono palette: - media: "(prefers-color-scheme: dark)" toggle: @@ -58,6 +55,7 @@ plugins: - gen-files: scripts: - docs/gen_ref_pages.py + - docs/copy_tutorials.py - literate-nav: nav_file: SUMMARY.md - section-index @@ -66,12 +64,26 @@ plugins: python: options: docstring_style: numpy + docstring_section_style: table + filters: ["!__"] # exclude all members starting with __ - include-markdown: # https://github.com/mondeja/mkdocs-include-markdown-plugin opening_tag: "{%" closing_tag: "%}" rewrite_relative_urls: true heading_offset: 1 +- mkdocs-jupyter: + include: ["*.ipynb"] + include_source: true + ignore_h1_titles: true + execute: false + allow_errors: true + include_requirejs: true nav: - Home: index.md - API Reference: reference/ +- Tutorials: + - Batch Analysis: tutorials/batch_analysis.ipynb + - Explained Variance: tutorials/explained_variance.ipynb + - Reactivation: tutorials/reactivation.ipynb + - Spatial Map: tutorials/spatial_map.ipynb diff --git a/pyproject.toml b/pyproject.toml index 7152ea3..6736da5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ dependencies = [ "mkdocs-literate-nav>=0.6.1", "mkdocs-section-index>=0.3.9", "mkdocs-include-markdown-plugin>=6.2.2", + "mkdocs-jupyter>=0.25.0", ] [project.urls] diff --git a/tutorials/batch_analysis.ipynb b/tutorials/batch_analysis.ipynb index 6f80335..1ebe067 100644 --- a/tutorials/batch_analysis.ipynb +++ b/tutorials/batch_analysis.ipynb @@ -1,5 +1,21 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Batch Analysis\n", + "\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -19,9 +35,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Define your analysis\n", + "## Section 1: Define the analysis\n", "\n", - "Here, I'm defining the analysis in the notebook, but in a real project, you would define it in a separate Python file and import it here." + "Here, I'm defining the analysis in the notebook, but in a real project, you would define it in a separate `.py` file and import it here." ] }, { @@ -30,11 +46,11 @@ "metadata": {}, "outputs": [], "source": [ - "def toy_analysis(basepath, paramater_1=1, paramater_2=2):\n", + "def toy_analysis(basepath, parameter_1=1, parameter_2=2):\n", " results = pd.DataFrame()\n", " results[\"basepath\"] = [basepath]\n", - " results[\"paramater_1\"] = paramater_1\n", - " results[\"paramater_2\"] = paramater_2\n", + " results[\"parameter_1\"] = parameter_1\n", + " results[\"parameter_2\"] = parameter_2\n", " results[\"random_number\"] = np.random.randint(0, 100)\n", " return results" ] @@ -43,9 +59,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Pandas dataframe of basepaths\n", - "\n", - "For your project, you will have a csv file with the basepaths you want to analyze. Here, I'm creating a dataframe with the basepaths for the purpose of this notebook." + "For your project, you will have a `.csv` file with the `basepaths` you want to analyze. Here, I'm creating a `DataFrame` with the `basepaths` for the purpose of this notebook." ] }, { @@ -54,23 +68,20 @@ "metadata": {}, "outputs": [], "source": [ - "sessions = pd.DataFrame()\n", - "sessions[\"basepath\"] = [\n", + "sessions = pd.DataFrame(dict(basepath=[\n", " r\"U:\\data\\hpc_ctx_project\\HP01\\day_1_20240227\",\n", " r\"U:\\data\\hpc_ctx_project\\HP01\\day_2_20240228\",\n", " r\"U:\\data\\hpc_ctx_project\\HP01\\day_3_20240229\",\n", - "]" + "]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# Save path\n", - "\n", "You will need to define the path where you want to save the results of your analysis.\n", "\n", - "It's useful to nest the analysis version in a subfolder (toy_analysis\\toy_analysis_v1) to keep track of the different versions of your analysis. " + "It's useful to nest the analysis version in a subfolder (`toy_analysis\\toy_analysis_v1`) to keep track of the different versions of your analysis. " ] }, { @@ -86,15 +97,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Batch analysis\n", + "## Section 2: Run the analysis\n", "\n", - "### Finally, you can run your analysis in batch mode. This will loop through the basepaths and save the results in the specified folder.\n", + "**Finally, you can run your analysis in batch mode. This will loop through the `basepaths` and save the results in the specified folder.**\n", "\n", - "The batch_analysis function is a general function that you can use for any analysis. You just need to pass the function you want to run, the basepaths you want to analyze, and the save path.\n", + "The `batch_analysis` function is a general function that you can use for any analysis. You just need to pass the function you want to run, the `basepaths` you want to analyze, and the save path.\n", "\n", "If your analysis fails, running again will start from where it left off.\n", "\n", - "There is a parallel option that you can set to True if you want to run the analysis in parallel. This will speed up the analysis if you have multiple cores." + "There is a `parallel` option that you can set to `True` if you want to run the analysis in parallel. This will speed up the analysis if you have multiple cores." ] }, { @@ -140,9 +151,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Load results\n", + "## Section 3: Load the results\n", "\n", - "There is a built in loader that concatenates the results of the analysis into a single dataframe." + "There is a built in loader that concatenates the results of the analysis into a single `DataFrame`." ] }, { @@ -229,11 +240,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# More complicated results\n", + "## Bonus: More complicated results\n", "\n", - "Your results won't always fit nicely into a single dataframe. Sometimes you will have multiple data types you need to save.\n", + "Your results won't always fit nicely into a single `DataFrame`. Sometimes you will have multiple data types you need to save.\n", "\n", - "For example, you might have values for each cell in a dataframe and also psths for each cell. Your analysis will store both in a dictionary and you will construct a custom loader in your analysis." + "For example, you might have values for each cell in a `DataFrame` and also PSTHs for each cell. Your analysis will store both in a dictionary and you will construct a custom loader in your analysis." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Define the analysis" ] }, { @@ -306,7 +324,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Run the analysis" + "### Run the analysis" ] }, { @@ -354,7 +372,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Load and display results" + "### Load the results" ] }, { @@ -555,11 +573,18 @@ "display(results_df)\n", "display(psths)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] } ], "metadata": { "kernelspec": { - "display_name": "hpc_ctx", + "display_name": "44n", "language": "python", "name": "python3" }, @@ -573,7 +598,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/tutorials/explained_variance_tutorial.ipynb b/tutorials/explained_variance.ipynb similarity index 99% rename from tutorials/explained_variance_tutorial.ipynb rename to tutorials/explained_variance.ipynb index 4c85d57..b1497a6 100644 --- a/tutorials/explained_variance_tutorial.ipynb +++ b/tutorials/explained_variance.ipynb @@ -1,5 +1,21 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Explained Variance\n", + "\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -26,7 +42,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# load spike, session epoch, and nrem intervals" + "## Section 1: Load spike data, session epochs, and Non-REM epochs" ] }, { @@ -144,12 +160,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# most simple use case\n", - "\n", - "Single output metrics:\n", - "- explained and reverse explained variance\n", + "## Section 2: Single output metrics: Explained and Reverse Explained Variance\n", "\n", - "Here we are calculating explained variance over the entire post task interval" + "Here we are calculating explained variance over the entire post-task interval" ] }, { @@ -188,9 +201,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## You can calculate a pvalue for the explained variance \n", - "- by comparing the explained variance to the explained variance of shuffled data (shuffled template correlations)\n", - "- only works when returning single explained variance value, not time resolved" + "You can calculate a *p*-value for the explained variance by comparing the\n", + "explained variance to the explained variance of shuffled data (shuffled template\n", + "correlations).\n", + "\n", + "> NOTE: This only works when returning single explained variance value, not a\n", + " set of explained variance values over time." ] }, { @@ -215,9 +231,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Time resolved explained variance\n", + "## Section 3: Time-resolved explained variance\n", "\n", - "Now we can see the time course of explained variance" + "\n", + "### Section 3.1: Calculate explained variance over time\n", + "\n", + "We can also see the time course of explained variance" ] }, { @@ -265,7 +284,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Inspect when the explained variance is high and low\n", + "### Section 3.2: Inspect when the explained variance is high and low\n", "\n", "You can see it is high during the task (by definition it should be) and during NREM sleep" ] @@ -308,9 +327,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Use epoch arrays get average explained variance in post task NREM sleep \n", + "### Section 3.3: Use EpochArray to get average explained variance in post-task NREM sleep \n", "\n", - "The outcome is similar to above when we used the entire post task epoch" + "The outcome is similar to above when we used the entire post-task epoch" ] }, { @@ -340,11 +359,18 @@ "\n", "print(f\"explained variance: {nrem_ev_avg}, reverse explained variance: {nrem_rev_avg}\")\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] } ], "metadata": { "kernelspec": { - "display_name": "hpc_ctx", + "display_name": "44n", "language": "python", "name": "python3" }, @@ -358,7 +384,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/tutorials/reactivation.ipynb b/tutorials/reactivation.ipynb index c5c12c9..c0e7e79 100644 --- a/tutorials/reactivation.ipynb +++ b/tutorials/reactivation.ipynb @@ -4,9 +4,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Simple ICA reactivation tutorial \n", + "# Reactivation \n", "\n", - "Here, we will show how to use the AssemblyReact class to identify assemblies and assess reactivation during post task sleep" + "Here, we will show how to use the `neuro_py.ensemble.assembly_reactivation.AssemblyReact` class to identify assemblies and assess reactivation during post-task sleep\n", + "\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup" ] }, { @@ -36,9 +45,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Pick basepath and initiate AssemblyReact class\n", + "## Section 1: Pick basepath and initialize AssemblyReact class\n", "\n", - "Here we will use ca1 pyramidal cells" + "Here we will use CA1 pyramidal cells." ] }, { @@ -61,7 +70,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### also load brain states for later use" + "Also, load brain states for later use." ] }, { @@ -97,9 +106,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### load need data (spikes, ripples, epochs)\n", + "## Section 2: Load spike data, session epochs, and ripple events\n", "\n", - "You can see there there are nice print outs that display important information about the class" + "You can see there there are nice printouts that display important information about the class" ] }, { @@ -128,9 +137,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Locate task you want to detect assemblies.\n", + "Locate the session from which you want to detect assemblies.\n", "\n", - "here we can see a novel linear track is the second epoch\n" + "Here we can see a *novel* `linear` track is the second epoch." ] }, { @@ -228,7 +237,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Detect assembles in linear track during theta\n", + "## Section 3: Detect assembles in linear track during theta\n", "\n", "You can see we have detected 15 assemblies" ] @@ -258,7 +267,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Use built in plotting function to visualize assembly weights\n", + "## Section 4: Analyze the obtained assemblies" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Section 4.1: Visualize assembly weights\n", "\n", "Each column is a assembly and each row is a cell\n", "\n", @@ -291,7 +307,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### compute time resolved activations for each assembly\n", + "### Section 4.2: Compute time-resolved activations for each assembly\n", "\n", "Will take around a minute to run." ] @@ -321,7 +337,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Get assembly strengths around ripples in pre sleep, the task, and in post sleep" + "### Section 4.3: Get assembly strengths around ripples in pre-sleep, the task, and in post-sleep epochs" ] }, { @@ -367,11 +383,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Plot reactivation in post task ripples\n", + "### Section 4.4: Visualize reactivation dynamics during post-task ripples\n", "\n", - "Here, we have plotted pre, post, and post subtracted by pre to estimate the difference\n", + "Here, we have plotted *Pre*, *Post*, and *Post* subtracted by *Pre* to estimate the difference.\n", "\n", - "You can see that many of the assembles have a higher reactivation in the post task ripples compared to the pre task ripples" + "You can see that many of the assembles have a higher reactivation during the post-task ripples compared to the pre-task ripples." ] }, { @@ -446,6 +462,13 @@ "\n", "plt.show()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] } ], "metadata": { diff --git a/tutorials/spatial_map_tutorial.ipynb b/tutorials/spatial_map.ipynb similarity index 99% rename from tutorials/spatial_map_tutorial.ipynb rename to tutorials/spatial_map.ipynb index 5be7b19..4dbf5ac 100644 --- a/tutorials/spatial_map_tutorial.ipynb +++ b/tutorials/spatial_map.ipynb @@ -4,23 +4,27 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# spatial map tutorial\n", + "# Spatial Map\n", "\n", - "This short notebook will guide you over loading data and using SpatialMap class\n", + "This short notebook will guide you over loading data and using\n", + "`neuro_py.tuning.maps.SpatialMap` class.\n", "\n", - "We first go over 2d maps and then have 1d maps, and finally mapping continuous data" + "We first go over 2D maps and then have 1D maps, and finally mapping continuous\n", + "variables.\n", + "\n", + "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### 0. import needed packages" + "## Setup" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -51,12 +55,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 1. specify basepath to your session of interest" + "## Section 1: Specify basepath to your session of interest" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -67,12 +71,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 2. load in behavior and spike data" + "## Section 2: load in behavior and spike data" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -97,14 +101,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 3. load in epochs and make a note of which session you want to look at\n", + "## Section 3: Load in epochs and make a note of which session you want to analyze\n", "\n", - "here, I'm first interested in the last bigSquare session" + "Here, I'm first interested in the last *bigSquare* session" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -133,6 +137,9 @@ " stopTime\n", " environment\n", " behavioralParadigm\n", + " manipulation\n", + " stimuli\n", + " notes\n", " basepath\n", " \n", " \n", @@ -144,6 +151,9 @@ " 321.9456\n", " sleep\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -153,6 +163,9 @@ " 2475.2456\n", " sleep\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -162,6 +175,9 @@ " 5748.3596\n", " sleep\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -171,6 +187,9 @@ " 6035.4892\n", " sleep\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -180,6 +199,9 @@ " 7481.7872\n", " linear\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -189,6 +211,9 @@ " 9050.3872\n", " linear\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -198,6 +223,9 @@ " 10959.9422\n", " sleep\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -207,6 +235,9 @@ " 13312.2752\n", " sleep\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -216,6 +247,9 @@ " 15073.9652\n", " linear\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -225,6 +259,9 @@ " 17064.4652\n", " bigSquare\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -234,6 +271,9 @@ " 18704.5652\n", " bigSquare\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -243,6 +283,9 @@ " 21714.0652\n", " bigSquare\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -252,6 +295,9 @@ " 23200.5032\n", " wheel\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -261,6 +307,9 @@ " 24717.6612\n", " wheel\n", " 10\n", + " NaN\n", + " NaN\n", + " NaN\n", " Z:\\Data\\Kenji\\ec013.961_974\n", " \n", " \n", @@ -284,24 +333,40 @@ "12 ec013.973_wheel 21714.0652 23200.5032 wheel \n", "13 ec013.974_wheel 23200.5032 24717.6612 wheel \n", "\n", - " behavioralParadigm basepath \n", - "0 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "1 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "2 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "3 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "4 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "5 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "6 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "7 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "8 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "9 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "10 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "11 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "12 10 Z:\\Data\\Kenji\\ec013.961_974 \n", - "13 10 Z:\\Data\\Kenji\\ec013.961_974 " + " behavioralParadigm manipulation stimuli notes \\\n", + "0 10 NaN NaN NaN \n", + "1 10 NaN NaN NaN \n", + "2 10 NaN NaN NaN \n", + "3 10 NaN NaN NaN \n", + "4 10 NaN NaN NaN \n", + "5 10 NaN NaN NaN \n", + "6 10 NaN NaN NaN \n", + "7 10 NaN NaN NaN \n", + "8 10 NaN NaN NaN \n", + "9 10 NaN NaN NaN \n", + "10 10 NaN NaN NaN \n", + "11 10 NaN NaN NaN \n", + "12 10 NaN NaN NaN \n", + "13 10 NaN NaN NaN \n", + "\n", + " basepath \n", + "0 Z:\\Data\\Kenji\\ec013.961_974 \n", + "1 Z:\\Data\\Kenji\\ec013.961_974 \n", + "2 Z:\\Data\\Kenji\\ec013.961_974 \n", + "3 Z:\\Data\\Kenji\\ec013.961_974 \n", + "4 Z:\\Data\\Kenji\\ec013.961_974 \n", + "5 Z:\\Data\\Kenji\\ec013.961_974 \n", + "6 Z:\\Data\\Kenji\\ec013.961_974 \n", + "7 Z:\\Data\\Kenji\\ec013.961_974 \n", + "8 Z:\\Data\\Kenji\\ec013.961_974 \n", + "9 Z:\\Data\\Kenji\\ec013.961_974 \n", + "10 Z:\\Data\\Kenji\\ec013.961_974 \n", + "11 Z:\\Data\\Kenji\\ec013.961_974 \n", + "12 Z:\\Data\\Kenji\\ec013.961_974 \n", + "13 Z:\\Data\\Kenji\\ec013.961_974 " ] }, - "execution_count": 24, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -321,7 +386,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 4. Make tuning curves and detect 2d place fields using the SpatialMap class\n", + "## Section 4: Make tuning curves and detect 2D place fields using the SpatialMap class\n", "\n", "You can see I am specifying positions and spikes within our epoch of choice\n", "\n", @@ -330,16 +395,16 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - " with shape (16, 64, 64)" + " with shape (16, 64, 64)" ] }, - "execution_count": 25, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -364,24 +429,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 4.1 you can also shuffle your data to find which cell has more spatial information than chance\n", - "\n", - "Depending on how many cells you have this can take a bit of time, but shouldn't take more than a minute with the default 500 shuffles\n", - "\n", - "#### 4.2 There are many more class methods available within spatial_maps.tc such as:\n", - "\n", - "* spatial_information\n", - "* smoothing\n", - "* spatial_sparsity\n", - "* occupancy\n", - "* max\n", - "* min\n", - "* n_fields\n", - "* field_width\n", - "* field_peak_rate\n", - "* field_mask\n", - "\n", - "etc." + "You can also shuffle your data to find which cell has more spatial information\n", + "than chance. Depending on how many cells you have this can take a bit of time,\n", + "but it shouldn't take more than a minute with the default 500 shuffles." ] }, { @@ -397,7 +447,68 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 5. Inspect the results by looking at the tuning curves and spikes on path plots" + "There are many more class methods available within `spatial_maps.tc`:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bin_centers',\n", + " 'bins',\n", + " 'field_mask',\n", + " 'field_peak_rate',\n", + " 'field_width',\n", + " 'information_rate',\n", + " 'is2d',\n", + " 'isempty',\n", + " 'label',\n", + " 'mask',\n", + " 'max',\n", + " 'mean',\n", + " 'min',\n", + " 'n_bins',\n", + " 'n_fields',\n", + " 'n_units',\n", + " 'n_xbins',\n", + " 'n_ybins',\n", + " 'normalize',\n", + " 'occupancy',\n", + " 'ratemap',\n", + " 'reorder_units_by_ids',\n", + " 'shape',\n", + " 'smooth',\n", + " 'spatial_information',\n", + " 'spatial_selectivity',\n", + " 'spatial_sparsity',\n", + " 'std',\n", + " 'unit_ids',\n", + " 'unit_labels',\n", + " 'unit_tags',\n", + " 'xbin_centers',\n", + " 'xbins',\n", + " 'ybin_centers',\n", + " 'ybins']" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[k for k in dir(spatial_maps.tc) if not k.startswith('_')]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Section 5: Inspect the results by looking at the tuning curves and spikes on path plots" ] }, { @@ -693,7 +804,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6. Now lets make 1d maps using the same class" + "## Section 6: Now lets make 1D maps using the same class" ] }, { @@ -912,9 +1023,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6.1 reconstruct the postion array with linearized coords\n", + "### Section 6.1: Reconstruct the position array with linearized coords\n", "\n", - "note, you can see if you print out nelpy arrays, there is very helpful information" + "Note, you can see if you print out `nelpy` arrays, there is very helpful\n", + "information." ] }, { @@ -947,7 +1059,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6.2 lets plot to see" + "### Section 6.2: Visualize the 1D position" ] }, { @@ -990,7 +1102,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6.2 we need to get outbound and inbound epochs " + "### Section 6.2: Get outbound and inbound epochs " ] }, { @@ -1074,7 +1186,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6.3 Now lets make tuning curves for the outbound trajectories" + "### Section 6.3: Make tuning curves for the outbound trajectories" ] }, { @@ -1097,7 +1209,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6.4 we can visualize with nice nelpy functions" + "### Section 6.4: Visualize the tuning curves" ] }, { @@ -1143,7 +1255,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 6.5 inspect field detection" + "### Section 6.5: Inspect the field detection" ] }, { @@ -1695,7 +1807,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## We can also map continuous variables\n", + "## Section 7: Map continuous behavioral or neurophysiological variables\n", "\n", "* You can map any continuous variable (speed, calcium signals, theta phase, etc.), but here we will use assembly activity" ] @@ -1770,7 +1882,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### visualize assembly weights" + "### Section 7.1: Visualize assembly weights" ] }, { @@ -1803,7 +1915,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### compute time resolved activations for each assembly\n", + "### Section 7.2: Compute time-resolved activations for each assembly\n", "\n", "These are continous signals that we can now map using the SpatialMap class" ] @@ -1833,7 +1945,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### calculate spatial maps for each assembly for both directions" + "### Section 7.3: Calculate spatial maps for each assembly for both directions" ] }, { @@ -1863,7 +1975,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### visualize spatial maps for each assembly" + "### Section 7.4: Visualize spatial maps for each assembly" ] }, { @@ -1918,11 +2030,18 @@ " ax.set_ylabel(\"n assemblies\")\n", " ax.set_xticks([0, tc.bins.max()])" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3.9.15 ('barrage_project')", + "display_name": "44n", "language": "python", "name": "python3" }, @@ -1936,14 +2055,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.19" }, - "orig_nbformat": 4, - "vscode": { - "interpreter": { - "hash": "1e9a962390aac794c3042f2d2c2c89aaf5025083d6ddf7598f81142092f2e4a4" - } - } + "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 From 9930a22eb19a370c9922b1ed91e0c1c441fb7f5e Mon Sep 17 00:00:00 2001 From: Kushaan Gupta Date: Sun, 13 Oct 2024 00:29:52 -0400 Subject: [PATCH 4/4] fix compatibility issue of mkdocs-jupyter with py3.8 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6736da5..b056d81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ dependencies = [ "mkdocs-literate-nav>=0.6.1", "mkdocs-section-index>=0.3.9", "mkdocs-include-markdown-plugin>=6.2.2", - "mkdocs-jupyter>=0.25.0", + "mkdocs-jupyter>=0.24.8", ] [project.urls]