From 96085761b58590196a89cc0ce4bc496141177392 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Fri, 29 Sep 2023 10:22:25 -0400 Subject: [PATCH] Initial commit --- .gitattributes | 1 + .gitignore | 116 +++++++++++++++ LICENSE.txt | 21 +++ MANIFEST.in | 11 ++ NEXTSTEPS.md | 151 ++++++++++++++++++++ README.md | 15 ++ docs/Makefile | 179 ++++++++++++++++++++++++ docs/README.md | 121 ++++++++++++++++ docs/make.bat | 35 +++++ docs/source/_static/theme_overrides.css | 13 ++ docs/source/conf.py | 112 +++++++++++++++ docs/source/conf_doc_autogen.py | 90 ++++++++++++ docs/source/credits.rst | 21 +++ docs/source/description.rst | 5 + docs/source/format.rst | 12 ++ docs/source/index.rst | 30 ++++ docs/source/release_notes.rst | 5 + requirements-dev.txt | 5 + requirements.txt | 3 + setup.cfg | 17 +++ setup.py | 72 ++++++++++ spec/ndx-microscopy.extensions.yaml | 8 ++ spec/ndx-microscopy.namespace.yaml | 14 ++ src/matnwb/README.md | 0 src/pynwb/README.md | 0 src/pynwb/ndx_microscopy/__init__.py | 26 ++++ src/pynwb/tests/__init__.py | 0 src/pynwb/tests/test_tetrodeseries.py | 170 ++++++++++++++++++++++ src/spec/create_extension_spec.py | 55 ++++++++ 29 files changed, 1308 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 MANIFEST.in create mode 100644 NEXTSTEPS.md create mode 100644 README.md create mode 100644 docs/Makefile create mode 100644 docs/README.md create mode 100644 docs/make.bat create mode 100644 docs/source/_static/theme_overrides.css create mode 100644 docs/source/conf.py create mode 100644 docs/source/conf_doc_autogen.py create mode 100644 docs/source/credits.rst create mode 100644 docs/source/description.rst create mode 100644 docs/source/format.rst create mode 100644 docs/source/index.rst create mode 100644 docs/source/release_notes.rst create mode 100644 requirements-dev.txt create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 spec/ndx-microscopy.extensions.yaml create mode 100644 spec/ndx-microscopy.namespace.yaml create mode 100644 src/matnwb/README.md create mode 100644 src/pynwb/README.md create mode 100644 src/pynwb/ndx_microscopy/__init__.py create mode 100644 src/pynwb/tests/__init__.py create mode 100644 src/pynwb/tests/test_tetrodeseries.py create mode 100644 src/spec/create_extension_spec.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4ce3503 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.rst whitespace=tab-in-indent conflict-marker-size=79 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf7a218 --- /dev/null +++ b/.gitignore @@ -0,0 +1,116 @@ +# output NWB files +*.nwb + +# generated docs +docs/source/_format_auto_docs + +# copied spec files +src/pynwb/ndx_microscopy/spec/*.yaml + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Mac finder +.DS_Store diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..636d369 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Cody Baker and Alessandra Trapani + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..079351b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,11 @@ +include LICENSE.txt +include README.md +include requirements.txt + +include spec/*.yaml + +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include docs *.css *.rst conf.py conf_doc_autogen.py Makefile make.bat README.md diff --git a/NEXTSTEPS.md b/NEXTSTEPS.md new file mode 100644 index 0000000..080f778 --- /dev/null +++ b/NEXTSTEPS.md @@ -0,0 +1,151 @@ + + +# Next Steps for ndx-microscopy Extension for NWB + +## Creating Your Extension + +1. In a terminal, change directory into the new ndx-microscopy directory. + +2. Add any packages required by your extension to `requirements.txt` and `setup.py`. + +3. Run `python -m pip install -r requirements.txt -r requirements-dev.txt` to install the `pynwb` package +and any other packages required to install, develop, and document your extension. + +4. Modify `src/spec/create_extension_spec.py` to define your extension. + +5. Run `python src/spec/create_extension_spec.py` to generate the +`spec/ndx-microscopy.namespace.yaml` and +`spec/ndx-microscopy.extensions.yaml` files. + +6. Define API classes for your new extension data types. + + - As a starting point, `src/pynwb/__init__.py` includes an example for how to use + the `pynwb.get_class` to get a basic Python class for your new extension data + type. This class contains a constructor and properties for the new data type. + - Instead of using `pynwb.get_class`, you can define your own custom class for the + new type, which will allow you to customize the class methods, customize the + object mapping, and create convenience functions. See + [https://pynwb.readthedocs.io/en/stable/tutorials/general/extensions.html](https://pynwb.readthedocs.io/en/stable/tutorials/general/extensions.html) + for more details. + +7. Define tests for your new extension data types in `src/pynwb/tests` or `src/matnwb/tests`. +A test for the example `TetrodeSeries` data type is provided as a reference and should be +replaced or removed. + + - Python tests should be runnable by executing [`pytest`](https://docs.pytest.org/en/latest/) + from the root of the extension directory. Use of PyNWB testing infrastructure from + `pynwb.testing` is encouraged (see + [documentation](https://pynwb.readthedocs.io/en/stable/pynwb.testing.html)). + - Creating both **unit tests** (e.g., testing initialization of new data type classes and + new functions) and **integration tests** (e.g., write the new data types to file, read + the file, and confirm the read data types are equal to the written data types) is + highly encouraged. + +8. You may need to modify `setup.py` and re-run `python setup.py install` if you +use any dependencies. + + +## Documenting and Publishing Your Extension to the Community + +1. Install the latest release of hdmf_docutils: `python -m pip install hdmf-docutils` + +2. Start a git repository for your extension directory ndx-microscopy + and push it to GitHub. You will need a GitHub account. + - Follow these directions: + https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line + +3. Change directory into `docs`. + +4. Run `make html` to generate documentation for your extension based on the YAML files. + +5. Read `docs/README.md` for instructions on how to customize documentation for +your extension. + +6. Modify `README.md` to describe this extension for interested developers. + +7. Add a license file. Permissive licenses should be used if possible. **A [BSD license](https://opensource.org/licenses/BSD-3-Clause) is recommended.** + +8. Make a release for the extension on GitHub with the version number specified. e.g. if version is 0.1.0, then this page should exist: https://github.com/CodyCBakerPhD/ndx-microscopy/releases/tag/0.1.0 . For instructions on how to make a release on GitHub see [here](https://help.github.com/en/github/administering-a-repository/creating-releases). + +9. Publish your updated extension on [PyPI](https://pypi.org/). + - Follow these directions: https://packaging.python.org/tutorials/packaging-projects/ + - You may need to modify `setup.py` + - If your extension version is 0.1.0, then this page should exist: https://pypi.org/project/ndx-microscopy/0.1.0 + + Once your GitHub release and ``setup.py`` are ready, publishing on PyPI: + ```bash + python setup.py sdist bdist_wheel + twine upload dist/* + ``` + +10. Go to https://github.com/nwb-extensions/staged-extensions and fork the +repository. + +11. Clone the fork onto your local filesystem. + +12. Copy the directory `staged-extensions/example` to a new directory +`staged-extensions/ndx-microscopy`: + + ```bash + cp -r staged-extensions/example staged-extensions/ndx-microscopy + ``` + +13. Edit `staged-extensions/ndx-microscopy/ndx-meta.yaml` +with information on where to find your NWB extension. + - The YAML file MUST contain a dict with the following keys: + - name: extension namespace name + - version: extension version + - src: URL for the main page of the public repository (e.g. on GitHub, BitBucket, GitLab) that contains the sources of the extension + - pip: URL for the main page of the extension on PyPI + - license: name of the license of the extension + - maintainers: list of GitHub usernames of those who will reliably maintain the extension + - You may copy and modify the following YAML that was auto-generated: + + ```yaml + name: ndx-microscopy + version: 0.1.0 + src: https://github.com/CodyCBakerPhD/ndx-microscopy + pip: https://pypi.org/project/ndx-microscopy/ + license: MIT + maintainers: + - CodyCBakerPhD + ``` + +14. Edit `staged-extensions/ndx-microscopy/README.md` +to add information about your extension. You may copy it from +`ndx-microscopy/README.md`. + + ```bash + cp ndx-microscopy/README.md staged-extensions/ndx-microscopy/README.md + ``` + +15. Add and commit your changes to Git and push your changes to GitHub. +``` +cd staged-extensions +git add ndx-microscopy +git commit -m "Add new catalog entry for ndx-microscopy" . +git push +``` + +16. Open a pull request. Building of your extension will be tested on Windows, +Mac, and Linux. The technical team will review your extension shortly after +and provide feedback and request changes, if any. + +17. When your pull request is merged, a new repository, called +ndx-microscopy-record will be created in the nwb-extensions +GitHub organization and you will be added as a maintainer for that repository. + + +## Updating Your Published Extension + +1. Update your ndx-microscopy GitHub repository. + +2. Publish your updated extension on PyPI. + +3. Fork the ndx-microscopy-record repository on GitHub. + +4. Open a pull request to test the changes automatically. The technical team +will review your changes shortly after and provide feedback and request changes, +if any. + +5. Your updated extension is approved. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b1b6576 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# ndx-microscopy Extension for NWB + +Description of the extension + +## Installation + + +## Usage + +```python + +``` + +--- +This extension was created using [ndx-template](https://github.com/nwb-extensions/ndx-template). diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..54e6545 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,179 @@ + +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXAPIDOC = sphinx-apidoc +PAPER = +BUILDDIR = build +SRCDIR = ../src +RSTDIR = source +CONFDIR = $(PWD)/source + + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext fulldoc allclean + +help: + @echo "To update documentation sources from the format specification please use \`make apidoc'" + @echo "" + @echo "To build the documentation please use \`make ' where is one of" + @echo " fulldoc to rebuild the apidoc, html, and latexpdf all at once" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " apidoc to to build RST from source code" + @echo " clean to clean all documents built by Sphinx in _build" + @echo " allclean to clean all autogenerated documents both from Sphinx and apidoc" + +allclean: + -rm -rf $(BUILDDIR)/* $(RSTDIR)/modules.rst + -rm $(RSTDIR)/_format_auto_docs/*.png + -rm $(RSTDIR)/_format_auto_docs/*.pdf + -rm $(RSTDIR)/_format_auto_docs/*.rst + -rm $(RSTDIR)/_format_auto_docs/*.inc + +clean: + -rm -rf $(BUILDDIR)/* $(RSTDIR)/modules.rst + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/sample.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/sample.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/sample" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/sample" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " "results in $(BUILDDIR)/doctest/output.txt." + +apidoc: + PYTHONPATH=$(CONFDIR):$(PYTHONPATH) nwb_generate_format_docs + @echo + @echo "Generate rst source files from NWB spec." + +fulldoc: + $(MAKE) allclean + @echo + @echo "Rebuilding apidoc, html, latexpdf" + $(MAKE) apidoc + $(MAKE) html + $(MAKE) latexpdf diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..9a3a30d --- /dev/null +++ b/docs/README.md @@ -0,0 +1,121 @@ + +# Getting started + +## Generate Documentation + +* To generate the HTML version of your documentation run ``make html``. +* The [hdmf-docutils](https://pypi.org/project/hdmf-docutils/) package must be installed. + +## Customize Your Extension Documentation + +* **extension description** + * Edit ``source/description.rst`` to describe your extension. + +* **release notes** + * Edit ``source/release_notes.rst`` to document improvements and fixes of your extension. + +* **documentation build settings** + * Edit ``source/conf.py`` to customize your extension documentation configuration. + * Edit ``source/conf_doc_autogen.py`` to customize the format documentation auto-generation based on + the YAML specification files. + + +# Overview + +The specification documentation uses Sphinx [http://www.sphinx-doc.org/en/stable/index.html](http://www.sphinx-doc.org/en/stable/index.html) + +## Rebuilding All + +To rebuild the full documentation in html, latex, and PDF simply run: + +``` +make fulldoc +``` + +This is a convenience function that is equivalent to: + +``` +make allclean +make apidoc +make html +make latexpdf +``` + +## Generating the format documentation from the format spec + +The format documentation is auto-generated from the format specification (YAML) sources via: + +``` +make apidoc +``` + +This will invoke the executable: + +``` +hdmf_generate_format_docs +``` + +The script automatically generates a series of .rst, .png, and .pdf files that are stored in the folder `source/format_auto_docs`. The generated .rst files are included in `source/format.rst` and the png and pdf files are used as figures in the autogenerated docs. + +The folder `source/format_auto_docs` is reserved for autogenerated files, i.e., files in the folder should not be added or edited by hand as they will be deleted and rebuilt during the full built of the documentation. + +By default the Sphinx configuration is setup to always regenerate the sources whenever the docs are being built (see next section). This behavior can be customized via the `spec_doc_rebuild_always` parameter in `source/conf.py` + +## Building a specific document type + +To build the documentation, run: + +``` +make +``` + +where `` is, e.g., `latexpdf`, `html`, `singlehtml`, or `man`. For a complete list of supported doc-types, see: + +``` +make help +``` + +## Cleaning up + +`make clean` cleans up all builds of the documentation located in `_build`. + +`make allclean` cleans up all builds of the documentation located in `_build` as well as all autogenerated sources stored in `source/format_auto_docs`. + +## Configuration + +The build of the documentation can be customized via a broad range of Sphinx options in: + +`source/conf_doc_autogen.py` + +In addition to standard Sphinx options, there are a number of additional options used to customize the content and structure of the autogenerated documents, e.g.: + +* `spec_show_yaml_src` - Boolean indicating whether the YAML sources should be included for the different Neurodata types +* `spec_generate_src_file` - Boolean indicating whether the YAML sources of the neurodata_types should be rendered in a separate section (True) or in the same location as the main documentation +* `spec_show_hierarchy_plots` - Boolean indicating whether we should generate and show figures of the hierarchy defined by the specifications as part of the documentation +* `spec_file_per_type` - Boolean indicating whether we should generate separate .inc reStructuredText for each neurodata_type (True) +or should all text be added to the main file (False) +* `spec_show_subgroups_in_tables` - Should subgroups of the main groups be rendered in the table as well. Usually this is disabled since groups are rendered as separate sections in the text +* `spec_appreviate_main_object_doc_in_tables` - Abbreviate the documentation of the main object for which a table is rendered in the table. This is commonly set to True as doc of the main object is already rendered as the main intro for the section describing the object +* `spec_show_title_for_tables` - Add a title for the table showing the specifications. +* `spec_show_subgroups_in_seperate_table` - Should top-level subgroups be listed in a separate table or as part of the main dataset and attributes table +* `spec_table_depth_char` - Char to be used as prefix to indicate the depth of an object in the specification hierarchy. NOTE: The char used should be supported by LaTeX. +* `spec_add_latex_clearpage_after_ndt_sections` - Add a LaTeX clearpage after each main section describing a neurodata_type. This helps in LaTeX to keep the ordering of figures, tables, and code blocks consistent in particular when the hierarchy_plots are included. +* `spec_resolve_type_inc` - Resolve includes to always show the full list of objects that are part of a type (True) or to show only the parts that are actually new to a current type while only linking to base types (False) + +In addition, the location of the input format specification can be customized as follows: + +* `spec_input_spec_dir` - Directory where the YAML files for the namespace to be documented are located +* `spec_input_namespace_filename` - Name of the YAML file with the specification of the Namespace to be documented +* `spec_input_default_namespace` - Name of the default namespace in the file + +Finally, the name and location of output files can be customized as follows: + +* `spec_output_dir` - Directory where the autogenerated files should be stored +* `spec_output_master_filename` - Name of the master .rst file that includes all the autogenerated docs +* `spec_output_doc_filename` - Name of the file where the main documentation goes +* `spec_output_src_filename` - Name of the file where the sources of the format spec go. NOTE: This file is only generated if `spec_generate_src_file` is enabled +* `spec_output_doc_type_hierarchy_filename` - Name of the file containing the type hierarchy. (Included in `spec_output_doc_filename`) + +In the regular Sphinx `source/conf.py` file, we can then also set: + +* `spec_doc_rebuild_always` - Boolean to define whether to always rebuild the source docs from YAML when doing a regular build of the sources (e.g., via `make html`) even if the folder with the source files already exists diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..dc1312a --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/source/_static/theme_overrides.css b/docs/source/_static/theme_overrides.css new file mode 100644 index 0000000..63ee6cc --- /dev/null +++ b/docs/source/_static/theme_overrides.css @@ -0,0 +1,13 @@ +/* override table width restrictions */ +@media screen and (min-width: 767px) { + + .wy-table-responsive table td { + /* !important prevents the common CSS stylesheets from overriding + this as on RTD they are loaded after this stylesheet */ + white-space: normal !important; + } + + .wy-table-responsive { + overflow: visible !important; + } +} diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..90cb378 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,112 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'ndx-microscopy' +copyright = '2023, Cody Baker and Alessandra Trapani' +author = 'Cody Baker and Alessandra Trapani' + +version = '0.1.0' +release = 'alpha' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + 'sphinx.ext.ifconfig', + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', +] + +templates_path = ['_templates'] +exclude_patterns = [] + +language = 'en' + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'alabaster' +html_static_path = ['_static'] + +# -- Options for intersphinx extension --------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#configuration + +intersphinx_mapping = { + 'python': ('https://docs.python.org/3', None), +} + + +############################################################################ +# CUSTOM CONFIGURATIONS ADDED BY THE NWB TOOL FOR GENERATING FORMAT DOCS +########################################################################### + +import sphinx_rtd_theme # noqa: E402 +import textwrap # noqa: E402 + +# -- Options for intersphinx --------------------------------------------- +intersphinx_mapping.update({ + 'core': ('https://nwb-schema.readthedocs.io/en/latest/', None), + 'hdmf-common': ('https://hdmf-common-schema.readthedocs.io/en/latest/', None), +}) + +# -- Generate sources from YAML--------------------------------------------------- +# Always rebuild the source docs from YAML even if the folder with the source files already exists +spec_doc_rebuild_always = True + + +def run_doc_autogen(_): + # Execute the autogeneration of Sphinx format docs from the YAML sources + import sys + import os + conf_file_dir = os.path.dirname(os.path.abspath(__file__)) + sys.path.append(conf_file_dir) # Need so that generate format docs can find the conf_doc_autogen file + from conf_doc_autogen import spec_output_dir + + if spec_doc_rebuild_always or not os.path.exists(spec_output_dir): + sys.path.append('./docs') # needed to enable import of generate_format docs + from hdmf_docutils.generate_format_docs import main as generate_docs + generate_docs() + + +def setup(app): + app.connect('builder-inited', run_doc_autogen) + # overrides for wide tables in RTD theme + try: + app.add_css_file("theme_overrides.css") # Used by newer Sphinx versions + except AttributeError: + app.add_stylesheet("theme_overrides.css") # Used by older version of Sphinx + +# -- Customize sphinx settings +numfig = True +autoclass_content = 'both' +autodoc_docstring_signature = True +autodoc_member_order = 'bysource' +add_function_parentheses = False + + +# -- HTML sphinx options +html_theme = "sphinx_rtd_theme" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + +# LaTeX Sphinx options +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + 'preamble': textwrap.dedent( + ''' + \\setcounter{tocdepth}{3} + \\setcounter{secnumdepth}{6} + \\usepackage{enumitem} + \\setlistdepth{100} + '''), +} diff --git a/docs/source/conf_doc_autogen.py b/docs/source/conf_doc_autogen.py new file mode 100644 index 0000000..aed891b --- /dev/null +++ b/docs/source/conf_doc_autogen.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +# Configuration file for generating sources for the format documentation from the YAML specification files + +import os + +# -- Input options for the specification files to be used ----------------------- + +# Directory where the YAML files for the namespace to be documented are located +spec_input_spec_dir = '..\spec' + +# Name of the YAML file with the specification of the Namespace to be documented +spec_input_namespace_filename = 'ndx-microscopy.namespace.yaml' + +# Name of the default namespace in the file +spec_input_default_namespace = 'ndx-microscopy' + + +# -- Options for customizing the locations of output files + +# Directory where the autogenerated files should be stored +spec_output_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "_format_auto_docs") + +# Name of the master rst file that includes all the autogenerated docs +spec_output_master_filename = 'format_spec_main.inc' + +# Name of the file where the main documentation goes +spec_output_doc_filename = 'format_spec_doc.inc' + +# Name of the file where the sources of the format spec go. NOTE: This file is only generated if +# spec_generate_src_file is enabled +spec_output_src_filename = 'format_spec_sources.inc' + +# Name of the file containing the type hierarchy. (Included in spec_output_doc_filename) +spec_output_doc_type_hierarchy_filename = 'format_spec_type_hierarchy.inc' + +# Clean up the output directory before we build if the git hash is out of date +spec_clean_output_dir_if_old_git_hash = True + +# Do not rebuild the format sources if we have previously build the sources and the git hash matches +spec_skip_doc_autogen_if_current_git_hash = False + + +# -- Options for the generation of the documentation from source ---------------- + +# Should the YAML sources be included for the different modules +spec_show_yaml_src = True + +# Show figure of the hierarchy of objects defined by the spec +spec_show_hierarchy_plots = True + +# Should the sources of the neurodata_types (YAML) be rendered in a separate section (True) or +# in the same location as the base documentation +spec_generate_src_file = True + +# Should separate .inc reStructuredText files be generated for each neurodata_type (True) +# or should all text be added to the main file +spec_file_per_type = True + +# Should top-level subgroups be listed in a separate table or as part of the main dataset and attributes table +spec_show_subgroups_in_seperate_table = True + +# Abbreviate the documentation of the main object for which a table is rendered in the table. +# This is commonly set to True as doc of the main object is alrready rendered as the main intro for the +# section describing the object +spec_appreviate_main_object_doc_in_tables = True + +# Show a title for the tables +spec_show_title_for_tables = True + +# Char to be used as prefix to indicate the depth of an object in the specification hierarchy +spec_table_depth_char = '.' # '→' '.' + +# Add a LaTeX clearpage after each main section describing a neurodata_type. This helps in LaTeX to keep the ordering +# of figures, tables, and code blocks consistent in particular when the hierarchy_plots are included +spec_add_latex_clearpage_after_ndt_sections = True + +# Resolve includes to always show the full list of objects that are part of a type (True) +# or to show only the parts that are actually new to a current type while only linking to base types +spec_resolve_type_inc = False + +# Default type map to be used. This is the type map where dependent namespaces are stored. In the case of +# NWB this is spec_default_type_map = pynwb.get_type_map() +import pynwb # noqa: E402 +spec_default_type_map = pynwb.get_type_map() + +# Default specification classes for groups datasets and namespaces. In the case of NWB these are the NWB-specfic +# spec classes. In the general cases these are the spec classes from HDMF +spec_group_spec_cls = pynwb.spec.NWBGroupSpec +spec_dataset_spec_cls = pynwb.spec.NWBDatasetSpec +spec_namespace_spec_cls = pynwb.spec.NWBNamespace diff --git a/docs/source/credits.rst b/docs/source/credits.rst new file mode 100644 index 0000000..da5cda1 --- /dev/null +++ b/docs/source/credits.rst @@ -0,0 +1,21 @@ +******* +Credits +******* + +.. note:: + Add the credits for your extension here + +Acknowledgments +=============== + + +Authors +======= + + +***** +Legal +***** + +License +======= diff --git a/docs/source/description.rst b/docs/source/description.rst new file mode 100644 index 0000000..6f8553e --- /dev/null +++ b/docs/source/description.rst @@ -0,0 +1,5 @@ +Overview +======== + +.. note:: + Add the description of your extension here diff --git a/docs/source/format.rst b/docs/source/format.rst new file mode 100644 index 0000000..4b88782 --- /dev/null +++ b/docs/source/format.rst @@ -0,0 +1,12 @@ + +.. _ndx-microscopy: + +************** +ndx-microscopy +************** + +Version |release| |today| + +.. .. contents:: + +.. include:: _format_auto_docs/format_spec_main.inc diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..207c9a0 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,30 @@ +Specification for the ndx-microscopy extension +============================================== + +.. toctree:: + :numbered: + :maxdepth: 8 + :caption: Table of Contents + + description + +.. toctree:: + :numbered: + :maxdepth: 3 + :caption: Extension Specification + + format + +.. toctree:: + :maxdepth: 2 + :caption: History & Legal + + release_notes + credits + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/release_notes.rst b/docs/source/release_notes.rst new file mode 100644 index 0000000..39ccd1c --- /dev/null +++ b/docs/source/release_notes.rst @@ -0,0 +1,5 @@ +Release Notes +============= + +.. note:: + Add the release notes of your extension here diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..1482a06 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,5 @@ +# pinned dependencies to reproduce an entire development environment to run tests and check code style +flake8==4.0.1 +pytest==6.2.5 +pytest-subtests==0.6.0 +hdmf-docutils==0.4.4 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1709b58 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# pinned dependencies to reproduce a working development environment +hdmf==3.1.1 +pynwb==2.0.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..f6c4008 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,17 @@ +[wheel] +universal = 1 + +[flake8] +max-line-length = 120 +max-complexity = 17 +exclude = + .git, + .tox, + __pycache__, + build/, + dist/, + docs/source/conf.py + versioneer.py + +[metadata] +description-file = README.md diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..25d401a --- /dev/null +++ b/setup.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +import os + +from setuptools import setup, find_packages +from shutil import copy2 + +# load README.md/README.rst file +try: + if os.path.exists('README.md'): + with open('README.md', 'r') as fp: + readme = fp.read() + readme_type = 'text/markdown; charset=UTF-8' + elif os.path.exists('README.rst'): + with open('README.rst', 'r') as fp: + readme = fp.read() + readme_type = 'text/x-rst; charset=UTF-8' + else: + readme = "" +except Exception: + readme = "" + +setup_args = { + 'name': 'ndx-microscopy', + 'version': '0.1.0', + 'description': 'An example extension to demonstrate the TAB proposal for enhancements to optical physiology neurodata types.', + 'long_description': readme, + 'long_description_content_type': readme_type, + 'author': 'Cody Baker and Alessandra Trapani', + 'author_email': 'cody.baker@catalystneuro.com', + 'url': '', + 'license': 'MIT', + 'install_requires': [ + 'pynwb>=1.5.0,<3', + 'hdmf>=2.5.6,<4', + ], + 'packages': find_packages('src/pynwb', exclude=["tests", "tests.*"]), + 'package_dir': {'': 'src/pynwb'}, + 'package_data': {'ndx_microscopy': [ + 'spec/ndx-microscopy.namespace.yaml', + 'spec/ndx-microscopy.extensions.yaml', + ]}, + 'classifiers': [ + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License" + ], + 'keywords': [ + 'NeurodataWithoutBorders', + 'NWB', + 'nwb-extension', + 'ndx-extension' + ], + 'zip_safe': False +} + + +def _copy_spec_files(project_dir): + ns_path = os.path.join(project_dir, 'spec', 'ndx-microscopy.namespace.yaml') + ext_path = os.path.join(project_dir, 'spec', 'ndx-microscopy.extensions.yaml') + + dst_dir = os.path.join(project_dir, 'src', 'pynwb', 'ndx_microscopy', 'spec') + if not os.path.exists(dst_dir): + os.mkdir(dst_dir) + + copy2(ns_path, dst_dir) + copy2(ext_path, dst_dir) + + +if __name__ == '__main__': + _copy_spec_files(os.path.dirname(__file__)) + setup(**setup_args) diff --git a/spec/ndx-microscopy.extensions.yaml b/spec/ndx-microscopy.extensions.yaml new file mode 100644 index 0000000..fa9a0ff --- /dev/null +++ b/spec/ndx-microscopy.extensions.yaml @@ -0,0 +1,8 @@ +groups: +- neurodata_type_def: TetrodeSeries + neurodata_type_inc: ElectricalSeries + doc: An extension of ElectricalSeries to include the tetrode ID for each time series. + attributes: + - name: trode_id + dtype: int32 + doc: The tetrode ID. diff --git a/spec/ndx-microscopy.namespace.yaml b/spec/ndx-microscopy.namespace.yaml new file mode 100644 index 0000000..9dc616d --- /dev/null +++ b/spec/ndx-microscopy.namespace.yaml @@ -0,0 +1,14 @@ +namespaces: +- author: + - Cody Baker and Alessandra Trapani + contact: + - cody.baker@catalystneuro.com + doc: An example extension to demonstrate the TAB proposal for enhancements to optical + physiology neurodata types. + name: ndx-microscopy + schema: + - namespace: core + neurodata_types: + - ElectricalSeries + - source: ndx-microscopy.extensions.yaml + version: 0.1.0 diff --git a/src/matnwb/README.md b/src/matnwb/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/pynwb/README.md b/src/pynwb/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/pynwb/ndx_microscopy/__init__.py b/src/pynwb/ndx_microscopy/__init__.py new file mode 100644 index 0000000..aeb3c06 --- /dev/null +++ b/src/pynwb/ndx_microscopy/__init__.py @@ -0,0 +1,26 @@ +import os +from pynwb import load_namespaces, get_class + +# Set path of the namespace.yaml file to the expected install location +ndx_microscopy_specpath = os.path.join( + os.path.dirname(__file__), + 'spec', + 'ndx-microscopy.namespace.yaml' +) + +# If the extension has not been installed yet but we are running directly from +# the git repo +if not os.path.exists(ndx_microscopy_specpath): + ndx_microscopy_specpath = os.path.abspath(os.path.join( + os.path.dirname(__file__), + '..', '..', '..', + 'spec', + 'ndx-microscopy.namespace.yaml' + )) + +# Load the namespace +load_namespaces(ndx_microscopy_specpath) + +# TODO: import your classes here or define your class using get_class to make +# them accessible at the package level +TetrodeSeries = get_class('TetrodeSeries', 'ndx-microscopy') diff --git a/src/pynwb/tests/__init__.py b/src/pynwb/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pynwb/tests/test_tetrodeseries.py b/src/pynwb/tests/test_tetrodeseries.py new file mode 100644 index 0000000..489297e --- /dev/null +++ b/src/pynwb/tests/test_tetrodeseries.py @@ -0,0 +1,170 @@ +import datetime +import numpy as np + +from pynwb import NWBHDF5IO, NWBFile +from pynwb.core import DynamicTableRegion +from pynwb.device import Device +from pynwb.ecephys import ElectrodeGroup +from pynwb.file import ElectrodeTable as get_electrode_table +from pynwb.testing import TestCase, remove_test_file, AcquisitionH5IOMixin + +from ndx_microscopy import TetrodeSeries + + +def set_up_nwbfile(): + nwbfile = NWBFile( + session_description='session_description', + identifier='identifier', + session_start_time=datetime.datetime.now(datetime.timezone.utc) + ) + + device = nwbfile.create_device( + name='device_name' + ) + + electrode_group = nwbfile.create_electrode_group( + name='electrode_group', + description='description', + location='location', + device=device + ) + + for i in np.arange(10.): + nwbfile.add_electrode( + x=i, + y=i, + z=i, + imp=np.nan, + location='location', + filtering='filtering', + group=electrode_group + ) + + return nwbfile + + +class TestTetrodeSeriesConstructor(TestCase): + + def setUp(self): + """Set up an NWB file. Necessary because TetrodeSeries requires references to electrodes.""" + self.nwbfile = set_up_nwbfile() + + def test_constructor(self): + """Test that the constructor for TetrodeSeries sets values as expected.""" + all_electrodes = self.nwbfile.create_electrode_table_region( + region=list(range(0, 10)), + description='all the electrodes' + ) + + data = np.random.rand(100, 3) + tetrode_series = TetrodeSeries( + name='name', + description='description', + data=data, + rate=1000., + electrodes=all_electrodes, + trode_id=1 + ) + + self.assertEqual(tetrode_series.name, 'name') + self.assertEqual(tetrode_series.description, 'description') + np.testing.assert_array_equal(tetrode_series.data, data) + self.assertEqual(tetrode_series.rate, 1000.) + self.assertEqual(tetrode_series.starting_time, 0) + self.assertEqual(tetrode_series.electrodes, all_electrodes) + self.assertEqual(tetrode_series.trode_id, 1) + + +class TestTetrodeSeriesRoundtrip(TestCase): + """Simple roundtrip test for TetrodeSeries.""" + + def setUp(self): + self.nwbfile = set_up_nwbfile() + self.path = 'test.nwb' + + def tearDown(self): + remove_test_file(self.path) + + def test_roundtrip(self): + """ + Add a TetrodeSeries to an NWBFile, write it to file, read the file, and test that the TetrodeSeries from the + file matches the original TetrodeSeries. + """ + all_electrodes = self.nwbfile.create_electrode_table_region( + region=list(range(0, 10)), + description='all the electrodes' + ) + + data = np.random.rand(100, 3) + tetrode_series = TetrodeSeries( + name='TetrodeSeries', + description='description', + data=data, + rate=1000., + electrodes=all_electrodes, + trode_id=1 + ) + + self.nwbfile.add_acquisition(tetrode_series) + + with NWBHDF5IO(self.path, mode='w') as io: + io.write(self.nwbfile) + + with NWBHDF5IO(self.path, mode='r', load_namespaces=True) as io: + read_nwbfile = io.read() + self.assertContainerEqual(tetrode_series, read_nwbfile.acquisition['TetrodeSeries']) + + +class TestTetrodeSeriesRoundtripPyNWB(AcquisitionH5IOMixin, TestCase): + """Complex, more complete roundtrip test for TetrodeSeries using pynwb.testing infrastructure.""" + + def setUpContainer(self): + """ Return the test TetrodeSeries to read/write """ + self.device = Device( + name='device_name' + ) + + self.group = ElectrodeGroup( + name='electrode_group', + description='description', + location='location', + device=self.device + ) + + self.table = get_electrode_table() # manually create a table of electrodes + for i in np.arange(10.): + self.table.add_row( + x=i, + y=i, + z=i, + imp=np.nan, + location='location', + filtering='filtering', + group=self.group, + group_name='electrode_group' + ) + + all_electrodes = DynamicTableRegion( + data=list(range(0, 10)), + description='all the electrodes', + name='electrodes', + table=self.table + ) + + data = np.random.rand(100, 3) + tetrode_series = TetrodeSeries( + name='name', + description='description', + data=data, + rate=1000., + electrodes=all_electrodes, + trode_id=1 + ) + return tetrode_series + + def addContainer(self, nwbfile): + """Add the test TetrodeSeries and related objects to the given NWBFile.""" + nwbfile.add_device(self.device) + nwbfile.add_electrode_group(self.group) + nwbfile.set_electrode_table(self.table) + nwbfile.add_acquisition(self.container) diff --git a/src/spec/create_extension_spec.py b/src/spec/create_extension_spec.py new file mode 100644 index 0000000..bdaa367 --- /dev/null +++ b/src/spec/create_extension_spec.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +import os.path + +from pynwb.spec import NWBNamespaceBuilder, export_spec, NWBGroupSpec, NWBAttributeSpec +# TODO: import other spec classes as needed +# from pynwb.spec import NWBDatasetSpec, NWBLinkSpec, NWBDtypeSpec, NWBRefSpec + + +def main(): + # these arguments were auto-generated from your cookiecutter inputs + ns_builder = NWBNamespaceBuilder( + doc="""An example extension to demonstrate the TAB proposal for enhancements to optical physiology neurodata types.""", + name="""ndx-microscopy""", + version="""0.1.0""", + author=list(map(str.strip, """Cody Baker and Alessandra Trapani""".split(','))), + contact=list(map(str.strip, """cody.baker@catalystneuro.com""".split(','))) + ) + + # TODO: specify the neurodata_types that are used by the extension as well + # as in which namespace they are found. + # this is similar to specifying the Python modules that need to be imported + # to use your new data types. + # all types included or used by the types specified here will also be + # included. + ns_builder.include_type('ElectricalSeries', namespace='core') + + # TODO: define your new data types + # see https://pynwb.readthedocs.io/en/latest/extensions.html#extending-nwb + # for more information + tetrode_series = NWBGroupSpec( + neurodata_type_def='TetrodeSeries', + neurodata_type_inc='ElectricalSeries', + doc=('An extension of ElectricalSeries to include the tetrode ID for ' + 'each time series.'), + attributes=[ + NWBAttributeSpec( + name='trode_id', + doc='The tetrode ID.', + dtype='int32' + ) + ], + ) + + # TODO: add all of your new data types to this list + new_data_types = [tetrode_series] + + # export the spec to yaml files in the spec folder + output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'spec')) + export_spec(ns_builder, new_data_types, output_dir) + print('Spec files generated. Please make sure to rerun `pip install .` to load the changes.') + + +if __name__ == '__main__': + # usage: python create_extension_spec.py + main()