MCS-177 Project 6: Plotting Earthquakes (Spring 2017)

Start: Thursday 4/6; Due: Wednesday 4/19, by 10pm


Overview

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.

This is a pair project. Please inform your lab instructor ASAP who your partner is. Please only submit one copy of the code with both names written in project6.py as comments.

Warning: you may need to use Python 3.5 (or a version slightly older than 3.5) to be able to test your work related to urllib.request for this project. This means that you and your partner may need to plan on using the computer lab machine (as opposed to your personal computers, if you have 3.6 installed) to work on this project.

Specific tasks

  1. Check out USGS for recent earthquakes. The website offers a comma-delimited list of earthquakes for every 3 months period.

    For consistency, we ask you to use the following URL (containing earthquakes between Nov 2011 and Feb 2012, listed from the most recent to least recent) in your program: http://mcs177.github.io/projects/earthquakedata-2012-02-23.txt.

    The data's header contains:

  2. Write the contract, docstring, and implementation for a procedure dateLessThan that takes two dates in the format YYYY/MM/DD (as string objects). It returns True if the 1st date comes strictly earlier than the 2nd date. Otherwise, it returns False.

    >>> dateLessThan("1999/01/01", "2000/05/15")
    True
    >>> dateLessThan("2000/05/15", "2005/05/01")
    True
    >>> dateLessThan("2017/01/01", "2010/07/01")
    False
    >>> dateLessThan("2013/10/24", "2013/9/24") # October is not earlier than September
    False
    
  3. Write the contract, docstring, and implementation for a procedure betweenDates that takes 3 dates (as string objects) in the format YYYY/MM/DD and returns True if the 1st date is earlier/equal to the 2nd date AND the 2nd date is strictly earlier than the 3rd date. That is, if the 2nd date is between the 1st date (inclusive) and the 3rd date (exclusive). Otherwise, it returns False.

    >>> betweenDates("2000/05/15", "2000/05/15", "2005/05/01")
    True
    >>> betweenDates("2000/05/09", "2000/05/09", "2000/05/10")
    True
    >>> betweenDates("1999/05/09", "2000/05/09", "1999/05/09")
    True
    >>> betweenDates("2011/01/01", "2011/07/01", "2011/12/31")
    True
    >>> betweenDates("2000/05/15", "2000/05/15", "2000/05/15")
    False
    >>> betweenDates("2011/01/01", "2010/07/01", "2011/12/31")
    False
    >>> betweenDates("2011/01/01", "2011/12/31", "2011/12/31")
    False
    
  4. Write the contract, docstring, and implementation of a function called makeDataDictionary. It takes in two string parameters. The first one is in the form of a header (separated by commas), and the second one is the data (separated by commas). It returns a dictionary with dictionary keys the words given from the header and the dictionary values the data values (as string objects). All leading and trailing spaces should be removed.

       
    >>> makeDataDictionary('State,HouseholdIncome,IQ,McCainVote,Region','Alaska,57071,99,0.602,W')
    {'Region': 'W', 'State': 'Alaska', 'IQ': '99', 'HouseholdIncome': '57071', 'McCainVote': '0.602'}
    >>> makeDataDictionary('day,  time,someinfo, magntd, depth', '2012/01/12,19:55:51.2,52.605,    , 50')
    {'someinfo': '52.605', 'depth': '50', 'time': '19:55:51.2', 'day': '2012/01/12', 'magntd': ''}
    >>> makeDataDictionary('1,2,3','val1,      ,   val3')
    {'1': 'val1', '3': 'val3', '2': ''}
    
  5. Write the contract, docstring, and implementation for a procedure readEarthquakes that takes two dates in the format YYYY/MM/DD, accesses the earthquakes from http://mcs177.github.io/projects/earthquakedata-2012-02-23.txt (taken from USGS). It returns a list of dictionaries for all earthquakes between the two dates, except for earthquakes with missing magnitude information.
    >>> L = readEarthquakes("2012/01/03", "2012/01/04")
    >>> L[0]
    {'Date': '2012/01/03', 'Longitude': '143.786', 'TimeUTC': '23:30:07.0', 'Magnitude': '4.6', 'Depth': '10', 'Latitude': '26.938'}
    

  6. Write the contract, docstring, and implementation for a procedure colorCode that takes the depth of an earthquake and returns the corresponding color for the earthquake.

    RangeColor
    0-33'orange'
    34-70'yellow'
    71-150'green'
    151-300'blue'
    301-500'purple'
    501-900'red'

    >>> colorCode(33)
    'orange'
    >>> colorCode(34)
    'yellow'
    
    Your procedure should not be overly complicated. In particular, don't include more than 2 nested selection statements.
  7. Please download the world map image by right-clicking on this link and put it in the same directory as the Python file you are working on right now. (This image is resized and converted from http://en.wikipedia.org/wiki/File:Equirectangular_projection_SW.jpg.)

  8. To become more familiar with useful methods from cTurtle (a module that is saved in the computer lab machines), please go to the prompt and use the following cTurtle methods shown below to show a window showing the image link and draw several dots at 4-5 different locations with various colors and sizes.

    Method ContractDescriptionExample
    # goto: number number -> void Moves the turtle to the given coordinate (x, y) myTurtle.goto(10, 150)
    # dot: number string -> void Makea a dot of the given size with the given color at the current position myTurtle.dot(30, 'blue')
    # down: -> void Put the turtle's tail down. Makes the turtle draw lines when it moves. myTurtle.down()
    # up: -> void Raise the turtle's tail up. Prevents the turtle from drawing lines when it moves. myTurtle.up()
    # speed: integer -> void Sets the speed of the turtle. 1 is slowest and 10 is fastest. myTurtle.speed(10)
    # setWorldCoordinates: number number number number -> void 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. myTurtle.setWorldCoordinates(-10, -5, 10, 5)
    # bgpic: string -> void Set the background of the canvas with the given image file myTurtle.bgpic('worldmap.gif')
    # hideturtle: -> void Make the turtle invisible myTurtle.hideturtle()
  9. Write the contract, docstring, and implementation for a procedure plotEarthquakes that takes two dates and plots all the earthquake data from http://mcs177.github.io/projects/earthquakedata-2012-02-23.txt (taken from USGS) between the given dates with dots on the world map.

Submitting your work

Submit your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit one Python file called

project6.py
which contains all the Python procedures described above.

Be sure that your module can run on IDLE on the computer lab machines (that is, IDLE 3.54).

Grading Rubric

If you submit your project early, you will get an early feedback on the accuracy of your work.

The grader will test your program against various input values. Check your work against the grading rubric project6gradesheet.pdf which the grader will use when grading your lab.