analysiscenter / cardio

CardIO is a library for data science research of heart signals
https://analysiscenter.github.io/cardio/
Apache License 2.0
247 stars 78 forks source link

'NoneType' object has no attribute 'ndim' #22

Closed Myles-JB closed 5 years ago

Myles-JB commented 5 years ago

I got this error whilst following the tutorial when trying to display the ecg signal using: sample.show_ecg('A00001')

File "<ipython-input-42-3742dca0684b>", line 1, in <module> sample.show_ecg('A00001')

File "/anaconda3/lib/python3.6/site-packages/cardio/core/ecg_batch.py", line 391, in show_ecg self._check_2d(signal) File "/anaconda3/lib/python3.6/site-packages/cardio/core/ecg_batch.py", line 218, in _check_2d if signal.ndim != 2:

AttributeError: 'NoneType' object has no attribute 'ndim'

Quite new to python so not sure if its something to do with me cloning the repo etc?

Any help would be much appreciated!

dpodvyaznikov commented 5 years ago

Hi, @Myles-JB !

Please provide the code that caused the error including the code you used to create and process sample object you've mentioned.

This error might appear in case you create an EcgBatch object and do not use load action to load the signals into it, but it's hard to tell without the code.

Myles-JB commented 5 years ago

Hi @dpodvyaznikov, Thanks for getting back! Below is the code that I have been using including imports etc.

import matplotlib.pyplot as plt
import pandas as pd
import wfdb as wf
import cardio
import cardio.batchflow as bf 
from cardio import EcgDataset
from cardio import EcgBatch

import sys
pathToDataSet = "physionet.org/physiobank/database/afdb/*.hea"
pathToRefCSV = "physionet.org/physiobank/database/afdb/REFERENCE.csv"
dataset = EcgDataset(path=pathToDataSet, no_ext=True, sort=True)

batch = dataset.next_batch(batch_size=6, unique_labels=['A', 'N', 'O'])

sample = batch.load(fmt='wf', components=['signal', 'meta'])

sample = sample.load(src = pathToRefCSV, fmt='csv', components='target' )
sample.show_ecg('A00001')
dpodvyaznikov commented 5 years ago

Great, thank you!

The problem is that you use fmt='wf' instead of fmt='wfdb' in load function. 'wfdb' is the proper value here to use for the wfdb files.

An error about the format should've been raised when you passed wrong value, I'll look into the reasons why it did not.

Myles-JB commented 5 years ago

Amazing! Thanks for your help!

dpodvyaznikov commented 5 years ago

Fixed in #23 Closing this issue.