In [ ]:
%matplotlib inline
from matplotlib import pylab as plt
from ipywidgets import interact
import ipywidgets as widgets
import matplotlib as mpl
import numpy as np
from geonotebook.wrappers import RasterDataCollection
import os
The following cell is a bash one-liner for downloading monthly NBAR geotiffs from roughly Dec 2008 to Dec 2011. This data will download into a data/
directory relative to the directory where this notebook is running. There are 36 files making up about 8Gb of data. This may take some time to download so please be patient. You should recieve notification in the cell output for each downloaded file.
For convenience here is an beautified version of the bash one-liner:
# Make the 'data' directory
if [ ! -d data ]; then
mkdir data;
fi;
# Recursively download the data via AWS CLI
if hash aws 2>/dev/null; then
aws s3 cp --recursive s3://golden-tile-geotiffs/ data;
else
echo "AWS CLI script 'aws' is required";
fi
Please note that the AWS command line script is required to download this data
In [ ]:
!if [ ! -d data ]; then mkdir data; fi; if hash aws 2>/dev/null; then aws s3 cp --recursive s3://golden-tile-geotiffs/ data; else echo "AWS CLI script 'aws' is required"; fi
In [ ]:
DATA_DIR="data/"
In [ ]:
def sort_NBAR(path):
m, y = int(path.split(".")[2][-2:]), int(path.split(".")[3])
return (y * 100) + m
PATHS = [DATA_DIR + p for p in sorted([
f for f in os.listdir(DATA_DIR) if f.startswith('L57')], key=sort_NBAR)]
In [ ]:
rdc = RasterDataCollection(PATHS)
In [ ]:
M.add_layer(rdc[:,[1,2,3]], 'NBAR', opacity=0.8, gamma=2.0)
In [ ]:
M.layers["NBAR"].forward()
In [ ]:
M.layers["NBAR"].backward()
In [ ]:
M.layers["NBAR"].idx(0)
In [ ]:
len(M.layers["NBAR"].data)
In [ ]:
def render_timeseries(idx=0):
M.layers["NBAR"].idx(idx)
interact(render_timeseries, idx=(0, len(M.layers["NBAR"].data) - 1))
In [ ]:
M.layers["NBAR"].idx(1)
In [ ]:
M.remove_layer("NBAR")
In [ ]:
M.add_layer(rdc[:,[4]], 'NBAR_NDVI', opacity=0.8)
In [ ]:
M.remove_layer("NBAR_NDVI")
In [ ]:
def ndvi_colormap(numcolors=11, name='custom_div_cmap',
mincol='blue', midcol='beige', maxcol='green'):
return mpl.colors.LinearSegmentedColormap.from_list(
name=name, colors=[mincol, midcol, maxcol], N=numcolors)
cmap = ndvi_colormap()
In [ ]:
M.add_layer(rdc[:,4], 'NBAR_NDVI', colormap=cmap, opacity=0.8)
In [ ]:
M.layers['NBAR_NDVI'].forward()
In [ ]:
M.layers