Note for MF:
Found it last weekend, quite useful:
Reproducible Data Analysis in Jupyter (jakevdp)
tool for version control in Jupyter (nbdime) (haven't try it!)
Let us follow the post: 28 jupyter tricks
%!
In [1]:
# how many magic function we got?
%lsmagic
Out[1]:
In [5]:
from matplotlib import pyplot as plt
%matplotlib inline
%config IPython.matplotlib.backend = 'retina'
%config InlineBackend.figure_format = 'retina'
plt.style.use('ggplot') # seaborn
plt.plot(range(10), [x*x for x in range(10)]);
In [6]:
%%writefile test.py
print('Hello, AstroTalk.')
In [8]:
%run test.py
In [ ]:
# %load test.py
print('Hello, AstroTalk.')
In [10]:
%pycat test.py
In [11]:
%%python2
print 'AstroTalk'
Cython Magic fast for loop
COOL things I've never used
In [13]:
%load_ext nbtutor
In [14]:
%%nbtutor -r -f
def AstroTalk(a):
a += 1
return a
AstroTalk(2)
In [15]:
from pivottablejs import pivot_ui
import pandas as pd
df = pd.DataFrame({
'Letter': ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'],
'X': [4, 3, 5, 2, 1, 7, 7, 5, 9],
'Y': [0, 4, 3, 6, 7, 10, 11, 9, 13],
'Z': [1, 2, 3, 1, 2, 3, 1, 2, 3]
})
pivot_ui(df)
Out[15]:
healpyNote for MF
RING & NESTED: Hierarchical Equal Area Iso Latitude pixelation of the spherensidenside (cheat)pixfuncvpython for 3D sphere.
In [18]:
from urllib import request
URL = 'http://attach.kmt.org.tw/200910/20091015163058.jpg'
request.urlretrieve(URL, filename='kmt.jpg')
Out[18]:
In [25]:
from PIL import Image
import numpy as np
image = Image.open('kmt.jpg').convert('L')
image = np.array(image)
In [29]:
from matplotlib import pyplot as plt
%matplotlib inline
plt.imshow(image); plt.colorbar();
In [31]:
image = image[image.shape[0]//2 - 300:image.shape[0]//2 + 300,
image.shape[1]//2 - 600:image.shape[1]//2 + 600]
plt.imshow(image)
Out[31]:
In [32]:
import numpy as np
import healpy as hp
def cart_healpix(cartview, nside):
'''read in a matrix and return a healpix pixelization map'''
# Generate a blank Healpix map and angular to pixels
healpix = np.zeros(hp.nside2npix(nside), dtype=np.double)
hptheta = np.linspace(0, np.pi, num=cartview.shape[0])[:, None]
hpphi = np.linspace(-np.pi, np.pi, num=cartview.shape[1])
pix = hp.ang2pix(nside, hptheta, hpphi)
# re-pixelize
healpix[pix] = cartview
return healpix
In [45]:
array = np.arange(hp.nside2npix(2))
hp.mollview(array, nest=False, sub=(1,2,1), title='RING')
hp.mollview(array, nest=True, sub=(1,2,2), title='NEST')
In [46]:
# cartview -> healpix
healpix = cart_healpix(image, 128)
hp.mollview(healpix, sub=(1,3,1))
hp.cartview(healpix, sub=(1,3,2))
hp.orthview(healpix, sub=(1,3,3))
In [49]:
cl = hp.anafast(healpix)
ell = np.arange(len(cl))
plt.loglog(ell, cl);
In [61]:
nside = 1
cartview = np.arange(200).reshape(10, 20)
# Generate a blank Healpix map and angular to pixels
healpix = np.zeros(hp.nside2npix(nside), dtype=np.double)
hptheta = np.linspace(0, np.pi, num=cartview.shape[0])[:, None]
hpphi = np.linspace(-np.pi, np.pi, num=cartview.shape[1])
pix = hp.ang2pix(nside, hptheta, hpphi)
In [64]:
pix
Out[64]:
In [63]:
cartview
Out[63]:
In [65]:
# re-pixelize
healpix[pix] = cartview
In [66]:
healpix
Out[66]:
In [ ]:
# Try yourself with your own image!