Skip to main content

Debugging with Python on Spyder

 This week's lab focused on debugging and catching errors in python code. I personally used the program Spyder to do this. 

We worked on three different pre-written scripts that had various different errors and/or exceptions. To find the errors in the code, I used the four steps we learned about in the lecture and our textbook (Python Scripting for ArcGIS Pro). 

1) Syntax

This type of error can be easily spotted when looking at your code (missing a letter, parenthesis, or something that should be upper or lowercase). You can also run the code and Spyder will tell you exactly what type of error, the line, and with a carrot, the location of the error. 

I used this method to debug the first script of the assignment. 

Script 1: List the field names of Shapefile in ArcGIS

2) Debugging and Stepping through the Code

In this lab, I also learned how to use the debugging tool. The debugger tool can be run to go the entire code, stopping after the error, or you can opt to go line by line of the code and see if there are any issues (None or error information stated) with each specific line. To go to the next line of code, simply enter n and you can edit each line as it runs. I used this method, as well as the syntax, to debug the second script of code in this lab. 

Script 2: List the spatial reference and layer names of ArcGIS Shapefile


3) Try/Except statements 

This method uses the statement try/except to sidestep errors in a code and be able to fully run the code/script.

I used this method to run Script 3 without fixing any errors it held.

 This method for me personally was the trickiest to use, as I had a tricky time determining where to place the except statement. Placing the try statement was easy to determine, as I simply ran the code and placed the statement right before the line where the error occurred. I tried to place the except statement in a couple of different places in the lines of the code of Part A, but I would get the NameError for different things like program and lyrlist (where they weren’t defined). I finally put the except statement, with an exception, at the end of all the code of Part A, which worked!


Script 3: List the name, data source, and spatial reference of each layer in shapefile. 


Comments

Popular posts from this blog

Positional Accuracy: NSSDA

 In this analysis, I compared the street and road intersect data collected for Alburquerque, NM by the City of Alburquerque and the application StreetMaps. I used an orthophoto base layer as the reference for this analysis, to compare and determine the accuracy of both the City and Streetmap layers using NSSDA procedures. The most difficult part of this analysis for me was how to determine what 20% per quadrant looks like. Because the reference map was divided into 208 quadrants, I had to determine how to subdivide all the quadrant's equality into 20%. After multiple trials and error, I decided to subdivide the entire area (208 sub-quadrants) into 4 equal-area subsections. In this way, I could do 5 random right intersection points per subsection or 20% per subsection.  Map 1: City of Albuquerque city map data.  Map 2: City of Alburquerque SteetMap data When selecting a random intersection to place the points within each quadrant, I choose a location that had data f...

Utilizing ERDAS Imagine to Analyze Map Features

 This week we learned how to utilize histograms and different bands to highlight different features in a map. On the following map that we worked on, dark bodies of water caused high peaks on the left of histograms while snow-peaked mountains were small blips on the far right. These simple distinctions help to quickly identify map features on a graph, that you can then utilize as a stepping stone to finding them on the image. I found it incredibly interesting how the different band layers highlighted different features on the map. Figure 1 below depicts three different features we found on the image.  Figure 1: Distinct features found on an image using ERDAS Imagine. Feature 1: Large body of water. Feature 2: Snow-capped mountains transitioning to thick vegetation. Feature 3: Shallow turbulent body of water near urbanized land, transitioning to deep calm body of water. 

Choropleth and Dot Mapping

 This week we explored choropleth and dot mapping. Choropleth is a thematic form of mapping that focuses on color units, whose color intensity is proportional to its corresponding data value. Dot mapping is also thematic. It uses either a proportional or graduated thematic symbol (like a circle), whose size increases due to its data value. Using ArcGIS pro, I analyzed the population densities of countries in Europe (person per square kilometer), as well as their wine consumption (liters per capita) to determine if there was a correlation between the two. In my choropleth map, I decided to use a natural breaks classification. I chose not to use Equal Interval because only 2 classes (with slight 3 rd class) were represented in the map, and it looked like almost just one color in the lower range. The standard deviation classification appeared to be more diverse at first glance but was actually skewed to the top ranges. I was then between Quantile and Natural Breaks. While both t...