Monday, May 30, 2016

Python Fundamentals Part 2

GIS Programming - Mod 3

Woohoo!  What a blast.  So far programming in Python is like sitting around playing with a jigsaw puzzle and getting credit for it.  This week's lesson was a bit more complicated.  This week we started with a code that was partially written, with a few mistakes in it.  We had to correct the mistakes for the code to create a dice game based on the players' name length.  

Results of Python Script
After correcting the existing code we then had to use the modules, methods, functions and conditional statements we had learned about in both this week's and previous weeks' lessons to generate a list of 20 random numbers ranging from 0-10, then select one unlucky number to remove from the list and print a statement saying what would be removed and how many times.  That was a very exciting, but extremely intimidating process.  Even after reading the instructions for the assignment twice I still missed a lot of the information and clues that were provided until I went back a third or a forth or even a fifth time.  

I didn't have any difficulties with the portion of the assignment we were required to take notes on; removing numbers from the list.  My difficulties came from the previous section where we had to print statements saying how many, if any numbers were to be removed from the list.
Flowchart of Python Script
 It was a fairly
simple process until my first test came back with the result of removing only one instance of my unlucky number.  That was when I realized  I was gong to need an elif statement in there too, otherwise the sentence would read that it was taking the unlucky number out "1 times." and that wasn't right.  Figuring the syntax out for that was pretty easy, but it took me quite a while to figure out how to express the elif statement in the flowchart.  All the examples I had seen were basically just if/else statements so I had to play with it for a bit to figure out what made sense for the if/elif/else combination. 

Another confusion I had with the flowchart was how to handle not starting at the beginning.  It was left to us to decide if we would include the code that had been provided for us or just start where we created the code ourselves.  I decided to start where I started, but I didn't want to leave the impression where I started was the beginning of the script so after showing we imported random I added a break to the flow line and hoped that would make sense.

While I learned a lot from this lesson I think one of the most important things I learned is that I need to reorganize my previous lessons so certain aspects of them are more easily accessed.  If this week's lesson is any indication it looks like I'll need to go back quite a bit to refresh and clarify how to do certain things.  There is so much to learn in each lesson it just isn't possible to absorb it all at once.

Thursday, May 26, 2016

Natural Hazards - Lahars

Applications in GIS - Mod 2


This week's assignment was on the Natural Hazard called  Lahars.  Lahars refers to a rapidly flowing mixture of rock debris and water that originates on the slopes of a volcano.  They pose a great hazard because more people live downstream in lahar-prone river valleys than live on the volcano's flanks and they can flow from a few meters per second to several tens of meters per second and vary in size from a few meters to hundreds of meters wide and several centimeters deep to tens of meters.  Lahars are also referred to as volcanic mud-flows or debris flows.

Our assignment  was to identify potential inundations zones for the Mt. Hood, Oregon area.  Mt. Hood, the highest peak in Oregon, is a volcano.  We started by creating a shapefile for the peak of Mt. Hood using the Add Point tool then converted that point to a feature. We then added two digital elevations rasters to run our analysis on.

Before we could do much with those images we needed to combine them into one using the Data Management tool Mosaic to New Raster.  By combining these two rasters into one we were able to run the analysis on the entire area just once and without worrying about differences in symbology between to the two images.

With our rasters combined we were then able to run a series of Spatial Analyst Hydrology tools to determent the likely flow of lahars from Mt. Hood.  We started with the Fill tool to be sure our stream would flow rather than pool, then the Flow Direction tool to determine the direction of flow based on the lowest relative elevation of the surrounding raster cells.  With the flow direction we are then able to run the Flow Accumulation tool to determine just how much flow we have, creating a stream network, or steam raster.

Because our raster image was a floating point raster, representing a continuous surface, we needed to convert it to integer so we could run further analysis on it.  We did this using the Math too Int.  We were then able to access the attribute table to determine the value of 1% the total number of pixels in the raster. With this information we were able to run the Conditional tool Con.  This tool defined the threshold of flow accumulation to determine what flow actually qualified as a stream.  From this we were able to create a polyline feature of our final steam using the Stream to Feature tool.  Once we knew where a stream was we were able to determine what population was at risk, in what cities and what schools by running queries on what fell within a 1/2 mile buffer zone from the stream.

This was a very interesting assignment and I really enjoyed it until I got to the labeling portion.  I think my biggest lesson learned was that I have to spend a bit more time delving into the mechanics of labeling and get a better handle on that.  I lost a lot of time trying to appropriately place my text because I didn't know how to stop it from shifting every time I zoomed in or out.  Fortunately I got some leads on how to deal with that through the discussion boards so I now have the starting point I had been unable to find on my own to start an investigation.  Had it not been for the labeling issue I would have finished this assignment in a quarter of the time.  Hopefully this will be the last assignment I have to deal with that frustration.

Monday, May 23, 2016

Python Fundamentals Part 1

GIS Programming - Mod 2

This week was another fun assignment.  We had to write a Python script that resulted in the length of our last name being multiplied by three, but the only information we could enter manually was a variable of a string of our full name.  Every other step required a function or method to pull the information out of that original string and manipulate it down to where we could get the length and multiply it.  Some of the methods and functions we used to accomplish this were split, indexing and len.

We also had to create a flowchart of our process.  The flowchart was a little more difficult for me to d
 I think mostly because I'm not very familiar with Power Point and I had some difficulty getting things to work the way I wanted them to.  The most annoying problem I had was trying to switch the layout from landscape to portrait so I could spread my boxes out a bit more, but I was never able to figure that out.  Otherwise it was fairly straight forward.

Friday, May 13, 2016

Intro to Python

GIS Programming - Mod 1

This week's assignment was a lot of fun.  We were introduced to Python, the preferred programming language for ArcGIS since 2010.  This assignment didn't require much from us, it was basically just an introduction to the programming language and the different methods for working with it such as IDLE and PythonWin.  The main point of the assignment was to learn how to run an existing script called "CreateModuleFolders.py" to create folders for all the mods of this course.


I followed the instructions exactly and had no problems with this.  When I got to the fourth step, the actual running of the script, I saw there were a few different methods that could be used.  From within the PythonWin window where I was viewing the script the easiest way to run the script would have been to click the little icon of the running man.  But I wanted to watch the actual process of the folders being created so I went back to Windows Explorer and double clicked on the file.  There was a little blip on the screen and then it was done.  So it turned out there was nothing to see after all, but the job was done.

This is such a cool little program I thought I would go ahead and use it to create the same folders on my hard drive.  I made a copy of the script so I wouldn't mess up the original, then changed the path from S to C, but it put it on my network C rather than my hard drive.  Oh, well.  I'm sure once I download Python onto my hard drive I'll solve that little problem.  In the meantime, I'm really excited to use it for setting up my folders for my applications class too, just as soon as I figure out what folders I'll need for that class.

I know this is just the first assignment and it was a simple one, but I just know I'm going to love this class.  I can tell already it's going to be a lot of fun, and even the mistakes will be a blast to troubleshoot and figure out.