Tuesday, May 14, 2024

Lab 1: Python Environments & Flowcharts

PEP 20 - The Zen of Python

Having read "The Zen of Python" in the past, it is something I have always found joyful, frustrating, and ironic given other languages or development philosophies. Below is my synopsis of these nineteen guiding Python design principles.
First, "Beautiful is better than ugly." Given the suite of other high-level interpreted programming languages, Python's syntax is rather ugly. Its usage of space to delineate code blocks is just frustrating and awkward. Yet its syntax is not as ugly as other interpreted languages like Perl or Bash.
"Explicit is better than implicit." has some merits but also some faults when comparing the Ruby on Rails mantra, "Convention over configuration." To limit software to strict explicit definition and not permit logical defaults through established conventions will generate a buggy, high-maintenance application.
The next two principles are symbiotic, "Simple is better than complex." and "Complex is better than complicated." are somewhat subjective. For the sake of brevity, let us add the seventh principle, "Readability counts." to this group since readability is largely based on experience and skill set. Authoring concise, optimized code at times may appear complex to novice programmers but with experience, it is anything but. As for myself, the two should be summed up as, "Get to the point and leverage as much of the information already in memory as possible," or simply, "Stop mucking about and creating an unnecessarily large memory footprint."

This next group of principles holds true regardless of the language: "Flat is better than nested.", "Sparse is better than dense.", "If the implementation is hard to explain, it's a bad idea.", and "If the implementation is easy to explain, it may be a good idea." The cognitive load necessary to understand a 50-line nested if-else statement is largely beyond even the best evil genius. Sparse code is somewhat subjective; as programming skills increase, a single line of dense code is effective and easy to understand. The last two in this group are basically the same as the programming jargon "rubber ducking," meaning that if you are unable to explain the problem in plain language, it's probably unnecessarily complex. The rubber duck aspect is from the book "The Pragmatic Programmer," where the author would explain code line-by-line to a rubber duck.

The next group of principles holds true regardless of the language: "Flat is better than nested," "Sparse is better than dense," "If the implementation is hard to explain, it's a bad idea," and "If the implementation is easy to explain, it may be a good idea." The cognitive load necessary to understand a 50-line nested if-else statement is largely beyond even the best evil genius. Sparse code is somewhat subjective; as programming skills increase, a single line of dense code is effective and easy to understand. The last two in this group are basically the same as the programming jargon of rubber ducking, meaning that if you are unable to explain the problem in plain language, it's probably unnecessarily complex. The rubber duck aspect comes from the book "The Pragmatic Programmer," where the author would explain code line-by-line to a rubber duck.

Those remaining which not so much coding or software design principles but practical, task-oriented methodologies to aid in getting things done or, better yet, prevent one from overthinking the design.

Python Environments - IDLE & ArcGIS Notebook

IDLE (Integrated Development Environment) is a basic shell and editor that is included with Python. It is a standalone application which is great for general purposes, quick prototyping, or one-off scripts. Its basic read-eval-print loop (REPL) is simple to use and understand but lacks a number of features more advanced users may seek.

As for ArcGIS Notebook, it is a vendor-specific spin of Jupyter Notebook, which is a web-based interactive development environment. Being part of the ArcGIS ecosystem, it is geared towards geospatial analysis and visualization. Unlike a line-by-line interaction like IDLE, ArcGIS Notebook utilizes cells which contain either code, data, markdown, or visuals, evaluated in a top-down manner. Yet, they are both development environments for Python which allow users to interactively author and execute code and display results.

Running the Python Script

One would think that they could press the Windows key, type "IDLE," and open the application. But in true Windows fashion, that expectation is a bust since it opens an IDLE for Python 2, not Python 3. I can only assume this is because ArcDesktop (ArcMap) is also installed, and to the best of my knowledge, it still utilizes Python 3. Looking over the CreateModFolders.py, it states that it was authored for the oddly precise version 3.6.5, so one can only conclude that running it using the installed IDLE, which leverages version 2.7.18.4, could fail or have an unexpected outcome.

To run the script, it was as simple as opening a terminal and passing the file as an argument to the Python interpreter. As to why a utility script like this does not contain a shebang is a mystery. Once executed, a quick look and voilĂ , the expected directory structure is created.

Flowchart

Software for creating flowcharts and Unified Modeling Language (UML) has come a long way. There are tons of freely available online tools like Visio, but my go-to tool is still the age-old Dia. It may not produce the most fancy-looking diagrams, but it is a great all-around tool, especially for class, entity-relationship (ER), and sequence diagrams. Embedded is the diagram for the radians to degrees formula, assuming that the Python math.pi constant exists.

Friday, May 3, 2024

M7 Lab: Google Earth

For the classes final lab we where instructed to export some data from ArcGIS Pro into Keyhole Markup Language (KML) format. Start and loading the data in ArcGIS Pro was a snap. The export to KML tool was straight forward and produced a Keyhole Markup Zipfile (KMZ).

With the layers population density and surface water layers as saved as a KMZ it was time to open and add them to Google Earth Pro. Empowered with prior knowledge of Google Earth creating folders and moving items from Temporary Place to My Places simple and easy.

The only thing which I deviated from the lab instructions was placing the legend. The instructions has us place the legend as an image GroundOverlay. A GroundOverlay is best suited for georeferencing an image in google earth. Considering the legend does not contain any geographic information it was better placed using a ScreenOverlay.

Original Google Earth Pro Generated GroundOverlay kml

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" 
  xmlns:gx="http://www.google.com/kml/ext/2.2"
  xmlns:kml="http://www.opengis.net/kml/2.2"
  xmlns:atom="http://www.w3.org/2005/Atom">
<GroundOverlay>
	<name>Legend</name>
	<Icon>
		<href>C:/Location/Of/Legend.jpg</href>
		<viewBoundScale>0.75</viewBoundScale>
	</Icon>
	<LatLonBox>
		<north>30.39911420308843</north>
		<south>27.82322070121159</south>
		<east>-76.71995963997009</east>
		<west>-79.22200220846706</west>
	</LatLonBox>
</GroundOverlay>
</kml>

ScreenOverlay KML


<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
  xmlns:gx="http://www.google.com/kml/ext/2.2"
  xmlns:kml="http://www.opengis.net/kml/2.2"
  xmlns:atom="http://www.w3.org/2005/Atom">
<ScreenOverlay>
	<name>Legend</name>
	<Icon>
		<href>C:/Location/Of/Legend.jpg</href>
		<viewBoundScale>0.75</viewBoundScale>
	</Icon>
	<overlayXY x="0" y="0" xunits="fraction" yunits="fraction"/>
	<screenXY x="25" y="95" xunits="pixels" yunits="pixels"/>
	<rotationXY x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
	<size x="0" y="0" xunits="pixels" yunits="pixels"/>
</ScreenOverlay>
</kml>

Saturday, April 27, 2024

M6 Lab: Isarithmic Mapping

This weeks lab assignment centered around the the elements of Isarithmic maps. The goal was to create a continuous color fill symbol,  hypsometric tinting, and contour maps with an existing PRISM precipitation data raster data of Washington State. 

 Completing the lab assignment was easy and fairly straight forward by first creating a map with continuous colors then adding a hypometric tinting or layer tenting showing the differences in relief. Basically, it accentuated the changes in elevation enhancing the users ability to see concentration of perceptional when encouraging changes in elevation.



The next step in the lab evolved reclassifying the raster from floating point values ot integer values. Using the raster of integer values it was necessary to create contour lines using the same manual breaks, shown in the final map below.