In this project, you will gain familiarity with reading data from the Internet. You will read data on earthquakes and plot dots with different radiuses and colors on a map.
You may choose to do this project with a partner. If you choose to work with a partner, Please only submit one copy of the code with both names written in plotEarthquakes.py as comments
Make a copy of the URL for the data as you will need to use it in your procedure. The list contains:
betweenDatesthat takes three dates in the format YYYY/MM/DD and returns a boolean indicating if the first date is between the other two dates (inclusive for the first date and exclusive for the second date).
>>> betweenDates("2011/07/01", "2011/01/01", "2011/12/31") True >>> betweenDates("2010/07/01", "2011/01/01", "2011/12/31") False >>> betweenDates("2011/01/01", "2011/01/01", "2011/12/31") True >>> betweenDates("2011/12/31", "2011/01/01", "2011/12/31") False
parseEarthquakeDatathat takes two dates in the format YYYY/MM/DD, accesses the earthquake data from the above USGS URL and returns a list of lists of four numbers representing latitude, longitude, magnitude and depth. The outer list should contain one of these four-number lists for each earthquake between the given dates.
NOTE: If you have the first-edition textbook, it has two errors that were corrected in the second-edition. First, the first-edition textbook has a typo: use
urllib.request instead of
urllib. Second, remember that you need to decode anything you read from the web as ASCII. For example, if you read a string into a variable
myString, you can decode it by:
decodedString = myString.decode('ascii')
Some lines do not have any information on the magnitude. You can skip these lines by checking if there are only spaces in the place of magnitude.
You may use the
strip procedure to make this task easier. The
strip acts on a string and
it takes away all the white spaces from the left and the right until it finds a non-whitespace.
>>> aString = " hello " >>> aString.strip() "hello" >>> bString = " " >>> bString == "" False >>> bString.strip() == "" True
colorCodethat takes the depth of an earthquake and returns the corresponding color for the earthquake.
cTurtlelibrary and familiarize yourself with them (if you have a second-edition textbook, your Appendix C describes the similar
turtlelibrary instead. You will have fewer difficulties if you use
cTurtleas shown here).
myTurtle = cTurtle.Turtle()
||Moves the turtle to the given coordinate (x, y)||
||Makea a dot of the given size with the given color at the current position||
||Put the turtle's tail down. Makes the turtle draw lines when it moves.||
||Raise the turtle's tail up. Prevents the turtle from drawing lines when it moves.||
||Sets the speed of the turtle. 1 is slowest and 10 is fastest.||
||Modify the world coordinates of the canvas that the turtle draws on. Automatically scale the canvas between (x1, y1) and (x2, y2). X values range from x1 to x2 while Y values range from y1 to y2.||
||Set the background of the canvas with the given image file||
||Wait for a mouse click inside the window, then close and exit||
||Make the turtle invisible||
plotEarthquakeDatathat takes two dates and plots all the earthquake data from USGS between the given dates with dots on the world map. You can use the procedure
cTurtlelibrary that takes the size and color. You can use the product of 4 and the magnitude for the size of dots while using the depth for the right color. The procedure
bgpicis useful to put the world map image in the background while the procedure
setWorldCoordinatescan help you plot the dots more easily.
Assume the entire map shows -180 to 180 degrees from left to right and -90 to 90 degrees from bottom to top.
>>> plotEarthquakeData("2013/06/01", "2013/06/04")
should produce the following map with all the earthquakes for 3 days (June 1st, 2nd, and 3rd in 2013) (accessing the earthquake data as of October 22, 2013 (Tuesday)).
You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following file:
You will earn one point for each of the following accomplishments:
betweenDatesincludes the first date.
betweenDatesexcludes the second date.
betweenDatesreturns the correct boolean value based on the two dates.
colorCodereturns the corresponding value.
plotEarthquakeDataputs the world map in the background.
plotEarthquakeDatasets the world coordinate system correctly.
plotEarthquakeDataplots the earthquake at the correct location.
plotEarthquakeDataplots the dot of the right size.
plotEarthquakeDataplots the dot of the right color.