Asked by zxke24
Question 1: Star Chart & Constellations Astronomers collect...
Question 1: Star Chart & Constellations
Astronomers collect lots of data about stars and there are many catalogues that identify the locations of stars. In this question, you will use data from a star catalogue to form a figure that plots the locations of stars.
Since a real data set often has some incorrect data and the occasional field missing, a cleaned up catalogue has been prepared for your use in this assignment. The file stars.txt contains one line for each star that is represented in the catalogue. The meaning of each field (column) is described below.
• The first three fields are the x, y, and z coordinates for the star. We will ignore the z coordinate, and use only the x and y coordinates. Each axis in the coordinate system goes from -1 to +1, and the centre point is 0,0. (See the figure below.) These coordinates have been converted from sky coordinates to values that will give you a plot of the northern sky, with the North Pole at (0,0).
• The fourth field is the Henry Draper (HD) number, which is simply a unique identifier for the star.
• The fifth field is the magnitude (or brightness) of the star. Larger positive numbers (e.g. 4 or 5) indicate fainter stars. Small positive numbers (e.g. 1 or 2) indicate bright stars, and zero and negative numbers (e.g. -1) indicate the brightest stars in the sky.
• The sixth field is the Harvard Revised number, another identifier.
• The seventh field exists only for a small number of stars and is a semicolon-separated list of names for a star. A star may have several names, or no common names and simply be known by its catalogue numbers.
Two unique identifiers appear in the data because the star data has been collected from different sources, and the catalogues have several different ways to uniquely identify stars. The fields that you will need for this assignment include the x and y coordinates, the magnitude, the Henry Draper number, and the name (or names) of each star.
Step 1: Build a dictionary of stars
Your first task is to load all 3526 stars into a dictionary. The HD number should be used as the key, and all of the other fields should be packed into a tuple and used as the value. The alternate names for a star should be stored into a list before packing into the tuple.
Prompt the user to enter the name of a text file containing star data. Pass the filename to a function that opens and reads the file, builds the dictionary, and returns the dictionary of stars.
Step 2: Filter by magnitude
Prompt the user to enter a limiting magnitude, representing the faintest stars that should be plotted. Pass the dictionary of stars and magnitude to a function that will identify which stars are brighter than the input magnitude (recall from above that larger magnitudes are fainter). The function should return a 2D array containing the stars that will be plotted in step 3. Column 0 should contain the x coordinates, column 1 should contain the y coordinates, and column 2 should contain the magnitudes. The number of rows should exactly match the number of stars that meet the magnitude criteria.
Step 3: Plot the stars
Build a plot displaying all of the stars that met the magnitude criteria in step 2. Import matplotlib.pyplot, for example:
import matplotlib.pyplot as plt
Use a scatterplot to display all of the stars. Usually when plotting star charts, brighter stars are represented by larger dots, and you will follow this convention. The line
plt.scatter(starX, starY, s=starSize, c='k')
includes two options for the scatterplot. s is a list of sizes for the dots that will be drawn. The list should be the same length as the list of x coordinates and the list of y coordinates. c is the colour to use when plotting ('k' is black, 'b' is blue, 'r' is red, etc.)
You will need to calculate a list or 1D array of sizes (one size per star to be plotted). Because a larger magnitude indicates a fainter star, we need to use something such as (5 - magnitude) to give us a larger number for brighter stars. (The faintest stars visible in the night sky are magnitude 5.) You will then need to multiple by some constant, or square the result, to get a noticeable difference between dot sizes on the plot. Play with your formula, and find something that is pleasing to you.
Step 4: Plot a constellation
Prompt the user to enter the name of a file containing a constellation. (Several have been provided in the Assignment 4 folder.)
For each line in the file, add a line to your star chart. Each line in a constellation file contains common names for two stars, separated by a comma. You will need to look in your star dictionary for the stars that have those names in their list of names, and extract their (x,y) coordinates. To draw a line on your plot, use something similar to
plt.plot([x1,x2], [y1,y2], lw=1, c='b')
In the above line, [x1,x2] is a list of x coordinates, [y1,y2] is a list of y coordinates, lw specifies the line width, and c specifies the color for the line. Note that if you list more that two coordinates, lines will be drawn from one point to the next. However, the constellations are not necessarily made up of lines where the end of one line is the start of the next line. You will need to draw one line per line in the constellation file.
Sample console output
Please enter the name of the file containing the stars > stars.txt
Please enter the limiting magnitude > 4
Please enter the name of a constellation file > UrsaMinor_lines.txt
Program Terminated Normally.
File example
0.994772,0.023164,-0.099456,28,4.61,3 0.972490,0.024187,0.231685,87,5.55,4 0.435119,0.012234,0.900290,144,5.57,7 0.998442,0.033711,-0.044468,315,6.43,11 0.998448,0.035746,-0.042707,352,6.18,14 0.873265,0.031968,0.486196,358,2.07,15,ALPHERATZ 0.512379,0.020508,0.858515,432,2.28,21,CAPH;CAS BETA 0.949168,0.037455,0.312534,448,5.57,22 0.882312,0.036017,-0.469285,493,5.42,24 0.697240,0.028641,-0.716265,496,3.88,25 0.980198,0.042952,0.193306,560,5.54,26 0.693047,0.031231,0.720216,571,5.01,27 0.135171
using just functions and 2d arrays and plotting.
Answered by MajorUniverse8052
Unlock full access to Course Hero
Explore over 16 million step-by-step answers from our library
Subscribe to view answersum dolor sit amet, cons
risus ante, dapibus a molestie consequat, ulac, dictum vitae odio. Donec aliquet.
gue
dui lectus, congue vel laoreet ac, dictum
s a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, d
acinia pulviec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum
gue vel laoreet ac,
gue