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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 using h5py
# --------------------------
# You can also use h5py to add new datasets to existing groups. Here's an example of
# adding a genotype dataset to the Subject object:

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

# First, let's create a file with a Subject that is missing a genotype
nwbfile = NWBFile(
session_description="example file with subject",
identifier="EXAMPLE_ID",
session_start_time=datetime.now(),
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 a genotype dataset to the Subject using h5py
with h5py.File("test_edit3.nwb", "r+") as f:
# Create the genotype dataset in the subject group
subject_group = f["general/subject"]
subject_group.create_dataset("genotype", data="Sst-IRES-Cre")

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