<jupyter_start><jupyter_text>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. *To use this notebook, please [first follow the instructions online here]().*<jupyter_code>import import_ipynb
from PPPP100 import *<jupyter_output><empty_output><jupyter_text>Using the PPPP library for EasyMapping"PPPP" is a library of code I've written to help you in your exploration of mapping data. It wraps up GeoPy, Plotly, and MapBox into one easy-to-use tool for creating maps with labeled points on them. This notebook introduces you to the library. We have some concepts to learn in Python before we're really ready to claim mastery with the library. But, you know enough to do a few things.  Creating the EasyMap objectFirst, you need to create a *map object*. Objects are... think of them as containers. They hold some data, and they hold some functions that can do things to that data. In the cell below, you need to give the EasyMap() a map name (for example, "Lewiston 2013", or really, whatever you like), and you need to give it your username. For me, that would be *mjadud*. This creates a *map object* that you can then interact with. I've stored it in a variable called *the_map*.<jupyter_code># The function EasyMap takes two parameters. The first is the
# name of your map, and the second is your username.
# It returns a *map object*.
the_map = EasyMap("Lewiston", "george")<jupyter_output><empty_output><jupyter_text>Setting the mapping tokenNext, you need to tell the EasyMap object what our secret token is. This is used to log into a map maping service called MapBox. I've included that token here.(For future readers: this is a MapBox API token. If the token below has been canceled, you can create a MapBox account and [get your own API token](https://www.mapbox.com/help/how-to-use-mapbox-securely/access-tokens).)<jupyter_code>the_map.set_token("pk.eyJ1IjoibWphZHVkIiwiYSI6ImNqbXl4eXl3cjBhcnAzcW55NjVkOTJpbmUifQ.jqwIx2Brdq76S0Ht3CsfmQ")<jupyter_output><empty_output><jupyter_text>Adding a point via latitude and longitudeIt is possible to add points to our map using latitude and longitude. For example, the middle of the puddle (Lake Andrews) is at latitude 44.107958 and longitude -70.203078. If I wanted to add a point to my map that was in the middle of the puddle, I would tell *the_map* that I wanted to *add_point()*, and pass it three parameters: the name of the point, the latitude, and the longitude.<jupyter_code>the_map.add_point("The Puddle", 44.107958, -70.203078)
the_map.add_point("Pettengill", 44.106487, -70.203212)<jupyter_output><empty_output><jupyter_text>You should add a cell after the one above, and add a few more points in Lewiston. Go to [Google Maps](https://maps.google.com/), and find some places of interest. [Then, use these instructions](https://support.google.com/maps/answer/18539) from Google to find out the latitude and longitude of those locations.If you then want to see the map plotted, you can tell *the_map* to plot itself.<jupyter_code>the_map.iplot()<jupyter_output><empty_output><jupyter_text>Adding a point via addressAdding points via geolocation is tough. It takes a lot of time to dig around and find the location of things. Fortunately, we have access to [GeoPy](https://geopy.readthedocs.io/), which is a marvelous library of code that turns addresses into latitude and longitude. You can ask our map to do this for you. For example, I can say```the_map.add_address("132 Nichols Street Lewiston ME")```and that address will be added to the map. If GeoPy can't find the address, an error is printed, and nothing is added to the map. If it works, a geocode comes back. I can also get lazy. I can just type```the_map.add_address("132 Nichols 04240")```and GeoPy will figure out that I want to find that street in the area code 04240 (which is Lewiston).Add a few addresses to your map. You should have a few addresses from Lewiston already from your dataset...<jupyter_code>the_map.add_address("132 Nichols 04240")
the_map.add_address("77 Nichols 04240")
the_map.add_address("55 Campus Ave 04240")
# If you want to see your map after adding points, you can ask the map to plot itself.
# the_map.iplot()<jupyter_output><empty_output><jupyter_text>Adding *categories* of pointsIt might be that your data comes in different categories. For example, you might have some points that represent... oh, say, students who attend one kind of school vs. another. Or, perhaps you are studying immigrants from the early 1900s, and some of those immigrants are French, or Irish, or ...If this is the case, you can create a *category* for your data points, and add your data to that specific category. This is demonstrated below. I've created a category called "Fr," because that is one of the codes from our dataset. I've given it the color dark green, and then I add two points by address using that category. **Note the syntax.** It is new to you, but I think you can figure out what is going on. You can use the [HTML Color Codes](https://htmlcolorcodes.com/) chooser to find HEX values for your colors.<jupyter_code># First, I tell the map that I'm creating a new category.
# The parameters are the size of the dot, the color, and the opacity (or, transparency)
# of the point that will represent this category.
#
# 
the_map.set_category_style("Fr", 8, "#336633", 0.8)
the_map.add_address("Cedar 29 04240", cat = "Fr")
the_map.add_address("Blake 254 04240", cat = "Fr")
# If you want to see your map after adding points, you can ask the map to plot itself.
the_map.iplot()<jupyter_output><empty_output><jupyter_text>As you can see, we now have the first points we added in garnet, and the last two points added were added in a dark green. You should experiment with creating some new categories, experiment with colors and point sizes, and get comfortable with using the map.  That's ItThat is everything the mapping library can do for now. Our next steps are to learn about *tuples*, *namedtuples*, *lists*, *for loops*, *data tables*, and eventually *objects*, although you are now using the last of these already. Lists are definitely next.There's a few other things the map can do, but perhaps the most useful is that you can ask the map for a URL that links to a version online, outside of the notebook. This is useful if you want a larger version for downloading and including in reports and the like.<jupyter_code>the_map.get_url()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07161639597834493, 'fraction_numerical': 0.021500386697602476, 'mean_word_length': 4.926672777268561, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 5, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '160604', 'license': 'MIT', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1804, 'n_words': 940, 'path': 'courses/2018-f-dcs103/IntroToMapping.ipynb', 'repo_name': 'jadudm/notebooks', 'size': '6465'}