Skip to content

[ENH, WIP] Refactor python code to be a bit cleaner#8

Open
alexrockhill wants to merge 7 commits intoMultimodalNeuroimagingLab:mainfrom
alexrockhill:refactor
Open

[ENH, WIP] Refactor python code to be a bit cleaner#8
alexrockhill wants to merge 7 commits intoMultimodalNeuroimagingLab:mainfrom
alexrockhill:refactor

Conversation

@alexrockhill
Copy link
Copy Markdown

@alexrockhill alexrockhill commented Aug 8, 2023

Okay, working version. This code exactly replicates the existing notebook (checked using the mefd data--i.e. loading in the data using the current notebook code and then running all the code after making V from this PR). Whoever is welcome to pick and choose or use this for neurohack or not, I just wanted a version that I understood better and that was a bit simpler so hopefully this helps. As a broad summary what happens is 1) the data is loaded by mne_bids so that it's agnostic of file type (done separately here as well), 2) epochs are made via MNE functions so that it's pretty neat and minimal and the indexing etc. is abstracted away so that once you get the epoch array and list/array of stimulation sites you can run the BPC code on those (3). The main theme of refactoring the BPC python code was to store data in matrices/vectors, try to name variables helpful things and make the code a little easier to follow exactly what it's doing. This took a bit more work than I thought but I hope it helps other people who want to use the python version and/or understand what the code is doing (just guessing based on a direct translation, this might be a tad more readable than the matlab even 😉).

cc @dorahermes happy to walk through tomorrow.

It's a work in progress because some commented code needs to be removed and maybe a bit more verbose descriptions could be added. I'll add sphinx rendering of the example when I get a chance but might not be right away.

Note somewhat to self to replicate using the mefd loader (first, run through "Calculate Significance Matrix"):

V = V.T  # this code uses n_epochs x n_times not the transpose
stim_sites = np.array(df_include_trials.electrical_stimulation_site)
times = np.linspace(bpc_tmin, bpc_tmax, V.shape[1])   # probably could be done better but just used to check plotting

Then start at "calculate BPCs" in the new code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant