Closed NikolayGromov closed 6 months ago
have you tried writing the samples beofre the annotations?
Yes, same error
One error I see is
setDatarecorduration
is set with FileDuration
Those are different things. One denotes the block size in which the EDF is written, one the length of the entire file (=all blocks).
Don't think you need to set FileDuration explicitly, it is inferedd automatically.
If that doesn't fix your problem I need the sample code and all variables to reproduce the problem on my pc.
Now I didn't set duration, got this error
I am using this code to reproduce the problem:
import datetime
import pyedflib
import numpy as np
header = {'technician': '',
'recording_additional': 'Neuroscope_6.3_r2497',
'patientname': '1 A',
'patient_additional': '',
'patientcode': '',
'equipment': '',
'admincode': '',
'sex': 'Male',
'startdate': datetime.datetime(2024, 1, 28, 21, 54, 45, 91798),
'birthdate': '',
'gender': ''}
signal_header = {'label': 'EEG Fp1-F3',
'dimension': 'uV',
'sample_rate': 199.50274692224406,
'sample_frequency': 199.50274692224406,
'physical_max': 3276.7,
'physical_min': -3276.8,
'digital_max': 32767,
'digital_min': -32768,
'prefilter': 'HP:0.5Hz LP:70.0Hz N:on',
'transducer': 'AgAgCl electrode'}
signals = np.zeros((20, 1551205))
annotations = [[6000.0, 6002.105234170855], [-1.0, 0.0451121608040201], ['StartPredictionTime', 'ModelPrediction']]
fw = pyedflib.EdfWriter('error.edf', 20, file_type=1)
fw.setHeader(header)
for i in range(20):
fw.setSignalHeader(i, signal_header)
for i in range(len(annotations[0])):
fw.writeAnnotation(annotations[0][i], annotations[1][i], annotations[2][i])
fw.writeSamples(signals)
fw.close()
try setting sample_frequency=199.5
instead of that odd number.
If you really need this millisecond sample-frequency, you need to find a float block_size s
between 1.0-60.0 such that s*sample_frequency
results in an integer, because unfortunately that's how the edf specs work :-/
PS: You don't need to set sample_rate
Yes, this error was because of sample_frequency (and I must also set sample_rate to ''). And yes, i need more precise frequency, but for the problem in this topic - it's done. Thank you!
Hi! I am trying to rewrite annotations in .edf file, but got this error, when trying to copy signals. Annotations are correct, I checked them in EdfBrowser. Could you please, help me, may be I didn't fill something?
f is a valid edf file, which is opened, using edfReader.