{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.3.0.dev\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "print(folium.__version__)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import cartopy.crs as ccrs\n", "import matplotlib.pyplot as plt\n", "import cartopy.feature as cfeature\n", "\n", "LAND = cfeature.NaturalEarthFeature('physical', 'land', '50m',\n", " edgecolor='face',\n", " facecolor=cfeature.COLORS['land'])\n", "\n", "\n", "def make_map(bbox, projection=ccrs.Mercator()):\n", " fig, ax = plt.subplots(figsize=(8, 6),\n", " subplot_kw=dict(projection=projection))\n", " ax.set_extent(bbox)\n", " ax.add_feature(LAND, facecolor='0.25')\n", " ax.coastlines(resolution='50m')\n", " return fig, ax" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy.ma as ma\n", "from scipy.io import loadmat\n", "\n", "fname = os.path.join('data', 'mercator_temperature.mat')\n", "merc = loadmat(fname, squeeze_me=True)\n", "\n", "x, y = merc['x'], merc['y']\n", "bbox = [x.min(), x.max(), y.min(), y.max()]\n", "\n", "level = 10 # 10 meters temperature.\n", "data = ma.masked_invalid(merc['temp'][level, ...])\n", "\n", "fig, ax = make_map(bbox=bbox)\n", "cs = ax.pcolormesh(x, y, data, transform=ccrs.PlateCarree())\n", "fig.savefig('GS.png', transparent=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n", "from PIL import Image, ImageChops\n", "\n", "\n", "def trim(img):\n", " border = Image.new(img.mode, img.size, img.getpixel((0, 0)))\n", " diff = ImageChops.difference(img, border)\n", " diff = ImageChops.add(diff, diff, 2.0, -100)\n", " bbox = diff.getbbox()\n", " if bbox:\n", " img = img.crop(bbox)\n", " return np.array(img)\n", "\n", "img = Image.open(\"GS.png\")\n", "img = trim(img)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "