Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Functions to read and process earthquake data saved in a file are adapted from Ch. 7 of the text. Function readFile is based on

Python

Functions to read and process earthquake data saved in a file are adapted from Ch. 7 of the text. Function readFile is based on the function in ch. 7 of the text (p. 255). You will need to revise it to accommodate the earthquake data file analyzed in this project: the earthquake file we are using has a header line, each line has a return ( ) character, the values are comma (not space) separated, and the longitude and latitude are in different fields (columns) than the data in the text. (readFile will be very similar to equake_readf from Project 7-2, except that it will return a dictionary rather than a list.) Functions euclidD, createCentroids, and createClusters are all copied from Ch. 7 of the text. You will need to add docstrings and helpful in-line comments. Note that the createClusters function includes code to report the results of the cluster analysis (for c in clusters ). This is helpful for testing createClusters with a small data dictionary (data file), but you may comment this out for the large earthquake file. visualizeQuakes is based on the function in Ch. 7 of the text. visualizeQuakes in this project has k (the number of clusters) and r (the number of times to repeat cluster analysis) as parameters, along with the dataFile parameter. As in the text, visualizeQuakes should call readFile, createCentroids, and createClusters. visualizeQuakes will also call a new function, eqDraw, to plot the earthquake data on a world map. visualizeQuakes should return None. You will need to write a docstring and add comments to visualizeQuakes. eqDraw is a new function that will be called by visualizeQuakes to do the work of plotting the results of the k-means analysis on a world map. eqDraw will have three parameters: k, eqDict, the earthquake data dictionary, and eqClusters, the list of clusters generated for the earthquake data by the k-means cluster analysis. eqDraw will comprise the drawing code that is included in visualizeQuakes in the text. You should change the screensize method arguments to 1800 and 900, to reflect the size of the world map .gif that we will use. You can also use the anonymous turtle from the turtle module (i.e., you do not need to define quakeT). Tip: include speed('fastest')*. Finally, define a main function to assign values to k, r, and f, and call visualizeQuakes. main should return None. Include code in your .py file to call the main function.

the files are:

Earthquakes.txt:

time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net,id,updated,place,type,horizontalError,depthError,magError,magNst,status,locationSource,magSource 2018-02-27T20:11:04.000Z,-6.2147,142.8358,10,5.2,mb,,24,5.328,0.8,us,us2000d8u9,2018-02-27T20:53:09.719Z,"90km W of Mendi, Papua New Guinea",earthquake,4.2,1.7,0.051,130,reviewed,us,us 2018-02-27T17:29:23.350Z,-60.1778,150.7321,10,5.9,mwb,,43,7.222,1.4,us,us2000d8rl,2018-02-27T19:31:51.991Z,"West of Macquarie Island",earthquake,8.2,1.8,0.053,34,reviewed,us,us 2018-02-27T16:19:53.880Z,-6.0855,142.8469,10,5.2,mb,,33,5.397,0.85,us,us2000d8r4,2018-02-27T17:50:36.040Z,"78km SSW of Porgera, Papua New Guinea",earthquake,8.4,1.8,0.045,162,reviewed,us,us 2018-02-27T14:11:18.610Z,-6.3589,142.9858,14.45,5,mb,,56,5.123,0.74,us,us2000d8q9,2018-02-27T17:54:04.040Z,"76km WSW of Mendi, Papua New Guinea",earthquake,9.2,4.4,0.082,47,reviewed,us,us 2018-02-27T13:58:27.080Z,-6.3793,143.203,14.7,5,mww,,28,4.939,0.67,us,us2000d8q3,2018-02-27T16:07:21.727Z,"54km WSW of Mendi, Papua New Guinea",earthquake,5.7,3.7,0.075,17,reviewed,us,us 2018-02-27T07:19:23.350Z,-6.3225,142.7909,10,5.2,mb,,51,5.301,0.89,us,us2000d8nf,2018-02-27T07:37:19.040Z,"96km W of Mendi, Papua New Guinea",earthquake,7.3,1.6,0.06,93,reviewed,us,us 2018-02-27T06:19:12.240Z,-6.4178,143.0483,10,5.6,mww,,34,5.038,1.29,us,us2000d8my,2018-02-27T17:25:19.040Z,"71km WSW of Mendi, Papua New Guinea",earthquake,7.6,1.9,0.061,26,reviewed,us,us 2018-02-27T05:17:58.320Z,-18.8524,169.2939,196.49,5.5,mww,,102,2.721,0.91,us,us2000d8mh,2018-02-27T21:05:42.040Z,"77km N of Isangel, Vanuatu",earthquake,8.4,4.5,0.073,18,reviewed,us,us 2018-02-27T02:15:07.930Z,-6.5309,143.2716,10,5.2,mb,,84,4.793,1.02,us,us2000d8k4,2018-02-27T05:36:51.666Z,"57km SW of Mendi, Papua New Guinea",earthquake,8.6,1.9,0.095,36,reviewed,us,us 2018-02-27T00:55:22.590Z,-6.0456,142.6355,10,5,mb,,29,5.588,1,us,us2000d8jk,2018-02-27T08:58:00.339Z,"89km SW of Porgera, Papua New Guinea",earthquake,7.6,1.9,0.064,77,reviewed,us,us 2018-02-27T00:08:13.280Z,-6.4713,143.3485,10,5.1,mb,,26,4.769,1.48,us,us2000d8j8,2018-02-27T00:30:37.040Z,"46km SW of Mendi, Papua New Guinea",earthquake,7.2,1.7,0.058,96,reviewed,us,us 2018-02-26T21:52:36.940Z,-6.3587,142.8545,10,5,mb,,30,5.229,0.92,us,us2000d8gk,2018-02-26T22:31:13.040Z,"90km WSW of Mendi, Papua New Guinea",earthquake,5.8,1.8,0.071,63,reviewed,us,us 2018-02-26T19:21:51.820Z,-6.4892,143.4601,22.52,5.1,mb,,26,4.67,1.34,us,us2000d8dl,2018-02-27T15:19:52.040Z,"40km SSW of Mendi, Papua New Guinea",earthquake,8,4.2,0.05,130,reviewed,us,us

and a GIF of the world map.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago

Question

3. Existing organizations and programs constrain behavior.

Answered: 1 week ago