diff --git a/docs/gallery/advanced_io/linking_data.py b/docs/gallery/advanced_io/linking_data.py index 07d535a06..767829f6f 100644 --- a/docs/gallery/advanced_io/linking_data.py +++ b/docs/gallery/advanced_io/linking_data.py @@ -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 @@ -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' @@ -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) ##################### @@ -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, +) #################### @@ -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) #################### @@ -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() ##################### @@ -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() diff --git a/docs/gallery/domain/brain_observatory.py b/docs/gallery/domain/brain_observatory.py index 11e490251..77b51afa0 100644 --- a/docs/gallery/domain/brain_observatory.py +++ b/docs/gallery/domain/brain_observatory.py @@ -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 @@ -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()) ) diff --git a/docs/gallery/domain/ecephys.py b/docs/gallery/domain/ecephys.py index 358750c7a..27c195dee 100644 --- a/docs/gallery/domain/ecephys.py +++ b/docs/gallery/domain/ecephys.py @@ -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 @@ -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", ) ####################### diff --git a/docs/gallery/domain/icephys.py b/docs/gallery/domain/icephys.py index 772e75e17..f5a27350d 100644 --- a/docs/gallery/domain/icephys.py +++ b/docs/gallery/domain/icephys.py @@ -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 diff --git a/docs/gallery/domain/images.py b/docs/gallery/domain/images.py index 41c50d390..d9e1ddb33 100644 --- a/docs/gallery/domain/images.py +++ b/docs/gallery/domain/images.py @@ -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 @@ -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 diff --git a/docs/gallery/domain/ophys.py b/docs/gallery/domain/ophys.py index a972e1859..eed4dc5e4 100644 --- a/docs/gallery/domain/ophys.py +++ b/docs/gallery/domain/ophys.py @@ -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 @@ -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", ) #################### diff --git a/docs/gallery/domain/plot_behavior.py b/docs/gallery/domain/plot_behavior.py index d10e88c0e..65c18094e 100644 --- a/docs/gallery/domain/plot_behavior.py +++ b/docs/gallery/domain/plot_behavior.py @@ -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 @@ -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 diff --git a/docs/gallery/domain/plot_icephys.py b/docs/gallery/domain/plot_icephys.py index e22f3ef12..4a94662e7 100644 --- a/docs/gallery/domain/plot_icephys.py +++ b/docs/gallery/domain/plot_icephys.py @@ -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 @@ -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", ) ##################################################################### diff --git a/docs/gallery/general/file.py b/docs/gallery/general/file.py index ccd823947..cf13a06ad 100644 --- a/docs/gallery/general/file.py +++ b/docs/gallery/general/file.py @@ -123,6 +123,8 @@ clarity, we define them here: """ # sphinx_gallery_thumbnail_path = 'figures/gallery_thumbnails_file.png' +from uuid import uuid4 + import numpy as np from pynwb import NWBFile, TimeSeries, NWBHDF5IO from pynwb.epoch import TimeIntervals @@ -154,16 +156,24 @@ nwbfile = NWBFile( session_description="Mouse exploring an open field", # required - identifier="Mouse5_Day3", # required + identifier=str(uuid4()), # required session_start_time=session_start_time, # required session_id="session_1234", # optional - experimenter="My Name", # optional - lab="My Lab Name", # optional + experimenter=["Baggins, Bilbo", ], # optional + lab="Bag End Laboratory", # optional institution="University of My Institution", # optional + experiment_description="I went on an adventure to reclaim vast treasures.", # optional related_publications="DOI:10.1016/j.neuron.2016.12.011", # optional ) print(nwbfile) +#################### +# .. note:: +# +# See the `NWBFile Best Practices `_ +# for detailed information about the arguments to +# :py:class:`~pynwb.file.NWBFile` + #################### # .. _basic_subject: # diff --git a/docs/source/conf.py b/docs/source/conf.py index cc21ff44e..fd8970708 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -146,13 +146,16 @@ def __call__(self, filename): 'fsspec': ("https://filesystem-spec.readthedocs.io/en/latest/", None), } -extlinks = {'incf_lesson': ('https://training.incf.org/lesson/%s', '%s'), - 'incf_collection': ('https://training.incf.org/collection/%s', '%s'), - 'nwb_extension': ('https://github.com/nwb-extensions/%s', '%s'), - 'pynwb': ('https://github.com/NeurodataWithoutBorders/pynwb/%s', '%s'), - 'nwb_overview': ('https://nwb-overview.readthedocs.io/en/latest/%s', '%s'), - 'hdmf-docs': ('https://hdmf.readthedocs.io/en/stable/%s', '%s'), - 'dandi': ('https://www.dandiarchive.org/%s', '%s')} +extlinks = { + 'incf_lesson': ('https://training.incf.org/lesson/%s', '%s'), + 'incf_collection': ('https://training.incf.org/collection/%s', '%s'), + 'nwb_extension': ('https://github.com/nwb-extensions/%s', '%s'), + 'pynwb': ('https://github.com/NeurodataWithoutBorders/pynwb/%s', '%s'), + 'nwb_overview': ('https://nwb-overview.readthedocs.io/en/latest/%s', '%s'), + 'hdmf-docs': ('https://hdmf.readthedocs.io/en/stable/%s', '%s'), + 'dandi': ('https://www.dandiarchive.org/%s', '%s'), + "nwbinspector": ("https://nwbinspector.readthedocs.io/en/dev/%s", "%s"), +} # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates']