Skip to content

Instantly share code, notes, and snippets.

View wmvanvliet's full-sized avatar

Marijn van Vliet wmvanvliet

View GitHub Profile
@wmvanvliet
wmvanvliet / example.py
Created April 15, 2025 10:10
Virtually move head position inside the MEG helmet using MNE-Python
"""Virtually move around head position."""
import os
from copy import deepcopy
from subprocess import run
import mne
import numpy as np
from move_head import move_head
@wmvanvliet
wmvanvliet / irasa_test.py
Created February 26, 2025 08:02
Comparing pyrasa with neurodsp on their IRASA implementations.
import neurodsp
import neurodsp.aperiodic
import neurodsp.plts
import neurodsp.sim
import neurodsp.spectral
import numpy as np
from pyrasa.irasa import irasa
n_seconds = 10
fs = 500 # sampling rate in Hz
@wmvanvliet
wmvanvliet / test_pickle_consume.py
Last active November 7, 2024 09:12
Example of the non-backwards compatibility of pickle files
import pickle
class MyClass:
"""Example class to pickle. Version 2."""
def __init__(self, a, b, c, d=4):
"""New field `d` with default value, so no problems right?"""
self.a = a
self.b = b
@wmvanvliet
wmvanvliet / aalto_meg.py
Last active July 16, 2024 07:20
Python code for interfacing with the hardware in the MEG core at Aalto University.
"""Interface between python and the MEG hardware at Aalto's MEG core.
This is intended to be used in combination with PsychoPy to perform classic experiments
involving simple events and responses.
Example that presents a visual stimulus, sends a trigger code to the MEG and waits for a
button response with one of the response pads:
>>> from psychopy import core, visual
>>> from aalto_meg import AaltoMEG
@wmvanvliet
wmvanvliet / _interactive
Created May 21, 2024 08:08
Script to request a node through SLURM and create an interactive TMUX session on it
#!/bin/bash
# Start tmux
tmux new -d -s "slurm$SLURM_JOB_ID"
# Make job wait for user to connect
sleep 8h
@wmvanvliet
wmvanvliet / plot_cluster.py
Created May 10, 2024 08:06
Plotting clusters coming out of the cluster-based permutation tests.
"""Plot a cluster.
Plot the spatial extend of a cluster (as those returned from the cluster-based
permutation stats) on a brain.
Author: Marijn van Vliet <[email protected]>
"""
import mne
import numpy as np
@wmvanvliet
wmvanvliet / cluster_plotting_example.py
Last active March 12, 2024 09:48
Plot the spatial extent of a cluster (as those returned from the cluster-based permutation stats) on a brain.
"""
Plot the spatial extent of a cluster (as those returned from the cluster-based
permutation stats) on a brain.
Author: Marijn van Vliet <[email protected]>
"""
import mne
import numpy as np
@wmvanvliet
wmvanvliet / mous_trans.py
Created October 13, 2023 10:10
Obtain head -> MRI transform for the MOUS dataset (DSC_3011020.09_236) for use with MNE-Python.
"""
Obtain head -> MRI transform for the MOUS dataset for use with MNE-Python.
If you want to analyze the "Mother of all unification studies" dataset with
FreeSurfer and MNE-Python, you will need the MRI->HEAD coordinate
transformations. In the original dataset, the T1w_space_CTF.nii files contain
this information, but it takes some doing to distill this into a transform
object as used by MNE-Python.
This script assumes you have ran FreeSurfer on the T1w.nii files of all the
@wmvanvliet
wmvanvliet / events.py
Last active May 6, 2023 11:16
Proposal for an event API for MNE-Python
"""
Proposal for an event API for MNE-Python.
-----------------------------------------
We want figures to be able to communicate with each other, such that a change
in one figure can trigger a change in another figure. For example, moving the
time cursor in a Brain plot can update the current time in an evoked plot.
Another scenario is two drawing routines drawing into the same window. For
example, one function is drawing a source estimate, while another is drawing
magnetic field lines. The event system will allow both drawing routines to
@wmvanvliet
wmvanvliet / template.rs
Created November 29, 2022 08:31
Advent of Code template for Rust
use std::io::{self, Read};
// This reads in the puzzle input from stdin. So you would call this program like:
// cat input | cargo run
// It then feeds the input as a string to the functions that solve both parts of the puzzle.
fn main() {
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
println!("Part 1 answer: {}", part1(strip_bom(&input)));
println!("Part 2 answer: {}", part2(strip_bom(&input)));