Skip to content

Instantly share code, notes, and snippets.

@erzk
erzk / fNIRS_experiment_alpha.py
Last active April 11, 2022 07:38
First version of the fNIRS experiment using the serial port (A triggers - blocks, B triggers - stimuli)
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy2 Experiment Builder (v1.83.04), February 07, 2017, at 16:33
If you publish work using this script please cite the relevant PsychoPy publications
Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13.
Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008
"""
from __future__ import division # so that 1/3=0.333 instead of 1/3=0
@erzk
erzk / fnirs_dygraph.R
Created June 2, 2017 22:09
interactive plot of fNIRS data
devtools::install_github("erzk/fnirsr")
library(dygraphs)
library(fnirsr)
file_path <- system.file("extdata", "Hitachi_ETG4000_24Ch_Total.csv", package = "fnirsr")
ETG_header <- load_ETG4000_header(file_path)
rawData <- load_ETG4000_data(file_path, ETG_header)
# prepare the events
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@erzk
erzk / zooplaR_introduction.R
Created January 7, 2018 01:51
Get UK property data from Zoopla
# install the package
devtools::install_github("erzk/zooplaR")
# load it
library(zooplaR)
# set up the keys
file.edit("~/.Renviron")
zoopla_key <- "YOUR_KEY_GOES_HERE"
zoopla_key <- Sys.getenv("zoopla_key")
@erzk
erzk / geofacet_grid_Poland.R
Last active July 21, 2019 09:24
geofacet - siatka z województwami
# geofacet - Polska
# Ludność w miastach w % ogółu ludności (dane roczne)
library(dplyr)
library(geofacet)
library(ggplot2)
library(readxl)
# dane z Banku Danych Lokalnych
# https://bdl.stat.gov.pl/BDL/dane/podgrup/tablica
clear all
clc
%% Version 3 update: channels and wavelengths are re-ordered such that they
% are in the order Homer2 software expects.
% User choice to remove marker at end of stimulus as this is not needed in
% Homer. Thanks to Ian Wiggins for your assistance with Version 3 edits.
% Rebecca S Dewey 29th July 2014
%% Revision update: stimulus markers are now read into the "aux" variable
% Reading vector of stimulus markers and arranging this into the format
% required by Homer2 and storing in the variable "aux"
markertimes = [find(vector_onset>0) find(vector_onset<0)];
markers = vector_onset(markertimes);
unique_markers = unique(markers);
aux = zeros(count, length(unique_markers));
for stimuli=1:length(unique_markers)
if offset == 'y' || offset == 'Y' % Version 3
stim_on_off = find(vector_onset==(unique_markers(stimuli))); % Version 3
stim_markers = stim_on_off(1:2:length(stim_on_off)-1); % Version 3
# install fnirsr
devtools::install_github("erzk/fnirsr")
library(dplyr)
library(fnirsr)
# file path
p01_path <- "/media/.../p01_fnirs_data_MES_Probe1.csv" # MES file
# load the header
# remove all but block borders
borders1 <- which(df$Mark == 1)
borders9 <- which(df$Mark == 9)
borders10 <- which(df$Mark == 10)
df[borders1,] <- 0
df[borders9,] <- 0
df[borders10,] <- 0
# block borders
# define a function
replace_nth_ETG4000 <- function(x, mark) {
x <- x %>% group_by(Mark) %>% mutate(Count = row_number()) %>% data.frame()
double_marks <- which(x$Mark == mark & x$Count %% 2 == 0)
x$Mark[double_marks] <- 0
x <- subset(x, select = -Count)
return(x)
}
# remove second occurrence of Mark 2