Monday, May 25, 2020

Python Debugging

This week's assignment was all about debugging.  Errors in programming are inevitable so it's important to learn how to begin to approach them while learning how to code.  We were provided with three different scripts and had to fix them so that they would all run correctly.
For this class most of our coding is done in Spyder.  When you run a script in Spyder, like all IDEs if it gets hung up on an error it will tell you with some kind of error message, like a traceback or syntax error.  Sometimes the easiest way to find a problem in your code is simply to run it and then see where the problem is.
Once mistakes such as misspellings or incorrect capitalization are cleared up then the program can run correctly. 
Another way to approach debugging is to use Spyder's debugger.  With this, you can work through the code line by line and see what is happening at each point.  This is a good way to identify an error where the code is running but not giving you the sort of output that you are expecting.

This script had eight bugs that needed to be teased out before it would properly run.

Sometimes, you might want to sidestep a bug entirely.  You can do this by adding in a "try" and except clause.  For this section of the assignment we had to identify that part of the code with an error and put it into a "try" clause.  This means that the code will be attempted, but if it cannot run it will turn to the except clause instead of simply breaking.  For the "except" clause I added in an error message that would identify what the problem was and print that out.  Afterwards, the code would continue as normal.
As you can see in Part A an error message is printed out from the "except" clause.  However, Part B runs without issue.


A Flowchart showing the try/except process


Bug fixing can be tedious but it's important to have different approaches to problem solving.  The more errors you fix, the easier it become to figure out other bugs in the future.

Monday, May 18, 2020

Python Fundamentals


The focus this week was getting down the basics of Python programming.  That means understanding variables and lists, using methods and functions, if-elif-else statements, for and while loops.

The first task was to make a string of my full name, then put each name into a list using the split function, then use string indexing to isolate just the last name.  Fairly straightforward, but it's a good way to make sure you have the basics down.

The next task was to fix two errors within a basic dice game.  I first tried to run the game to see where the code got hung up.  I then identified the problems (you can't concatenate an int to a string without first changing the type of the int, and a variable capitalization issue) and fixed them so that the code would properly run.

The final task this week was mastering loops.  First, I used a while loop to append 20 integers to an empty list.  When the list was complete the program printed the list.  Then I chose an integer that I wanted to remove from the list and assigned it to a variable.  I used the count method to check for the presence of this variable within the list in an if-else statement.  The statement would print out if the integer was in the list and how many times it was there.  Then I used a while that ran while the count of the chosen integer was greater than zero.  For each pass through the loop it removed one instance of the chosen integer.  Then the adjusted list was printed again.

Showing the results of the various basic processes covered in this lesson.
Flowchart for the luckyList section of the code.




Monday, May 11, 2020

Python Programming for GIS

This week is the start of another class - GIS programming.  Currently, the predominate scripting language for ArcGIS is Python which we will be using for this class.  Learning to program is useful as it helps to automate tasks and make routine functions much faster.

So far, we have been introduced to the concept of pseudocode which is the line-by-line process of thinking about what we want the code to do without writing it in standard Python syntax.  We also ran a Python script in the IDE Spyder which automatically generated a set of folders for out projects in the coming weeks.

The script-generated folders for the class.

Thursday, April 16, 2020

Google Earth and 3D Mapping

The final project for Cartography class was using Google Earth Pro and .kmz files.  The goal of this lab was to familiarize ourselves with presenting 3D depictions of data by creating a multi-city tour of Southern Florida.

We first had to convert our surface water date in ArcPro to a .kmz file so that it could be imported into Google Earth.  This is done with the "Layer to KML" tool.  Next, I launched Google Earth Pro and imported the required .kmz files.  I also placed a legend on the 3D map.

To create the tour itself, I had to locate the points of interest on the map and then create placemark points for each one.  Following that, I used the program's "record tour" feature to make a recording of each location.  This produces a video of each location that shows off the 3D cityscapes.

Google Earth Pro is fairly straightforward to use, though because of its large scale it can be taxing on a lower end computer when the map is zoomed out.  I think this technology could work particularly well for creating virtual tours of places - such as historic neighborhoods - where an audio narrative could accompany the video.

A dot density population map of Southern Florida presented in Google Earth Pro.  Various body of water are also colorized to make it more obvious that the population of Florida is centered near the coasts and away from marshy areas.


Saturday, April 11, 2020

Isarithmic Mapping

The focus of the lab this week was isarithmic mapping.  Isarithmic maps depict continuous phenomenon that occur across an area.  The process of interpolation makes it possible for an algorithm to generate data across an entire area even though there are only set locations gathering data..  This type of map is particular common for climatological data and is used in a number of industries such as agriculture and engineering.  

I created a map of the average annual precipitation rates in Washington state using a 30 year data set ranging from 1981-2010.  The interpolation method used on this data was the Parameter-elevation Relationships on Independent Slopes Model, also known as PRISM.  This method takes data from the weather stations and factors in environmental attributes such as elevation and proximity to the coast in order to generate a complete set of data.

To create this map I first map a hillshade effect layer using data from the annual precipitation raster.  This improves the look of the terrain by creating the appearance of depth.  Areas of high elevation tend to have higher rates of precipitation, so this is a logical feature to incorporate into this map.

The next step was to create hypsometric tints.  A hypsometric tint is a set of classed graduated colors useful for showing the range of a environmental phenomenon.  This used the spatial analyst tool "int" to process the annual precipitation raster.  I then symbolized the colors into proper classes that corresponded with precipitation amounts.

The last part of map creation was to create contours.  Contours are lines that show the discrete changes between value ranges.  This process involved the contours tool on the annual precipitation layer at the same values as were assigned for the hypometric tints.  This makes the divisions between the different classes even more obvious.

An isarithmic map of Washington state showing the average annual precipitation rates over 30 years.  The map utilizes hypometric tinting as well as contour lines to display the data.



Sunday, April 5, 2020

Choropleth Mapping

In this week's lab we continued to learn about making choropleth maps.  This week we also learned how to work with proportional and graduated symbols.  Choropleth maps are maps with shaded sections to convey the intensity of a phenomenon.  These maps must be normalized by area so when comparing different enumeration units you are making a comparison based off of density and not raw data. 

The goal for this week's lab was to create a map that showed the population density throughout Europe in a choropleth format as well as the consumption of wine per captia.  The map was primarily constructed in ArcGIS Pro with some editing in Adobe Illustrator. 

For the population density, I wrote a SQL exclusion to take the countries of Gibraltar, Jersey, Malta, and Monaco out for when classifying the breaks between populations.  This is because those countries are very small, and thus densely populated - making them outliers in the data.  I classed the remaining countries using the natural breaks method into four different classes.  This created a map with a good amount of contrast between countries. 

The wine consumption was shown through a set of graduated symbols with its associated country.  I decided to take on the extra challenge of using custom symbols for this section.  I downloaded a wine glass icon by Thengakola from the Noun Project.  I then edited this icon in illustrator so that it would have a different fill amount for each of the different classes of consumption.  Again I used natural breaks to divide up the data.  I classed the data into five separate groups to create a range of very low consumption to high consumption.

I used ArcGIS Pro's labeling and annotation feature to generate labels for each country.  Some countries are very small and do not consume significant quantities of wine so they have been omitted.  These include: Gibraltar, Guernsey, Isle of Man, Monaco, Jersey, and San Marino. 

In the final map, I created an inset for the countries near the Adriatic Sea.  This is because in the overview map the information in that area was crowded and difficult to read.  The inset allows for clearer interpretation of the data.

A comparison between the population densities of European countries and their per liter wine consumption.  The population density is shown with choropleth mapping and the wine consumption is showed with overlaid graduated wine glass symbols.
Overall, the take away from this map is that wine consumption correlates a lot with the cultural and agricultural practices of a country.  Vatican City beats all other European countries in wine consumption with a whopping 73.78 liters per person (if an average wine bottle is .75 liters, that's about 100 bottles a year!).  This is in large part to the all-Catholic population of the country that takes part in drinking wine for communion.  Appreciation of wine is also cultural as it is popular in France and Italy.  This is in part because they have a long tradition of growing grapes for wine and have the perfect climate and soil conditions for it.  Other countries may not prefer wine as much but that does not mean they are altogether dry.  Countries with low wine consumption tend to have foodways that put more emphasis on other forms of alcohol such as vodka in Russia and Lithuania.

The most challenging part of this map was placing the wine glass symbols and the country labels just so that it was obvious what they were in reference to without occluding anything else.  I now have great appreciation for cartographers who did this work in the pre-digital age.  As a bonus, I think I now have a much better sense of the geography of Europe too.

Saturday, March 28, 2020

Data Classification

The module this week had us exploring different classification methods for data.  The ones we looked at most closely and used for this lab were equal interval, quantile, natural breaks, and standard deviation.  These different classification systems determine what groups data are divided into and thus was color they correspond to on a choropleth map.  Therefore, the classification style chosen for a map can greatly effect the message that it conveys to the audience.  It is important to know what each classification system does and when best to apply it as to not create maps that are misleading.

The equal interval system divides the data into range breaks of equal size based off of number of classes desired.  The range breaks will get however much data there is within the ranges - whether they contain most of the data or none at all.  The ranges are thus almost always going to be unequally filled because of how they are equally spaced out.

The quantile system classifies data into categories with an equal number of data values within each category.  The spacing within the categories will be uneven, but the quantity of content within each class is equal.

The natural break system uses a mathematical algorithm to calculate natural groupings within the data.  The algorithm computes a unique grouping of classifications for each data set. Because how tailored it is this is a preferred choice for many maps.

For standard deviation, classes are created by adding or subtracting the standard deviation from the mean of the dataset. Standard deviation does a good job at creating (statistically) evenly spaced classes.  The way that the data is broken into classes is statistically logical. However, a casual audience may not understand what standard deviation is.

For this project we used census tract data for Miami-Dade county to create maps showing the senior population using different classification methods.  I created eight maps in all.  The first set was the percentage of seniors in each census tract displayed via equal interval, quantile, natural breaks, and standard deviation classifications.  The second used the same grouping of classifications but normalized the population based off of square mileage to find the density of the senior population in each census tract.  The purpose of the lab was to get us to understand the differences between classification systems, how to normalize data, and the overall usage of choropleth maps.  All of this work was performed using ArcGIS Pro.
The percent of senior citizens living within different census tracts of Miami-Dade County.
The population density living within different census tracts of Miami-Dade County.  This data took the count of senior living in each census tract and normalized it based off of the square mileage of each tract.

Most of this maps all use the same graduated bluish-purple color ramp except for the standard deviation maps.  This is because standard deviation maps typically use a diverging color ramp - one color for the classes below the mean and another for those above.

The natural breaks map normalized by square mileage isolated.  This is a strong map for both presentation and for data interpretation. 
I organized the map frames in this order because I believe that they go from conceptually easiest to understand to hardest.  Equal interval is very straight-forward, and quantile is one step of complexity above that.  The actual algorithm behind natural breaks is fairly sophisticated, but it is easy to explain to someone that they are grouped into most alike classes.  Standard deviation is harder to explain to someone without a statistics primer first.  If your audience isn't mathematically inclined using this methodology requires an extra layer of explanation in a way that the others do not. 

The best classification method for this map is natural breaks.  Since the algorithm finds the best class sections within the data it creates a map with good contrast while taking into account possible outliers.  The equal interval maps for both percent and density make it look like there are hardly any seniors at all. While the standard deviation classification is mathematically sound, it is difficult to explain to an audience who is not mathematically oriented and may not be interested in a lengthy explanation.  Quantile also produces a pretty solid looking map, but I like how natural breaks takes into account the grouping of the data. Where people live is influenced by a lot of factors, such as cost of living and access to health care so to divide the data up arbitrarily in quantiles has the potential to be problematic.  It makes more sense to use natural breaks which is able to take into account natural clusters of data.

Additionally, using the natural breaks map that is normalized by square mileage makes the most sense. Normalized data is a more useful depiction than the percentage maps.  If a county official was using a map to determine funding for geriatric-specific medical care, it makes more sense for that official to consult a population density map.  The density map makes comparisons between counties equal, while a percent map the comparisons do not easily transfer between counties.

To further drive this point, imagine if the city official was tasked with allocating funding to ambulances for each tract.  If the official looked at just the percentage, they would assign a large number of ambulances to that rather small dark purple tract that shows up in the Northeast quadrant of the county, but hardly any to the much larger country directly West of it.  When consulting the normalized natural breaks map, these two quadrants are in the same class. Resources should probably be allocated approximately equally between them instead making that decision off of the less balanced population map.