IRkernel/IRkernel: Running R kernel for Jupyter

In order to be able to use native R kernel for Jupyter, you need to do the following:

1) Install R

brew tap homebrew/science 
brew install r

2) Run R in a terminal, the run the following

install.packages(c('repr', 'pbdZMQ', 'devtools'))
devtools::install_github(c('IRkernel/IRdisplay', 'IRkernel/IRkernel'))
IRkernel::installspec(user = FALSE)


brew update
brew doctor

The SDSS 1D Spectrum of Q1357+0525

In [1]:
#Font style
from IPython.core.display import HTML
css = open('style-table.css').read() \
+ open('style-notebook.css').read()

Here, I demonstrate that we can make plots of SDSS spectra without downloading the actual fits file into a local machine. In this example, we grab the 1D spectrum of quasar Q1357+0525 from the SDSS DR12 Data Archive Server (DAS).

The wavelength range of the plot can be interactively adjusted using the sliders.

SDSS Notes:

  • ### Physical quantities pertinent to the object obtained by SDSS can be accessed here.

  • ### The 1D spectrum can be pre-viewed here.

In [2]:
import as fits
import numpy as np

import matplotlib
import matplotlib.pyplot as plt

from matplotlib.ticker import AutoMinorLocator
from matplotlib.ticker import FuncFormatter
import matplotlib.font_manager as font_manager
from matplotlib import rcParams

from ipywidgets import interact, fixed

%matplotlib inline

We now grab the spectrum and plot. Extract the wavelength, flux and error columns.

In [3]:
def plot_spec(min_wave=3800, max_wave=9200):
    spec, header = fits.getdata('', 1, header=True)
    wave = 10**spec['loglam']
    flux = spec['flux']
    error = np.sqrt(1./spec['ivar'])
    plt.plot(wave, flux, drawstyle='steps')
    #plt.plot(wave, error)
    if min_wave >= max_wave:
        min_wave = 3800
        max_wave = 9200
    plt.xlim(min_wave, max_wave)
    flux_vals = flux[np.where((wave >= min_wave) & (wave <= max_wave)) ]
    plt.ylim(flux_vals.min(), flux_vals.max())
    plt.xlabel('Observed Wavelength '+r'[$\mathrm{\AA}$]', fontsize=25)
    plt.ylabel(r'$f_{\lambda}$ '+ r'$\mathrm{[10^{-17} ergs/cm/\AA/s]}$' , fontsize=25)
    plt.tick_params('both', length=8, width=2, which='minor')
    plt.tick_params('both', length=12, width=3, which='major')
In [4]:
#Make the plot HUGE and vivid
minorLocatorx   = AutoMinorLocator(10)
minorLocatory   = AutoMinorLocator(4)
matplotlib.rc('xtick', labelsize=20) 
matplotlib.rc('ytick', labelsize=20) 
matplotlib.rcParams['axes.linewidth'] = 2.
plt.rcParams['axes.linewidth'] = 4
plt.rc('font', family='serif')
plt.rc('font', serif='Times New Roman') 
fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 18
fig_size[1] = 9
plt.rcParams["figure.figsize"] = fig_size

# Use interact to explore the galaxy detection algorithm.
interact(plot_spec, min_wave=(3800, 9000, 100), max_wave=(4000,9200, 100));

SSH Login Without Password

If you want to ssh from 'userx' of host X to 'usery' of host Y without typing password, you need to do the following.

  1. Log in on host X as userx and generate a pair of authentication keys. Make sure not to enter a passphrase:
    userx@X:~> ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/userx/.ssh/id_rsa): 
    Created directory '/home/userx/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/userx/.ssh/id_rsa.
    Your public key has been saved in /home/userx/.ssh/
    The key fingerprint is:
    3x:5f:05:79:3d:8f:9e:7c:3b:ad:e9:58:37:bc:37:e4 userx@X

    Read more…

Installing Python mysql.connector

import mysql.connector

For OSX, the import above requires installation of

For Ubuntu (or a Debian based distro),

sudo pip install mysql-connector-python --allow-external mysql-connector-python

OCaml and Jupyter

I decided to try out OCaml as a kernel in a Jupyter notebook. Doing it was pretty straight forward. All I did was:

1) Install OPAM

brew install opam

2) Install OCaml and some libraries

opam init
eval `opam config env`
opam install batteries core

3) Install iocaml

opam install iocaml
In [ ]:

Calculating dndz parameters.

The low-redshift $\frac{\partial n}{\partial z}$ of HI

This code calculates an $n_0$ and an $\alpha$ via least-squares $\chi^{2}$ fit.

Read more…

Effects of the New HST 2016 Calibration Corrections on M31 Results (PID: 11658)

In [1]:
#Font style
from IPython.core.display import HTML
css = open('style-table.css').read() \
+ open('style-notebook.css').read()

Old versus New HST Calibrations for G230L M31 Data

Read more…

Python Cheatsheet

Python Cheatsheet



a = 1           # integer
b = 1.0         # float
c = 1.0e5       # exponential
d = 1.0 + 2.5j  # complex
e = 1 > 0       # boolean
f = 'string'    # string

Read more…

Electoral Fraud in the Phil Vice Presidential Race?

Due to the deluge of “expert” opinion online regarding the Phil VP race, we decided to do our own due diligence in the search for the truth. Special thanks to Reina Reyes for the dataset.

In the context of the data that are readily available, we want an approach that is quick and simple. In our opinion, the data that we have would not be sufficient to prove whether or not fraud was committed, but the data would be useful in verifying whether or not BBM’s claim is reasonable.

BBM claims that at some point in time (~roughly 3AM of May 10th, Phil time) the transmitted data were rigged, making way for Leni’s eventual lead in the VP race. One nice feature of such a claim that we can exploit is that there are effectively two sets of data, separated in time: (1) a set of clean, “un-manufactured” data (i.e. votes transmitted prior to ~3AM), and (2) a set of fraudulent, manufactured data (i.e. votes transmitted after ~3AM).

From a statistical standpoint, datasets have underlying distributions, dependent upon the fundamental process(es) that generated the dataset. To manufacture data, one must go to great lengths to preserve the underlying distributions of the data. Aside from the difficulty of generating fake data

Read more…