Skip to content

Commit 7abc4a5

Browse files
committed
update readme and add notebook
1 parent 282048f commit 7abc4a5

File tree

2 files changed

+225
-3
lines changed

2 files changed

+225
-3
lines changed

README.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,94 @@ Aman Desai
1414
A package to read SPARC data for Galactic Rotation Curves
1515

1616
## Installation
17+
1718
```bash
18-
pip install git+https:https://github.com/amanmdesai/pygrc
19+
pip install pygrc
20+
```
21+
22+
## Example Usage
23+
24+
- 1. Import libraries
25+
26+
```python
27+
import math
28+
import numpy as np
29+
import matplotlib.pyplot as plt
30+
import pygrc as gr
31+
```
32+
33+
- 2. Read Sparc Data
34+
35+
```python
36+
df = gr.Reader.read(filepath="/home/amdesai/Physics/data/NGC5055_rotmod.dat")
37+
gr.Plot().overlap(df,"Rad",["Vobs","Vgas","Vbul","Vdisk"],"observed velocity")
38+
df
39+
```
40+
41+
- 3. Some sample function
42+
```python
43+
# mond and mass function are based on Galaxies 2018, 6(3), 70; https://doi.org/10.3390/galaxies6030070
44+
45+
def mass(r, M0, R0):
46+
return M0*(1- (1+(r/R0))*np.exp(-r/R0))
47+
48+
def mond(r, M0, rc, R0,b, beta):
49+
a = 1.2e-10
50+
G = 4.300e-6 #parsecs
51+
m = mass(r,M0, R0)
52+
f = (G*m/r)*(1 + b*(1+(r/rc)))#*10e-3
53+
return np.sqrt(f)*10e-3
54+
55+
def newton(r, M0, rc, R0,beta):
56+
a = 1.2e-10
57+
G = 4.30e-6 #parsecs
58+
m = mass(r,M0, R0)
59+
f = G*m/r
60+
#f = (G*m/r)*(1/np.sqrt(2)) * np.sqrt(1 + np.sqrt(1 + (r**4) * (2*a/(G*m))**2))
61+
return np.sqrt(f)*10e-3
62+
```
63+
64+
- 4a. Perform fit (uses iminuit in the background)
65+
66+
```python
67+
r = np.linspace(1e-5,df['Rad'].max(),2000)
68+
69+
m_1=gr.Fit(df['Rad'],df['Vobs'],1.,1.,3,.35,1.)
70+
71+
m_2=gr.Fit(df['Rad'],df['Vobs'],1.,1.,3,1.)
72+
```
73+
74+
- 4b. Continue:
75+
76+
```python
77+
m1= m_1.fit_lsq(mond, [(1.,1e17),(1.,10.),(2.,5.),(0.1,2),(0.1,2)],df['errV'],[False,False,True,True,True])
78+
m1
1979
```
2080

21-
SPARC Data can be obtained from here:
22-
http://astroweb.cwru.edu/SPARC/
81+
- 4c. Continue:
82+
83+
```python
84+
m2 = m_2.fit_lsq(newton, [(1.,1e16),(1.,10.),(1,10),(0.1,2)],df['errV'],[False,True,True,True])
85+
m2
86+
```
87+
88+
- 5a. draw plots
89+
```python
90+
m_2.get_profile(m2,'M0')
91+
m_1.draw_contours(m1,['M0','rc'])
92+
```
93+
94+
- 6b.
95+
96+
```python
97+
fig, ax =plt.subplots()
98+
gr.Plot().plot_grc(df,m1,mond,'MOND','NGC',ax)
99+
gr.Plot().plot_grc(df,m2,newton,'Newton','NGC',ax)
100+
plt.savefig('1.pdf')
101+
```
102+
103+
104+
References:
23105

106+
- SPARC Data can be obtained from here: http://astroweb.cwru.edu/SPARC/
107+
- Mond and Mass function are based on Galaxies 2018, 6(3), 70; https://doi.org/10.3390/galaxies6030070

notebooks/example.ipynb

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "e7a1fc45",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import math\n",
11+
"import numpy as np\n",
12+
"import matplotlib.pyplot as plt\n",
13+
"import pygrc as gr"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"id": "7e27a301",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"df = gr.Reader.read(filepath=\"/home/amdesai/Physics/data/NGC5055_rotmod.dat\")\n",
24+
"gr.Plot().overlap(df,\"Rad\",[\"Vobs\",\"Vgas\",\"Vbul\",\"Vdisk\"],\"observed velocity\")\n",
25+
"df"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"id": "642a96a4",
32+
"metadata": {},
33+
"outputs": [],
34+
"source": [
35+
"# some example functions based on Galaxies 2018, 6(3), 70; https://doi.org/10.3390/galaxies6030070\n",
36+
"\n",
37+
"def mass(r, M0, R0):\n",
38+
" return M0*(1- (1+(r/R0))*np.exp(-r/R0))\n",
39+
"\n",
40+
"def mond(r, M0, rc, R0,b, beta):\n",
41+
" a = 1.2e-10\n",
42+
" G = 4.300e-6 #parsecs \n",
43+
" m = mass(r,M0, R0)\n",
44+
" f = (G*m/r)*(1 + b*(1+(r/rc)))#*10e-3\n",
45+
" return np.sqrt(f)*10e-3\n",
46+
"\n",
47+
"def newton(r, M0, rc, R0,beta):\n",
48+
" a = 1.2e-10\n",
49+
" G = 4.30e-6 #parsecs \n",
50+
" m = mass(r,M0, R0)\n",
51+
" f = G*m/r\n",
52+
" #f = (G*m/r)*(1/np.sqrt(2)) * np.sqrt(1 + np.sqrt(1 + (r**4) * (2*a/(G*m))**2))\n",
53+
" return np.sqrt(f)*10e-3\n"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": null,
59+
"id": "6df730b3",
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"r = np.linspace(1e-5,df['Rad'].max(),2000)\n",
64+
"\n",
65+
"m_1=gr.Fit(df['Rad'],df['Vobs'],1.,1.,3,.35,1.)\n",
66+
"\n",
67+
"m_2=gr.Fit(df['Rad'],df['Vobs'],1.,1.,3,1.)"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"id": "0deaae95",
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"m1= m_1.fit_lsq(mond, [(1.,1e17),(1.,10.),(2.,5.),(0.1,2),(0.1,2)],df['errV'],[False,False,True,True,True])\n",
78+
"m1"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "64e5e876",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"m2 = m_2.fit_lsq(newton, [(1.,1e16),(1.,10.),(1,10),(0.1,2)],df['errV'],[False,True,True,True])\n",
89+
"m2"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "efb56302",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"m_2.get_profile(m2,'M0')\n",
100+
"m_1.draw_contours(m1,['M0','rc'])"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"id": "98ed80d2",
107+
"metadata": {},
108+
"outputs": [],
109+
"source": [
110+
"fig, ax =plt.subplots()\n",
111+
"gr.Plot().plot_grc(df,m1,mond,'MOND','NGC',ax)\n",
112+
"gr.Plot().plot_grc(df,m2,newton,'Newton','NGC',ax)\n",
113+
"plt.savefig('1.pdf')"
114+
]
115+
}
116+
],
117+
"metadata": {
118+
"kernelspec": {
119+
"display_name": "Python 3 (ipykernel)",
120+
"language": "python",
121+
"name": "python3"
122+
},
123+
"language_info": {
124+
"codemirror_mode": {
125+
"name": "ipython",
126+
"version": 3
127+
},
128+
"file_extension": ".py",
129+
"mimetype": "text/x-python",
130+
"name": "python",
131+
"nbconvert_exporter": "python",
132+
"pygments_lexer": "ipython3",
133+
"version": "3.10.6"
134+
}
135+
},
136+
"nbformat": 4,
137+
"nbformat_minor": 5
138+
}

0 commit comments

Comments
 (0)