ikarosilva / wfdb-app-toolbox

The WFDB Toolbox for MATLAB/Octave is a collection of functions for reading, writing, and processing physiologic signals in the formats used by PhysioNet (see README for details).
http://physionet.org/physiotools/matlab/wfdb-app-matlab/
GNU General Public License v3.0
92 stars 45 forks source link

rdann outputs incorrect annotations if only one output requested #132

Closed alistairewj closed 7 years ago

alistairewj commented 7 years ago

Thanks to @mansirankawat for noticing this. Reproducible using slp01a.ecg and slp01a.hea at https://www.physionet.org/physiobank/database/slpdb/

If all outputs of rdann are requested, then the output looks correct:

[ann,type,subtype,chan,num,comments]=rdann('slp01a', 'ecg');
ann(1:5)
ans =

    20
   235
   458
   688
   912

But if only a single output is requested, then the annotations all return 50:

ann=rdann('slp01a', 'ecg');
ann(1:5)
ans =

    50
    50
    50
    50
    50

Verified using the wfdb-app-toolbox-0-9-9 release on Ubuntu 16.04.

cx1111 commented 7 years ago

The inconsistency is produced by the output of line 172: ann=javaWfdbExec.execToDoubleArray(wfdb_argument);

I did notice that this ann array is Nx5 for records with headers without a time/date, and Nx6 for those with a time/date like this problem record.

I'm just reasoning here without delving into the workings of the java class but my simple change seems to have fixed the error. Do you think I should close this issue?

mansirankawat commented 7 years ago

Thanks @cx1111 for looking into this issue. It works for the following case now ann = rdann('slp01a', 'ecg') But, for the following case [ann_atr]=rdann('slp01a', 'ecg', 1, 1650000, 1500001);

It gives me error: [java] java.lang.NullPointerException error: called from: error: /home/user/Desktop/entry_sleep/entry_87.53_best_correct/wfdb-app-toolbox-0-9-9/mcode/rdann.m at line 172, column 4

Although, there are annotations beyond 1650000

cx1111 commented 7 years ago

I'm using the latest github development version of everything. I copied your command in exactly and got a 668x1 double for ann_atr. Can you try with the most up to date version of the toolbox and tell me what you get?

cx1111 commented 7 years ago

Either way I found another error when reading annotation files with aux fields (when the number of outputs is 1).

 Error using rdann (line 173)
 Java exception occurred:
 java.lang.ArrayIndexOutOfBoundsException: 8
    at org.physionet.wfdb.Wfdbexec.execToDoubleArray(Unknown Source)

So unfortunately the problem is within the java code. I'll be investigating.

cx1111 commented 7 years ago

I'm not using a tarball/release version but rather the latest development version on github. I git clone the repo, then in matlab:

[old_path]=which('rdsamp');if(~isempty(old_path)) rmpath(old_path(1:end-8)); end
cd mcode
addpath(pwd);savepath
cx1111 commented 7 years ago

In terminal:

cd ~/Testfolder/
git clone https://github.com/ikarosilva/wfdb-app-toolbox.git
matlab &

In matlab:

[old_path]=which('rdsamp');if(~isempty(old_path)) rmpath(old_path(1:end-8)); end
cd wfdb-app-toolbox/mcode
addpath(pwd);savepath
cx1111 commented 7 years ago
>> tic; sig=rdsamp('16265'); toc;
Elapsed time is 1.488436 seconds.
mansirankawat commented 7 years ago

Thanks @cx1111, I also spotted that error in rdann. Also, when using wrann in matlab/octave for this slpdb dataset, I get the following error.

[ann_atr]=rdann('slp01a', 'ecg') wrann('slp01a', 'ecg1', ann_atr)

java.io.IOException: Broken pipe at java.io.FileOutputStream.writeBytes(Native Method) at java.io.FileOutputStream.write(FileOutputStream.java:318) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:122) at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282) at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125) at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207) at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129) at java.io.BufferedWriter.write(BufferedWriter.java:230) at java.io.Writer.write(Writer.java:157) at org.physionet.wfdb.InputWriter.run(Unknown Source) Process exited with errors!! Error code = 139 warning: broken pipe -- some output may be lost

Maybe they are related

mansirankawat commented 7 years ago

@cx1111 Did you figure out why java code is causing problems for slpdb database?

cx1111 commented 7 years ago

Sorry I haven't had time to work on it but yea I found the error. I'll be editing the java method. In the meantime if you want you can delete that if(nargout==1) clause to make rdann work.

cx1111 commented 7 years ago

Ok hopefully I've fixed the issue. Changed Wfdbexec.java and Wfdbexec.class in the jar files, along with a bit in rdann.

Also thanks @mansirankawat for pointing out the wrann issue. I've just made some moderately large changes to wrann. Let me know if it works now.