edfwriter not copying arrays perfectly. Random elements, most do not differ, differ from the numpy array used to create edf file by exactly -0.0984668518066405 or 0.0984668518066405 every time. #254
edfwriter not copying arrays perfectly. Random elements, most do not differ, differ from the numpy array used to create edf file by exactly -0.0984668518066405 or 0.0984668518066405 every time.
Here is the most relevant function. Just know when I find the differences between the returned numpy array of the written file and the original numpy array you see those random differences by that exact amount scattered in the indicies.
def write_edf_slice(shm_original_names, signal_headers, f, output_edf_file_path, start_time, end_time, shm_concat_names, start_pos, n_elements, total_elements, channel_number):
# Create a new EDF file writer for the time slice
output_edf_writer = pyedflib.EdfWriter(output_edf_file_path, len(signal_headers), file_type=pyedflib.FILETYPE_EDFPLUS)
original_signal_data = []
shm_original_list = []
for i in range(len(shm_original_names)):
shm_original_list.append(shared_memory.SharedMemory(name=shm_original_names[i]))
original_signal_data.append(np.ndarray((total_elements), dtype=np.float64, buffer=shm_original_list[i].buf))
concatenated_signal = []
shm_concat_list = []
for i in range(len(shm_concat_names)):
shm_concat_list.append(shared_memory.SharedMemory(name=shm_concat_names[i]))
concatenated_signal.append(np.ndarray((n_elements), dtype=np.float64, buffer=shm_concat_list[i].buf, offset=start_pos * np.dtype(np.float64).itemsize))
# Copy signal headers to the new EDF file
for i in range(channel_number):
signal_header = signal_headers[i]
output_edf_writer.setSignalHeader(i, signal_header)
start_index = int(start_time * f[i])
end_index = int(end_time * f[i])
original_data_current_channel = original_signal_data[i][start_index:end_index]
np.copyto(concatenated_signal[i], original_data_current_channel)
output_edf_writer.writeSamples(concatenated_signal)
output_edf_writer.close()
# Close shared memory segment
for shm in shm_original_list:
shm.close()
for shm in shm_concat_list:
shm.close()
edfwriter not copying arrays perfectly. Random elements, most do not differ, differ from the numpy array used to create edf file by exactly -0.0984668518066405 or 0.0984668518066405 every time.
Here is the most relevant function. Just know when I find the differences between the returned numpy array of the written file and the original numpy array you see those random differences by that exact amount scattered in the indicies.