NeurodataWithoutBorders / matnwb

A Matlab interface for reading and writing NWB files
BSD 2-Clause "Simplified" License
49 stars 32 forks source link

Error reading nwb files datetime created in pynwb #82

Closed andylikescodes closed 5 years ago

andylikescodes commented 5 years ago

Hi all,

The nwb file is created using pynwb.

Here is the code that used to create this nwb file.

 # Create the NWB file
    nwbfile = NWBFile(
        #source='https://datadryad.org/bitstream/handle/10255/dryad.163179/RecogMemory_MTL_release_v2.zip',
        session_description='RecogMemory dataset session use 5' + session['session'],
        identifier=session['session_id'],
        session_start_time=datetime.datetime.now(),# TODO: need to check out the time for session start
        file_create_date=datetime.datetime.now(),
        experiment_description="learning: " + str(experiment_id_learn) + ", " + \
                               "recognition: " + \
                               str(experiment_id_recog),
        subject=nwb_subject
    )

The session_start_time and file_create_date are created using the python datetime package default now() function datetime.datetime.now().

However, when the nwb file is outputted in pynwb and read in to matlab using matnwb, the date time format cannot be recognized.

Here is the error message:

Error using datetime (line 616)
Could not recognize the date/time format of '2018-12-02T12:57:27.371444-08:00'. You can specify a format character vector
using the 'InputFormat' parameter. If the date/time text contains day, month, or time zone names in a language foreign to
the 'en_US' locale, those might not be recognized. You can specify a different locale using the 'Locale' parameter.

Error in types.util.checkDtype (line 90)
                val = datetime(val);

Error in types.core.NWBFile/validate_file_create_date (line 299)
        val = types.util.checkDtype('file_create_date', 'isodatetime', val);

Error in types.core.NWBFile/set.file_create_date (line 185)
        obj.file_create_date = obj.validate_file_create_date(val);

Error in types.core.NWBFile (line 138)
        obj.file_create_date = p.Results.file_create_date;

Error in nwbfile (line 15)
            obj = obj@types.core.NWBFile(varargin{:});

Error in io.parseGroup (line 68)
        parsed = nwbfile(kwargs{:});

Error in nwbRead (line 20)
    nwb = io.parseGroup(filename, info);

Is there any documentation for the InputFormat parameter?

Also, is it possible to make matnwb recognize some default date time format?

Thanks,

lawrence-mbf commented 5 years ago

As it turns out, MATLAB's datetime does not support the extended versions of ISO8601 which python uses.

The quickest fix is to go to types.util.checkDtype, look for 'isodatetime', and either comment out the datetime() conversion or add the desired format as per documentation.

Will follow up later.

bendichter commented 5 years ago

Man, why are time standards always so hard?! Thanks for looking into this.

bendichter commented 5 years ago

I'll take a crack at this

bendichter commented 5 years ago

be30afae42f2440fd586ac10cca6521cd3d457b1 (the latest master commit) fixes this on my end. @andylikescodes, let me know if this works for you