Skip to content

Commit

Permalink
Merge branch 'dev' into fix/one_photon_series
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter authored Mar 14, 2023
2 parents 9f67694 + 60ec5db commit 76aa95b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 101 deletions.
102 changes: 57 additions & 45 deletions docs/gallery/advanced_io/linking_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_linking_data.png'
from datetime import datetime
from uuid import uuid4

from dateutil.tz import tzlocal
from pynwb import NWBFile
from pynwb import TimeSeries
Expand All @@ -66,7 +68,6 @@

# Create the base data
start_time = datetime(2017, 4, 3, 11, tzinfo=tzlocal())
create_date = datetime(2017, 4, 15, 12, tzinfo=tzlocal())
data = np.arange(1000).reshape((100, 10))
timestamps = np.arange(100)
filename1 = 'external1_example.nwb'
Expand All @@ -75,36 +76,45 @@
filename4 = 'external_linkdataset_example.nwb'

# Create the first file
nwbfile1 = NWBFile(session_description='demonstrate external files',
identifier='NWBE1',
session_start_time=start_time,
file_create_date=create_date)
nwbfile1 = NWBFile(
session_description="my first synthetic recording",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)
# Create the second file
test_ts1 = TimeSeries(name='test_timeseries1',
data=data,
unit='SIunit',
timestamps=timestamps)
nwbfile1.add_acquisition(test_ts1)

# Write the first file
io = NWBHDF5IO(filename1, 'w')
io.write(nwbfile1)
io.close()
with NWBHDF5IO(filename1, 'w') as io:
io.write(nwbfile1)

# Create the second file
nwbfile2 = NWBFile(session_description='demonstrate external files',
identifier='NWBE2',
session_start_time=start_time,
file_create_date=create_date)
nwbfile2 = NWBFile(
session_description='demonstrate external files',
identifier=str(uuid4()),
session_start_time=start_time,
)
# Create the second file
test_ts2 = TimeSeries(name='test_timeseries2',
data=data,
unit='SIunit',
timestamps=timestamps)
test_ts2 = TimeSeries(
name='test_timeseries2',
data=data,
unit='SIunit',
timestamps=timestamps,
)
nwbfile2.add_acquisition(test_ts2)

# Write the second file
io = NWBHDF5IO(filename2, 'w')
io.write(nwbfile2)
io.close()
with NWBHDF5IO(filename2, 'w') as io:
io.write(nwbfile2)


#####################
Expand All @@ -117,10 +127,11 @@
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

# Create the first file
nwbfile4 = NWBFile(session_description='demonstrate external files',
identifier='NWBE4',
session_start_time=start_time,
file_create_date=create_date)
nwbfile4 = NWBFile(
session_description='demonstrate external files',
identifier=str(uuid4()),
session_start_time=start_time,
)


####################
Expand All @@ -142,10 +153,12 @@
# To link to the dataset we can simply assign the data object (here `` timeseries_1.data``) to a new ``TimeSeries``

# Create a new timeseries that links to our data
test_ts4 = TimeSeries(name='test_timeseries4',
data=timeseries_1_data, # <-------
unit='SIunit',
timestamps=timestamps)
test_ts4 = TimeSeries(
name='test_timeseries4',
data=timeseries_1_data, # <-------
unit='SIunit',
timestamps=timestamps,
)
nwbfile4.add_acquisition(test_ts4)

####################
Expand All @@ -158,23 +171,22 @@
from hdmf.backends.hdf5.h5_utils import H5DataIO

# Create another timeseries that links to the same data
test_ts5 = TimeSeries(name='test_timeseries5',
data=H5DataIO(data=timeseries_1_data, # <-------
link_data=True), # <-------
unit='SIunit',
timestamps=timestamps)
test_ts5 = TimeSeries(
name='test_timeseries5',
data=H5DataIO(data=timeseries_1_data, # <-------
link_data=True), # <-------
unit='SIunit',
timestamps=timestamps,
)
nwbfile4.add_acquisition(test_ts5)

####################
# Step 4: Write the data
# ^^^^^^^^^^^^^^^^^^^^^^^
#
from pynwb import NWBHDF5IO

io4 = NWBHDF5IO(filename4, 'w')
io4.write(nwbfile4,
link_data=True) # <-------- Specify default behavior to link rather than copy data
io4.close()
with NWBHDF5IO(filename4, 'w') as io4:
io4.write(nwbfile4,
link_data=True) # <-------- Specify default behavior to link rather than copy data
io1.close()

#####################
Expand Down Expand Up @@ -230,17 +242,17 @@
#

# Create a new NWBFile that links to the external timeseries
nwbfile3 = NWBFile(session_description='demonstrate external files',
identifier='NWBE3',
session_start_time=start_time,
file_create_date=create_date)
nwbfile3 = NWBFile(
session_description='demonstrate external files',
identifier=str(uuid4()),
session_start_time=start_time,
)
nwbfile3.add_acquisition(timeseries_1) # <--------
nwbfile3.add_acquisition(timeseries_2) # <--------

# Write our third file that includes our two timeseries as external links
io3 = NWBHDF5IO(filename3, 'w', manager=manager)
io3.write(nwbfile3)
io3.close()
with NWBHDF5IO(filename3, 'w', manager=manager) as io3:
io3.write(nwbfile3)
io1.close()
io2.close()

Expand Down
3 changes: 0 additions & 3 deletions docs/gallery/domain/brain_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# :url: https://gist.githubusercontent.com/nicain/82e6b3d8f9ff5b85ef01a582e41e2389/raw/

# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_allenbrainobservatory.png'
from datetime import datetime
from dateutil.tz import tzlocal

from allensdk.core.brain_observatory_cache import BrainObservatoryCache
import allensdk.brain_observatory.stimulus_info as si
Expand Down Expand Up @@ -61,7 +59,6 @@
session_description='Allen Brain Observatory dataset',
identifier=str(metadata['ophys_experiment_id']),
session_start_time=metadata['session_start_time'],
file_create_date=datetime.now(tzlocal())
)


Expand Down
11 changes: 6 additions & 5 deletions docs/gallery/domain/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_ecephys.png'
from datetime import datetime
from uuid import uuid4

from dateutil.tz import tzlocal

import numpy as np
Expand All @@ -38,14 +40,13 @@

nwbfile = NWBFile(
session_description="my first synthetic recording",
identifier="EXAMPLE_ID",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter="Dr. Bilbo Baggins",
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure with thirteen dwarves "
"to reclaim vast treasures.",
session_id="LONELYMTN",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)

#######################
Expand Down
18 changes: 12 additions & 6 deletions docs/gallery/domain/icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@

# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_icephys_sweeptable.png'
from datetime import datetime
from uuid import uuid4

from dateutil.tz import tzlocal
from pynwb import NWBFile
import numpy as np

nwbfile = NWBFile('my first synthetic recording', 'EXAMPLE_ID', datetime.now(tzlocal()),
experimenter='Dr. Bilbo Baggins',
lab='Bag End Laboratory',
institution='University of Middle Earth at the Shire',
experiment_description='I went on an adventure with thirteen dwarves to reclaim vast treasures.',
session_id='LONELYMTN')
nwbfile = NWBFile(
session_description="my first synthetic recording",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)

#######################
# Device metadata
Expand Down
19 changes: 11 additions & 8 deletions docs/gallery/domain/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
"""
# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_image_data.png'
from datetime import datetime
from uuid import uuid4

from dateutil import tz

import numpy as np
from PIL import Image
from dateutil.tz import tzlocal

from pynwb import NWBFile, NWBHDF5IO
from pynwb.base import Images
Expand All @@ -48,14 +51,14 @@
session_start_time = datetime(2018, 4, 25, 2, 30, 3, tzinfo=tz.gettz("US/Pacific"))

nwbfile = NWBFile(
session_description="Mouse exploring an open field", # required
identifier="Mouse5_Day3", # required
session_start_time=session_start_time, # required
session_id="session_1234", # optional
experimenter="My Name", # optional
lab="My Lab Name", # optional
institution="University of My Institution", # optional
related_publications="DOI:10.1016/j.neuron.2016.12.011", # optional
session_description="my first synthetic recording",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)

nwbfile
Expand Down
19 changes: 10 additions & 9 deletions docs/gallery/domain/ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_ophys.png'
from datetime import datetime
from uuid import uuid4

from dateutil.tz import tzlocal

import numpy as np
Expand All @@ -39,15 +41,14 @@


nwbfile = NWBFile(
'my first synthetic recording',
'EXAMPLE_ID',
datetime.now(tzlocal()),
experimenter='Dr. Bilbo Baggins',
lab='Bag End Laboratory',
institution='University of Middle Earth at the Shire',
experiment_description='I went on an adventure with thirteen dwarves '
'to reclaim vast treasures.',
session_id='LONELYMTN'
session_description="my first synthetic recording",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)

####################
Expand Down
18 changes: 10 additions & 8 deletions docs/gallery/domain/plot_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_behavior.png'

from datetime import datetime
from uuid import uuid4

import numpy as np
from dateutil import tz
from dateutil.tz import tzlocal
from pynwb.misc import IntervalSeries

from pynwb.epoch import TimeIntervals
Expand All @@ -67,14 +69,14 @@
session_start_time = datetime(2018, 4, 25, 2, 30, 3, tzinfo=tz.gettz("US/Pacific"))

nwbfile = NWBFile(
session_description="Mouse exploring an open field", # required
identifier="Mouse5_Day3", # required
session_start_time=session_start_time, # required
session_id="session_1234", # optional
experimenter="My Name", # optional
lab="My Lab Name", # optional
institution="University of My Institution", # optional
related_publications="DOI:10.1016/j.neuron.2016.12.011", # optional
session_description="my first synthetic recording",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)

nwbfile
Expand Down
16 changes: 9 additions & 7 deletions docs/gallery/domain/plot_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
# sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_icephys.png'
# Standard Python imports
from datetime import datetime
from uuid import uuid4

from dateutil.tz import tzlocal
import numpy as np
import pandas
Expand Down Expand Up @@ -211,14 +213,14 @@

# Create the file
nwbfile = NWBFile(
session_description='my first synthetic recording',
identifier='EXAMPLE_ID',
session_description="my first synthetic recording",
identifier=str(uuid4()),
session_start_time=datetime.now(tzlocal()),
experimenter='Dr. Bilbo Baggins',
lab='Bag End Laboratory',
institution='University of Middle Earth at the Shire',
experiment_description='I went on an adventure with thirteen dwarves to reclaim vast treasures.',
session_id='LONELYMTN'
experimenter=["Baggins, Bilbo", ],
lab="Bag End Laboratory",
institution="University of Middle Earth at the Shire",
experiment_description="I went on an adventure to reclaim vast treasures.",
session_id="LONELYMTN001",
)

#####################################################################
Expand Down
Loading

0 comments on commit 76aa95b

Please sign in to comment.