Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deprecated sample_rate in our own code #231

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions pyedflib/edfwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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': ''})

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion pyedflib/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down