diff --git a/pyedflib/edfwriter.py b/pyedflib/edfwriter.py index 6d99b83..9c1f2ef 100644 --- a/pyedflib/edfwriter.py +++ b/pyedflib/edfwriter.py @@ -171,19 +171,6 @@ def __init__(self, file_name, n_channels, edflib.FILETYPE_EDFPLUS edflib.FILETYPE_BDFPLUS n_channels is the number of channels without the annotation channel - - channel_info should be a - list of dicts, one for each channel in the data. Each dict needs - these values: - - 'label' : channel label (string, <= 16 characters, must be unique) - 'dimension' : physical dimension (e.g., mV) (string, <= 8 characters) - 'sample_rate' : sample frequency in hertz (int). Deprecated: use 'sample_frequency' instead. - 'sample_frequency' : number of samples per record (int) - 'physical_max' : maximum physical value (float) - 'physical_min' : minimum physical value (float) - 'digital_max' : maximum digital value (int, -2**15 <= x < 2**15) - 'digital_min' : minimum digital value (int, -2**15 <= x < 2**15) """ self.path = file_name self.file_type = file_type @@ -205,13 +192,15 @@ def __init__(self, file_name, n_channels, self.sample_buffer = [] for i in np.arange(self.n_channels): if self.file_type == FILETYPE_BDFPLUS or self.file_type == FILETYPE_BDF: - self.channels.append({'label': f'ch{i}', 'dimension': 'mV', 'sample_rate': 100, - 'sample_frequency': None, 'physical_max': 1.0, 'physical_min': -1.0, + self.channels.append({'label': f'ch{i}', 'dimension': 'mV', + 'sample_frequency': 100, + 'physical_max': 1.0, 'physical_min': -1.0, 'digital_max': 8388607,'digital_min': -8388608, 'prefilter': '', 'transducer': ''}) elif self.file_type == FILETYPE_EDFPLUS or self.file_type == FILETYPE_EDF: - self.channels.append({'label': f'ch{i}', 'dimension': 'mV', 'sample_rate': 100, - 'sample_frequency': None, 'physical_max': 1.0, 'physical_min': -1.0, + self.channels.append({'label': f'ch{i}', 'dimension': 'mV', + 'sample_frequency': 100, + 'physical_max': 1.0, 'physical_min': -1.0, 'digital_max': 32767, 'digital_min': -32768, 'prefilter': '', 'transducer': ''}) @@ -314,6 +303,19 @@ def setSignalHeader(self, edfsignal, channel_info): 'digital_max' : maximum digital value (int, -2**15 <= x < 2**15) 'digital_min' : minimum digital value (int, -2**15 <= x < 2**15) """ + try: + sample_rate = channel_info.pop('sample_rate') + except KeyError: + pass + else: + if 'sample_frequency' in channel_info: + if sample_rate != channel_info['sample_frequency']: + warnings.warn("The 'sample_rate' parameter is deprecated. " + "Please use 'sample_frequency' instead.", + DeprecationWarning) + else: + channel_info['sample_frequency'] = sample_rate + if edfsignal < 0 or edfsignal > self.n_channels: raise ChannelDoesNotExist(edfsignal) self.channels[edfsignal].update(channel_info) diff --git a/pyedflib/highlevel.py b/pyedflib/highlevel.py index e884814..cc3046c 100644 --- a/pyedflib/highlevel.py +++ b/pyedflib/highlevel.py @@ -239,10 +239,14 @@ def make_signal_header(label, dimension='uV', sample_rate=256, sample_frequency= a signal header that can be used to save a channel to an EDF. """ + if sample_frequency is None: + sample_frequency = sample_rate + elif sample_rate != 256 and sample_rate != sample_frequency: + warnings.warn("The 'sample_rate' parameter is deprecated. Please use " + "'sample_frequency' instead.", DeprecationWarning) signal_header = {'label': label, 'dimension': dimension, - 'sample_rate': sample_rate, 'sample_frequency': sample_frequency, 'physical_min': physical_min, 'physical_max': physical_max,