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

DataChunkIterator converting data to float #140

Closed
luiztauffer opened this issue Sep 25, 2019 · 3 comments · Fixed by #143
Closed

DataChunkIterator converting data to float #140

luiztauffer opened this issue Sep 25, 2019 · 3 comments · Fixed by #143
Labels
category: bug errors in the code or code behavior

Comments

@luiztauffer
Copy link

Description

pynwb==1.1.0.post0.dev1 and hdmf==1.2.0.post0.dev1
I’m trying to store int16 data using DataChunkIterator but it seems to be converting dtype to float. Here’s an example:

from datetime import datetime
from dateutil.tz import tzlocal
from pynwb import NWBFile
from pynwb import NWBHDF5IO
from pynwb.ecephys import ElectricalSeries
from hdmf.data_utils import DataChunkIterator
import numpy as np
import os

nwb = NWBFile(session_description='session', identifier='1', session_start_time=datetime.now(tzlocal()))

# Add electrode groups and channels
nChannels = 10
dev0 = nwb.create_device(name='dev0')
elecs_group = nwb.create_electrode_group(name='electrodes', description='', location='ctx', device=dev0)
for i in np.arange(nChannels):
    ii = float(i)
    nwb.add_electrode(x=ii, y=ii, z=ii, imp=ii, location='', filtering='', group=elecs_group)

#Add signal
elecs_region = nwb.electrodes.create_region(name='electrodes',
                                            region=np.arange(nChannels).tolist(),
                                            description='')

def data_generator(nChannels):
    X_data = np.zeros((nChannels,1000)).astype('int16')
    for id in range(0, nChannels):
        data = X_data[id,:]
        print(data.dtype)
        yield data
data = data_generator(nChannels=10)
iter_data = DataChunkIterator(data=data, iter_axis=1)

signal = ElectricalSeries(name='ElectricalSeries', 
                          data=iter_data, 
                          electrodes=elecs_region,
                          starting_time=0.,
                          rate=1.)
nwb.add_acquisition(signal)

#Write file
with NWBHDF5IO('file_1.nwb', mode='w') as io:
    io.write(nwb)
    
# Read file
io = NWBHDF5IO('file_1.nwb', 'r+')
nwbfile = io.read()
print(nwbfile.acquisition['ElectricalSeries'].data[:,0].dtype)
io.close()

If I pass the data directly, it works fine:

# iter_data = DataChunkIterator(data=data, iter_axis=1)
iter_data = np.zeros((nChannels,1000)).astype('int16')

Checklist

  • [ x] Have you ensured the feature or change was not already reported ?
  • [ x] Have you included a brief and descriptive title?
  • [ x] Have you included a clear description of the problem you are trying to solve?
  • [ x] Have you included a minimal code snippet that reproduces the issue you are encountering?
  • [ x] Have you checked our Contributing document?
@luiztauffer luiztauffer added the category: bug errors in the code or code behavior label Sep 25, 2019
@bendichter
Copy link
Contributor

reproduced, and is still an issue if iter_axes=1 is omitted

@oruebel
Copy link
Contributor

oruebel commented Sep 25, 2019

Have you tried setting the dtype explicitly in the constructor of DataChunkIterator via

iter_data = DataChunkIterator(data=data, iter_axis=1, dtype=np.dtype('int16'))

If that fixes the issue then this should be an issue either in the generator function or the constructor of DataChunkIterator.

@luiztauffer
Copy link
Author

thanks for the suggestion, but it did not solve the issue

@rly rly closed this as completed in #143 Sep 26, 2019
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants