Skip to content

Problem using record.wrsamp() #543

Closed
@RPadial

Description

@RPadial

Hello,
I trying to save a Record but when usin record.wrsamp(write_dir=str(directory)), it requests some optional parameters like checksum. After defining them i get the following error:

path/src/python/utils/init.py:9: UserWarning: Module tf_keras not found, some of the submodules cannot be pre-imported
warnings.warn(f"Module {e.name} not found, some of the submodules cannot be pre-imported", UserWarning)
Backend tkagg is interactive backend. Turning interactive mode on.
Loaded: ARR_07.dat with 6 channels
An error occurred during wrsamp():
Traceback (most recent call last):
File "path/src/python/utils/dataset.py", line 120, in write_dat_file
record.wrsamp(write_dir=str(directory))
File "path/.venv/lib/python3.10/site-packages/wfdb/io/record.py", line 929, in wrsamp
checksums = self.calc_checksum(expanded=expanded)
File "path/.venv/lib/python3.10/site-packages/wfdb/io/_signal.py", line 957, in calc_checksum
cs = np.sum(self.d_signal, 0) % 65536
TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

Find below the code

output_path = Path(output_path)
record_name = output_path.stem
directory = output_path.parent
directory.mkdir(parents=True, exist_ok=True)

fs = metadata['sampling_frequency']
signal_array = signal_array.T  # (samples, channels)
n_sig = signal_array.shape[1]
sig_len = signal_array.shape[0]
comments = metadata.get("comments", [])
comments = [str(c) for c in comments] # This ensures a flat list of strings.
file_name = f"{record_name}_upsampled"
file_name = [str(c) for c in file_name]

baseline = [0] * n_sig
adc_gain = [1] * n_sig
d_signal = np.round((signal_array- baseline) * adc_gain).astype(np.int16)
checksum = [int(np.sum(d_signal[:, i]) % 65536) for i in range(n_sig)]



record = wfdb.Record(
    file_name=file_name,
    record_name=record_name,
    fs=fs,
    sig_len=sig_len,
    n_sig=n_sig,
    p_signal=signal_array,
    fmt=['16'] * n_sig,
    units=['mV'] * n_sig,
    sig_name=channel_names,
    adc_gain=adc_gain,
    baseline=baseline,
    adc_res=[16] * n_sig,
    adc_zero=[0] * n_sig,
    init_value=[0] * n_sig,
    checksum=checksum,
    block_size=[0] * n_sig,
    base_date=None,
    base_time=None,
    comments=comments
)

import traceback

try:
  record.wrsamp(write_dir=str(directory))
except Exception as e:
  print("An error occurred during wrsamp():")
  traceback.print_exc()

print(f"Saved record to: {directory.joinpath(record_name)}.hea and .dat")

running wfdb-4.3.0 in python 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions