Skip to content

Instantly share code, notes, and snippets.

# save map as html:
saveWidget(map, "map.html")
# creat map widget:
map <- leaflet() %>% addTiles() %>%
addCircleMarkers(lng = file_sub$lon,
lat = file_sub$lat,
color = pal(file_sub$hours),
popup = paste0(file_sub$dateTime, "<br/>",
round(file_sub$lon, 6), "<br/>",
round(file_sub$lat, 6))) %>%
addLegend(position = "topleft", pal = pal, values = file_sub$hours, title = "hours past<br/>midnight")
map
# for each file obtain the EXIF codes and extract the coordinates
GPStags <- apply(array(file_info$file.name), 1, function(x) {
EXIF_code <- NULL
try (EXIF_code <- attr(GDALinfo(x), "mdata"), silent = T)
if (is.null(EXIF_code)) return(data.frame(lon = NA, lat = NA, dateTime = NA)) else return(get_EXIF_coordinate(EXIF_code))
})
#bind the results:
GPStags <- do.call(rbind, GPStags)
# store in the data.frame
# required packages
require(rgdal)
require(leaflet)
require(htmlwidgets)
# select files for which geotags need to
# be extracted and store filenames in data.frame
file_info <- data.frame(file.name = choose.files(filters = Filters["jpeg",]))
# function to get a parameter value from EXIF code,
@pepijn-devries
pepijn-devries / ProTrackR02.01.r
Last active February 6, 2019 13:45
Download and play a ProTracker module in R
# load the required packages
require(ProTrackR)
# set up a connection to 'cyberrid.mod':
con <- url("http://api.modarchive.org/downloads.php?moduleid=40293", "rb")
# download module:
mod <- read.module(con)
close(con)
rm(con)
# select a sample:
plot_samp <- PTSample(mod, 25)
# generate power spectrum
spec <- powspec(waveform(plot_samp),
wintime = 0.1,
steptime = 0.005)
spec_cutoff <- quantile(log10(spec), 0.01)
spec[log10(spec) < spec_cutoff] <- 10^spec_cutoff
# play all samples in the module at note "C-3"
playSample(mod)
# play chromatic scales of octaves 2 and 3 using the 23rd sample
data(period_table)
for (i_note in as.vector(outer(names(period_table)[-1:-2],
c(2:3), function(x, y) paste(x, y, sep = ""))))
{
print(i_note)
playSample(PTSample(mod, 23), 0.1, T, i_note, 0.5)
# required packages:
require(plot3D)
require(ProTrackR)
# Read the module 'elekfunk' from the Mod Archive:
con <- url("http://api.modarchive.org/downloads.php?moduleid=41528", "rb")
mod <- read.module(con)
close(con)
rm(con)
#################################
# ball and stick model
#################################
# get bond info
bonds <- get.bonds(molfile)
bonds.atoms <- data.frame(do.call('rbind', lapply(bonds, function(x){
atoms <- get.atoms(x)
start <- get.point3d(atoms[[1]])
end <- get.point3d(atoms[[2]])
# simply plot the atoms as coloured spheres.
# multiply the Van der Waals radii with 0.75
# to reduce overlap of atoms.
mapply(function(x, y, z, vdw, col){
spheres3d(x, y, z, + vdw*0.75, col = col, add = T)
}, atom_dat$x, atom_dat$y, atom_dat$z,
atom_dat$vanderwaals, atom_dat$colour)
# Save as an interactive model on web page
writeWebGL()