The purpose of these assignments are to get you comfortable in the Wing IDE, start programming in Python, and also to do something useful. It is of great value to be able to generate a specific series of numbers based on mathematical functions. These series can be used to; sub-sample data, test new statistical methods, and create fake or "synthetic" data for modeling.
Create a loop that outputs a series of numbers. This can be done with a "while" loop, some print statements, and a statement to increment a counter. Then, use the counter as a parameter for a mathematical function. This can be a function you create or one from a math package (remember to include the math package). Loop enough times that you can see the series clearly in a graph (30 to 100 works well). Use "print" functions to output the values and you'll see them appear in the "Debug I/O" tab. Then, paste the values into Excel (or another spreadsheet package) and insert a new chart in Excel.
Print out a message to Debug I/O and then add another loop with a different function. Do this for 5 different loops.
If you choose to output all the series in one loop, you'll need to do some string concatenation which we will cover in more detail in future weeks. The code below will convert the numeric values into a string and then "concatenate" them with the "comma" character". When you paste this into Excel, you'll want to go to the "Data" tab, select "Text to Columns" and break up the text with a comma as the delimiter.
print(format(NumericValue1)+","+format(NumericValue2))
The final step is to document your program (or do it as you go along). You'll want to add a header block with the purpose of the program, author's name (or initials), and the date it was last modified. Also, add enough "in line" comments for someone else to understand the code quickly.
A common task in geospatial programming is converting azimuths (directions) and distances to coordinates. This is common from surveying data where they will setup a central station and then "shoot" locations getting their direction and distance from the central station. The distances and directions are also call "meets and bounds".
To convert a direction and a distance to a coordinate we just need the original coordinate and a little trigonometry.
x=sin(Angle)*Distance
y=cos(Angle)*Distance
You can have some fun with this by creating a loop that goes from 0 to 360 recording the x and y values generated by the equations above. You just need to remember that in Python, the trigonometric functions work in radians so you'll need to convert the Angles to radians.
AngleInRadians=(AngleInDegrees/180)*PI
The constant "PI" is defined in the math library. There is also a "radians()" function in the math library if you'd like to use it.
Once you write the loop and import the values in the Excel, plot them in a scatter gram or and you'll see you've created a circle. Now change the value of the "Distance" based on the Angle and you can make a variety of interesting designs. This part is just for fun.
Note that this is a two-part assignment:
Remember to send me the code file that ends in ".py" so I can run it to make sure it works.
© Copyright 2018 HSU - All rights reserved.