You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Open
NathanTBurgess opened this issue
Jun 12, 2024
· 2 comments
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.
defwrite_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 sliceoutput_edf_writer=pyedflib.EdfWriter(output_edf_file_path, len(signal_headers), file_type=pyedflib.FILETYPE_EDFPLUS)
original_signal_data= []
shm_original_list= []
foriinrange(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= []
foriinrange(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 fileforiinrange(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 segmentforshminshm_original_list:
shm.close()
forshminshm_concat_list:
shm.close()
The text was updated successfully, but these errors were encountered:
You are using a np.float64 ( (2^64 steps) datatype. EDF stores float16 (2^16 steps) ranging from -digital_minimum to +digital_minimum and using physical_minumum and physical_maximum. This might explain (some) of the differences you see?
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.
The text was updated successfully, but these errors were encountered: