```python
import sys
sys.path.append('python/')

import time
startTime = time.time()      # Calculate time for running this notebook

import numpy as np
import matplotlib.pyplot as plt 
import load_galaxies as lg   # Load load_galaxies.py library
```

_Python help: Running the notebook the first time, make sure to run all cells to be able to make changes in the notebook. Hit Shift+Enter to run the cell or click on the top menu: Kernel > Restart & Run All > Restart and Run All Cells to rerun the whole notebook. If you make any changes in a cell, rerun that cell._

# Measured data plotting

In this notebook you can load radial velocity measurements of multiple galaxies from a prepared Python library. Plot them all in a single graph so you can compare them with each other. <br><br>
Plotting these measurements is the first step of producing a rotation curve for a galaxy and an indication of how much mass the galaxy contains. Setting Newton's law of gravitation and the circular motion equation equal to each other, you can derive the equation for circular velocity in terms of enclosed mass and radius: 

\begin{equation}
v(r) = \sqrt{\frac{G M_{enc}(r)}{r}}
\end{equation}
<br>

>where:<br>
        $G$ = gravitational constant<br>
        $M_{enc}(r)$ = enclosed mass as a function of radius<br>
        $r$ = radius or distance from the center of the galaxy
    <br>

Knowing the radial velocity of stars at different radii, you can estimate the mass that is enclosed in that radius. By measuring the brightnesses (photometric profile) of stars and the amount of gas, you can approximate the mass of "visible" matter. Compare it with the actual mass calculated from the radial velocities to get an idea of how much mass is "missing". The result is a ratio (mass-to-light ratio or M/L) that has been useful to describe the amount of dark matter in galaxies. <br>

### Vocabulary
__Rotation curve__: velocity of stars and gas at distances from the center of the galaxy and plotted as a curve<br>
__Radial velocity__: how fast stars and gas are moving at different distances from the center of the galaxy<br>
__NGC__: New General Catalogue of galaxies<br>
__UGC__: Uppsala General Catalogue of galaxies<br>
__kpc__: kiloparsec: 1 kpc = 3262 light years = 3.086e+19 meters = 1.917e+16 miles

## Load data of multiple galaxies

Load the radii, velocities, and errors in velocities of multiple galaxies from a Python library. 


```python
# NGC 5533
r_NGC5533, v_NGC5533, v_err_NGC5533 = lg.NGC5533['m_radii'],lg.NGC5533['m_velocities'],lg.NGC5533['m_v_errors']

# NGC 891
r_NGC0891, v_NGC0891, v_err_NGC0891 = lg.NGC0891['m_radii'],lg.NGC0891['m_velocities'],lg.NGC0891['m_v_errors']

# NGC 7814
r_NGC7814, v_NGC7814, v_err_NGC7814 = lg.NGC7814['m_radii'],lg.NGC7814['m_velocities'],lg.NGC7814['m_v_errors']

# NGC 5005
r_NGC5005, v_NGC5005, v_err_NGC5005 = lg.NGC5005['m_radii'],lg.NGC5005['m_velocities'],lg.NGC5005['m_v_errors']

# NGC 3198
r_NGC3198, v_NGC3198, v_err_NGC3198 = lg.NGC3198['m_radii'],lg.NGC3198['m_velocities'],lg.NGC3198['m_v_errors']

# UGC 89
#r_UGC89, v_UGC89, v_err_UGC89 = lg.UGC89['m_radii'],lg.UGC89['m_velocities'],lg.UGC89['m_v_errors']

# UGC 477
r_UGC477, v_UGC477, v_err_UGC477 = lg.UGC477['m_radii'],lg.UGC477['m_velocities'],lg.UGC477['m_v_errors']

# UGC 1281
r_UGC1281, v_UGC1281, v_err_UGC1281 = lg.UGC1281['m_radii'],lg.UGC1281['m_velocities'],lg.UGC1281['m_v_errors']

# UGC 1437
r_UGC1437, v_UGC1437, v_err_UGC1437 = lg.UGC1437['m_radii'],lg.UGC1437['m_velocities'],lg.UGC1437['m_v_errors']

# UGC 2953
r_UGC2953, v_UGC2953, v_err_UGC2953 = lg.UGC2953['m_radii'],lg.UGC2953['m_velocities'],lg.UGC2953['m_v_errors']

# UGC 4325
r_UGC4325, v_UGC4325, v_err_UGC4325 = lg.UGC4325['m_radii'],lg.UGC4325['m_velocities'],lg.UGC4325['m_v_errors']

# UGC 5253
r_UGC5253, v_UGC5253, v_err_UGC5253 = lg.UGC5253['m_radii'],lg.UGC5253['m_velocities'],lg.UGC5253['m_v_errors']

# UGC 6787
r_UGC6787, v_UGC6787, v_err_UGC6787 = lg.UGC6787['m_radii'],lg.UGC6787['m_velocities'],lg.UGC6787['m_v_errors']

# UGC 10075
r_UGC10075, v_UGC10075, v_err_UGC10075 = lg.UGC10075['m_radii'],lg.UGC10075['m_velocities'],lg.UGC10075['m_v_errors']
```

## Plot measured data with errorbars

Measured data points of 13 galaxies are plotted below.<br>

1. __Change the limits of the x-axis to zoom in and out of the graph.__ <br>
_Python help: change the limits of the x-axis by modifying the two numbers (left and right) of the line: plt.xlim then rerun the notebook or the cell._ <br><br>

2. __Finding supermassive black holes:__ A high velocity at a radius close to zero (close to the center of the galaxy) indicates that there is a supermassive black hole is present at the center of that galaxy, changing the velocities of the close-by stars only. The reason the black hole does not have that much effect on the motion of stars at larger distances is because it acts as a point mass with negligible radius and the velocity drops off as $1 / \sqrt r$. <br>
__Can you find the galaxies with a possible central supermassive black hole and hide the curves of the rest of the galaxies?__ <br>
_Python help: Turn off the display of all lines and go through them one by one. You can "turn off" the display of each galaxy by typing a # sign in front of the line "plt.errorbar"._<br>
_Sneak peak: In the Interactive_\__Rotation_\__Curve_\__Plotting notebook you will be able to find out which stars are affected by the central supermassive black hole, or in other words, what we mean by "close-by" stars._ <br><br> 

3. __What do you notice about the size of the error bars at radii close to the center and far from the center? What could be the reason?__


```python
# Define radius for plotting
r = np.linspace(0,100,100)

# Plot
plt.figure(figsize=(10.0,7.0))                                     # size of the plot
plt.title('Measured data of multiple galaxies', fontsize=14)      # giving the plot a title
plt.xlabel('Radius (kpc)', fontsize=12)                           # labeling the x-axis
plt.ylabel('Velocity (km/s)', fontsize=12)                        # labeling the y-axis
plt.xlim(0,20)                                                    # limits of the x-axis (default from 0 to 20 kpc)
plt.ylim(0,420)                                                   # limits of the y-axis (default from 0 to 420 km/s)

# Plotting the measured data
plt.errorbar(r_NGC5533,v_NGC5533,yerr=v_err_NGC5533,    label='NGC 5533',  marker='o', markersize=6, linestyle='none', color='royalblue')
plt.errorbar(r_NGC0891,v_NGC0891,yerr=v_err_NGC0891,    label='NGC 891',   marker='o', markersize=6, linestyle='none', color='seagreen')
plt.errorbar(r_NGC7814,v_NGC7814,yerr=v_err_NGC7814,    label='NGC 7814',  marker='o', markersize=6, linestyle='none', color='m')
plt.errorbar(r_NGC5005,v_NGC5005,yerr=v_err_NGC5005,    label='NGC 5005',  marker='o', markersize=6, linestyle='none', color='red')
plt.errorbar(r_NGC3198,v_NGC3198,yerr=v_err_NGC3198,    label='NGC 3198',  marker='o', markersize=6, linestyle='none', color='gold')
plt.errorbar(r_UGC477,v_UGC477,yerr=v_err_UGC477,       label='UGC 477',   marker='o', markersize=6, linestyle='none', color='lightpink')
plt.errorbar(r_UGC1281,v_UGC1281,yerr=v_err_UGC1281,    label='UGC 1281',  marker='o', markersize=6, linestyle='none', color='aquamarine')
plt.errorbar(r_UGC1437,v_UGC1437,yerr=v_err_UGC1437,    label='UGC 1437',  marker='o', markersize=6, linestyle='none', color='peru')
plt.errorbar(r_UGC2953,v_UGC2953,yerr=v_err_UGC2953,    label='UGC 2953',  marker='o', markersize=6, linestyle='none', color='lightslategrey')
plt.errorbar(r_UGC4325,v_UGC4325,yerr=v_err_UGC4325,    label='UGC 4325',  marker='o', markersize=6, linestyle='none', color='darkorange')
plt.errorbar(r_UGC5253,v_UGC5253,yerr=v_err_UGC5253,    label='UGC 5253',  marker='o', markersize=6, linestyle='none', color='maroon')
plt.errorbar(r_UGC6787,v_UGC6787,yerr=v_err_UGC6787,    label='UGC 6787',  marker='o', markersize=6, linestyle='none', color='midnightblue')
plt.errorbar(r_UGC10075,v_UGC10075,yerr=v_err_UGC10075, label='UGC 10075', marker='o', markersize=6, linestyle='none', color='y')

plt.legend(loc='upper right')
plt.show()
```


```python
# Time
executionTime = (time.time() - startTime)
ttt=executionTime/60
print(f'Execution time: {ttt:.2f} minutes')
```

    Execution time: 8.77 minutes


# References
>De Naray, Rachel Kuzio, Stacy S. McGaugh, W. J. G. De Blok, and A. Bosma. __"High-resolution optical velocity fields of 11 low surface brightness galaxies."__ The Astrophysical Journal Supplement Series 165, no. 2 (2006): 461. https://doi.org/10.1086/505345.<br><br>
>De Naray, Rachel Kuzio, Stacy S. McGaugh, and W. J. G. De Blok. __"Mass models for low surface brightness galaxies with high-resolution optical velocity fields."__ The Astrophysical Journal 676, no. 2 (2008): 920. https://doi.org/10.1086/527543.<br><br>
>Epinat, B., P. Amram, M. Marcelin, C. Balkowski, O. Daigle, O. Hernandez, L. Chemin, C. Carignan, J.-L. Gach, and P. Balard. __“GHASP: An Hα Kinematic Survey of Spiral and Irregular GALAXIES – Vi. New HΑ Data Cubes for 108 Galaxies.”__ Monthly Notices of the Royal Astronomical Society 388, no. 2 (July 19, 2008): 500–550. https://doi.org/10.1111/j.1365-2966.2008.13422.x. <br><br>
>Fraternali, F., R. Sancisi, and P. Kamphuis. __“A Tale of Two Galaxies: Light and Mass in NGC 891 and NGC 7814.”__ Astronomy &amp; Astrophysics 531 (June 13, 2011). https://doi.org/10.1051/0004-6361/201116634.<br><br> 
>Karukes, E. V., P. Salucci, and Gianfranco Gentile. __"The dark matter distribution in the spiral NGC 3198 out to 0.22 $R_{vir}$."__ _Astronomy & Astrophysics_ 578 (2015): A13. https://doi.org/10.1051/0004-6361/201425339. <br><br>
>Lelli, Federico, ed. __“Spitzer Photometry and Accurate Rotation Curves.”__ SPARC, May 29, 2020. http://astroweb.cwru.edu/SPARC/. <br><br> 
>Noordermeer, Edo. __"The rotation curves of flattened Sérsic bulges."__ _Monthly Notices of the Royal Astronomical Society_ 385, no. 3 (2007): 1359-1364. https://doi.org/10.1111/j.1365-2966.2008.12837.x<br><br>
>Richards, Emily E., L. van Zee, K. L. Barnes, S. Staudaher, D. A. Dale, T. T. Braun, D. C. Wavle, et al. __“Baryonic Distributions in the Dark Matter Halo of NGC 5005.”__ Monthly Notices of the Royal Astronomical Society 449, no. 4 (June 1, 2015): 3981–96. https://doi.org/10.1093/mnras/stv568. 
***


```python

```

e76c20ddc822d5339c26f977d95effd12bfc5d72
ipynb
Jupyter Notebook
binder/DM_workshop_082721/Interactive_Measured_Data_Plotting.ipynb
villano-lab/galactic-spin
16b67b319008a4bb91ef3b2e80828e98cf13173b
MIT
2020-04-04T23:05:15.000Z
2021-10-01T15:42:53.000Z
binder/DM_workshop_082721/Interactive_Measured_Data_Plotting.ipynb
villano-lab/galactic-spin
16b67b319008a4bb91ef3b2e80828e98cf13173b
MIT
2021-11-12T18:51:21.000Z
2022-01-14T19:39:59.000Z
binder/DM_workshop_082721/Interactive_Measured_Data_Plotting.ipynb
villano-lab/galactic-spin
16b67b319008a4bb91ef3b2e80828e98cf13173b
MIT
Qwen/Qwen-72B
1. YES
2. YES