-
Notifications
You must be signed in to change notification settings - Fork 7
Artifacts: Eye movements, power line noise #165
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
Open
maanikmarathe
wants to merge
32
commits into
unfoldtoolbox:main
Choose a base branch
from
maanikmarathe:artifacts-pln
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
366285f
initial commit to add code from notebooks
maanikmarathe e17ef7d
clean up & merge functions for intermediate steps; add general functi…
maanikmarathe bdb1bca
simplify ensemble simulation
maanikmarathe f9559b4
simplify crd simulation; clean up
maanikmarathe 4af5954
fix calculate_orientation direction parameter
maanikmarathe afc45a6
cleanup
maanikmarathe 0b95b2e
bring simulation functions to the same level
maanikmarathe 1483628
add first tests for eyemovement
maanikmarathe 1152943
import package for eyemovement
maanikmarathe 0c90b84
move artifact-related tests to a separate test file
maanikmarathe e917223
rename some variables and functions; edit docstrings
maanikmarathe 58aeb99
add example data from real dataset
maanikmarathe 6ebb1e7
add CSV
maanikmarathe 0a77797
add AbstractContinuousSignal, a-z simulation beginnings
maanikmarathe b3c6544
added dependency & mat files for eyemodel import
maanikmarathe 76636f4
fix types
maanikmarathe 9ece1b7
update a-z simulation & corresponding fixes in other files
maanikmarathe e0446d8
PoC simulation just eyemovements, t=1:200 from sample data
maanikmarathe 62ed12a
add regression test for PoC with previously saved simulation result
maanikmarathe 4e0faa0
reorder exports
maanikmarathe e303661
A-Z change EEG to multichannel; simulate noise; test with multiple EE…
maanikmarathe bd44114
remove events from artifact simulation results (temporary, for PoC)
maanikmarathe 8e96973
add eeg, artifact, noise after padding
maanikmarathe 9edc288
update a-z simulation
maanikmarathe 00dc199
misc small changes
maanikmarathe 0b4fec6
add eye_model selection
maanikmarathe 38f7a91
add basic PLN simulation
maanikmarathe eb71a7e
address PR comments + small changes
maanikmarathe b24616d
unify flow for pln & noise; intermediate - test deepcopy(rng) broadcast
maanikmarathe 1ac745b
rng testing results
maanikmarathe 397956b
basic implementation -- drift + userdefined artifact
maanikmarathe 8602eee
update docs & comments
maanikmarathe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| function simulate_continuoussignal(rng::AbstractRNG, s::EyeMovement, controlsignal::AbstractMatrix, sim::Simulation) | ||
| # at the lowest level, eyemovement simulation takes a controlsignal = Matrix having size 3 x n_timepoints i.e. a set of gaze direction vectors | ||
| headmodel = s.headmodel | ||
| eye_model = s.eye_model | ||
| return simulate_eyemovement(headmodel,controlsignal, eye_model) | ||
| end | ||
|
|
||
| """ | ||
| controlsignal: actual weights (n_channels x n_timepoints) to be applied to the simulated single-channel powerline noise | ||
| """ | ||
| function simulate_continuoussignal(rng::AbstractRNG, s::PowerLineNoise, controlsignal::AbstractMatrix, sim::Simulation) | ||
| base_freq = s.base_freq | ||
| harmonics = s.harmonics | ||
| sampling_rate = s.sampling_rate | ||
| weights_harmonics = s.weights_harmonics | ||
|
|
||
| n_samples = size(controlsignal)[end] | ||
| k = 0:1:n_samples-1 | ||
| # TODO add check for nyquist criterion? -> warn or error? | ||
|
|
||
| harmonics_signals = [sin.(2 * pi * (base_freq.*h)/sampling_rate .* k) for h in harmonics].*weights_harmonics | ||
|
|
||
| return reduce(+,harmonics_signals)' .*controlsignal | ||
| end | ||
|
|
||
|
|
||
| function simulate_continuoussignal(rng::AbstractRNG, s::AbstractNoise, controlsignal::AbstractArray, sim::Simulation) | ||
| return reshape(simulate_noise(rng,s,length(controlsignal)),size(controlsignal)) .* controlsignal | ||
| end | ||
|
|
||
| function simulate_continuoussignal(rng::AbstractRNG, s::UserDefinedContinuousSignal, controlsignal::AbstractArray, sim::Simulation) | ||
| return s.signal .* controlsignal # the user has already defined what they want | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # generate_controlsignal - returns controlsignal for the specified type of AbstractContinuousSignal. | ||
| # also takes the simulation object since it might influence the generated controlsignal (e.g. generate blinks right after event A -> controlsignal depends on the design) | ||
|
|
||
|
|
||
| # for EyeMovement, always return a 3 x n_timepoints matrix containing gaze direction vectors (n_timepoints number of gaze vectors, in 3 dimensions) | ||
|
|
||
| function generate_controlsignal(rng::AbstractRNG, cs::GazeDirectionVectors, sim::Simulation) | ||
| @assert size(cs.val)[1] == 3 "Please make sure gaze data has the shape 3 x n_timepoints." | ||
| return cs.val | ||
| end | ||
|
|
||
| function generate_controlsignal(rng::AbstractRNG, cs::HREFCoordinates, sim::Simulation) | ||
| return reduce(hcat,gazevec_from_angle_3d.(cs.val[1,:],cs.val[2,:])) | ||
| end | ||
|
|
||
| function generate_controlsignal(rng::AbstractRNG, cs::AbstractContinuousSignal, sim::Simulation) | ||
| return generate_controlsignal(deepcopy(rng), cs.controlsignal, sim) | ||
| end | ||
|
|
||
| # for PowerLineNoise we do not yet know the required n_timepoints, so we postpone controlsignal generation until the eeg and the known-size artifacts have already been generated | ||
| function generate_controlsignal(rng::AbstractRNG, cs::PowerLineNoise, sim::Simulation) | ||
| return nothing | ||
| end | ||
|
|
||
| # AbstractNoise: returns nothing for now, however in future the controlsignal for AbstractNoise may depend on the Simulation. | ||
| function generate_controlsignal(rng::AbstractRNG, cs::AbstractNoise, sim::Simulation) | ||
| return nothing | ||
| end | ||
|
|
||
| # identity function - in case the user already specified the final controlsignal while creating the artifact | ||
| function generate_controlsignal(rng::AbstractRNG, cs::AbstractMatrix, sim::Simulation) | ||
| return cs | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # simulate_continououssignal - simulates the continuoussignal based on the signal type and the specified controlsignal. | ||
|
|
||
| function simulate_continuoussignal(rng::AbstractRNG, s::Union{ARDriftNoise,DCDriftNoise,LinearDriftNoise}, controlsignal::AbstractMatrix, sim::Simulation) | ||
| # call the singlechannel simulate_continououssignal(..., controlsignal[i,:]) for each row (channel) of controlsignal | ||
| return hcat(map(controlsignal_channelwise->simulate_continuoussignal(rng,s,controlsignal_channelwise,sim), eachrow(controlsignal))...)' | ||
| end | ||
|
|
||
| function simulate_continuoussignal(rng::AbstractRNG, s::LinearDriftNoise, controlsignal::AbstractVector, sim::Simulation) | ||
| # simulate single-channel drift | ||
| n_samples = size(controlsignal)[end] | ||
| return range(0,1,length=n_samples).* | ||
| (rand((rng))*2-1) .* # slope of the line for this particular channel | ||
| s.scaling_factor .* # global scaling factor for the entire current LinearDriftNoise | ||
| controlsignal # user-controllable weights (1 x timepoint : current_channel vector taken from the entire artifact controlsignal) | ||
| end | ||
|
|
||
| function simulate_continuoussignal(rng::AbstractRNG, s::ARDriftNoise, controlsignal::AbstractVector, sim::Simulation) | ||
| n_samples = size(controlsignal)[end] | ||
| return cumsum(s.σ .* randn((rng),n_samples).*controlsignal) | ||
| end | ||
|
|
||
| function simulate_continuoussignal(rng::AbstractRNG, s::DCDriftNoise, controlsignal::AbstractVector, sim::Simulation) | ||
| n_samples = size(controlsignal)[end] | ||
| return ones(n_samples).*rand((rng)).* s.scaling_factor .*controlsignal | ||
| end | ||
|
|
||
| # generic drift noise: contains multiple fields having different driftnoise types. Simulate the artifact for each of these. | ||
| function simulate_continuoussignal(rng::AbstractRNG, s::DriftNoise, controlsignal::AbstractMatrix, sim::Simulation) | ||
| fn = fieldnames(DriftNoise) | ||
| all_s = [] | ||
| for f in fn | ||
| push!(all_s,simulate_continuoussignal(rng,getfield(s,f),controlsignal,sim)) | ||
| end | ||
|
|
||
| return sum(all_s) | ||
| end |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "end" needs to go to the end of the file.