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
from scipy.constants import *
In [2]:
solmass=1.99e30
In [3]:
G
Out[3]:
In [4]:
parsec
Out[4]:
In [5]:
uconv=np.sqrt(G*1e-12/(parsec*solmass))
In [6]:
print uconv
In [7]:
4.65e-20/np.sqrt(solmass)
Out[7]:
In [8]:
4.0/3.0*pi
Out[8]:
In [9]:
tab1=ascii.read("Table1.csv")
#tab2=ascii.read("Table2.csv")
#tab3=ascii.read("Table3.csv")
In [ ]:
In [ ]:
In [29]:
def linexpy2(x, M, a, l):
return uconv*np.sqrt((M/x)*(1.0+a*(1.0+x/l)*np.exp(-x/l)))
In [9]:
tab1
Out[9]:
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 [49]:
def linexpy(x, M, a):
return (M*np.exp(-x/10.0)/np.sqrt(x))*(1.0+a*(1+x/6.0)*np.exp(-x/6.0))
In [33]:
popt, pcov = curve_fit(linexpy2, tab1['radius'], tab1['rvel'])
In [34]:
popt
Out[34]:
In [35]:
pcov
Out[35]:
In [36]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['rvel'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100) # define values to plot the function for
plt.plot(xfine, linexpy2(xfine, popt[0], popt[1],popt[2]), '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_y.pdf')
plt.savefig('gasdwarf_fit_y.jpeg')
In [11]:
tab2
Out[11]:
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 [71]:
def linexpy(x, M, a):
return (M*np.exp(-x/2.0)/np.sqrt(x))*(1.0+a*(1+x/6.0)*np.exp(-x/6.0))
In [37]:
popt2, pcov2 = curve_fit(linexpy2, tab2['Radius'], tab2['Rvelocity'])
In [38]:
popt2
pcov2
Out[38]:
In [41]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Rvelocity'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100) # define values to plot the function for
plt.plot(xfine, linexpy2(xfine, popt2[0],popt2[1],popt2[2]), '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_y.pdf')
plt.savefig('diskspiral_fit_y.jpeg')
In [16]:
print popt2
print pcov2
In [17]:
tab3
Out[17]:
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 [104]:
def linexpy(x, M, a):
return (M*np.exp(-x/1.0)/np.sqrt(x))*(1.0+a*(1+x/2.0)*np.exp(-x/2.0))
In [42]:
popt3, pcov3 = curve_fit(linexpy2, tab3['radius'], tab3['rvel'])
In [44]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(1., 20, 100) # define values to plot the function for
plt.plot(xfine, linexpy2(xfine, popt3[0],popt3[1],popt3[2]), '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_y.pdf')
plt.savefig('bulgespiral_fit_y.jpeg')
In [21]:
print popt3
print pcov3
In [91]:
popt, pcov = curve_fit(line, tab1['radius'][2:], tab1['Ydiffval'][2:])
In [90]:
tab1['radius'][2:]
Out[90]:
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 [205]:
def linexpy1(x, M, a, l):
return np.sqrt((M*x**2)*(1.0+a*(1.0+x/l)*np.exp(-x/l)))
In [206]:
popt, pcov = curve_fit(linexpy1, tab1['radius'], tab1['rvel'], sigma=tab1['rvelerr'])
perr = np.sqrt(np.diag(pcov))
In [207]:
print popt
print pcov
print perr
In [208]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['rvel'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100) # define values to plot the function for
plt.plot(xfine, linexpy1(xfine, popt[0], popt[1],popt[2]), '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_expy1.pdf')
plt.savefig('gasdwarf_fit_omega_expy1.jpeg')
In [170]:
popt2, pcov2 = curve_fit(linexpy1, tab2['Radius'], tab2['Rvelocity'],sigma=tab2['Velerr'])
perr = np.sqrt(np.diag(pcov2))
In [171]:
print popt2
print pcov2
print perr
In [172]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Rvelocity'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100) # define values to plot the function for
plt.plot(xfine, linexpy1(xfine, popt2[0], popt2[1],popt2[2]), '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_y1.pdf')
plt.savefig('diskspiral_fit_y1.jpeg')
In [176]:
popt3, pcov3 = curve_fit(linexpy1, tab3['radius'], tab3['rvel'],sigma=tab3['velerr'])
perr = np.sqrt(np.diag(pcov3))
In [177]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100) # define values to plot the function for
plt.plot(xfine, linexpy1(xfine, popt3[0], popt3[1], popt3[2]), '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_y1.pdf')
plt.savefig('bulgespiral_fit_y1.jpeg')
In [178]:
print popt3
print pcov3
print perr
In [218]:
def linexpy1(x, M, a, l):
return 4.0/3.0*pi*x*np.sqrt(M*(1.0+a*(1.0+x/l)*np.exp(-x/l)))
In [219]:
popt, pcov = curve_fit(linexpy1, tab1['radius'], tab1['rvel'])
perr = np.sqrt(np.diag(pcov))
In [220]:
print popt
print pcov
print perr
In [221]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['rvel'],yerr=tab1['rvelerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 7.5, 100) # define values to plot the function for
plt.plot(xfine, linexpy1(xfine, popt[0], popt[1],popt[2]), '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_y1.pdf')
plt.savefig('gasdwarf_fit_y1.jpeg')
In [222]:
popt2, pcov2 = curve_fit(linexpy1, tab2['Radius'], tab2['Rvelocity'])
perr = np.sqrt(np.diag(pcov2))
In [223]:
print popt2
print pcov2
print perr
In [225]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Rvelocity'],yerr=tab2['Velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 25, 100) # define values to plot the function for
plt.plot(xfine, linexpy1(xfine, popt2[0], popt2[1], popt2[2]), '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_1y.pdf')
plt.savefig('diskspiral_fit_1y.jpeg')
In [227]:
popt3, pcov3 = curve_fit(linexpy1, tab3['radius'], tab3['rvel'])
perr = np.sqrt(np.diag(pcov3))
In [228]:
print popt3
print pcov3
print perr
In [230]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100) # define values to plot the function for
plt.plot(xfine, linexpy1(xfine, popt3[0], popt3[1],popt3[2]), '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_1y.pdf')
plt.savefig('bulgespiral_fit_1y.jpeg')
In [ ]:
In [5]:
popt3, pcov3 = curve_fit(linexpy2, tab3['radius'], tab3['rvel'])
perr = np.sqrt(np.diag(pcov3))
In [8]:
print popt3
print pcov3
print perr
In [11]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],yerr=tab3['velerr'],fmt='o',capsize=3)
xfine = np.linspace(0., 20, 100) # define values to plot the function for
plt.plot(xfine, linexpy2(xfine, popt3[0], popt3[1],popt3[2]), '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_y2.pdf')
plt.savefig('gasdwarf_fit_y2.jpeg')
In [58]:
popt2, pcov2 = curve_fit(linexp2, tab2['Radius'], tab2['Veldiff'])
In [59]:
print popt2
print pcov2
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')
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')
In [ ]:
In [22]:
def linexp3(x, M, a):
return (G*M/np.sqrt(x))*(1.0+a*(1+x/4.0)*np.exp(-x/4.0))
In [23]:
popt, pcov = curve_fit(linexp3, tab1['radius'], tab1['rvel'])
In [24]:
print popt
print pcov
In [25]:
plt.figure()
plt.errorbar(tab1['radius'],tab1['rvel'],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')
In [26]:
popt2, pcov2 = curve_fit(linexp3, tab2['Radius'], tab2['Rvelocity'])
In [27]:
print popt2
print pcov2
In [28]:
plt.figure()
plt.errorbar(tab2['Radius'],tab2['Rvelocity'],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')
In [29]:
popt3, pcov3 = curve_fit(linexp3, tab3['radius'], tab3['rvel'])
In [30]:
plt.figure()
plt.errorbar(tab3['radius'],tab3['rvel'],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')
In [122]:
help(curve_fit)
In [45]:
plt.hist([1,2,3,4])
Out[45]:
In [ ]: