Skip to content

Instantly share code, notes, and snippets.

@megbedell
Created January 3, 2020 17:02
Show Gist options
  • Save megbedell/760edb8472935e966170bbccd0419a28 to your computer and use it in GitHub Desktop.
Save megbedell/760edb8472935e966170bbccd0419a28 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy.optimize import least_squares, curve_fit\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"tc = np.array([953,\n",
"1327,\n",
"1641,\n",
"1302,\n",
"1505,\n",
"1647,\n",
"1573,\n",
"1427,\n",
"1291,\n",
"1150,\n",
"1347,\n",
"1348,\n",
"1033,\n",
"1328,\n",
"1455,\n",
"1647,\n",
"1736,\n",
"1447,\n",
"1570,\n",
"1477,\n",
"1574,\n",
"1594,\n",
"1580,\n",
"1347,\n",
"1647,\n",
"1647], dtype=np.float64)\n",
"\n",
"ab = np.array([-0.005,\n",
"0.062,\n",
"0.054,\n",
"0.063,\n",
"0.112,\n",
"0.08,\n",
"0.097,\n",
"0.093,\n",
"0.084,\n",
"0.042,\n",
"0.05,\n",
"0.05,\n",
"0.003,\n",
"0.09,\n",
"0.19,\n",
"0.17,\n",
"0.17,\n",
"0.23,\n",
"0.19,\n",
"0.21,\n",
"0.18,\n",
"0.22,\n",
"0.14,\n",
"0.16,\n",
"0.14,\n",
"0.15])\n",
"\n",
"err = np.array([0.012, 0.008, 0.002, 0.004, 0.005, 0.017, \n",
" 0.013, 0.009, 0.016, 0.006, 0.005, 0.005, \n",
" 0.031, 0.004, 0.006, 0.011, 0.01, 0.01,\n",
" 0.031, 0.012, 0.014, 0.01, 0.021, 0.014, \n",
" 0.006, 0.066])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### least-squares fit without uncertainties:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def resid(par, x, y):\n",
" \"\"\"residuals of linear fit\"\"\" \n",
" m, b = par\n",
" return y - (m*x + b)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"soln = least_squares(resid, [0.,0.], args=(tc, ab))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"best-fit slope is: 2.20e-04\n"
]
}
],
"source": [
"print('best-fit slope is: {0:.2e}'.format(soln['x'][0]))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEOCAYAAAB4nTvgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XucVXW9//HXx+E2agoKXrhMgzKQmhdsQqpfnsoLUCpUdtKs7GRpJtapR5z02M/KslRONxFTUtMuimVGVBrqQe2myCAaqY0M92FQwRFKGYGZ+Zw/1hrYs9kzaw/stddee7+fj8d+zN5rfdfsz8xWPrO+t4+5OyIiIr3ZJ+kARESk9ClZiIhIJCULERGJpGQhIiKRlCxERCSSkoWIiERSshARkUhKFiIiEknJQkREIilZiIhIpH5JB1AoQ4cO9dra2qTDEBFJlSVLlmxy92FR7WJNFmY2GfgBUAXc4u7XZJ3/IvApoB3YCHzS3deE5zqAZWHTte5+Vm/vVVtbS0NDQ4F/AhGR8mZma/JpF1uyMLMqYDZwGtAMLDaz+e7+bEazpUC9u281s4uB64APh+fa3P2EuOITEZH8xTlmMQFocveV7r4dmAtMzWzg7g+7+9bw5ePAyBjjERGRPRRnshgBrMt43Rwe68kFwP0ZrweZWYOZPW5m0+IIUERE8hPnmIXlOJaz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ZQsREQk0v8B9V/O3aus+NIAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.scatter(tc, ab)\n",
"xx = np.linspace(min(tc), max(tc), 100)\n",
"plt.plot(xx, soln['x'][0]*xx + soln['x'][1], c='orange')\n",
"plt.xlabel(r'T$_c$')\n",
"plt.ylabel(r'[X/H]');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### least-squares fit with uncertainties:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def chi(par, x, y, yerr):\n",
" \"\"\"error-weighted residuals of linear fit\"\"\" \n",
" r = resid(par, x, y)\n",
" return r/yerr"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"soln = least_squares(chi, [0., 0.], args=(tc, ab, err))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"best-fit slope is: 4.23e-05\n"
]
}
],
"source": [
"print('best-fit slope is: {0:.2e}'.format(soln['x'][0]))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEOCAYAAAB4nTvgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHdJJREFUeJzt3X2QXXWd5/H3J52nFhI6T47QEIkYMsTFJdqCsxkfBh8SnVmScXWB1SrGcQt1h9mtmTJUUjiMi+sYyTxUzS6uYcrUOroDKIsxuwsTGTO6tS6EBIJE4kZCwNAdViMhAhrS6e7v/nHPTU5f7u1zutPn3nP7fl5Vt/qc3znn3m/3rT7fc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k4WZmWVysjAzs0xOFmZmlsnJwszMMjlZmJlZpumtDsBsKpFUHawJ8BpgGDiSrF8elRlDzdqOB+WZFUTSZ4CXIuLPWx2L2ZlyNZSZmWVysjAzs0xOFmZmlskN3GZNkjy/4FYqD635SUT8dYtDMsvNycKseT4JfCsivtfqQMzGy9VQZs3zJuD7rQ7CbCLcddasSSStAa4CjgKfj4ijLQ7JLDcnCzMzy+RqKDMzy+RkYWZmmZwszMwsk5OFmZllcrIwM7NMThZmZpbJycLMzDI5WZiZWSYnCzMzy/T/AYao0Zs9GsXdAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.errorbar(tc, ab, err, fmt='o', ls='')\n",
"xx = np.linspace(min(tc), max(tc), 100)\n",
"plt.plot(xx, soln['x'][0]*xx + soln['x'][1], c='orange')\n",
"plt.xlabel(r'T$_c$')\n",
"plt.ylabel(r'[X/H]');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### checking with linear algebra:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"Y = np.copy(ab)\n",
"A = np.ones((len(ab),2))\n",
"A[:,0] = tc\n",
"Cinv = np.diag(1./err**2) # sorry Hogg"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"ACA = np.dot(A.T, np.dot(Cinv, A))\n",
"ACY = np.dot(A.T, np.dot(Cinv, Y))\n",
"soln = np.linalg.solve(ACA, ACY)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"best-fit slope is: 4.23e-05\n"
]
}
],
"source": [
"print('best-fit slope is: {0:.2e}'.format(soln[0]))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment