https://docs.scipy.org/doc/numpy/reference/routines.random.html
In [1]:
import numpy as np
print(dir(np.random))
In [2]:
%pylab inline
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams.update({'font.size': 20})
rdata = np.random.randn(1000)
fig = plt.figure(figsize=(6, 4))
plt.hist(rdata)
print(np.mean(rdata), np.median(rdata), np.std(rdata))
In [3]:
np.std(np.random.randn(1000) + np.random.randn(1000))
Out[3]:
In [4]:
randexp = np.random.exponential(2., size=(1000))
hist(randexp, np.linspace(0,10,50));
In [5]:
randps = np.random.poisson(10, size=(10000,))
hist(randps, np.arange(20));
In [6]:
M = 4.
m = 15.
merr = 0.1
rand_m = np.random.randn(1000)*0.1+m
hist(rand_m);
$\log_{10}(d) = 1 + \mu /5 $
In [7]:
rand_d = 10.**(1+0.2*(rand_m-M))
hist(rand_d, np.linspace(1300, 1900, 30));
In [ ]:
In [8]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams.update({'font.size':20})
In [9]:
# fig = plt.figure(figsize=(10,10))
x = np.linspace(0, 6*np.pi, 100)
plt.plot(x, np.cos(x), 'rv--');
plt.plot(x, np.sin(x), 'bs-.', alpha=.1);
In [10]:
plt.scatter(x, np.cos(x)+0.2, s=np.random.rand(*x.shape)*80, c=np.sin(x)+1)
Out[10]:
In [11]:
# use numpy.savetxt & numpy.loadtxt
a = np.random.randn(4, 5)
print(a)
In [12]:
np.savetxt('./data/text/rdata.dat', a)
In [13]:
!gedit ./data/text/rdata.dat
In [14]:
b = np.loadtxt('./data/text/rdata.dat')
print(b)
In [15]:
a==b.reshape(4, 5)
Out[15]:
In [16]:
impath = "./data/image_data/G178_final.850.fits"
%pylab inline
from matplotlib import rcParams
rcParams.update({'font.size': 20})
from aplpy import FITSFigure
fig = FITSFigure(impath)
fig.show_colorscale()
In [ ]:
In [17]:
impath = "./data/wise_image/w1_cut.fits"
%pylab inline
%matplotlib inline
from matplotlib import rcParams
rcParams.update({'font.size': 20})
from aplpy import FITSFigure
fig = FITSFigure(impath)
fig.show_colorscale()
fig.show_grayscale()
In [ ]:
In [18]:
ls ./data/lamost_dr2_spectra/
In [19]:
specpath = "./data/lamost_dr2_spectra/spec-55892-F9205_sp09-174.fits"
In [20]:
from astropy.io import fits
In [21]:
hl = fits.open(specpath)
In [22]:
hl.info()
In [23]:
hl
Out[23]:
In [24]:
hl[0]
Out[24]:
In [25]:
hl[0].header
Out[25]:
CRVAL1 = 3.5682 / Central wavelength (log10) of first pixel
CD1_1 = 0.0001 / Log10 dispersion per pixel
CRPIX1 = 1 / Starting pixel (1-indexed)
CTYPE1 = 'LINEAR ' /
In [26]:
wave = 10.**(hl[0].header['CRVAL1']+np.arange(hl[0].header['NAXIS1'])*hl[0].header['CD1_1'])
In [27]:
wave
Out[27]:
In [28]:
np.log10(wave)
Out[28]:
In [29]:
flux = hl[0].data # [flux, ivar, wave, and_mask, or_mask]
In [30]:
flux
Out[30]:
In [31]:
%pylab
%matplotlib inline
fig = figure(figsize=(10, 5))
plt.plot(wave, flux[0, :])
Out[31]:
In [32]:
# fig.savefig("here goes the file path")
In [ ]:
In [ ]: