Skip to content

Instantly share code, notes, and snippets.

from collections import OrderedDict
import nibabel as nib
from brainvoyagertools import voi # Get it from https://github.com/fladd/brainvoyagertools
v1 = voi.VOIsDefinition(framing_cube=256, reference_space="MNI")
v2 = voi.VOIsDefinition(framing_cube=256, reference_space="MNI")
import time
titles = ("Clock", "Implementation", "Monotonic", "Adjustable", "Resolution")
print("".join(str(x).ljust(30) for x in titles))
print("".join(("-" * len(x)).ljust(30) for x in titles))
for clock in ("time",
"clock",
"monotonic",
"perf_counter",
def stimulus_size_as_visual_angles(stim_size, screen_size, screen_angles):
"""Convert stimulus size (in pixels) to visual viewing angle (in degree).
Parameters
----------
stim_size : (int, int)
the size of the stimulus in pixels (width, height)
screen_dims : (int, int)
the pixel dimensions of the screen (width, height)
screen_angles : (float, float)
@fladd
fladd / style.py
Created March 15, 2020 11:12
Python style guide
#!/usr/bin/env python
"""Summary of module.
Description of module.
Can contain multiple lines.
"""
__author__ = 'Name Surname <Email address>'
@fladd
fladd / zoom_security.md
Last active April 3, 2020 08:16
Detailed step-by-step tutorial on how to fix Zoom security issues

Steps to fix Zoom security issues:

  1. Don't use Zoom
@fladd
fladd / spm_vs_fsl.md
Last active September 23, 2020 13:06
Differences in GLM modelling approaches between SPM and FSL

Script demonstrating differences in GLM modelling approaches between SPM and FSL:

import numpy as np
from nipy.modalities.fmri.glm import GeneralLinearModel


# Simulated data (20 'rest' volumes followed by 20 'task' volumes)
Y = np.hstack((np.random.normal(4200, 50, size=20),
               np.random.normal(4300, 50, size=20)))
ProjectName
├── sub-001-patient
│ ├── ses-001-pre
│ │ ├── anat
│ │ │ ├── 001-Localiser
│ │ │ │ └─── DICOM
| │ │ │ └── ...
│ │ │ └── 002-Anatomy
│ │ │ └─── DICOM
| │ │ └── ...
@fladd
fladd / fladd_CM2.xrnc
Created October 8, 2020 23:06
fladd's Renoise theme (a variation on hlv_autumn_cm)
<?xml version="1.0" encoding="UTF-8"?>
<SkinColors doc_version="12">
<Main_Back>0,0,0</Main_Back>
<Main_Font>228,228,228</Main_Font>
<Alternate_Main_Back>121,156,199</Alternate_Main_Back>
<Alternate_Main_Font>217,217,217</Alternate_Main_Font>
<Body_Back>87,87,87</Body_Back>
<Body_Font>191,191,191</Body_Font>
<Strong_Body_Font>255,255,255</Strong_Body_Font>
<Button_Back>40,40,40</Button_Back>
@fladd
fladd / licensing_info.py
Last active November 10, 2020 22:43
Get licencing information of packages and their dependencies from pip
from email import message_from_string
from pkg_resources import get_distribution
def get_pkg_info(package, extras=False):
"""Get information about an installed package.
This function will also attempt to get the licence text from a bundled
licence file, if available.
Parameters

Sorry I misunderstood before.

What you want to achieve is possible in two ways.

  1. Within Expyriment, by manually defining how to process control keys (e.g. ESC) in all wait functions you use:
def custom_process_control_keys():
    expyriment.io.Keyboard.process_control_keys(quit_confirmed_function=convert_variables)