In [1]:
from scipy.optimize import curve_fit
import astropy.io.ascii as ascii
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np

In [2]:
tab1=ascii.read("Table1.csv")
tab2=ascii.read("Table2.csv")
tab3=ascii.read("Table3.csv")

In [3]:
tab1


Out[3]:
<Table length=21>
radiusrvelTheoryvalYdiffvalrvelerr
float64float64float64float64float64
0.21582733812912.99.03.91.8
0.4496402877717.110.86.31.8
0.64748201438823.711.8511.851.8
0.8992805755426.412.014.41.8
1.1870503597127.612.015.61.8
1.3669064748227.011.5515.451.8
1.6187050359727.611.5516.051.8
1.834532374131.211.5519.651.8
2.0503597122332.711.421.31.8
2.2661870503633.311.5521.751.8
2.5539568345337.212.1525.051.8
2.7697841726639.012.626.41.8
3.2374100719441.713.228.51.8
3.7230215827343.213.529.71.8
4.2086330935345.314.131.21.8
4.6402877697847.114.432.71.8
5.1079136690649.214.734.51.8
5.5935251798650.414.735.71.8
6.0431654676350.714.736.01.8
6.5287769784251.014.436.61.95
7.0143884892152.3514.138.252.7

In [4]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['rvel'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
plt.plot(tab1['radius'],tab1['Theoryval'],'-')
plt.plot(tab1['radius'],tab1['Ydiffval'],'--')
plt.title('Gas Dominated Dwarf (NGC 3741)')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf.pdf')
plt.savefig('gasdwarf.jpeg')



In [5]:
def line(x, a):
    return a * x

In [6]:
popt, pcov = curve_fit(line, tab1['radius'], tab1['Ydiffval'])

In [7]:
popt


Out[7]:
array([ 6.85024949])

In [8]:
pcov


Out[8]:
array([[ 0.13622374]])

In [10]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100)  # define values to plot the function for
plt.plot(xfine, line(xfine, popt), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit_omega.pdf')
plt.savefig('gasdwarf_fit_omega.jpeg')



In [11]:
tab2


Out[11]:
<Table length=31>
RadiusRvelocityTheoryVeldiffVelerr
float64float64float64float64float64
0.61643835616477.472527472551.648351648425.824175824210.4395604396
1.43835616438100.089.01098901110.9890109893.2967032967
2.19178082192109.89010989100.5494505499.340659340663.2967032967
2.87671232877118.13186813296.153846153821.9780219783.2967032967
3.69863013699121.42857142986.813186813234.61538461543.2967032967
4.45205479452121.42857142981.318681318740.10989010993.2967032967
5.20547945205117.58241758274.175824175843.40659340663.2967032967
5.61643835616116.48351648472.527472527543.9560439563.2967032967
6.09589041096115.93406593470.329670329745.60439560443.2967032967
6.84931506849115.93406593466.483516483549.45054945053.2967032967
...............
15.0684931507117.58241758251.648351648465.93406593413.2967032967
15.8904109589115.93406593450.549450549565.38461538463.2967032967
16.5753424658114.83516483550.064.83516483523.2967032967
17.397260274114.83516483548.901098901165.93406593413.2967032967
18.1506849315114.83516483547.802197802267.0329670333.2967032967
19.5205479452114.83516483546.153846153868.68131868133.2967032967
20.9589041096115.93406593445.054945054970.87912087913.2967032967
21.8493150685114.83516483543.95604395670.87912087914.3956043956
22.6712328767118.13186813243.406593406674.72527472534.3956043956
23.4246575342116.48351648442.307692307774.175824175810.4395604396

In [12]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Rvelocity'],yerr=tab2['Velerr'],fmt='o',capsize=3)
plt.plot(tab2['Radius'],tab2['Theory'],'-')
plt.plot(tab2['Radius'],tab2['Veldiff'],'--')
plt.title('Disk-Dominated Spiral (NGC6503)')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral.pdf')
plt.savefig('diskspiral.jpeg')



In [13]:
popt2, pcov2 = curve_fit(line, tab2['Radius'], tab2['Veldiff'])

In [15]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100)  # define values to plot the function for
plt.plot(xfine, line(xfine, popt2), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit_omega.pdf')
plt.savefig('diskspiral_fit_omega.jpeg')



In [16]:
print popt2
print pcov2


[ 4.1327069]
[[ 0.04702947]]

In [17]:
tab3


Out[17]:
<Table length=18>
radiusrvelRtheoryveldiffvelerr
float64float64float64float64float64
1.59482758621255.833333333276.666666667-20.833333333314.1666666667
1.76724137931241.666666667246.666666667-5.014.1666666667
2.80172413793224.166666667220.04.166666666676.66666666667
3.87931034483220.833333333199.16666666721.66666666676.66666666667
5.04310344828219.166666667184.16666666735.06.66666666667
6.12068965517219.166666667170.049.16666666676.66666666667
7.19827586207218.333333333158.33333333360.06.66666666667
8.23275862069216.666666667150.066.66666666675.0
9.35344827586213.333333333142.570.83333333335.0
10.474137931211.666666667135.83333333375.83333333335.0
11.5086206897207.5130.077.55.0
12.4568965517205.833333333125.080.83333333335.0
13.7068965517206.666666667119.16666666787.55.0
14.7413793103205.833333333115.090.83333333335.0
15.775862069205.0111.66666666793.33333333335.0
16.9396551724205.0108.33333333396.66666666675.0
17.974137931204.166666667104.166666667100.05.0
19.0517241379205.0100.833333333104.1666666675.0

In [18]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],yerr=tab3['velerr'],fmt='o',capsize=3)
plt.plot(tab3['radius'],tab3['Rtheory'],'-')
plt.plot(tab3['radius'],tab3['veldiff'],'--')
plt.title('Bulge-Dominated Spiral (NGC7814)')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral.pdf')
plt.savefig('bulgespiral.jpeg')



In [19]:
popt3, pcov3 = curve_fit(line, tab3['radius'], tab3['veldiff'])

In [20]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100)  # define values to plot the function for
plt.plot(xfine, line(xfine, popt3), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit_omega.pdf')
plt.savefig('bulgespiral_fit_omega.jpeg')



In [21]:
print popt3
print pcov3


[ 6.15506884]
[[ 0.06964819]]

In [91]:
popt, pcov = curve_fit(line, tab1['radius'][2:], tab1['Ydiffval'][2:])

In [90]:
tab1['radius'][2:]


Out[90]:
<Column name='radius' dtype='float64' length=19>
0.647482014388
0.89928057554
1.18705035971
1.36690647482
1.61870503597
1.8345323741
2.05035971223
2.26618705036
2.55395683453
2.76978417266
3.23741007194
3.72302158273
4.20863309353
4.64028776978
5.10791366906
5.59352517986
6.04316546763
6.52877697842
7.01438848921

In [93]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100)  # define values to plot the function for
plt.plot(xfine, line(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Diff between theory & observed (in km/s/Mpc)')
plt.savefig('gasdwarf_diff_fit.pdf')
plt.savefig('gasdwarf_diff_fit.jpeg')



In [95]:
popt2, pcov2 = curve_fit(line, tab2['Radius'][4:], tab2['Veldiff'][4:])
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100)  # define values to plot the function for
plt.plot(xfine, line(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Diff between theory & observed (in km/s/Mpc)')
plt.savefig('diskspiral_diff_fit.pdf')
plt.savefig('diskspiral_diff_fit.jpeg')



In [96]:
popt3, pcov3 = curve_fit(line, tab3['radius'][2:], tab3['veldiff'][2:])
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100)  # define values to plot the function for
plt.plot(xfine, line(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Diff between theory & observed (in km/s/Mpc)')
plt.savefig('bulgespiral_diff_fit.pdf')
plt.savefig('bulgespiral_diff_fit.jpeg')



In [22]:
def linexp(x, a, b):
    return a * x * np.exp(b*x)

In [23]:
popt, pcov = curve_fit(linexp, tab1['radius'], tab1['Ydiffval'])

In [24]:
print popt


[ 13.87255675  -0.13957306]

In [26]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100)  # define values to plot the function for
plt.plot(xfine, linexp(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit_omega_exp.pdf')
plt.savefig('gasdwarf_fit_omega_exp.jpeg')



In [29]:
popt2, pcov2 = curve_fit(linexp, tab2['Radius'], tab2['Veldiff'])

In [30]:
print popt2
print pcov2


[ 9.69318051 -0.05125356]
[[  2.03556902e-01  -1.26896768e-03]
 [ -1.26896768e-03   9.06721199e-06]]

In [32]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100)  # define values to plot the function for
plt.plot(xfine, linexp(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit_omega_exp.pdf')
plt.savefig('diskspiral_fit_omega_exp.jpeg')



In [33]:
popt3, pcov3 = curve_fit(linexp, tab3['radius'], tab3['veldiff'])

In [34]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100)  # define values to plot the function for
plt.plot(xfine, linexp(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit_omega_exp.pdf')
plt.savefig('bulgespiral_fit_omega_exp.jpeg')



In [36]:
print popt3
print pcov3


[ 8.20725534 -0.01978487]
[[  1.35084716e+00  -1.08074934e-02]
 [ -1.08074934e-02   9.36132066e-05]]

In [45]:
def linexp1(x, a, b):
    return a * np.exp(b*x)

In [46]:
popt, pcov = curve_fit(linexp1, tab1['radius'], tab1['Ydiffval'])

In [47]:
print popt
print pcov


[ 13.71815518   0.16465184]
[[  1.56248410e+00  -2.09533954e-02]
 [ -2.09533954e-02   3.38885992e-04]]

In [48]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100)  # define values to plot the function for
plt.plot(xfine, linexp1(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit_omega_exp1.pdf')
plt.savefig('gasdwarf_fit_omega_exp1.jpeg')



In [49]:
popt2, pcov2 = curve_fit(linexp1, tab2['Radius'], tab2['Veldiff'])

In [50]:
print popt2
print pcov2


[ 33.57395059   0.03853322]
[[  6.32882197e+00  -1.07957812e-02]
 [ -1.07957812e-02   2.20317898e-05]]

In [51]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100)  # define values to plot the function for
plt.plot(xfine, linexp1(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit_omega_exp1.pdf')
plt.savefig('diskspiral_fit_omega_exp1.jpeg')



In [52]:
popt3, pcov3 = curve_fit(linexp1, tab3['radius'], tab3['veldiff'])

In [53]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100)  # define values to plot the function for
plt.plot(xfine, linexp1(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit_omega_exp1.pdf')
plt.savefig('bulgespiral_fit_omega_exp1.jpeg')



In [ ]:


In [54]:
def linexp2(x, a, b):
    return a * np.exp(b/x)

In [55]:
popt, pcov = curve_fit(linexp2, tab1['radius'], tab1['Ydiffval'])

In [56]:
print popt
print pcov


[ 42.74594111  -1.25279963]
[[ 2.8838049  -0.16093615]
 [-0.16093615  0.0126969 ]]

In [57]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100)  # define values to plot the function for
plt.plot(xfine, linexp2(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit_omega_exp2.pdf')
plt.savefig('gasdwarf_fit_omega_exp2.jpeg')


/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: divide by zero encountered in divide
  from ipykernel import kernelapp as app

In [58]:
popt2, pcov2 = curve_fit(linexp2, tab2['Radius'], tab2['Veldiff'])

In [59]:
print popt2
print pcov2


[ 82.94523877  -3.59263564]
[[ 7.08181719 -0.70943047]
 [-0.70943047  0.09845183]]

In [60]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100)  # define values to plot the function for
plt.plot(xfine, linexp2(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit_omega_exp2.pdf')
plt.savefig('diskspiral_fit_omega_exp2.jpeg')


/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: divide by zero encountered in divide
  from ipykernel import kernelapp as app

In [61]:
popt3, pcov3 = curve_fit(linexp2, tab3['radius'], tab3['veldiff'])

In [62]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100)  # define values to plot the function for
plt.plot(xfine, linexp2(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit_omega_exp2.pdf')
plt.savefig('bulgespiral_fit_omega_exp2.jpeg')


/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: divide by zero encountered in divide
  from ipykernel import kernelapp as app

In [ ]:


In [63]:
def linexp3(x, a, b):
    return a *x* np.exp(b/x)

In [64]:
popt, pcov = curve_fit(linexp3, tab1['radius'], tab1['Ydiffval'])

In [65]:
print popt
print pcov


[ 6.2073411   0.44688667]
[[ 0.09905815 -0.0160852 ]
 [-0.0160852   0.00899746]]

In [66]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['Ydiffval'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100)  # define values to plot the function for
plt.plot(xfine, linexp3(xfine, popt[0], popt[1]), 'r-')
plt.title('Gas Dominated Dwarf best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit_omega_exp3.pdf')
plt.savefig('gasdwarf_fit_omega_exp3.jpeg')


/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: divide by zero encountered in divide
  from ipykernel import kernelapp as app
/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: invalid value encountered in multiply
  from ipykernel import kernelapp as app

In [69]:
popt2, pcov2 = curve_fit(linexp3, tab2['Radius'], tab2['Veldiff'])

In [70]:
print popt2
print pcov2


[ 3.70761512  1.69268452]
[[ 0.02947047 -0.01683011]
 [-0.01683011  0.04805995]]

In [71]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Veldiff'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100)  # define values to plot the function for
plt.plot(xfine, linexp3(xfine, popt2[0], popt2[1]), 'r-')
plt.title('Disk-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit_omega_exp3.pdf')
plt.savefig('diskspiral_fit_omega_exp3.jpeg')


/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: divide by zero encountered in divide
  from ipykernel import kernelapp as app
/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: invalid value encountered in multiply
  from ipykernel import kernelapp as app

In [73]:
popt3, pcov3 = curve_fit(linexp3, tab3['radius'], tab3['veldiff'])

In [74]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['veldiff'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100)  # define values to plot the function for
plt.plot(xfine, linexp3(xfine, popt3[0], popt3[1]), 'r-')
plt.title('Bulge-dominated Spiral best fit')
plt.xlabel('Radius(in kpc)')
plt.ylabel('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit_omega_exp3.pdf')
plt.savefig('bulgespiral_fit_omega_exp3.jpeg')


/Users/rohin/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: divide by zero encountered in divide
  from ipykernel import kernelapp as app

In [ ]: