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

Bivariate Choropleth and Proportional Symbols

In the first part of this lab, we used proportional symbols to represent positive and negative values in job increases/decreases in the USA.  Because there were negative values in this data set, I created a new map to "fix" the data. In this new map, I created a new field and copied the negative job loss data. I then used the Calculate field data and multiplied it by one to make it positive. Lastly, I overlaid both maps on the data and was able to accurately represent the increase and decrease of jobs in the USA by state.   In the second part of this lab, we delved into how to prepare data for a bivariate choropleth map, choose colors for the legend, and create a good layout.  I created three separate fields to analyze the data: Class Obese, Class Inactivity, and Class Final. I used the symbology tool to create 3 Quantile for the Obese and Inactivity classes and used each quantile to set the three classifications in the fields I created using the Select by Attributes tool to

Infographic's

 This week was a fun and challenging week as we learned about and created infographics. It was fun to create the infographics themselves, but challenging to figure out the best methods and practices in analyzing raw data.  We used 2018 County Health Rankings National Data from countyhealthrankings.org. I chose to move forward with the two values: Unhealthy Mental Days and Premature Dealth.  I   choose these two variables because those that struggle with mental health die before their time due to depression, anxiety, and/or a combination of similar issues. Both variables are normalized by relating their value to all counties within each state in the USA. For example, the poor mental health days is normalized as the average number of reported mentally unhealthy days per month per ctizen. The normalized premature rate is the “age-adjusted years of potential life lost rate per 100,000.”  Below, I created a scatterplot of the normalized data.  I choose to keep the scatterplot in a pretty tr

Color and Choropleths

This lab was very interesting as we dived into color theory.  In the first part of the lab, we created and compared linear and adjusted progression color ramps to themselves as well as a color ramp from the website colorbrewer.org.  I found, the colorbrewer color ramps are not as rhythmic when compared to the other methods, as they don’t step up at set intervals or rates. However, I don’t think that a set rate is needed to go from color to color. I preferred the colorbrewer ramp because each color was distinct from its neighbors. In the linear and adjusted color ramps, the colors looked too similar to each other and were not distinct enough for each step. I think that as long as the color ramp is moving in the opposite direction of the same color hue, the step rate or interval is not as relevant. When I first was completing the linear step I started with the purple hue option but had a difficult time, as each step in the color ramp looked the same. At one point, I created my own color