-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Object IDs in NWBFile (#991)
* add LabelledDict default search key * add neurodata specific name for data_id * index all objects in an NWB file * drop neurodata_id rename, rename data_id to object_id * fix import, add object_id resolution to roundtrip test * Clean up tests and check object id matches in roundtrip tests * Make test modular storage not extend testroundtrip * Test string printing in roundtrip properly * Set parent attribute instead of using add_child (deprecated) * Do not save object_ids in map if none. Warn if None. * Add script to add object ID to files without it * Remove unused set_parents function * Do not set parent when it already exists so that a link can be created * Fix flake8 * Fix for when parent is still a Proxy * Fix printing of DataIO wrapped dataset that has been closed * Fix modular storage test errors * Enhance modular storage test, requires latest hdmf
- Loading branch information
Showing
7 changed files
with
119 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
This script adds an 'object_id' attribute to each neurodata_type of an hdf5 file that was written before object IDs | ||
existed. Specifically, it traverses through the hierarchy of objects in the file and sets the 'object_id' attribute | ||
to a UUID4 string on each group, dataset, and link that has a 'neurodata_type' attribute and does not have an | ||
'object_id' attribute. | ||
Usage: python add_object_id filename | ||
""" | ||
|
||
from h5py import File | ||
from uuid import uuid4 | ||
import sys | ||
|
||
|
||
def add_uuid(name, obj): | ||
if 'neurodata_type' in obj.attrs and 'object_id' not in obj.attrs: | ||
obj.attrs['object_id'] = str(uuid4()) | ||
print('Adding uuid4 %s to %s' % (obj.attrs['object_id'], str(obj))) | ||
|
||
|
||
def main(): | ||
filename = sys.argv[1] | ||
with File(filename, 'a') as f: | ||
f.visititems(add_uuid) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters