In [ ]:
%matplotlib inline
In [ ]:
from matplotlib.pylab import plt
import numpy as np
import pandas as pd
legend = pd.DataFrame([
(11, "Open Water", "#476BA0"),
(12, "Perennial Ice/Snow", "#D1DDF9"),
(21, "Developed, Open Space","#DDC9C9"),
(22, "Developed, Low Intensity", "#D89382"),
(23, "Developed, Medium Intensity", "#ED0000"),
(24, "Developed High Intensity", "#AA0000"),
(31, "Barren Land (Rock/Sand/Clay)", "#B2ADA3"),
(41, "Deciduous Forest", "#68AA63"),
(42, "Evergreen Forest", "#1C6330"),
(43, "Mixed Forest", "#B5C98E"),
(51, "Dwarf Scrub", "#A58C30"),
(52, "Shrub/Scrub", "#CCBA7C"),
(71, "Grassland/Herbaceous", "#E2E2C1"),
(72, "Sedge/Herbaceous", "#C9C977"),
(73, "Lichens", "#99C147"),
(74, "Moss", "#77AD93"),
(81, "Pasture/Hay", "#DBD83D"),
(82, "Cultivated Crops", "#AA7028"),
(90, "Woody Wetlands", "#BAD8EA"),
(95, "Emergent Herbaceous Wetlands","#70A3BA")],
columns=["Code", "Desc", "Color"])
def highlight(e):
return 'background-color: {}'.format(e)
In [ ]:
from geonotebook.wrappers import RasterData
rd = RasterData("../data/nlcd_2011_landcover_2011_edition_2014_10_10.tif")
In [ ]:
colormap = legend[["Code", "Color"]].rename(columns={
"Code": "quantity", "Color": "color"}).to_dict("records")
In [ ]:
M.add_layer(rd[1], colormap=colormap, opacity=0.7)
In [ ]:
legend.set_index("Code").style.applymap(highlight)
In [ ]:
from geonotebook.vis.ktile.utils import get_layer_vrt
print(get_layer_vrt(M.layers[0]))
In [ ]:
M.remove_layer(M.layers[0])
In [ ]:
M.add_layer(rd[1], colormap=colormap, opacity=0.7, vrt_path="vrt/nlcd.vrt")
In [ ]:
print(get_layer_vrt(M.layers[0]))
In [ ]:
l, d = M.layers.annotation.polygons[0].data.next()
In [ ]:
d.shape
In [ ]:
df = pd.DataFrame({"Code": d.data.ravel()})
df["Count"] = 1
df = df.groupby("Code").sum().join(legend.set_index("Code"))\
.sort_values("Count", ascending=False).dropna()
df.style.applymap(highlight)
In [ ]:
from matplotlib.colors import LinearSegmentedColormap
df.set_index("Desc").T.ix['Count'].plot(kind="barh", color=list(df["Color"]))
In [ ]:
M.layers[0].name
In [ ]:
import ipykernel
ipykernel.get_connection_file()