<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 ## <p style="text-align
Step1:  how to draw samples from a gaussian distribution
Step2:  other distributions ...
Step3:  $\log_{10}(d) = 1 + \mu /5 $
Step4:  2. plotting
Step5:  3. IO (text files & fits files)
Step6:  LAMOST spectra
Step7:  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  '           /
<ASSISTANT_TASK:>
Python Code:
import numpy as np
print(dir(np.random))
Explanation: ## <p style="text-align: center; font-size: 4em;"> Python tutorial 2 </p>
1. random number generators: numpy.random
https://docs.scipy.org/doc/numpy/reference/routines.random.html
End of explanation
%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))
np.std(np.random.randn(1000) + np.random.randn(1000))
Explanation: how to draw samples from a gaussian distribution
End of explanation
randexp = np.random.exponential(2., size=(1000))
hist(randexp, np.linspace(0,10,50));
randps = np.random.poisson(10, size=(10000,))
hist(randps, np.arange(20));
M = 4.
m = 15.
merr = 0.1
rand_m = np.random.randn(1000)*0.1+m
hist(rand_m);
Explanation: other distributions ...
End of explanation
rand_d = 10.**(1+0.2*(rand_m-M))
hist(rand_d, np.linspace(1300, 1900, 30));
Explanation: $\log_{10}(d) = 1 + \mu /5 $
End of explanation
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams.update({'font.size':20})
# 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);
plt.scatter(x, np.cos(x)+0.2, s=np.random.rand(*x.shape)*80, c=np.sin(x)+1)
Explanation: 2. plotting
End of explanation
# use numpy.savetxt & numpy.loadtxt
a = np.random.randn(4, 5)
print(a)
np.savetxt('./data/text/rdata.dat', a)
!gedit ./data/text/rdata.dat
b = np.loadtxt('./data/text/rdata.dat')
print(b)
a==b.reshape(4, 5)
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()
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()
Explanation: 3. IO (text files & fits files)
End of explanation
ls ./data/lamost_dr2_spectra/
specpath = "./data/lamost_dr2_spectra/spec-55892-F9205_sp09-174.fits"
from astropy.io import fits
hl = fits.open(specpath)
hl.info()
hl
hl[0]
hl[0].header
Explanation: LAMOST spectra
End of explanation
wave = 10.**(hl[0].header['CRVAL1']+np.arange(hl[0].header['NAXIS1'])*hl[0].header['CD1_1'])
wave
np.log10(wave)
flux = hl[0].data # [flux, ivar, wave, and_mask, or_mask]
flux
%pylab
%matplotlib inline
fig = figure(figsize=(10, 5))
plt.plot(wave, flux[0, :])
# fig.savefig("here goes the file path")
Explanation: 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  '           /
End of explanation
<END_TASK>