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

passes cache_spec=False to nwb_io.write() to avoid spec writer shape … #406

Closed
wants to merge 2 commits into from

Conversation

MatthewAitken
Copy link
Member

@MatthewAitken MatthewAitken commented Apr 24, 2020

Resolve #404 …error

@t-b
Copy link
Collaborator

t-b commented Apr 24, 2020

Is it really required to not cache the spec? Caching the specification should always be done in order to ensure that the files can be validated later on.

@MatthewAitken MatthewAitken force-pushed the 404/fix-spec-write-shape-error branch from 05a793f to 27d7de3 Compare April 24, 2020 19:43
@MatthewAitken
Copy link
Member Author

Is it really required to not cache the spec? Caching the specification should always be done in order to ensure that the files can be validated later on.

@t-b When we write the file after adding the spike times, during the spec update in H5SpecWriter (https://github.com/hdmf-dev/hdmf/blob/dev/src/hdmf/backends/hdf5/h5_utils.py#L276) H5py's self.__group.require_dataset(name, shape=tuple(), data=data, dtype=self.__str_type) is called with the shape=tuple() argument. But the preexisting dataset has shape (1,), so it errors out instead keeping the old spec. This is just a temporary fix right now, and we do want to update the spec when we write nwb files. I'm opening an issue on pynwb.

@wbwakeman
Copy link

Will this change be used by ipfx.attach_metadata?
(i.e. when I do feature extraction with bin/run_pipeline_from_nwb_file.py it works, but when I try to attach metadata I still get the "Shapes do not match" error)

@sgratiy
Copy link
Contributor

sgratiy commented Apr 30, 2020

@wbwakeman have skipping spec update in the attach_metadata module fixed the issue with metadata attachment?

@wbwakeman
Copy link

@sgratiy Yes, I can attach metadata now

@sgratiy sgratiy requested review from sgratiy and NileGraddis April 30, 2020 17:19
@sgratiy
Copy link
Contributor

sgratiy commented Apr 30, 2020

@MatthewAitken I could not see the issue open on pynwb as mentioned above. I wanted to link it to this issue.
Are we ready to merge this PR?

@wbwakeman
Copy link

@MatthewAitken I discussed this with @t-b and he had some good thoughts on the issue. The NWB2 files that I am working with for the June release are being written by MIES and include a cached_specification already. When ipfx attach_metadata and append_spike_times write the NWB2 file, they are also attempting to cache the spec again. This causes the "Shapes do not match" error.

This PR solves that problem by not caching the spec again, which leaves the one written by MIES. Another approach (thanks @t-b ) would be to remove the MIES one. That can be done with something like

import h5py
with h5py.File("HardwareTests-V2.nwb", mode="r+") as f:
    for spec in ['/specifications/core', '/specifications/hdmf-common']:
        if spec in f:
            del f[spec]

What do you think about following this strategy to correct the problem?

@wbwakeman
Copy link

This may be unnecessary once this PR is merged?
hdmf-dev/hdmf#346

@wbwakeman wbwakeman closed this Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants