Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Handle all-NaN channels in calc_adc_params

Đang mở
#485 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
numpy, python
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu trong wfdb/io/_signal.py tại calc_adc_params và lần theo cách xử lý nanmin/nanmax được wfdb.wrsamp sử dụng. Tái hiện ví dụ về một kênh có toàn bộ giá trị là NaN, sau đó xác minh rằng các kênh có toàn bộ giá trị là NaN không còn phát sinh cảnh báo hoặc bị lỗi, trong khi các kênh chứa giá trị vẫn giữ nguyên hành vi hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

If all samples in a channel are NaN, calc_adc_params will fail:

>>> wfdb.wrsamp("xxx", fs=500, units=["mV"], sig_name=["I"], p_signal=numpy.array([[numpy.nan]]), fmt=["16"])
/home/bmoody/work/wfdb-python/wfdb/io/_signal.py:740: RuntimeWarning: All-NaN slice encountered
  minvals = np.nanmin(self.p_signal, axis=0)
/home/bmoody/work/wfdb-python/wfdb/io/_signal.py:741: RuntimeWarning: All-NaN slice encountered
  maxvals = np.nanmax(self.p_signal, axis=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bmoody/work/wfdb-python/wfdb/io/record.py", line 2943, in wrsamp
    record.set_d_features(do_adc=1)
  File "/home/bmoody/work/wfdb-python/wfdb/io/_signal.py", line 470, in set_d_features
    self.adc_gain, self.baseline = self.calc_adc_params()
  File "/home/bmoody/work/wfdb-python/wfdb/io/_signal.py", line 787, in calc_adc_params
    baseline = int(np.floor(baseline))
ValueError: cannot convert float NaN to integer

A couple things are wrong here:

  1. if pmin == np.nan doesn't do what you think.

  2. nanmin and nanmax will give a RuntimeWarning if all samples in a channel are NaN.

(1) is easy to fix. (2) is a little weirder; have a look at the code of nanmin:

    if type(a) is np.ndarray and a.dtype != np.object_:
        # Fast, but not safe for subclasses of ndarray, or object arrays,
        # which do not implement isnan (gh-9009), or fmin correctly (gh-8975)
        res = np.fmin.reduce(a, axis=axis, out=out, **kwargs)
        if np.isnan(res).any():
            warnings.warn("All-NaN slice encountered", RuntimeWarning,
                          stacklevel=3)

In other words, for ordinary numeric numpy arrays, np.fmin.reduce gives what we want (minimum non-NaN value if there is one, otherwise NaN, and no warning.) It might not work if the array is something more exotic (e.g. a numpy-compatible array class created by some other python package.)

I think I understand the comment about object arrays (https://github.com/numpy/numpy/issues/8975, https://github.com/numpy/numpy/issues/9009), but I don't understand the "subclasses of ndarray" comment. When I try creating a trivial subclass of ndarray, fmin still appears to work as expected. So I don't see why the strict is np.ndarray is needed.

Ngôn ngữ chính
Jupyter Notebook
Star
853
Fork
322
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MIT-LCP/wfdb-python

Tất cả issue của MIT-LCP/wfdb-python

Issue tương tự

Thêm issue về Data Engineering

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.