# apply head position to empty room

**URL:** <https://mne.discourse.group/t/apply-head-position-to-empty-room/8988>\
**Category:** Support & Discussions\
**Tags:** mne-bids\
**Created:** [June 24, 2024, 5:56pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988 "2024-06-24T17:56:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [June 24, 2024, 5:56pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/1 "2024-06-24T17:56:20Z")

</div>

Hello,  
We’ve been trying to improve our covariance matrix.  
I read [this excellent paper](https://doi.org/10.3389/fneur.2022.827529), and I’m working on trying to apply.

I started with[this documentation](https://mne.tools/dev/auto_examples/preprocessing/movement_compensation.html#ex-movement-comp), but I have several questions.

Can anyone provide an example command of how you might use tsss on empty room data with an applied real head movement position?

Thanks,  
Megan

---

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [June 24, 2024, 8:13pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/2 "2024-06-24T20:13:27Z")

</div>

Apologies, here is the correct DOI for the paper: [https://doi.org/10.3389/fneur.2022.827529](https://doi.org/10.3389/fneur.2022.827529)

---

<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:** [June 25, 2024, 7:08am UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/3 "2024-06-25T07:08:13Z")

</div>

You’ll find some reference in this post: [head position parameter for maxfiltering empty-room recording](https://mne.discourse.group/t/head-position-parameter-for-maxfiltering-empty-room-recording/8402)

---

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [June 26, 2024, 4:08pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/4 "2024-06-26T16:08:49Z")

</div>

Thank you! Looks very helpful!  
Megan

---

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [June 26, 2024, 7:07pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/5 "2024-06-26T19:07:39Z")

</div>

Hello,  
I’m stuck using mne.preprocessing.maxwell\_filter\_prepare\_emptyroom. Could someone please provide a usage example?

My command looks like:

> mne.preprocessing.maxwell\_filter\_prepare\_emptyroom(empty\_raw, raw)

I get the following error

> * * *
> 
> TypeError Traceback (most recent call last)  
> ----\> 1 mne.preprocessing.maxwell\_filter\_prepare\_emptyroom(empty\_raw, raw)
> 
> TypeError: maxwell\_filter\_prepare\_emptyroom() takes 1 positional argument but 2 were given

I also tried

> mne.preprocessing.maxwell\_filter\_prepare\_emptyroom(empty\_raw, \*, raw, bads=‘from\_raw’, meas\_date=‘keep’, verbose=None)

which gave this error:

> SyntaxError: invalid syntax
> 
> * * *
> 
> TypeError Traceback (most recent call last)  
> ----\> 1 mne.preprocessing.maxwell\_filter\_prepare\_emptyroom(empty\_raw, raw, bads=‘from\_raw’, meas\_date=‘keep’, verbose=None)
> 
> TypeError: maxwell\_filter\_prepare\_emptyroom() takes 1 positional argument but 2 positional arguments (and 3 keyword-only arguments) were given

Thank you,  
Megan

---

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [June 26, 2024, 7:16pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/6 "2024-06-26T19:16:37Z")

</div>

Hello,  
Perhaps there is an error in the documentation?

I tried

> mne.preprocessing.maxwell\_filter\_prepare\_emptyroom(empty\_raw, raw =raw, verbose=True)

using raw as a keyword argument instead of positional, and the command was successful.

Thank you,  
Megan

---

<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:** [June 27, 2024, 5:38am UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/7 "2024-06-27T05:38:55Z")

</div>

There is no error in the documentation:

```python
mne.preprocessing.maxwell_filter_prepare_emptyroom(raw_er, *, raw, bads='from_raw', annotations='from_raw', meas_date='keep', emit_warning=False, verbose=None)

```

In Python, every argument after the \* is a keyword-only argument. This is to force users to use keywords and don’t do e.g.

```python
maxwell_filter_prepare_emptyroom(raw, raw_er)

```

You also have positional only arguments:

```python
def foo(arg1, arg2, /, arg3, arg4, *, arg5, arg6, *args, **kwargs):
    ...

```

Before the `/` → positional argument only, thus `foo(arg1=...)` will raise.  
Between the `/` and `*` → positional or keyword arguments  
After the `*` → keyword only argument, thus `foo(x1, x2, x3, x4, x5)` will raise.

Mathieu

---

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [June 28, 2024, 3:35pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/8 "2024-06-28T15:35:32Z")

</div>

Hi, Thanks for your explanation. This is new to me!  
Should it be then, raw=raw instead of just  
…, \*, raw, …  
? Is raw the keyword **and** the object being passed to the keyword parameter?

Thanks! I sincerely appreciate your help,  
Megan

---

<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:** [July 1, 2024, 6:44am UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/9 "2024-07-01T06:44:46Z")

</div>

Correct, it should be either `maxwell_filter_prepare_emptyroom(raw_er=..., raw=...)` or `maxwell_filter_prepare_emptyroom(..., raw=...)` because all of the arguments after the `*` must be provided with their keyword name (`raw=`, `bads=`, …).  
Note that the variable name passed can differ, e.g. `maxwell_filter_prepare_emptyroom(empty_room_raw, raw=process_raw)`.

---

<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:** [July 1, 2024, 8:55am UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/10 "2024-07-01T08:55:17Z")

</div>

@mschendel I’ve asked ChatGPT to generate an explanation.

> Please explain Python’s keyword-only arguments in simple terms to somebody who’s not familiar with this concept. Please explain how to spot them and how to use them (from a user side). Please include examples of keyword-only arguments with and without default values.

> ### Understanding Python’s Keyword-Only Arguments
> 
> In Python, keyword-only arguments are parameters that can only be passed by their name (keyword) and not by their position in the function call. These arguments provide more clarity and prevent confusion, especially when a function takes multiple parameters.
> 
> ### How to Spot Keyword-Only Arguments
> 
> You can identify keyword-only arguments in a function definition by looking for an asterisk (`*`) in the parameter list. Any parameter after the `*` must be passed as a keyword argument.
> 
> ### Using Keyword-Only Arguments
> 
> When calling a function with keyword-only arguments, you must explicitly name these arguments. This can improve readability and reduce errors.
> 
> ### Examples
> 
> Let’s go through examples of keyword-only arguments with and without default values.
> 
> #### Example 1: Keyword-Only Arguments without Default Values
> 
> ```python
> def greet(name, *, greeting):
> return f"{greeting}, {name}!"
> 
> # Correct usage
> print(greet("Alice", greeting="Hello")) # Output: Hello, Alice!
> 
> # Incorrect usage (will raise a TypeError)
> # print(greet("Alice", "Hello"))
> 
> ```
> 
> In this example, `greeting` is a keyword-only argument. You must specify `greeting` when calling the function.
> 
> #### Example 2: Keyword-Only Arguments with Default Values
> 
> ```python
> def introduce(name, *, age=None, city="Unknown"):
> return f"Meet {name}, who is {age} years old and lives in {city}."
> 
> # Correct usage with default values
> print(introduce("Bob")) # Output: Meet Bob, who is None years old and lives in Unknown.
> 
> # Correct usage with provided values
> print(introduce("Bob", age=30, city="New York")) # Output: Meet Bob, who is 30 years old and lives in New York.
> 
> # Incorrect usage (will raise a TypeError)
> # print(introduce("Bob", 30, "New York"))
> 
> ```
> 
> In this example, `age` and `city` are keyword-only arguments with default values. You can either use the defaults or provide specific values by naming the arguments.
> 
> ### Summary
> 
> - **Keyword-only arguments** are specified after an asterisk (`*`) in the function definition.
> - They **must be passed by name** when calling the function.
> - They can have **default values**.
> - They improve code clarity and reduce potential errors.
> 
> By using keyword-only arguments, you can make your function calls more explicit and easier to understand.

> What are advantages and disadvantages of keyword-only arguments?

> ### Advantages and Disadvantages of Keyword-Only Arguments
> 
> #### Advantages
> 
> 1. **Improved Readability** :
> 
> 2. **Reduced Risk of Errors** :
> 
> 3. **Flexibility with Default Values** :
> 
> 4. **Better Support for APIs and Libraries** :
> 
> 5. **Easier Maintenance** :
> 
> #### Disadvantages
> 
> 1. **Verbose Syntax** :
> 
> 2. **Learning Curve** :
> 
> 3. **Incompatibility with Positional-Only APIs** :
> 
> 4. **Potential for Overhead** :
> 
> ### Summary
> 
> **Advantages** :
> 
> - Improves code readability and clarity.
> - Reduces the risk of argument misplacement errors.
> - Provides flexibility with default values.
> - Enhances support for public APIs and libraries.
> - Easier maintenance with future changes to function signatures.
> 
> **Disadvantages** :
> 
> - Can lead to verbose syntax.
> - May present a learning curve for new programmers.
> - Less compatible with positional-only argument expectations.
> - Potential for overhead in writing and maintaining simple functions.
> 
> Keyword-only arguments are a powerful feature in Python that, when used judiciously, can significantly enhance the clarity and robustness of your code.

---

<div class="post-metadata">

**Author:** ![mschendel](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@mschendel](https://mne.discourse.group/u/mschendel)\
**Post date:** [July 1, 2024, 5:17pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/11 "2024-07-01T17:17:43Z")

</div>

Hi all,  
I really appreciate your help! That all helps me understand.

Sincerely, Megan

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [July 31, 2024, 6:56pm UTC](https://mne.discourse.group/t/apply-head-position-to-empty-room/8988/12 "2024-07-31T18:56:09Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
