Skip to content

Commit

Permalink
Update .gitignore to exclude virtual environment directories and enha…
Browse files Browse the repository at this point in the history
…nce documentation on adding datasets with h5py (#2032)

* Update .gitignore to exclude virtual environment directories and enhance documentation on adding datasets with h5py

* Fix session start time to include local timezone in NWBFile example

* Update documentation to demonstrate adding datasets using PyNWB instead of h5py

* Update plot_editing.py

---------

Co-authored-by: Ryan Ly <[email protected]>
  • Loading branch information
bendichter and rly authored Feb 18, 2025
1 parent 5a72510 commit f3b3306
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ docs/build/
docs/source/pynwb.*.rst


# Virtual Environment
venv/
env/
ENV/

# setuptools
build/
dist/
Expand Down
38 changes: 38 additions & 0 deletions docs/gallery/advanced_io/plot_editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,41 @@
"synthetic_timeseries_renamed",
"/analysis/synthetic_timeseries_renamed",
)

##############################################
# Adding datasets to existing groups
# ----------------------------------
# You can add new datasets to existing groups using PyNWB by calling ``set_modified()``.
# Here's an example of adding a genotype to a Subject:

from pynwb import NWBFile, NWBHDF5IO
from pynwb.file import Subject

# First, let's create a file with a Subject that is missing the genotype, which is optional
nwbfile = NWBFile(
session_description="example file with subject",
identifier="EXAMPLE_ID",
session_start_time=datetime.now(tzlocal()),
session_id="LONELYMTN",
subject=Subject(
subject_id="mouse001",
species="Mus musculus",
age="P30D",
)
)

with NWBHDF5IO("test_edit3.nwb", "w") as io:
io.write(nwbfile)

# Now add the genotype using PyNWB and set_modified()
with NWBHDF5IO("test_edit3.nwb", "a") as io:
nwbfile = io.read()
nwbfile.subject.genotype = "Sst-IRES-Cre"
nwbfile.subject.set_modified() # Required to mark the container as modified
io.write(nwbfile)

# Verify the dataset was added
with NWBHDF5IO("test_edit3.nwb", "r") as io:
nwbfile = io.read()
print(f"Subject genotype: {nwbfile.subject.genotype}")
# Output: Subject genotype: Sst-IRES-Cre

0 comments on commit f3b3306

Please sign in to comment.