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

Auto-detect the trigger channel based on retrieved channel names #306

Merged
merged 76 commits into from
Feb 17, 2021

Conversation

vinferrer
Copy link
Collaborator

Closes #257
auto-detect the trigger channel comparing ch_name list to a of possible trigger names

Proposed Changes

  • Default chtrig is now 0 which will trigger the auto option
  • Create an alias list with possible trigger names
  • raise a warning if the trigger channel's name does not contain any element in the alias list
  • if the user didn't give a trigger channel, we look into the names and check if there is a match to any element of the alias list. If there is not, we raise an error.

@vinferrer
Copy link
Collaborator Author

Hello, @eurunuela, @tsalo, @smoia. I have implemented the auto option for the chtrig inside BlueprintInput class, because for me this makes more sense since it is the moment we start using the chtrig parameter. I left this as draft because i wan't you to corroborate that it makes sense to implement here the functionality the main reason is that independently of which interface we are running they all endup dropping the data in this class so no need for duplicities.
Also feel free to suggest new names for the chtrig alias names.

phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
@tsalo
Copy link
Member

tsalo commented Sep 18, 2020

I'll leave the discussion of the proper index for the trigger channel (i.e., 0 or 1) and where that switch happens to others, but I had some minor code edits/comments. Thanks for this!

Copy link
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't wait to see this implemented and working!

However, I have few comments and changes to ask (see comments).

There's another thing: I like the fact that this functionality is implemented in the object methods, but I don't know if it's actually good to have it there, and in any case I wouldn't put it in the initialisation of the object.

The reason for which I'm not sure it's good to have it in the object is that I think we're using the trigger channel to extract the time array when we deal with acq files (in the respective interface script), and that's a step that takes place before the initialisation of the object.
Maybe a better place would be the (refactored) interfaces script/folder, with this step taking place before the input processing. It's not vital though, we can just specify the change in the initialisation of acq files.

If we want to leave it as an object method (and I see why), I would make it a separate method and call it in case chtrig is zero, even after the initialisation of the object. It just means updating its properties.

phys2bids/cli/run.py Show resolved Hide resolved
phys2bids/interfaces/txt.py Outdated Show resolved Hide resolved
phys2bids/phys2bids.py Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
@eurunuela
Copy link
Collaborator

Hi @vinferrer , thanks a lot for this! I agree with the comments from @tsalo and @smoia . My other concern would be the linting not passing the test. I think once the comments are added we can merge it. Thanks again!

@codecov
Copy link

codecov bot commented Sep 18, 2020

Codecov Report

Merging #306 (2046244) into master (bdf4480) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   94.63%   94.77%   +0.14%     
==========================================
  Files           8        8              
  Lines         839      862      +23     
==========================================
+ Hits          794      817      +23     
  Misses         45       45              
Impacted Files Coverage Δ
phys2bids/cli/run.py 96.55% <ø> (ø)
phys2bids/phys2bids.py 88.13% <100.00%> (+0.06%) ⬆️
phys2bids/physio_obj.py 93.75% <100.00%> (+0.73%) ⬆️

@vinferrer
Copy link
Collaborator Author

Okay i have

I can't wait to see this implemented and working!

However, I have few comments and changes to ask (see comments).

There's another thing: I like the fact that this functionality is implemented in the object methods, but I don't know if it's actually good to have it there, and in any case I wouldn't put it in the initialisation of the object.

The reason for which I'm not sure it's good to have it in the object is that I think we're using the trigger channel to extract the time array when we deal with acq files (in the respective interface script), and that's a step that takes place before the initialisation of the object.
Maybe a better place would be the (refactored) interfaces script/folder, with this step taking place before the input processing. It's not vital though, we can just specify the change in the initialisation of acq files.

If we want to leave it as an object method (and I see why), I would make it a separate method and call it in case chtrig is zero, even after the initialisation of the object. It just means updating its properties.

I see what you mean about acq files. Is it critical that you use the chtrig channel to obtain the frequency and the time index?

@vinferrer
Copy link
Collaborator Author

vinferrer commented Sep 21, 2020

So guys I have implemented the partial match thingy as you can see, if you don't want me to have this in physio_obj.py we could put it as a utils function that is used in each of the interfaces.py script but i think that would make more duplicities. Is there a way we can avoid using chtrig in acq.py?

@eurunuela
Copy link
Collaborator

So guys I have implemented the partial match thingy as you can see, if you don't want me to have this in physio_obj.py we could put it as a utils function that is used in each of the interfaces.py script but i think that would make more duplicities. Is there a way we can avoid using chtrig in acq.py?

I agree that not using chtrig in acq.py would make the code cleaer. Any idea @smoia ? I believe that piece of code was yours.

@tsalo
Copy link
Member

tsalo commented Feb 4, 2021

You're right. It would require a couple of changes to the CLI, although we have a good template for that kind of argument in tedana now, with --tedpca. See here.

If it seems like too much work, or otherwise just not a good idea, what about -1? Most Python users would think 0 would be a standard value, while -1 is a common "special value".

@vinferrer
Copy link
Collaborator Author

Okay, actually I do have a very strong opinion about using auto or -1 as the default option, think that the check is done after reading the file, all our io.py are designed to use chtrig as a number and there is actually an error designed to pop up when chtrig is negative, so I would stay with the 0 as default option

Copy link
Member

@tsalo tsalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
phys2bids/physio_obj.py Outdated Show resolved Hide resolved
@smoia
Copy link
Member

smoia commented Feb 16, 2021

I checked again the regex comparison, and came up with the alternative solution (see this comment) that doesn't have the issue of matching wrong channel names due to empty strings in the channel name split.
Granted, it's less elegant because it uses more lines of code, but it's a bit more specific.
I opened a PR to your branch, here if @tsalo or @eurunuela want to have a look at it.

Propose less elegant but more specific comparison
@vinferrer
Copy link
Collaborator Author

vinferrer commented Feb 17, 2021

Well I think we are ready to merge this @smoia

Copy link
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'm biased!
@tsalo @eurunuela do you want to give a second look? If so, the last one can merge this in!

Copy link
Member

@tsalo tsalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smoia smoia self-assigned this Feb 17, 2021
@smoia smoia merged commit f6f5191 into physiopy:master Feb 17, 2021
@smoia
Copy link
Member

smoia commented Feb 17, 2021

🚀 PR was released in 2.4.0 🚀

@smoia smoia added the released This issue/pull request has been released. label Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minormod This PR generally closes an `Enhancement` issue. It increments the minor version (0.+1.0) released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'auto' option for populate_phys_input chtrig parameter
4 participants