Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self.exportEDFAnnotations:
print "Will export Events from EDF to CSV in:", self.path_and_file_name_event + '.edf' + '.csv'
self.feventEDF = open(self.path_and_file_name_event + '.edf' + '.csv', 'a', buffering=100000)
self.feventEDF.write('onset' + self.delim + 'annotation' + '\n')
# if self.isActivated:
# self.fevent.write('#Streaming restarted at ' + self.time_stamp + '\n')
# self.fevent.write('#Streaming started at ' + self.time_stamp + '\n')
if self.writeEDF:
EDF_format_extention = ".edf"
EDF_format_filetype = pyedflib.FILETYPE_EDFPLUS
temp_filterStringFileIndicator = "_prefiltered"
temp_filterStringHeader = 'HP ' + str(self.prefilterEDF_hp) + ' Hz'
if self.prefilterEDF_hp is None:
EDF_format_extention = ".bdf"
EDF_format_filetype = pyedflib.FILETYPE_BDFPLUS
temp_filterStringFileIndicator = "_unfiltered"
temp_filterStringHeader = 'none'
self.edfWriter = pyedflib.EdfWriter(self.path_and_file_name + "_missing_samples_corrected" + temp_filterStringFileIndicator + EDF_format_extention, self.nChannels+3, file_type=EDF_format_filetype)
"""
Only when the number of annotations you want to write is more than the number of seconds of the duration of the recording, you can use this function to increase the storage space for annotations */
/* Minimum is 1, maximum is 64 */
"""
if self.writeEDFAnnotations:
self.edfWriter.set_number_of_annotation_signals(self.edfAnnotationChannels) #7*60 = 420 annotations per minute on average
channel_info = {'label': 'ch', 'dimension': 'uV', 'sample_rate': int(round(self.fs)),
'physical_max': self.EDF_Physical_max_microVolt, 'physical_min': self.EDF_Physical_min_microVolt,
'digital_max': 32767, 'digital_min': -32767,
'prefilter': temp_filterStringHeader, 'transducer': 'none'}
channel_info_accel = {'label': 'acc', 'dimension': 'G', 'sample_rate': int(round(self.fs)),
def write_edf(fname, raw):
"""Export raw to EDF/BDF file (requires pyEDFlib)."""
import pyedflib
ext = "".join(Path(fname).suffixes)
if ext == ".edf":
filetype = pyedflib.FILETYPE_EDFPLUS
dmin, dmax = -32768, 32767
elif ext == ".bdf":
filetype = pyedflib.FILETYPE_BDFPLUS
dmin, dmax = -8388608, 8388607
data = raw.get_data() * 1e6 # convert to microvolts
fs = raw.info["sfreq"]
nchan = raw.info["nchan"]
ch_names = raw.info["ch_names"]
if raw.info["meas_date"] is not None:
meas_date = raw.info["meas_date"]
else:
meas_date = None
prefilter = (f"{raw.info['highpass']}Hz - "
f"{raw.info['lowpass']}")
pmin, pmax = data.min(axis=1), data.max(axis=1)
f = pyedflib.EdfWriter(fname, nchan, filetype)
channel_info = []
data_list = []
for i in range(nchan):