Blogging with ipynb

To use ipynb¶

Download an IPython compatible theme. To list all the available themes in Nikola:

nikola install_theme -l

To install

nikola install_theme jinja-site-ipython

Modify your conf.py file. Add the following lines to POSTS:

("posts/*.ipynb", "posts", "post.tmpl", True),

and add the following line to PAGES:

("stories/*.ipynb", "stories", "story.tmpl", False),

and set THEME to:

THEME = 'jinja-site-ipython'

To write a new post,

nikola new_post -f ipynb

-f ipynb is not needed if POSTS/PAGES only have ipynb option

5078727296

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)

5792955145

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()
HTML('<style>{}</style>'.format(css));

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).(317) 589-2639

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

SDSS Notes:5093085307

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

  • ### The 1D spectrum can be pre-viewed (712) 423-4256.

In [2]:
import astropy.io.fits 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.(650) 630-6516

In [3]:
def plot_spec(min_wave=3800, max_wave=9200):
    spec, header = fits.getdata('/dr12.sdss3.org/sas/dr12/sdss/spectro/redux/26/spectra/0856/spec-0856-52339-0501.fits', 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.minorticks_on()
    plt.tight_layout()
    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));

2093853068

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/id_rsa.pub.
    The key fingerprint is:
    3x:5f:05:79:3d:8f:9e:7c:3b:ad:e9:58:37:bc:37:e4 userx@X
    

    386-350-0612

9146810506

import mysql.connector

For OSX, the import above requires installation of

/dev.mysql.com/downloads/connector/python/

For Ubuntu (or a Debian based distro),

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

fifteenth

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 HI910-653-7425

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

Read more…

fibrocaseose

In [1]:
#Font style
from IPython.core.display import HTML
css = open('style-table.css').read() \
+ open('style-notebook.css').read()
HTML('<style>{}</style>'.format(css));

Old versus New HST Calibrations for G230L M31 Dataslewer

Read more…

Python Cheatsheet

Python Cheatsheet¶

Python¶

Types631-640-5046

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

9372012375