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 [74]:
tab1=ascii.read("Table1.csv")
tab2=ascii.read("Table2.csv")
tab3=ascii.read("Table3.csv")

In [24]:
tab1


Out[24]:
<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 [56]:
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 [79]:
def line(x, a, b):
    return a * x + b

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

In [81]:
popt


Out[81]:
array([ 4.69883003,  9.53941453])

In [52]:
pcov


Out[52]:
array([[ 0.13540867, -0.41239572],
       [-0.41239572,  1.82856657]])

In [82]:
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('Rotational velocity (in km/s/Mpc)')
plt.savefig('gasdwarf_fit.pdf')
plt.savefig('gasdwarf_fit.jpeg')



In [75]:
tab2


Out[75]:
<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 [76]:
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 [84]:
popt2, pcov2 = curve_fit(line, tab2['Radius'], tab2['Veldiff'])

In [85]:
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('Rotational velocity (in km/s/Mpc)')
plt.savefig('diskspiral_fit.pdf')
plt.savefig('diskspiral_fit.jpeg')



In [66]:
tab3


Out[66]:
<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 [69]:
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['velerr'],'--')
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 [86]:
popt3, pcov3 = curve_fit(line, tab3['radius'], tab3['veldiff'])

In [88]:
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('Rotational velocity (in km/s/Mpc)')
plt.savefig('bulgespiral_fit.pdf')
plt.savefig('bulgespiral_fit.jpeg')



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 [ ]: