Skip to content

Instantly share code, notes, and snippets.

View rly's full-sized avatar

Ryan Ly rly

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / fix_dandiset_000114.py
Last active November 21, 2023 02:46
Script to fix incorrect namespace attributes in NWB files in dandiset 000114
import glob
import h5py
import argparse
from typing import Union
def replace_namespace(_: str, h5obj: Union[h5py.Dataset, h5py.Group]):
# change the attribute "namespace" from value "hdmf-experimental" to "hdmf-common"
# for all DynamicTableRegion and VectorData neurodata types from ndx-photometry.
if h5obj.attrs.get("namespace") == "hdmf-experimental":
@rly
rly / test_modify_nwb.ipynb
Created October 9, 2023 21:44
Tests on what is currently possible for modifying an NWB file using PyNWB and h5py
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / get_namespace_versions.ipynb
Last active August 16, 2023 17:56
Get the versions of the namespaces/extensions cached in an NWB file or used by PyNWB
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / spec_non_string_value.ipynb
Created June 17, 2023 12:29
Test behavior of PyNWB/HDMF with an attribute spec that has a non-text or non-scalar default value.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / test_column_of_containers.ipynb
Last active May 30, 2023 20:07
Create an NWB DynamicTable with a column of object references
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / trim_nwbfile.ipynb
Last active May 30, 2023 20:07
Notebook demonstrating how to trim data carefully from an NWB file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / adjust_nwb.py
Last active February 24, 2023 23:31
Tailored Python script to replace particular values in an NWB file to conform with DANDI upload requirements
import glob
import h5py
import numpy as np
import argparse
import pynwb
STR_DTYPE = h5py.special_dtype(vlen=str)
@rly
rly / get_num_chunks.ipynb
Created January 10, 2023 22:59
Get the number of chunks in an h5py.Dataset
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rly
rly / get_neurodata_type_objects.py
Last active July 25, 2023 14:12
Function to return all PyNWB objects in the file that are instances of the neurodata_type class
from pynwb import NWBHDF5IO, NWBFile
def get_neurodata_type_objs_io(io: NWBHDF5IO, neurodata_type: str, namespace: str):
"""Return all PyNWB objects in the file that have a neurodata type from a namespace.
This works regardless of whether the extension was imported earlier in the python execution.
All objects that are instances of the class associated with the given neurodata_type in the
given namespace will be returned. This includes objects that are instances of a subclass.