Compsci 101, Fall 2016, Earthquake Part 2 HOWTO

Getting Started

There are no files to snarf for this assignment. You'll need to write your program from scratch. Feel free to look at other programs you have written to help you get started, such as assignment 3.

You should read the datafile from the URL given.

It would be helpful to understand the example program we went over in the Nov 3 lecture on using dictionaries to calculate information about names, such as the first name that occurs the most often.

Note: Some magnitudes may be negative numbers. According to the USGS website faq: "An earthquake of negative magnitude is a very small earthquake that is not felt by humans." Those numbers are fine, still average them in.

Using a small data file for testing

To convince yourself that your program is working, consider using a small data file for testing first. We have provided a smaller file you can also read from this url. Note that this small data file is different than the small data file we used with assignment 3.

http://www.cs.duke.edu/courses/fall16/compsci101/data/earthquakeSmall.txt

Each line of data represents the registering of an earthquake in the format "$magnitude - descriptionOfLocation".

Here is the file:

$4.9 - North Atlantic Ocean
$0.4 - 31km NW of West Yellowstone, Montana
$1.0 - 144km SE of McGrath, Alaska
$1.4 - 14km SSE of Ridgemark, California
$1.8 - 17km SSW of Volcano, Hawaii
$-0.5 - 25km SE of Ronan, Montana
$1.6 - 14km SSE of Ridgemark, California
$1.8 - 14km SSE of Ridgemark, California
$0.6 - 22km SSW of La Quinta, CA
$0.5 - 30km SSE of Lakeview, Oregon
$1.1 - 44km E of Hoback, Wyoming
$2.3 - 7km WSW of Ludlow, CA
$1.4 - 59km WNW of Anchor Point, Alaska
$3.3 - 53km SW of Unalaska, Alaska
$1.4 - 22km NNE of Badger, Alaska
$1.3 - 96km WNW of Talkeetna, Alaska
$2.0 - 14km SSE of Ridgemark, California
$1.3 - 22km NNE of Badger, Alaska
$1.6 - 58km E of Cape Yakataga, Alaska
$1.6 - 122km SE of Old Iliamna, Alaska
$1.2 - 22km NNE of Badger, Alaska
$1.2 - 70km ENE of Cape Yakataga, Alaska
$1.0 - 14km SSE of Ridgemark, California
$1.8 - 12km SW of Cape Yakataga, Alaska
$4.0 - 9km ENE of Polykastron, Greece
$1.2 - 62km ENE of Cape Yakataga, Alaska
$1.2 - 28km WNW of Burney, California

Processing the data

After reading in the data, you might want to put it in a list first to make it easier to process. Alternatively you could put it in a dictionary, and then use that dictionary to create other dictionaries. Either way is fine

You will need to create three dictionaries.

  1. To calculate how many times each base location occurs (see the definition of base location on the main page for this assignment), you may want to create a dictionary mapping a base location (string) to an integer representing how many times it occurs.

  2. To calculate the highest average magnitude for locations, you may want to create a dictionary mapping a location (string) to a list of all its magnitudes. In the sample data file above, you would map the location "14km SSE of Ridgemark, California" to the list of all its magnitudes: [1.4, 1.6, 1.8, 2.0, 1.0]. Then you can use the list later to calculate the average of these numbers for the average magnitude for this location. In this case, the average magnitude for "14km SSE of Ridgemark, California" is 1.56.

  3. To calculate the magnitude that occurs the most often, and how many times it occurs and in how many unique locations, you will need to know for each magnitude what those locations are. You could create a dictionary mapping a magnitude (as a string) to a list of all its locations. Then you should be able to easily calculate the total number of locations for this magnitude, and use the locations to find the total number of unique locations for this magnitude.

Sample Run with Sample data file above

Here is a sample run. Your output does not have to be exactly like this, but should be understandable output and have all the relevant information in it.

 
The maximum base location with earthquakes is: Alaska
It had 12 earthquakes

The highest average magnitude with 5 or more quakes is 1.56
which occured at location: 14km SSE of Ridgemark, California

The magnitude that occurs the most often is 1.2
It occurs 4 times in 4 unique locations
Here is a sample run with extra output to convince me that things are working. We also print out the dictionaries here, just for testing purposes, not to turn in. Note that you can print out the dictionary with the small file but it is NOT recommended to print out the dictionaries with the large earthquake file. THEY ARE TOO BIG.

Strongly encourage you to print out additional information such as the three dictionaries with the small data file to convince yourself your program is working.

 
Dictionary of Base Locations to Counts (printed as tuples):

[('North Atlantic Ocean', 1), ('CA', 2), ('Wyoming', 1), ('Alaska', 12),
('Oregon', 1), ('Hawaii', 1), ('Montana', 2), ('California', 6), ('Greece',
1)]

The maximum base location with earthquakes is: Alaska
It had 12 earthquakes

Dictionary of location to magnitudes:

{'58km E of Cape Yakataga, Alaska': [1.6], '31km NW of West Yellowstone,
Montana': [0.4], '22km SSW of La Quinta, CA': [0.6], '62km ENE of Cape
Yakataga, Alaska': [1.2], '14km SSE of Ridgemark, California': [1.4, 1.6,
1.8, 2.0, 1.0], '96km WNW of Talkeetna, Alaska': [1.3], '22km NNE of
Badger, Alaska': [1.4, 1.3, 1.2], 'North Atlantic Ocean': [4.9], '70km ENE
of Cape Yakataga, Alaska': [1.2], '122km SE of Old Iliamna, Alaska': [1.6],
'17km SSW of Volcano, Hawaii': [1.8], '53km SW of Unalaska, Alaska': [3.3],
'30km SSE of Lakeview, Oregon': [0.5], '28km WNW of Burney, California':
[1.2], '144km SE of McGrath, Alaska': [1.0], '59km WNW of Anchor Point,
Alaska': [1.4], '7km WSW of Ludlow, CA': [2.3], '12km SW of Cape Yakataga,
Alaska': [1.8], '9km ENE of Polykastron, Greece': [4.0], '25km SE of Ronan,
Montana': [-0.5], '44km E of Hoback, Wyoming': [1.1]}

The highest average magnitude with 5 or more quakes is 1.56
which occured at location: 14km SSE of Ridgemark, California

Dictionary of magnitudes to locations:

{'1.4': ['14km SSE of Ridgemark, California', '59km WNW of Anchor Point,
Alaska', '22km NNE of Badger, Alaska'], '1.6': ['14km SSE of Ridgemark,
California', '58km E of Cape Yakataga, Alaska', '122km SE of Old Iliamna,
Alaska'], '1.0': ['144km SE of McGrath, Alaska', '14km SSE of Ridgemark,
California'], '1.1': ['44km E of Hoback, Wyoming'], '1.2': ['22km NNE of
Badger, Alaska', '70km ENE of Cape Yakataga, Alaska', '62km ENE of Cape
Yakataga, Alaska', '28km WNW of Burney, California'], '1.3': ['96km WNW of
Talkeetna, Alaska', '22km NNE of Badger, Alaska'], '4.9': ['North Atlantic
Ocean'], '1.8': ['17km SSW of Volcano, Hawaii', '14km SSE of Ridgemark,
California', '12km SW of Cape Yakataga, Alaska'], '0.4': ['31km NW of West
Yellowstone, Montana'], '0.6': ['22km SSW of La Quinta, CA'], '-0.5':
['25km SE of Ronan, Montana'], '3.3': ['53km SW of Unalaska, Alaska'],
'2.3': ['7km WSW of Ludlow, CA'], '0.5': ['30km SSE of Lakeview, Oregon'],
'2.0': ['14km SSE of Ridgemark, California'], '4.0': ['9km ENE of
Polykastron, Greece']}

The magnitude that occurs the most often is 1.2
It occurs 4 times in 4 unique locations