Skip to content

Instantly share code, notes, and snippets.

View christopherlovell's full-sized avatar
🍊

Chris Lovell christopherlovell

🍊
View GitHub Profile
@christopherlovell
christopherlovell / m3u-2-JSON.R
Created November 1, 2015 21:49
m3u to JSON converter
library(rjson)
trim <- function (x) gsub("^\\s+|\\s+$", "", x)
data_dir = 'Documents/playlists/'
play_list = list()
for(i in list.files(data_dir,"^.*\\.(m3u)$")){
year = substr(i,1,4) # record file specific information, in this case year from playlist group
library(FITSio)
library(sphereplot)
library(cosmoFns)
library(devtools)
## Data
data <- FITSio::readFITS("WP8_photoz_XMM_LSS.fits", hdu = 2)
dt <- data.frame(data$col)
@christopherlovell
christopherlovell / display.py
Last active November 18, 2023 22:22
display youtube video in jupyter notebook
from IPython.display import HTML
# Youtube
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/S_f2qV2_U00?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>')
# Vimeo
HTML('<iframe src="https://player.vimeo.com/video/26763844?title=0&byline=0&portrait=0" width="700" height="394" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe><p><a href="https://vimeo.com/26763844">BAXTER DURY - CLAIRE (Dir Cut)</a> from <a href="https://vimeo.com/dannysangra">Danny Sangra</a> on <a href="https://vimeo.com">Vimeo</a>.</p>')
@christopherlovell
christopherlovell / lognormal.R
Last active September 5, 2019 13:29
Fitting a lognormal in R to a large data set and plotting the Q-Q distribution
library(MASS)
# generate a million lognormal samples
n <- 1000000
dat <- rlnorm(n, meanlog = 0, sdlog = 1)
# add some noise (optional)
dat <- dat + runif(n, 0, 1)
# create a vector of histogram breaks
@christopherlovell
christopherlovell / _supermongo_matplotlib_stylesheet.md
Last active July 5, 2016 14:13
Matplotlib Stylesheet for creating SM style plots

To use this stylesheet, you need to put it inside your mplconfig_dir. By default, mpl_configdir should be ~/.config/matplotlib, but you can check where yours is with matplotlib.get_configdir(). You can then import it with styleuse('sm').

Based on work by Monica L. Turner, http://space.mit.edu/~turnerm/python.html (accessed 5/7/2016)

$ git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch filename' --prune-empty -f -- --all
$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --prune=now
$ git gc --aggressive --prune=now
$ git push origin --force --all
$ git push origin --force --tags
@christopherlovell
christopherlovell / mondrian.html
Last active May 9, 2018 23:01
D3 Mondrian Generator
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mondrian Generator</title>
<script src="https://d3js.org/d3.v4.js" charset="utf-8"></script>
<style>
</style>
</head>
<body>
@christopherlovell
christopherlovell / resample_distribution.py
Created May 11, 2018 11:07
Resample a distribution to match another
from scipy.stats import binned_statistic
import random
def resample_distribution(x, y, k=300, bin_limits=None):
"""
Resample y to fit distribution of x
Args:
x, y (array) distributions
k (int) number of samples
@christopherlovell
christopherlovell / sdss-dr7-wget.sh
Created June 13, 2018 16:47
Create list of URLs for wget from SDSS DR7 spec info
#!/bin/bash
# Clear output file
> out.csv
while read f; do
# read in line to array, comma delimited
arrIn=(${f//,/ })
@christopherlovell
christopherlovell / example.md
Last active July 27, 2018 11:51
t-SNE example

t-SNE spectra example

Apply t-SNE to galaxy spectra from two different simulations.

First import some modules

import numpy as np

%matplotlib inline