Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Feb 18, 2025
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
Loading