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

Adding pipelines for cli analysis #202

Merged
merged 38 commits into from
Oct 16, 2022
Merged

Adding pipelines for cli analysis #202

merged 38 commits into from
Oct 16, 2022

Conversation

Parvfect
Copy link
Collaborator

@Parvfect Parvfect commented Aug 8, 2022

As discussed, it makes sense to transition from the notebooks for analysis of eegnb experiments to a cli that can provide the user an opportunity to do the analysis without getting his hands messy with the code. This is what is being implemented in this PR.

As of now, automating the two experiments VisualN170 and VisualP300 analysis by callable functions whose use is specified in the code and repeated here,

#Visual N170:
raw, epochs = load_eeg_data('visual-n170', device_name='muse2016_bfn')
make_erp_plot(epochs)

#Visual P300:
raw, epochs = load_eeg_data('visual-P300', device_name='muse2016', event_id={'Non-Target': 1, 'Target': 2})
make_erp_plot(epochs, conditions=OrderedDict(NonTarget=[1],Target=[2]))

Some discussion to be had on implementing all experiments and where this can go, but a start to make sure that there is something to talk about.

Implemented as a part of the GSOC period for EEG - Notebooks under the mentorship of John Griffiths.

@Parvfect
Copy link
Collaborator Author

Parvfect commented Aug 8, 2022

@Parvfect Parvfect self-assigned this Aug 8, 2022
@Parvfect Parvfect requested a review from hbk008 August 11, 2022 13:28
@hbk008
Copy link
Collaborator

hbk008 commented Aug 17, 2022

The results are reproducible for N170 (in line with the tutorial for load and visualize data) but NOT for P300 due to differences in tmax value and reject={'eeg': } values along with differences in plotting values. I believe we need to make CLI plots in line with those in tutorials, right?

@Parvfect
Copy link
Collaborator Author

The results are reproducible for N170 (in line with the tutorial for load and visualize data) but NOT for P300 due to differences in tmax value and reject={'eeg': } values along with differences in plotting values. I believe we need to make CLI plots in line with those in tutorials, right?

yeah you're right, I'll have a look and fixing it

@Parvfect
Copy link
Collaborator Author

Current Status:

Automated Report generation done, looks like this
image

The Report gets saved in the appropiate save directory as per
"""
Analysis report saved to C:\Users\Parv/.eegnb\analysis\visual-N170\local\muse2\subject1\session3
"""

Autoscaling for the plots is done using matplotlib's provided function (amen to that)

plt.autoscale(tight=True)

That fits it to the limits of the data which is what we want.

Some errors when trying automated generation after a live recorded session that need to be handled, would appreciate help if anyone has time with that.

PDF needs to be beautified with more explanation and made cleaner with the images aspect ratio.

For Reviewer

Kindly

  1. Look through code structure in pipelines.py to make sure it is good programming practice. Currently for the report have to save two images so I can add it to the pdf and then delete them once its made. Don't know if that's really hacky or bad.
  2. PDF gets automatically generated if analysis function is invoked, should there be an option to disable that?
  3. Do we need an interface for the cli that prompts users for inputs or should I leave it as it is that can be used with two lines of code?
  4. What should be added to the analysis report besdies some basic descriptive text, subject and session info?

@Parvfect Parvfect added the enhancement New feature or request label Aug 28, 2022
Copy link
Collaborator

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

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

Looking good!

Didn't do a super-thorough review, but had a few comments :)

eegnb/cli/__main__.py Outdated Show resolved Hide resolved
Comment on lines +520 to +528
prompt_time = time()
print(f"Starting next cycle in 5 seconds, press C and enter to cancel")
while time() < prompt_time + 5:
if keyboard.is_pressed('c'):
print("\nStopping signal quality checks!")
flag = True
break
if flag:
break
Copy link
Collaborator

@ErikBjare ErikBjare Aug 29, 2022

Choose a reason for hiding this comment

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

This loop is hot and will lead to 100% CPU until c is pressed. Enter is also no longer needed, contrary to instructions.

I suggest something like this instead:

print("Starting next cycle in 5 seconds, press Ctrl+C to cancel")
try:
    sleep(5)
except KeyboardInterrupt:
    break

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a good suggestion, but let's implement it on another dev branch PR to this one, as it's not directly related to the new code from this contribution.

Comment on lines 1 to 6
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't commit this file.

You can add .ipynb_checkpoints to .gitignore to prevent this from happening again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Parvfect re: this - IMHO it is best to name files individually when committing.

i.e. do

git commit file1.py file2.py file3.py file4.py file5.py -m"my commit description"

rather than

git commit * -m"my commit description"

or

git commit -a -m"my commit description"

because the latter, even though syntactically simpler, will frequently lead to unintended files being committed, even when one is not being particularly sloppy.

@hbk008
Copy link
Collaborator

hbk008 commented Sep 1, 2022

Just checked again, works for N170 but does not work for P300 with example = True. I can see that the device name is passed on line 256 for P300 when example = True. Can you check that again?

@Parvfect
Copy link
Collaborator Author

Parvfect commented Sep 1, 2022

Just checked again, works for N170 but does not work for P300 with example = True. I can see that the device name is passed on line 256 for P300 when example = True. Can you check that again?

device changes again to muse_2016. I'd prefer you use the example_analysis_report() function so it can handle the device issues

@Parvfect
Copy link
Collaborator Author

Parvfect commented Sep 5, 2022

Things to complete on this (as discussed 1/9/22)

(TBC starting 20 September finishing and deploying by the end of the month)

  1. Global Variables in pipelines.py to passed around dictionary parameters (to be completed in the Experiment Class Library as well)
  2. Add an option of launching saved pdf using one line in the terminal for ease of use
  3. PDF Beautification (section heading, hyperlinks, picture aspect ratio, information about experiment and linking to further explanation in documentation, including sample drop percentage and other relevant outputs)
  4. Newline after terminal message for the inputs
  5. Fix multiple images for the filters that get displayed
  6. Add a ten second timer for automatically closing figures
  7. Automatic analysis report for recorded session through cli
  8. Add pdf library to requirements

@oreHGA, @retiutut, @ErikBjare, @JohnGriffiths - I would really appreciate a solid PR review with some feedback for this because I feel this is quite a cool feature that we can simply add to EEG Notebooks and can expand the user base as well as improve general functionality. Additionally, I do think that I have assumed a lot of things while writing this code because it was rushed, which might be ignored because everything works so could really appreciate some feedback.

General instructions for running it

eegnb create-analysis-report -ip

Specifically using pipeline functions

Usage:
For Recorded Data:

from eegnb.analysis.pipelines import create_analysis_report()
create_analysis_report(experiment, eegdevice, subject, session, filepath)s

For Example Datasets:

from eegnb.analysis.pipelines import example_analysis_report()
example_analysis_report()


return report_path

def create_analysis_report_(experiment, eegdevice, subject=None, session=None, data_path=None, bluemuse_file_fix=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: remove trailing _

@Parvfect
Copy link
Collaborator Author

Parvfect commented Sep 26, 2022

Things to complete on this (as discussed 1/9/22)

(TBC starting 20 September finishing and deploying by the end of the month)

  1. Global Variables in pipelines.py to passed around dictionary parameters (to be completed in the Experiment Class Library as well)
  2. Add an option of launching saved pdf using one line in the terminal for ease of use
  3. PDF Beautification (section heading, hyperlinks, picture aspect ratio, information about experiment and linking to further explanation in documentation, including sample drop percentage and other relevant outputs)
  4. Newline after terminal message for the inputs
  5. Fix multiple images for the filters that get displayed
  6. Add a ten second timer for automatically closing figures
  7. Automatic analysis report for recorded session through cli
  8. Add pdf library to requirements

@oreHGA, @retiutut, @ErikBjare, @JohnGriffiths - I would really appreciate a solid PR review with some feedback for this because I feel this is quite a cool feature that we can simply add to EEG Notebooks and can expand the user base as well as improve general functionality. Additionally, I do think that I have assumed a lot of things while writing this code because it was rushed, which might be ignored because everything works so could really appreciate some feedback.

General instructions for running it

eegnb create-analysis-report -ip

Specifically using pipeline functions

Usage: For Recorded Data:

from eegnb.analysis.pipelines import create_analysis_report()
create_analysis_report(experiment, eegdevice, subject, session, filepath)s

For Example Datasets:

from eegnb.analysis.pipelines import example_analysis_report()
example_analysis_report()

Things completed

  1. Packaging global variables as experimental parameters
  2. Added hyperlink to make it easy for user to see report from terminal
  3. Added eegdevice list prompt for selection
  4. Automatically close figures after 10 seconds of viewing them
  5. Fixed requirements.txt
  6. Embedded images into html using b64

Big change of switiching from pdf to generating html for stylistic purposes following comments left by John. Linking to different sections done, and image stretching etc has been resolved - here's what the template looks like

image

  • [ ]
    image

The text is rudimentary and the taskbar links to different sections for easy navigation.

Testing

The way of testing this remains the same as before and is the previous comment in this thread that this one replies to but in simple terms,

eegnb create-analysis-report -ip

Things left to do

  • Two images show up in fresh installation
  • Link not shown in some terminals
  • Automated report generation - filename passing test otherwise functional -> tabled
  • Actual styling of report needs to be considered

Would really appreciate some quick feedback so we can get the ball rolling and get this done soon.

@retiutut
Copy link
Contributor

retiutut commented Sep 27, 2022

Why are the checks still failing? It looks like all but one PR fails the tests 🤷‍♂️

@Parvfect
Copy link
Collaborator Author

Why are the checks still failing? It looks like all but one PR fails the tests 🤷‍♂️

I'm not completely sure but my thinking is that these things could be responsible,

  1. Changed requirements by adding Airium
  2. Changed the cli by adding automated analysis option

@JohnGriffiths
Copy link
Collaborator

It's the requirements change. If you look at the task list the red cross appears at install dependencies.

@Parvfect
Copy link
Collaborator Author

Parvfect commented Oct 6, 2022

@ErikBjare I'm trying to figure out why there is a docs build error, shown as follows,
image

I see that you have updated something in the main branch about wxpython's wheels to PyPi with reference to #190

image

Although it seems to say that the module attrdict is not found, do you know what is actually happening because I am pretty confused. There aren't major changes in the cli that have to do with building wxpython so it's hard to understand why it's creating an issue. Would love some assistance.

@Parvfect Parvfect marked this pull request as ready for review October 16, 2022 08:49
@JohnGriffiths
Copy link
Collaborator

JohnGriffiths commented Oct 16, 2022

Finished with basic functionality testing. Merging now.

I have some improvements to the report generation functionality and some of the function options, will add those as a new PR rather than over-complicating this one.

( Note, the doc build issue here is unrelated to the content of this PR, seems due to a wxpython issue that came up whilst this PR was made. So will address that separately and not on this PR. )

Good job @Parvfect !

@JohnGriffiths JohnGriffiths merged commit 6714740 into develop Oct 16, 2022
JohnGriffiths added a commit that referenced this pull request Jan 19, 2023
* example test commit (#182)

* example test commit

* example edit

* ci: run test workflow on develop branch

* ci: add develop branch to job triggers

* ci: fix syntax issue in workflow

* fix: fixed import (brainflow updated API)

* build(deps): locked pylsl==1.10.5 (#187)

* Experiment Class Refactor (update to #183), converting specific experiments to subclasses (#184)

* First commit

* Second commit

* Modifications

* Lol

* Lol

* Incorporated N170 and p300, looking good for a PR

* ssvep update

* Implementing subclasses instead of loose functions

* fix: fixed import (brainflow updated API)

* Playing around still

* Fixing import errors

* Adding abstractmethod decorators

* Still working on the import error

* Guess what's finally working

* Comments and naming ticks

* More comments

* Live coding demonstration

* ssvep adapted

* Adapting Auditory Oddball

* changing save_fn to self.save_fun

* This maybe the last big change

* utils file changed, changes work through cli

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>

* Submodule added for gsoc

* Adding pipelines for cli analysis (#202)

* started pipelines function

* almost working simple function equivalents of nb scripts

* fix: fixed import (brainflow updated API)

* sqc fixes for unicorn (#176)

* Ignore pushes

* Trying to create a cli

* Stepping through the problem

* First commit

* Fixing pause in signal quality check

* Fixing Signal quality check problem

* fix the technical debt

* Save path done for automated saving pdf

* I feel amazing

* Almost through

* Update eegnb/cli/__main__.py

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>

* Trying to create cli but it's being really painful

* Extra word cli error

* Changed example handling

* Pain

* Adding whole datapath

* Finally fixed cli

* hmm

* Looking good

* added hyperlink

* Having some issues with detecting css and image deltetion

* Just the css now

* Fixed the css linking problem though it's a weird soln

* Automated running, still fnames problem

* Hahahah embedded images in html

* Improving code

* Okay now

* Look at that

* Almost there just the two figures now

* Now

* Added attrdict to do with cli error

Co-authored-by: John Griffiths <j.davidgriffiths@gmail.com>
Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>

* added more options for site args; improved function names; removed some redundant lines (#209)

* fix subject num parsing bug

* analysis report function improvements for openbci cyton and gtec unicorn devices

* run exp fix

* Update requirements.txt

* fixes to get docs building by github action (#210)

* fixes to get docs building by github action

* reverted some changes

* Update 01r__ssvep_viz.py

Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>

* Update README.rst

small commit to test doc build workflow on this branch

* removing gsoc submodule

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: Parv Agarwal <65726543+Parvfect@users.noreply.github.com>
Co-authored-by: Parvfect <parvagrw02@gmail.com>
Co-authored-by: Ben Pettit <pelleter@gmail.com>
oreHGA added a commit that referenced this pull request Mar 4, 2023
* major update: merging develop to master (#217)

* example test commit (#182)

* example test commit

* example edit

* ci: run test workflow on develop branch

* ci: add develop branch to job triggers

* ci: fix syntax issue in workflow

* fix: fixed import (brainflow updated API)

* build(deps): locked pylsl==1.10.5 (#187)

* Experiment Class Refactor (update to #183), converting specific experiments to subclasses (#184)

* First commit

* Second commit

* Modifications

* Lol

* Lol

* Incorporated N170 and p300, looking good for a PR

* ssvep update

* Implementing subclasses instead of loose functions

* fix: fixed import (brainflow updated API)

* Playing around still

* Fixing import errors

* Adding abstractmethod decorators

* Still working on the import error

* Guess what's finally working

* Comments and naming ticks

* More comments

* Live coding demonstration

* ssvep adapted

* Adapting Auditory Oddball

* changing save_fn to self.save_fun

* This maybe the last big change

* utils file changed, changes work through cli

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>

* Submodule added for gsoc

* Adding pipelines for cli analysis (#202)

* started pipelines function

* almost working simple function equivalents of nb scripts

* fix: fixed import (brainflow updated API)

* sqc fixes for unicorn (#176)

* Ignore pushes

* Trying to create a cli

* Stepping through the problem

* First commit

* Fixing pause in signal quality check

* Fixing Signal quality check problem

* fix the technical debt

* Save path done for automated saving pdf

* I feel amazing

* Almost through

* Update eegnb/cli/__main__.py

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>

* Trying to create cli but it's being really painful

* Extra word cli error

* Changed example handling

* Pain

* Adding whole datapath

* Finally fixed cli

* hmm

* Looking good

* added hyperlink

* Having some issues with detecting css and image deltetion

* Just the css now

* Fixed the css linking problem though it's a weird soln

* Automated running, still fnames problem

* Hahahah embedded images in html

* Improving code

* Okay now

* Look at that

* Almost there just the two figures now

* Now

* Added attrdict to do with cli error

Co-authored-by: John Griffiths <j.davidgriffiths@gmail.com>
Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>

* added more options for site args; improved function names; removed some redundant lines (#209)

* fix subject num parsing bug

* analysis report function improvements for openbci cyton and gtec unicorn devices

* run exp fix

* Update requirements.txt

* fixes to get docs building by github action (#210)

* fixes to get docs building by github action

* reverted some changes

* Update 01r__ssvep_viz.py

Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>

* Update README.rst

small commit to test doc build workflow on this branch

* removing gsoc submodule

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: Parv Agarwal <65726543+Parvfect@users.noreply.github.com>
Co-authored-by: Parvfect <parvagrw02@gmail.com>
Co-authored-by: Ben Pettit <pelleter@gmail.com>

* update dependencies - seaborn

* docs/perf: reduced the imports: `cueing` example

* bug: update deprecated `plot_psd()` method

- feature of new `mne` version.
- instead of doing plot_psd() from the `mne.io.Raw` object, must do this:
	- `raw.compute_psd().plot()`
	- i.e., has to pass through a `spectrum` object

* updated deprec. `mne` function

* perf: removed importage of unused packages from example
- One of them, i.e., `collections.Iterable` is even deprecated.
- Must use `collections.abc.Iterable` instead now.
- Resulting in faster build/user run

* bugfix: `plot_conditions` - due to `sns` deprecation

* bugfix: resolved `psd_welch()` deprecation (`mne`)

---------

Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>
Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: Parv Agarwal <65726543+Parvfect@users.noreply.github.com>
Co-authored-by: Parvfect <parvagrw02@gmail.com>
Co-authored-by: Ben Pettit <pelleter@gmail.com>
Co-authored-by: Taha Morshedzadeh <taha.morshedzadeh@neuromatch.io>
oreHGA added a commit that referenced this pull request Mar 10, 2023
…Refactor (#218)

* major update: merging develop to master (#217)

* example test commit (#182)

* example test commit

* example edit

* ci: run test workflow on develop branch

* ci: add develop branch to job triggers

* ci: fix syntax issue in workflow

* fix: fixed import (brainflow updated API)

* build(deps): locked pylsl==1.10.5 (#187)

* Experiment Class Refactor (update to #183), converting specific experiments to subclasses (#184)

* First commit

* Second commit

* Modifications

* Lol

* Lol

* Incorporated N170 and p300, looking good for a PR

* ssvep update

* Implementing subclasses instead of loose functions

* fix: fixed import (brainflow updated API)

* Playing around still

* Fixing import errors

* Adding abstractmethod decorators

* Still working on the import error

* Guess what's finally working

* Comments and naming ticks

* More comments

* Live coding demonstration

* ssvep adapted

* Adapting Auditory Oddball

* changing save_fn to self.save_fun

* This maybe the last big change

* utils file changed, changes work through cli

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>

* Submodule added for gsoc

* Adding pipelines for cli analysis (#202)

* started pipelines function

* almost working simple function equivalents of nb scripts

* fix: fixed import (brainflow updated API)

* sqc fixes for unicorn (#176)

* Ignore pushes

* Trying to create a cli

* Stepping through the problem

* First commit

* Fixing pause in signal quality check

* Fixing Signal quality check problem

* fix the technical debt

* Save path done for automated saving pdf

* I feel amazing

* Almost through

* Update eegnb/cli/__main__.py

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>

* Trying to create cli but it's being really painful

* Extra word cli error

* Changed example handling

* Pain

* Adding whole datapath

* Finally fixed cli

* hmm

* Looking good

* added hyperlink

* Having some issues with detecting css and image deltetion

* Just the css now

* Fixed the css linking problem though it's a weird soln

* Automated running, still fnames problem

* Hahahah embedded images in html

* Improving code

* Okay now

* Look at that

* Almost there just the two figures now

* Now

* Added attrdict to do with cli error

Co-authored-by: John Griffiths <j.davidgriffiths@gmail.com>
Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>

* added more options for site args; improved function names; removed some redundant lines (#209)

* fix subject num parsing bug

* analysis report function improvements for openbci cyton and gtec unicorn devices

* run exp fix

* Update requirements.txt

* fixes to get docs building by github action (#210)

* fixes to get docs building by github action

* reverted some changes

* Update 01r__ssvep_viz.py

Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>

* Update README.rst

small commit to test doc build workflow on this branch

* removing gsoc submodule

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: Parv Agarwal <65726543+Parvfect@users.noreply.github.com>
Co-authored-by: Parvfect <parvagrw02@gmail.com>
Co-authored-by: Ben Pettit <pelleter@gmail.com>

* Updated doc examples

* Update 00x__n170_run_experiment.py

fix: typo in func param

---------

Co-authored-by: John Griffiths <JohnGriffiths@users.noreply.github.com>
Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
Co-authored-by: Ben Pettit <pelleter@gmail.com>
Co-authored-by: Ore O <oreogundipe@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants