Simple simulations and convolution with instrumental broadening"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The text.latex.preview rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The mathtext.fallback_to_cm rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: Support for setting the 'mathtext.fallback_to_cm' rcParam is deprecated since 3.3 and will be removed two minor releases later; use 'mathtext.fallback : 'cm' instead.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The validate_bool_maybe_none function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The savefig.jpeg_quality rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The keymap.all_axes rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The animation.avconv_path rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /Users/holtz/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The animation.avconv_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n"
]
}
],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Spectrum simulation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's start with some simple simulations of a spectrum: flux as a function of wavelength. We'll start with simulating a pure emission line spectrum, where we'll assume intrinsic line width to be much less than our instrumental line width."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's further assume that our instrumental broadening profile can be represented by a Gaussian. Start by writing a function to return a Gaussian given a set of input wavelengths, a wavelength center, and the $\\sigma$ corresponding to the broadening."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def gauss(x,mean=0,sig=1) :\n",
" \"\"\" Return normalized Gaussian function here\"\"\"\n",
"\n",
" return 1/np.sqrt(2*np.pi)/sig*np.exp(-0.5*(x-mean)**2/sig**2) # add code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Suppose we have a spectrograph that is chararacterized by a resolution, $R\\equiv \\frac{\\lambda}{\\Delta\\lambda} = 2000$, where $\\Delta\\lambda$ refers to the full-width half-maximum (FWHM) of the broadening profile. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Suppose we are going to simulate a line at $\\lambda=6563$ A. Given the relation between the FWHM and the $\\sigma$ of the Gaussian (which you should easily be able to derive, if you don't already know it), what is the $\\sigma$ corresponding to this resolution? Write a function to return it"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"R: 2000.000000 sig: 1.393418 fwhm: 3.281500\n"
]
}
],
"source": [
"def get_sigma(R,lam) :\n",
" fwhm=lam/R # compute fwhm in wavelength\n",
" sig=fwhm/2.355 # compute Gaussian sigma in wavelength\n",
" return sig\n",
"\n",
"R=2000\n",
"lam=6563\n",
"sig=get_sigma(R,lam)\n",
"print('R: {:f} sig: {:f} fwhm: {:f}'.format(R,sig, lam/R))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For our simulation, we'll create a wavelength array and a flux array. Given the FWHM of the instrumental profile, what would be a good choice for a wavelength spacing (the dispersion) of the spectrum, given the sampling theorem, which says you should have at least 2 samples per FWHM?"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"disp= 1 #set an appropriate dispersion (A/pixel)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a wavelength array to run between 6000 and 7000 A with your chosen dispersion. Also create an empty flux array:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAO0ElEQVR4nO3cbYxcZ3nG8f9Vu45E2+CkdsDYhnVbg+pWFYSpFURf1IRQO01jPjpqGyuoskBNBagUnEbqy7cAVakiokQWUCUCEQGFxq2MkpC+fGpe1iEJdYybJYV6sUkWpAJqJCKLux/mWEy2s95dz9jrnef/k0ZzzvPcZ85zW+u5fM7OOFWFJKldP7HSC5AkrSyDQJIaZxBIUuMMAklqnEEgSY1bu9ILOBcbNmyoqamplV6GJK0qR44c+U5VbZw/viqDYGpqiunp6ZVehiStKkm+OWzcW0OS1DiDQJIaZxBIUuMMAklqnEEgSY0zCCSpcQaBJDXOIJCkxhkEktQ4g0CSGmcQSFLjDAJJapxBIEmNMwgkqXEGgSQ1ziCQpMYZBJLUOINAkhpnEEhS4wwCSWqcQSBJjTMIJKlxBoEkNc4gkKTGGQSS1LixBEGSXUmOJ5lJcmDIfJLc0c0/neTKefNrknwlyT+NYz2SpKUbOQiSrAHuBHYDO4Abk+yYV7Yb2N499gN3zZt/D3Bs1LVI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