Last active
May 11, 2018 03:47
-
-
Save texasdave2/2db90efc7a0589410eabb53177efe6be to your computer and use it in GitHub Desktop.
Volcano map test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun May 6 20:29:19 2018 | |
@author: astro 1 | |
""" | |
#Volcano eruption map from 2010 to present | |
#data downloaded from | |
#https://www.ngdc.noaa.gov/nndc/servlet/ShowDatasets?dataset=102557&search_look=50&display_look=50 | |
#script extracts relavent properties of volcanoes and places colored markers | |
#with popup info about each one | |
import pandas as pd | |
import folium | |
#download filename is "results" tab delimited | |
df1 = pd.read_csv("results", sep = '\t') | |
#look at the shape of the df and get column names | |
#print(df1.shape) | |
#print(df1.columns) | |
#subset df1 to only get all rows and only columns we need | |
df2 = df1.loc[:, ("Year", "Name", "Country", | |
"Latitude", "Longitude", "Type")] | |
#since this data is from the web check to see if there are any Nan | |
#df2.isnull().sum().sum() | |
#can also pass to check if true to run an if statement | |
#df2.isnull().any().any() | |
if df2.isnull().any().any() is True: | |
print("Sorry there is at least 1 NaN value") | |
else: | |
pass | |
#check the first and last 5 rows | |
#df2.head(n = 5) | |
#df2.tail(n = 5) | |
#established by now that it's clean data we need to first subset the lat long | |
df_ll = df2.loc[:, ("Latitude", "Longitude")] | |
#subset desired properties to display in popup | |
df_year = df2.loc[:, ("Year")] | |
df_name = df2.loc[:, ("Name")] | |
df_country = df2.loc[:, ("Country")] | |
df_type = df2.loc[:, ("Type")] | |
#take the dataframe values for lat long and make a list of lists | |
df_ll_list = df_ll.values.tolist() | |
#center map at some location if desired | |
#latlong = [30.2672, -97.7431] | |
#build the base map centered on latlong with zoom | |
# | |
#map = folium.Map(location = [*latlong], | |
# zoom_start = 2, tiles = "Mapbox Bright") | |
#build the map based on no location, just default center of map, no zoom | |
#map = folium.Map(location = None, tiles = "Mapbox Bright") | |
#use terrain map layer to actually see volcano terrain | |
map = folium.Map(location = None, tiles = "Stamen Terrain") | |
#insert multiple markers, iterate through list | |
#each marker popup will display the lat lon coordinates from the list | |
# | |
#possibly add a different color marker for the type and look for | |
#trends where certain types are prevalent | |
i = 0 | |
for coordinates in df_ll_list: | |
#assign a color marker for the type of volcano, Strato being the most common | |
if df_type[i] == "Stratovolcano": | |
type_color = "green" | |
elif df_type[i] == "Complex volcano": | |
type_color = "blue" | |
elif df_type[i] == "Shield volcano": | |
type_color = "orange" | |
else: | |
type_color = "black" | |
#now place the markers with the popup labels and data | |
map.add_child(folium.Marker(location = coordinates, | |
popup = | |
"Year: " + str(df_year[i]) + '<br>' + | |
"Name: " + str(df_name[i]) + '<br>' + | |
"Country: " + str(df_country[i]) + '<br>' | |
"Type: " + str(df_type[i]) + '<br>' | |
"Coordinates: " + str(df_ll_list[i]), | |
icon = folium.Icon(color = "%s" % type_color))) | |
i = i + 1 | |
#title the map | |
fg = folium.FeatureGroup(name = "Volcano eruptions since 2010") | |
#add title | |
map.add_child(fg) | |
#save map | |
map.save("volcanoes2010.html") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment