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

Cannot read file after nwbfile.copy() with Units #1223

Open
5 tasks done
rly opened this issue Apr 15, 2020 · 3 comments
Open
5 tasks done

Cannot read file after nwbfile.copy() with Units #1223

rly opened this issue Apr 15, 2020 · 3 comments
Labels
category: bug errors in the code or code behavior priority: medium non-critical problem and/or affecting only a small set of NWB users

Comments

@rly
Copy link
Contributor

rly commented Apr 15, 2020

Description

When reading a file generated from a shallow copy copy() on an NWBFile with a Units table, I get the error:

  File "c:\users\ryan\documents\nwb\hdmf\src\hdmf\build\objectmapper.py", line 1007, in construct
    override = self.__get_override_carg(argname, builder, manager)
  File "c:\users\ryan\documents\nwb\hdmf\src\hdmf\build\objectmapper.py", line 467, in __get_override_carg
    return func(self, *remaining_args)
  File "c:\users\ryan\documents\nwb\pynwb\src\pynwb\io\misc.py", line 16, in resolution_carg
    return builder['spike_times'].attributes.get('resolution')
AttributeError: 'LinkBuilder' object has no attribute 'attributes'

Steps to Reproduce

from pynwb import NWBFile, NWBHDF5IO
from datetime import datetime
import math


nwbfile = NWBFile(session_description='session_description',
                  identifier='identifier',
                  session_start_time=datetime.now().astimezone())

device = nwbfile.create_device('Device')

electrode_group = nwbfile.create_electrode_group(
    name='ElectrodeGroup',
    description='',
    location='',
    device=device
)

nwbfile.add_electrode(x=math.nan,
                      y=math.nan,
                      z=math.nan,
                      imp=math.nan,
                      location='none',
                      filtering='none',
                      group=electrode_group)

nwbfile.add_unit(electrodes=(0,),
                 spike_times=(1., 2., 3.))

filename = 'nwbfile.nwb'
copy_filename = 'nwbfile_copy.nwb'

with NWBHDF5IO(filename, 'w') as io:
    io.write(nwbfile)

with NWBHDF5IO(filename, 'r') as io:
    read_nwbfile = io.read()
    copy_nwbfile = read_nwbfile.copy()

    with NWBHDF5IO(copy_filename, mode='w', manager=io.manager) as write_io:
        write_io.write(copy_nwbfile)

with NWBHDF5IO(copy_filename, 'r') as io:
    copy_nwbfile = io.read()

Environment

Python Executable: Python
Python Version: Python 3.7
Operating System: Windows
HDMF Version: dev

Checklist

  • Have you ensured the feature or change was not already reported?
  • Have you included a brief and descriptive title?
  • Have you included a clear description of the problem you are trying to solve?
  • Have you included a minimal code snippet that reproduces the issue you are encountering?
  • Have you checked our Contributing document?
@rly rly added the category: bug errors in the code or code behavior label Apr 15, 2020
@seankmartin
Copy link

Hi @rly, I was wondering if there is a known workaround for this?

I'm running into the same issue when trying to follow a similar process to the tutorial to add analysis data to NWB.

I instead directly append to the original file and that seems to have worked.
I was just wondering if there was any suggestion for copying files with units.
Just because a new file with extra analysis would probably be preferable to appending to the data file.

Thank you so much for the package and any help you can give!
Best - Sean

@seankmartin
Copy link

It would seem I answered my own question, by using the export feature.
It appears that this duplicates the raw data, so probably isn't feasible for very large files.

But anyway, for reference, in case it helps someone else;
Instead of opening the nwbfile in append mode and then writing back to the same file;
Open the nwbfile in read mode, and then create a new NWBHDF5IO in write mode.
Then use this new io to export to a new file, like:
new_io.export(src_io=read_io, nwbfile=processed_nwbfile)

@slcalgin
Copy link

Hi @rly ,
I'm also running into the same issue @seankmartin described above.
Sean's work around using the export feature seems to work but it kind of defeats the purpose of linking files for scratch data, especially with large datasets.
Do you know of any solutions to this issue?

@stephprince stephprince added the priority: medium non-critical problem and/or affecting only a small set of NWB users label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior priority: medium non-critical problem and/or affecting only a small set of NWB users
Projects
None yet
Development

No branches or pull requests

4 participants