In this lab, you’ll write a program to read historical earthquake data from a le and plot each earthquake on a map using turtle graphics. An example output is shown in Figure 1.
Figure 1: The output from my solution code.
Setup
Create a lab8 directory in your lab environment of choice. Download the following les from the course webpage and place them in your lab8 folder:
plot earthquakes.py - this le contains skeleton code and pseudocode earthquakes.csv - this le contains the data you’ll be reading
earth.png - this will be set as the background image in the turtle graphics canvas (this is done for you by the turtle setup function given in the skeleton code).
1
Approach and Guidelines
Implement the parse row function and the remainder of the main function according to the pseudocode included in comments. Follow the same coding style conventions we’ve been using up to this point: comment at the top, good variable naming, and so on.
You’ll nd that you need many of the structures and concepts we’ve covered in this course to complete this task|ask your TA if you encounter any problems, and use this opportunity to take note of any topics you need to brush up on before the nal exam.
Some hints:
The code to read the csv le will look pretty similar to the code I provided in A5 to read the cancer data les.
The rst line of the le contains column headers, so you’ll need to skip over it before starting to read data.
Plotting earthquakes on the map is quite simple: the map image (and turtle canvas) is 720x360 pixels, with (0,0) in the center. Longitude (the x axis) goes from -180 to 180 and latitude (y axis) goes from -90 to 90, so (0,0) is in the center. To get the canvas (x; y) coordinates based on a given (lon, lat) coordinate, simply multiply each coordinate by 2.
The skeleton includes an implementation of the teleport function from Lab 5.
You can use a turtle object’s circle method to draw a circle. See the documentation for details on how it is called.
Coloring the circles is optional. In my color scheme, the red channel is proportional to magnitude, while the green and blue channels are inversely proportional to magnitude. For an extra challenge, try coloring the circles based on the date instead of the magnitude.
Submission
Take a screenshot of your program’s output and save it as earthquakes.png. Zip your screen-shot and completed plot earthquakes.py le in a le called lab8.zip and submit to Canvas.
2
Rubric
You submitted a single zip le called lab8.zip, containing the correct les 2
The top of your program has comments including your name, date, and a short 3 description of the program’s purpose.
The program reads the earthquake data into a list of dictionaries 15
A circle is drawn for each earthquake 5
The circle’s size varies with the earthquake’s magnitude 5