Skip to content

Instantly share code, notes, and snippets.

@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
@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 / serial_test.py
Created February 12, 2017 18:37
Testing a serial port with ETG-4000
import serial
port = serial.Serial('COM1', 9600, timeout=0)
port.write('A \r')
@erzk
erzk / loading_and_plotting_nirs_data.Rmd
Created December 18, 2016 23:44
RMarkdown file showing the nirs data analysis
---
title: "Loading and plotting nirs data"
author: "Eryk Walczak"
date: "18 December 2016"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
@erzk
erzk / load_and_plot_nirs.R
Created December 18, 2016 23:30
This script shows how to load and plot fnirs data (.nirs format)
# install the package if not available with:
# install.packages("R.matlab")
library(R.matlab)
# load the nirs file
data <- readMat("Simple_Probe.nirs")
# get the available names
names(data)
@erzk
erzk / roh_performances_scraper.R
Last active November 6, 2016 14:03
Scrape the performance data from ROH collections
library(rvest)
# URL: http://www.rohcollections.org.uk/SearchResults.aspx?searchtype=performance&page=0&genre=Opera
performances <- c()
for (i in 0:233){
site_perf <- paste0("http://www.rohcollections.org.uk/SearchResults.aspx?searchtype=performance&page=",
i,
"&genre=Opera")
print(site_perf) # optional print to see the progress
# load this package to use HTTP verbs
library(httr)
postcode_lookup <- function(postcode) {
r <- GET(paste0("https://api.postcodes.io/postcodes/", postcode))
warn_for_status(r)
content(r)
}
# returns a list
@erzk
erzk / postcode_area
Created June 6, 2016 16:00
Postcode Area Regex - Tableau calculated field
// based on calculation from Tableau's website
REGEXP_EXTRACT([Postcode], "([A-Z][A-Z]?)")
@erzk
erzk / shapefile_map_poland_3.R
Created April 1, 2016 22:24
plot ESRI shapefiles - Leaflet
# interactive leaflet plot
library(leaflet)
leaflet() %>%
addTiles() %>%
addPolygons(data = sh2,
weight = 2) %>%
addPolygons(data = sh1,
color = "red",
weight = 1)
@erzk
erzk / shapefile_map_poland_2.R
Created April 1, 2016 22:22
plot ESRI shapefiles - Google Maps
# shapefile overlapping Google Maps
library(ggplot2)
library(ggmap)
library(rgdal)
# geographical centre of Poland
poland <- get_googlemap(c(lon=19.27, lat=52.03),
zoom = 6,
maptype = "satellite")