# custom frequency bands for calculating power band features

**URL:** <https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951>\
**Category:** Support & Discussions\
**Tags:** time-frequency, preprocessing\
**Created:** [November 14, 2021, 8:29pm UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951 "2021-11-14T20:29:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![FRSHT](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/frsht/32/139_2.png) [@FRSHT](https://mne.discourse.group/u/FRSHT)\
**Post date:** [November 14, 2021, 8:29pm UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/1 "2021-11-14T20:29:11Z")

</div>

Dear community members,

I’m extracting band power features from single channel eeg data with mne\_features and I need to know if it is possible to create custom frequency bands for calculating power. For example, I’d like to have normalised and relative power over these ranges:

“delta”: [0.5, 3.5], “theta”: [3.5, 7.5], “alpha1”: [7.5, 9.5],“alpha2”: [9.5,12.5], “beta1”: [12.5, 17.5], “beta1”: [17.5, 25], “gamma”: [25,40]

I tried this code, and it returned 6 final results for each epoch, whereas I expected 7 data points based on the frequency band definition. .

bands = {“delta”: [0.5, 3.5], “theta”: [3.5, 7.5], “alpha1”: [7.5, 9.5],“alpha2”: [9.5,12.5], “beta1”: [12.5, 17.5], “beta1”: [17.5, 25], “gamma”: [25,40]}  
X\_psd\_2 = extract\_features(X = epochs.get\_data([‘F7’]),  
sfreq = epochs.info[‘sfreq’],  
selected\_funcs = [‘pow\_freq\_bands’],  
funcs\_params = {‘pow\_freq\_bands\_\_freq\_bands’: bands,  
‘pow\_freq\_bands\_\_normalize’ : True})

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 14, 2021, 8:54pm UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/2 "2021-11-14T20:54:48Z")

</div>

Hello,

> [@FRSHT](#):
>
> bands = {“delta”: [0.5, 3.5], “theta”: [3.5, 7.5], “alpha1”: [7.5, 9.5],“alpha2”: [9.5,12.5], “beta1”: [12.5, 17.5], “beta1”: [17.5, 25], “gamma”: [25,40]}

`beta1` occurs twice, I suppose the second one needs to be `beta2` instead.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![FRSHT](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/frsht/32/139_2.png) [@FRSHT](https://mne.discourse.group/u/FRSHT)\
**Post date:** [November 15, 2021, 8:46pm UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/3 "2021-11-15T20:46:28Z")

</div>

Thanks for your response @richard ,  
I fixed that and it worked but now I am faced with this error while using the same code:  
**\_check\_input() missing 1 required keyword-only argument: 'reset’**  
I have no idea what had happened.

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [November 16, 2021, 9:26am UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/4 "2021-11-16T09:26:45Z")

</div>

Can you give the full traceback of the error? It suggests the private method `_check_input()` is used with an argument provided as a positional argument instead of a keyword argument somewhere. i.e. it should be `_check_input(positional_arguments, reset=..., other_keword_argument)`

---

<div class="post-metadata">

**Author:** ![FRSHT](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/frsht/32/139_2.png) [@FRSHT](https://mne.discourse.group/u/FRSHT)\
**Post date:** [November 16, 2021, 5:43pm UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/5 "2021-11-16T17:43:41Z")

</div>

@mscheltienne, Thanks for your response,  
Of course, I’ll share the entire error trace back, which consists of 21 frames:  
Specifically, I’d like to extract spectral and temporal properties from “F7” eeg channel data.

bands = {“delta”: [0.5, 3.5], “theta”: [3.5, 7.5],“alpha1”: [7.5, 9.5],“alpha2”: [9.5,12.5], “beta1”: [12.5, 17.5], “beta2”: [17.5, 25], “gamma”: [25,40], ‘total’:[0.5,40]}

X\_psd\_2 = extract\_features(X = epochs.get\_data([‘F7’]),  
sfreq = epochs.info[‘sfreq’],  
selected\_funcs = [‘pow\_freq\_bands’] ,  
funcs\_params = {‘pow\_freq\_bands\_\_freq\_bands’: bands,  
‘pow\_freq\_bands\_\_normalize’ : True})

* * *

TypeError Traceback (most recent call last)  
 in ()  
4 selected\_funcs = [‘pow\_freq\_bands’] ,  
5 funcs\_params = {‘pow\_freq\_bands\_\_freq\_bands’: bands,  
----\> 6 ‘pow\_freq\_bands\_\_normalize’ : True})

21 frames  
/usr/local/lib/python3.7/dist-packages/mne\_features/feature\_extraction.py in extract\_features(X, sfreq, selected\_funcs, funcs\_params, n\_jobs, return\_as\_df)  
433 extractor.set\_params(\*\*funcs\_params)  
434 res = joblib.Parallel(n\_jobs=n\_jobs)(joblib.delayed(\_apply\_extractor)(  
 → 435 extractor, X[j, :, :], return\_as\_df) for j in range(n\_epochs))  
436 feature\_names = res[0][1]  
437 res = list(zip(\*res))[0]

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in **call** (self, iterable)  
1041 # remaining jobs.  
1042 self.\_iterating = False  
 → 1043 if self.dispatch\_one\_batch(iterator):  
1044 self.\_iterating = self.\_original\_iterator is not None  
1045

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in dispatch\_one\_batch(self, iterator)  
859 return False  
860 else:  
 → 861 self.\_dispatch(tasks)  
862 return True  
863

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in \_dispatch(self, batch)  
777 with self.\_lock:  
778 job\_idx = len(self.\_jobs)  
 → 779 job = self.\_backend.apply\_async(batch, callback=cb)  
780 # A job can complete so quickly than its callback is  
781 # called before we get here, causing self.\_jobs to

/usr/local/lib/python3.7/dist-packages/joblib/\_parallel\_backends.py in apply\_async(self, func, callback)  
206 def apply\_async(self, func, callback=None):  
207 “”“Schedule a func to be run”""  
 → 208 result = ImmediateResult(func)  
209 if callback:  
210 callback(result)

/usr/local/lib/python3.7/dist-packages/joblib/\_parallel\_backends.py in **init** (self, batch)  
570 # Don’t delay the application, to avoid keeping the input  
571 # arguments in memory  
 → 572 self.results = batch()  
573  
574 def get(self):

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in **call** (self)  
261 with parallel\_backend(self.\_backend, n\_jobs=self.\_n\_jobs):  
262 return [func(\*args, \*\*kwargs)  
 → 263 for func, args, kwargs in self.items]  
264  
265 def **reduce** (self):

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in (.0)  
261 with parallel\_backend(self.\_backend, n\_jobs=self.\_n\_jobs):  
262 return [func(\*args, \*\*kwargs)  
 → 263 for func, args, kwargs in self.items]  
264  
265 def **reduce** (self):

/usr/local/lib/python3.7/dist-packages/mne\_features/feature\_extraction.py in \_apply\_extractor(extractor, X, return\_as\_df)  
199 Not None, only if `return_as_df` is True.  
200 “”"  
 → 201 X = extractor.fit\_transform(X)  
202 feature\_names = None  
203 if return\_as\_df:

/usr/local/lib/python3.7/dist-packages/sklearn/pipeline.py in fit\_transform(self, X, y, \*\*fit\_params)  
1170 sum of `n_components` (output dimension) over transformers.  
1171 “”"  
 → 1172 results = self.\_parallel\_func(X, y, fit\_params, \_fit\_transform\_one)  
1173 if not results:  
1174 # All transformers are None

/usr/local/lib/python3.7/dist-packages/sklearn/pipeline.py in \_parallel\_func(self, X, y, fit\_params, func)  
1202 \*\*fit\_params,  
1203 )  
 → 1204 for idx, (name, transformer, weight) in enumerate(transformers, 1)  
1205 )  
1206

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in **call** (self, iterable)  
1041 # remaining jobs.  
1042 self.\_iterating = False  
 → 1043 if self.dispatch\_one\_batch(iterator):  
1044 self.\_iterating = self.\_original\_iterator is not None  
1045

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in dispatch\_one\_batch(self, iterator)  
859 return False  
860 else:  
 → 861 self.\_dispatch(tasks)  
862 return True  
863

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in \_dispatch(self, batch)  
777 with self.\_lock:  
778 job\_idx = len(self.\_jobs)  
 → 779 job = self.\_backend.apply\_async(batch, callback=cb)  
780 # A job can complete so quickly than its callback is  
781 # called before we get here, causing self.\_jobs to

/usr/local/lib/python3.7/dist-packages/joblib/\_parallel\_backends.py in apply\_async(self, func, callback)  
206 def apply\_async(self, func, callback=None):  
207 “”“Schedule a func to be run”""  
 → 208 result = ImmediateResult(func)  
209 if callback:  
210 callback(result)

/usr/local/lib/python3.7/dist-packages/joblib/\_parallel\_backends.py in **init** (self, batch)  
570 # Don’t delay the application, to avoid keeping the input  
571 # arguments in memory  
 → 572 self.results = batch()  
573  
574 def get(self):

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in **call** (self)  
261 with parallel\_backend(self.\_backend, n\_jobs=self.\_n\_jobs):  
262 return [func(\*args, \*\*kwargs)  
 → 263 for func, args, kwargs in self.items]  
264  
265 def **reduce** (self):

/usr/local/lib/python3.7/dist-packages/joblib/parallel.py in (.0)  
261 with parallel\_backend(self.\_backend, n\_jobs=self.\_n\_jobs):  
262 return [func(\*args, \*\*kwargs)  
 → 263 for func, args, kwargs in self.items]  
264  
265 def **reduce** (self):

/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py in **call** (self, \*args, \*\*kwargs)  
209 def **call** (self, \*args, \*\*kwargs):  
210 with config\_context(\*\*self.config):  
 → 211 return self.function(\*args, \*\*kwargs)  
212  
213

/usr/local/lib/python3.7/dist-packages/sklearn/pipeline.py in \_fit\_transform\_one(transformer, X, y, weight, message\_clsname, message, \*\*fit\_params)  
891 with \_print\_elapsed\_time(message\_clsname, message):  
892 if hasattr(transformer, “fit\_transform”):  
 → 893 res = transformer.fit\_transform(X, y, \*\*fit\_params)  
894 else:  
895 res = transformer.fit(X, y, \*\*fit\_params).transform(X)

/usr/local/lib/python3.7/dist-packages/sklearn/base.py in fit\_transform(self, X, y, \*\*fit\_params)  
845 if y is None:  
846 # fit method of arity 1 (unsupervised transformation)  
 → 847 return self.fit(X, \*\*fit\_params).transform(X)  
848 else:  
849 # fit method of arity 2 (supervised transformation)

/usr/local/lib/python3.7/dist-packages/mne\_features/feature\_extraction.py in fit(self, X, y)  
85 self  
86 “”"  
—\> 87 self.\_check\_input(X)  
88 \_feature\_func = \_get\_python\_func(self.func)  
89 if hasattr(\_feature\_func, ‘get\_feature\_names’):

TypeError: \_check\_input() missing 1 required keyword-only argument: ‘reset’

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [November 17, 2021, 10:27am UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/6 "2021-11-17T10:27:42Z")

</div>

This bug has been fix on the github repository:

> <https://github.com/mne-tools/mne-features/blob/master/mne_features/feature_extraction.py#L103>

in this commit: [passing reset=True in \_check\_input() · mne-tools/mne-features@629f5d4 · GitHub](https://github.com/mne-tools/mne-features/commit/629f5d48f03e5facf0280c989b26cbebab4d199d)

To get rid of it, you could update to the development version, either by cloning the repository and then doing:

`python setup.py install`

Or by using the pip command:

`pip install git+https://github.com/mne-tools/mne-features.git#egg=mne_features`

---

<div class="post-metadata">

**Author:** ![FRSHT](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/frsht/32/139_2.png) [@FRSHT](https://mne.discourse.group/u/FRSHT)\
**Post date:** [November 18, 2021, 12:25pm UTC](https://mne.discourse.group/t/custom-frequency-bands-for-calculating-power-band-features/3951/7 "2021-11-18T12:25:28Z")

</div>

@mscheltienne Many thanks for your help.
