Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot notebooks #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 290 additions & 0 deletions pipeline/.ipynb_checkpoints/Plot-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"import numpy as np\n",
"import pandas as pd\n",
"from itertools import permutations\n",
"from netCDF4 import Dataset\n",
"import geopandas as gpd\n",
"from osgeo import gdal, ogr\n",
"import rasterio\n",
"import xarray as xr\n",
"from itertools import product\n",
"\n",
"\n",
"import bokeh\n",
"from bokeh.io import output_notebook, show\n",
"from bokeh.plotting import figure\n",
"from bokeh.models import (ColumnDataSource, HoverTool, LogColorMapper)\n",
"from bokeh.palettes import RdYlGn as palette\n",
"from shapely.geometry import LinearRing, Polygon, Point\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.pyplot import *\n",
"from gmplot import gmplot\n",
"palette = palette[9]\n",
"palette.reverse()\n",
"color_mapper = LogColorMapper(palette=palette)\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>geometry</th>\n",
" <th>polygon_id</th>\n",
" <th>land_distance</th>\n",
" <th>pretected_areas</th>\n",
" <th>county</th>\n",
" <th>critical_species</th>\n",
" <th>biomass</th>\n",
" <th>depth</th>\n",
" <th>mean_sst</th>\n",
" <th>max_sst</th>\n",
" <th>min_sst</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>POLYGON ((-124.511849 40.2062109680851, -124.4...</td>\n",
" <td>77</td>\n",
" <td>4.785556</td>\n",
" <td>[(13, Sea Lion Gulch State Marine Reserve, 0.0...</td>\n",
" <td>[(21, Humboldt, 4.785556275622082)]</td>\n",
" <td>[(41, green sturgeon, 0.0), (22, stellar sea l...</td>\n",
" <td>0.0</td>\n",
" <td>-122.4</td>\n",
" <td>11.929242</td>\n",
" <td>14.013989</td>\n",
" <td>9.125995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>POLYGON ((-124.511849 40.30584561702128, -124....</td>\n",
" <td>78</td>\n",
" <td>2.007310</td>\n",
" <td>[(12, Mattole Canyon State Marine Reserve, 0.0...</td>\n",
" <td>[(21, Humboldt, 2.00731033547805)]</td>\n",
" <td>[(41, green sturgeon, 0.0), (22, stellar sea l...</td>\n",
" <td>0.0</td>\n",
" <td>-45.0</td>\n",
" <td>11.929242</td>\n",
" <td>14.013989</td>\n",
" <td>9.125995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>POLYGON ((-124.511849 40.40548026595744, -124....</td>\n",
" <td>79</td>\n",
" <td>0.222856</td>\n",
" <td>[(9, Sugarloaf Island Special Closure, 0.0), (...</td>\n",
" <td>[(21, Humboldt, 0.22285562284475044)]</td>\n",
" <td>[(41, green sturgeon, 0.0), (28, stellar sea l...</td>\n",
" <td>0.0</td>\n",
" <td>-29.6</td>\n",
" <td>11.929242</td>\n",
" <td>14.013989</td>\n",
" <td>9.125995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>POLYGON ((-124.511849 40.50511491489362, -124....</td>\n",
" <td>80</td>\n",
" <td>2.325414</td>\n",
" <td>[(9, Sugarloaf Island Special Closure, 6.54469...</td>\n",
" <td>[(21, Humboldt, 2.32541354349618)]</td>\n",
" <td>[(41, green sturgeon, 0.0), (22, stellar sea l...</td>\n",
" <td>0.0</td>\n",
" <td>-38.6</td>\n",
" <td>11.929242</td>\n",
" <td>14.013989</td>\n",
" <td>9.125995</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>POLYGON ((-124.4120138767123 40.10657631914894...</td>\n",
" <td>171</td>\n",
" <td>1.252525</td>\n",
" <td>[(14, Big Flat State Marine Conservation Area,...</td>\n",
" <td>[(21, Humboldt, 1.2525254119315425)]</td>\n",
" <td>[(41, green sturgeon, 0.0), (22, stellar sea l...</td>\n",
" <td>0.0</td>\n",
" <td>-58.2</td>\n",
" <td>11.929242</td>\n",
" <td>14.013989</td>\n",
" <td>9.125995</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" geometry polygon_id \\\n",
"0 POLYGON ((-124.511849 40.2062109680851, -124.4... 77 \n",
"1 POLYGON ((-124.511849 40.30584561702128, -124.... 78 \n",
"2 POLYGON ((-124.511849 40.40548026595744, -124.... 79 \n",
"3 POLYGON ((-124.511849 40.50511491489362, -124.... 80 \n",
"4 POLYGON ((-124.4120138767123 40.10657631914894... 171 \n",
"\n",
" land_distance pretected_areas \\\n",
"0 4.785556 [(13, Sea Lion Gulch State Marine Reserve, 0.0... \n",
"1 2.007310 [(12, Mattole Canyon State Marine Reserve, 0.0... \n",
"2 0.222856 [(9, Sugarloaf Island Special Closure, 0.0), (... \n",
"3 2.325414 [(9, Sugarloaf Island Special Closure, 6.54469... \n",
"4 1.252525 [(14, Big Flat State Marine Conservation Area,... \n",
"\n",
" county \\\n",
"0 [(21, Humboldt, 4.785556275622082)] \n",
"1 [(21, Humboldt, 2.00731033547805)] \n",
"2 [(21, Humboldt, 0.22285562284475044)] \n",
"3 [(21, Humboldt, 2.32541354349618)] \n",
"4 [(21, Humboldt, 1.2525254119315425)] \n",
"\n",
" critical_species biomass depth \\\n",
"0 [(41, green sturgeon, 0.0), (22, stellar sea l... 0.0 -122.4 \n",
"1 [(41, green sturgeon, 0.0), (22, stellar sea l... 0.0 -45.0 \n",
"2 [(41, green sturgeon, 0.0), (28, stellar sea l... 0.0 -29.6 \n",
"3 [(41, green sturgeon, 0.0), (22, stellar sea l... 0.0 -38.6 \n",
"4 [(41, green sturgeon, 0.0), (22, stellar sea l... 0.0 -58.2 \n",
"\n",
" mean_sst max_sst min_sst \n",
"0 11.929242 14.013989 9.125995 \n",
"1 11.929242 14.013989 9.125995 \n",
"2 11.929242 14.013989 9.125995 \n",
"3 11.929242 14.013989 9.125995 \n",
"4 11.929242 14.013989 9.125995 "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pickle.load(open(\"grid_df.pkl\", \"rb\"))\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"xs = [df[\"geometry\"][i].exterior.xy[0].tolist() for i in range(df.shape[0])]\n",
"ys = [df[\"geometry\"][i].exterior.xy[1].tolist() for i in range(df.shape[0])]\n",
"biomass_kg = df.biomass.tolist()\n",
"water_depth_m = df.depth.tolist()\n",
"sst = df.mean_sst.tolist()\n",
"species = [df.critical_species[i][0][1] for i in range(df.shape[0])]\n",
"county = [df.county[i][0][1] for i in range(df.shape[0])]\n",
"pretected_areas = [df.pretected_areas[i][0][1] for i in range(df.shape[0])]"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"#Big, Color Pallete\n",
"from bokeh.io import output_file, show\n",
"from bokeh.models import ColumnDataSource, GMapOptions, GMapPlot, Patches, HoverTool\n",
"from bokeh.plotting import gmap\n",
"\n",
"output_file(\"combinedplot.html\")\n",
"\n",
"map_options = GMapOptions(lat=32.88, lng=-118.460745, map_type=\"roadmap\", zoom=10)\n",
"\n",
"#NEVER SHARE THIS GOOGLE MAPS API KEY\n",
"p = gmap(\"AIzaSyAqMlpFrenE6SClJJ15goq0GmY-MDeN8tg\", map_options, title=\"CA Kelp Areas - Big Squares, Combined Data\", height = 1000, width = 1000)\n",
"\n",
"source = ColumnDataSource(data=dict(\n",
" x=xs,\n",
" y=ys,\n",
" kelp=biomass_kg,\n",
" bathymetry=water_depth_m,\n",
" sst=sst,\n",
" species=species,\n",
" county=county,\n",
" pretected_areas=pretected_areas\n",
"))\n",
"\n",
"patched = Patches(xs=\"x\", ys=\"y\", fill_color= {\"field\": \"kelp\", \"transform\":color_mapper}, \n",
" fill_alpha=0.8, line_color = \"white\", line_width = 0.7)\n",
"p.add_glyph(source, patched)\n",
"p.add_tools(HoverTool(tooltips=[(\"Kelp Biomass (KG)\", \"@kelp\"), \n",
" (\"Water Depth (M)\", \"@bathymetry\"), \n",
" (\"Sea Surface Temp\", \"@sst\"), \n",
" (\"Critical Species\", \"@species\"), \n",
" (\"County\", \"@county\"), \n",
" (\"Protected Areas\", \"@pretected_areas\"), \n",
" (\"(Lat, Long)\", \"($y, $x)\")]))\n",
"\n",
"\n",
"show(p)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading