# Write code to read in the contents of the ascii file here




# Don't forget to comment code! 

"""
Explanation: Final Coding Homework: Creating Colour-Magnitude Diagram
Essential Background Information
We've seen the Hertzsprung-Russell (HR) diagram a few times in class now (see slides for Writing 1 and last cell in Lesson 6: Plotting iPython Notebook). Recall that the HR diagram plots a star's luminosity (y-axis) as a function of its effective temperature (x-axis). You've seen the HR diagram in the context of an idealized representation of distinct groupings of stars, e.g., the Main Sequence, the Horizontal Branch, the Red Giant Branch, etc. So what about in practice? What does a HR diagram look like with real observational data? 
When astronomers make an HR diagram based off of real data in the night sky, they call it the "observer's HR diagram" or the Colour-Magnitude Diagram (CMD). This is because instead of luminosity and temperature on the y and x axes, respectively, observers plot the apparent brightness in magnitude vs. colour. Typically, observers use the B, V, R, I bandpasses, and so will plot V mag vs. B-I mag. 
To make an HR diagram based off of real observations, we point our telescopes at stars in stellar clusters and observe their brightness in various bandpasses. There are several reasons why we do this:
1) Looking at a stellar cluster ensures that our observer's HR diagram won't have just 10 lonely stars in it, but rather fill the whole parameter space.
2) In order to measure the luminosity of an object, you have to know its distance (which is hard, but see footnote); but if you observe the apparent brightnesses of stars in the same stellar cluster, they are roughly at the same distance, which means you can compare the brightness of the stars relative to each other in the cluster, no problem. 
3) Observing the brightnesses of stars in multiple bandpasses or filters allow us to estimate their temperatures; recall the idealized stellar Planck/blackbody curve, stars that are hotter will be brighter in bluer bandpasses relative to redder bandpasses, whereas stars that are cooler will be brighter in redder bandpasses relative to blue. For this reason, the relative brightness of an astronomical object between two bandpasses (or the difference in magnitude) is called "colour". 
The stellar cluster CMD technique is a powerful tool because it simultaneously tells you the age of the cluster and distance to that cluster! An "observed" HR diagram, or CMD will look different from the idealized HR diagram from Lesson 6! Consider this: stars in the same cluster will have the same age (and composition), since they were born out of the same molecular cloud. However, because more massive stars fuse hydrogen faster, they evolve off the main sequence faster, and consequently an older stellar cluster will have fewer massive stars still in the main sequence phase. As the cluster ages, more and more low-mass stars will evolve off the main sequence, and this "turn-off" from the main sequence track is called... "the main sequence turn off" (MSTO). You can see this effect in the image below. Each panel depicts a snapshot of a stellar cluster at a particular age ($t=0$ when cluster is just born), and shaded region = main sequence.
<img src="http://pages.uoregon.edu/jimbrau/BrauImNew/Chap20/8th/20_17_Figure_Unanno.jpg">
You can read more about CMDs here (optional).
What You Need To Do
In this homework, you will create a CMD based off real data of the M15 cluster astronomers collected! Make sure to comment your code.
First, you will read in the ascii data file that contains the B, V, and I magnitudes of stars. ###
Download the ascii data file from the class github directory data/m15.tsv and save it to your computer.
Read in the downloaded data file using functions you learned in Lessons 6 and 7. Note the file m15.tsv has ;-separated values, so when you apply the function you will have to specify keyword argument delimiter=';'.
End of explanation
"""


# Write code to make & prettify the plot, use either plt.plot or plt.scatter







# Don't forget to comment code!

"""
Explanation: Next, make a plot with B-I colour on the x-axis, and V magnitude on the y-axis.
Make sure you give the proper x, y axis labels (with units), and make sure the limits of the y-axis is correct (remember the bigger the magnitude, the fainter an object).
End of explanation
"""


# Copy and paste your plotting code, and modify it to address question 1.











# Question 2 response:




# Question 3 response:

"""
Explanation: Finally, let's interpret the pretty plot you've made!
1) Locate at least 3 "groups" of stars in your CMD and label them accordingly.  
2) Based on your CMD, is M15 an old cluster or young cluster... how did you come to this conclusion? 
3) Why are there so many data points that are scattered everywhere, and don't look like they belong in the idealized HR diagram?
End of explanation
"""


