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

Add example appending to NWB using LINDI and PyNWB #90

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ with lindi.StagingArea.create(base_dir='lindi_staging') as staging_area:
# upload the changes to the remote .nwb.lindi.json file
```

See [this complete example](https://github.com/NeurodataWithoutBorders/lindi/blob/main/examples/example3.py).

### Upload a .nwb.lindi.json file with staged datasets to a cloud storage service such as DANDI

See [this example](https://github.com/magland/lindi-dandi/blob/main/devel/lindi_test_2.py).
Expand Down
35 changes: 35 additions & 0 deletions examples/example3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import lindi
import pynwb
from pynwb import TimeSeries
from pynwb.epoch import TimeIntervals

# URL of the remote .nwb.lindi.json file
url = 'https://lindi.neurosift.org/dandi/dandisets/000713/assets/b2391922-c9a6-43f9-8b92-043be4015e56/nwb.lindi.json'

# Load the h5py-like client for the reference file system
# in read-write mode with a staging area
with lindi.StagingArea.create(base_dir='lindi_staging') as staging_area:
client = lindi.LindiH5pyFile.from_lindi_file(
url,
mode="r+",
staging_area=staging_area
)

with pynwb.NWBHDF5IO(file=client, mode="r+") as io:
nwbfile = io.read()

timeseries = TimeSeries("test_timeseries", description="test", unit="unit", data=[1, 2, 3], timestamps=[1, 2, 3])
nwbfile.add_acquisition(timeseries)

intervals = TimeIntervals("test_timeintervals", description="test")
intervals.add_row(start_time=1.0, stop_time=2.0)
nwbfile.add_time_intervals(intervals)

io.write(nwbfile)

client.write_lindi_file('example.nwb.lindi.json')
# you can open the example.nwb.lindi.json file and confirm that the new timeseries
# and time intervals table are present, under the "refs" key at the keys
# "acquisition/test_timeseries" and "acquisition/test_timeintervals"

# upload example.nwb.lindi.json to DANDI...
Loading