How to use the pyedflib.EdfWriter function in pyEDFlib

To help you get started, we’ve selected a few pyEDFlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Frederik-D-Weber / cosleep / software / installation / source_python / OpenBCI_csv_collect.py View on Github external
# 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)),
                                      'physical_max': 4, 'physical_min': -4,
                                      'digital_max': 32767, 'digital_min': -32767,
                                      'prefilter': 'none', 'transducer': 'none'}
github holgern / pyedflib / demo / writeEDFFile.py View on Github external
#    4    pulse 2           100 uV    1 Hz    256 Hz
#    5    pulse 3           100 uV    1 Hz    217 Hz
#    6    noise             100 uV    - Hz    200 Hz
#    7    sine 1 Hz         100 uV    1 Hz    200 Hz
#    8    sine 8 Hz         100 uV    8 Hz    200 Hz
#    9    sine 8.1777 Hz    100 uV    8.25 Hz 200 Hz
#    10    sine 8.5 Hz       100 uV    8.5Hz   200 Hz
#    11    sine 15 Hz        100 uV   15 Hz    200 Hz
#    12    sine 17 Hz        100 uV   17 Hz    200 Hz
#    13    sine 50 Hz        100 uV   50 Hz    200 Hz


if __name__ == '__main__':
    test_data_file = os.path.join('.', 'test_generator2.edf')
    file_duration = 600
    f = pyedflib.EdfWriter(test_data_file, 13,
                           file_type=pyedflib.FILETYPE_EDFPLUS)
    channel_info = []
    data_list = []

    ch_dict = {'label': 'squarewave', 'dimension': 'uV', 'sample_rate': 200, 'physical_max': 100, 'physical_min': -100, 'digital_max': 32767, 'digital_min': -32768, 'transducer': '', 'prefilter':''}
    channel_info.append(ch_dict)
    time = np.linspace(0, file_duration, file_duration*200)
    xtemp = np.sin(2*np.pi*0.1*time)
    x1 = xtemp.copy()
    x1[np.where(xtemp > 0)[0]] = 100
    x1[np.where(xtemp < 0)[0]] = -100
    data_list.append(x1)

    ch_dict = {'label': 'ramp', 'dimension': 'uV', 'sample_rate': 200, 'physical_max': 100, 'physical_min': -100, 'digital_max': 32767, 'digital_min': -32768, 'transducer': '', 'prefilter':''}
    channel_info.append(ch_dict)
    time = np.linspace(0, file_duration, file_duration*200)
github skjerns / AutoSleepScorerDev / edfx / convert_edfx_database.py View on Github external
:param signals: The signals as a list of arrays or a ndarray
    :param signal_headers: a list with one signal header for each signal (see function `make_signal_header)
    :param header: a header (see make_header())
    :param digital: whether signals are presented digitally or in physical values
    """
    assert header is None or isinstance(header, dict), 'header must be dictioniary'
    assert isinstance(signal_headers, list), 'signal headers must be list'
    signals = np.atleast_2d(signals)
    assert len(signal_headers)==len(signals), 'signals and signal_headers must be same length'
    
    if header is None: header = make_header()
    
    n_channels = len(signals)
    
    with pyedflib.EdfWriter(edf_file, n_channels=n_channels) as f:  
        f.setSignalHeaders(signal_headers)
        f.setHeader(header)
        f.writeSamples(signals, digital=digital)
        
    return os.path.isfile(edf_file) and os.path.getsize(edf_file)>signals.shape[1]