### Instructions

When running the notebook the first time, make sure to run all cells before making changes in the notebook. Hit Shift + Enter to run the selected cell or, in the top menu, click on: `Kernel` > `Restart Kernel and Run All Cells...` to rerun the whole notebook. If you make any changes in a cell, rerun that cell.

If you make any changes in a coding cell, rerun the notebook by `Run` > `Run Selected Cell and All Below`


```python
# Import dependencies
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
```

# Measured Data Plotting

Plotting radial velocity 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, the equation for circular velocity in terms of enclosed mass and radius can be derived: 

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


>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>
    
In the following activity, you will load radial velocity measurements of multiple galaxies from our Python library. The rotation curves are plotted on a single graph for comparison. <br>

Knowing the radial velocity of stars at different radii allows you to estimate the mass enclosed for a given radius. By measuring the brightness (luminosity) 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

__Radial velocity__: the speed stars and gas are moving at different distances from the center of the galaxy<br>
__Rotation curve__: a plot of a galaxy's radial velocity vs the radius<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 mile

### Load data of multiple galaxies

Load the radii, velocities, and errors in velocities of multiple galaxies from our 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 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><br>

<div class="alert-info">Activity 1)</div> 

>In the coding cell below, 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>

<div class="alert-info">Activity 2)</div>

>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 present at the center of that galaxy, changing the velocities of the close-by stars. 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, which has negligible effect at large radii as 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`. This turns the line into a comment so that Python will ignore it._<br>

_Insight: In the `04_Plotting_Rotation_Curves.ipynb` notebook, you will be able to calculate the rotation curve of the central supermassive black hole._ <br><br> 

<div class="alert-info">Activity 3)</div> 

>What do you notice about the size of the error bars at radii close and far from the center? What might be the reason for this?


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

# Plot
plt.figure(figsize=(14,8))                                        # size of the plot
plt.title('Measured radial velocity 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(bbox_to_anchor=(1,1), loc="upper left")
plt.show()
```


```python
#NBVAL_IGNORE_OUTPUT
#Because the timing won't be exactly the same each time.
# Time
executionTime = (time.time() - startTime)
ttt=executionTime/60
print(f'Execution time: {ttt:.2f} minutes')
```

    Execution time: 0.06 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, F., McGaugh, S. S., &amp; Schombert, J. M. (2016). **SPARC: Mass models for 175 disk galaxies with Spitzer photometry and accurate rotation curves.** _The Astronomical Journal_, 152(6), 157. https://doi.org/10.3847/0004-6256/152/6/157 <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. 
***

c73d3923c3a4c08ffd7d89c9ac0daf624fdf4447
ipynb
Jupyter Notebook
binder/03_Measured_Data_Plotting.ipynb
villano-lab/galactic-spin-W1
d95c706ccbc347f9bc61bb7c96b1314460bc2d0f
CC-BY-4.0
2022-03-22T04:00:17.000Z
2022-03-22T04:00:17.000Z
binder/03_Measured_Data_Plotting.ipynb
villano-lab/galactic-spin-W1
d95c706ccbc347f9bc61bb7c96b1314460bc2d0f
CC-BY-4.0
2021-11-05T18:17:19.000Z
2022-02-19T20:35:05.000Z
binder/03_Measured_Data_Plotting.ipynb
villano-lab/galactic-spin-W1
d95c706ccbc347f9bc61bb7c96b1314460bc2d0f
CC-BY-4.0
Qwen/Qwen-72B
1. YES
2. YES