Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

PROJECTS

Goals

Use file processing and data mining to discover patterns of earthquake activity around the world over the past year; plot results on a world map.

Practice with
- data mining and file processing
- reading, understanding, and revising a program that has mostly been already written. This will require a thorough understanding of the k-means cluster analysis algorithm and file processing.

Background - Data Mining

In this project we continue to study earthquake activity. We will use a file with data once again obtained from the United States Geological Survey website, about earthquakes of magnitude 5 or greater that have occurred across the planet over the past year (since November 1, 2016).

We will implement a k-means cluster analysis data mining algorithm from Ch. 7 of the text and use it to analyze the earthquake data. We will then use Python turtle graphics to graphically report the earthquake clusters discovered by the k-means algorithm on a world map.

Requirements

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 (\n) 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 want to 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.

Testing your code

doctest.testmod will be useful for testing individual functions. Use small, made-up examples to test each individual function before calling it from another function. Start with a short version of the earthquake file (around 15 lines not including the header should be small enough to understand, but large enough to generate results).

Getting Started

Open a new Python editor window. Save it with the name p8f_equakes_vis.py.

Download the earthquake file (earthquakes.txt) and the world map (worldmap1800_900.gif) you will use for plotting earthquake points. Make sure the earthquake and map files are in the same folder as p8f_equakes_vis.py.

This program is somewhat longer than prior programs you have written, but when it is viewed function by function it should not seem so different. A good strategy for implementing a medium-sized project such as this one is to understand the code from the top down, and implement the code from the bottom up, with careful testing of each function at each step.

For example:
Start by carefully reading Ch. 7 of the text and reviewing class notes. When you are comfortable with your understanding of the k-means cluster algorithm, have a closer look at the code that is given in Ch. 7 to implement the algorithm. Type the code into a Python file, one function at a time.

For each auxiliary cluster algorithm function in turn (euclidD, createCentroids and createClusters), write the docstring for the function.

Test each individual function to make sure you understand and trust the function. Create your own small test dictionaries to test the functions. Use simple examples, like individual scores or earthquake magnitudes, at first. Then, try examples with two-dimensional points, such as earthquake longitude and latitudes.

Next, write the function that will access earthquake data, readFile. Note that you wrote a similar function for Project 7-2. You may want to start with that function and revise it to access longitude and latitude data (rather than magnitudes) and store the data into a dictionary (rather than a list).

You may want to create a short version of the earthquake files, for testing readFile. The data in the earthquake files is structured as for project 7-2:
time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net,id,updated,place,type,horizontal Error,depthError,magError,magNst,status,locationSource,magSource
2010-07-28T16:12:05.610Z,43.756,-125.815,10,5.2,mwc,193,143.9,,0.93,us,usp000hh0t,2017-
T16:34:36.951Z,"off the coast of Oregon",earthquake,,,,,reviewed,us,gcmt 1993-12-04T22:15:19.720Z,42.2915,-
122.0086667,4.797,5.1,md,126,113,,0.11,uw,uw10316468,2017-04-
13T22:06:07.852Z,"Oregon",earthquake,0.468,0.56,0.04,7,reviewed,uw,uw

The first line of the file is a header, which gives the meaning of each field (column) of the data. The data itself is comma-separated values, with one value (or the empty string) per field. Use the header to determine how to access latitude and longitude data. Note that when you access the earthquake file to create the dictionary, you will need to skip the header to get to the earthquake data.

Next, start putting it together, by writing visualizeQuakes. First call only readFile. When this is working, add a call to createCentroids, and so on.

When visualizeQuakes is working, write the main function and add a call to main
(main()) to your program.

Programming style is important!
Programs are read much more than they are written. All programs must include a program header at the top of the file with
- project identification
- author
- credit for any and all sources of significant help with the project excluding the class text and CIS 210 instructional staff. This includes programming partners, other texts, online information, etc.
- short, precise file description

Also remember to
- include a docstring in every function (type contract, brief description of the function, examples of use)
- use whitespace between operators and operands
- use descriptive variable names
- add appropriate in-code comments (why, not what).

Attachment:- Assignment_Data.rar

Python, Programming

  • Category:- Python
  • Reference No.:- M92541059
  • Price:- $110

Guranteed 48 Hours Delivery, In Price:- $110

Have any Question?


Related Questions in Python

Lab assignment -background - we have discussed in detail

Lab Assignment - Background - We have discussed, in detail, the function of Stacks and Queues and how they are specifically implemented in Python. To get a better understanding of the utility of these data structures, we ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Simple python traffic lightswrite a program that simulates

Simple Python (Traffic lights) Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and onl ...

Below zero - ice cream storethe local ice-cream store needs

Below Zero - ice cream store The local ice-cream store needs a new ordering system to improve customer service by streamlining the ordering process. The manager of the store has found that many orders are incorrect and s ...

Question write a python program with a graphical user

Question: Write a python program with a graphical user interface that will allow a user to create a custom pizza which they wish to order. At minimum, the user should be able to choose the size of the pizza, the type of ...

Environment setupthe first mini project will be based on

Environment Setup The first mini project will be based on Ladder Logic programming. We will be using Schneider Electric's IDE called SoMachine Basic to do the programming. The latest ver- sion of SoMachine Basic for Wind ...

Question why is software configuration management

Question : Why is software configuration management considered an umbrella activity in software engineering? Please include examples and supporting discussion. The response must be typed, single spaced, must be in times ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

Sieve of eratosthenes in pythonthe goal is to find all the

Sieve of Eratosthenes (in Python) The goal is to find all the prime numbers less than or equal to some natural number maxn. We have a list that tells us if any of the numbers 0..maxn are "marked". It can be an array of b ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As