import folium
print(folium.__file__)
print(folium.__version__)
/home/filipe/.virtualenvs/iris/lib/python2.7/site-packages/folium/__init__.py 0.2.0
import numpy.ma as ma
import matplotlib.pyplot as plt
from scipy.io import loadmat
def colorize(array, cmap='rainbow'):
normed_data = (array - array.min()) / (array.max() - array.min())
cm = plt.cm.get_cmap(cmap)
return cm(normed_data)
merc = loadmat('./data/mercator_temperature.mat', squeeze_me=True)
x, y = merc['x'], merc['y']
level = 10 # 10 meters temperature.
data = ma.masked_invalid(merc['temp'][level, ...])
colored_data = colorize(data, cmap='rainbow')
import numpy as np
from datetime import datetime
from folium import plugins
mapa = folium.Map(location=[y.mean(), x.mean()], zoom_start=5)
plugins.ImageOverlay(np.flipud(colored_data),
[[y.min(), x.min()], [y.max(), x.max()]],
opacity=0.5).add_to(mapa)
jd_now = datetime.utcnow()
url = ('http://hfradar.ndbc.noaa.gov/tilesavg.php?'
's=10&e=100&x={x}&y={y}&z={z}&t=' +
str(jd_now.year) + '-' + str(jd_now.month) +
'-' + str(jd_now.day) + ' ' +
str(jd_now.hour-2) + ':00:00&rez=2')
folium.TileLayer(tiles=url, name='hfradar 2km', attr='HFRadar NDBC').add_to(mapa)
mapa.add_children(folium.LayerControl())
mapa