Update HAPs (more like LFs)

This commit is contained in:
Florent Guiotte 2018-04-03 15:34:23 +02:00
parent 6b179c4bfb
commit c900add842

View File

@ -30,18 +30,21 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# Specific Utils\n", "# Specific Utils\n",
"im_size = 2\n",
"\n", "\n",
"def DFC_filter(raster):\n", "def DFC_filter(raster):\n",
" raster[raster > 1e4] = raster[raster < 1e4].max()\n", " raster[raster > 1e4] = raster[raster < 1e4].max()\n",
"\n", "\n",
"def show(im):\n", "def show(im, im_size=1, save=None):\n",
" plt.figure(figsize=(16*im_size,3*im_size))\n", " plt.figure(figsize=(16*im_size,3*im_size))\n",
" plt.imshow(im)\n", " plt.imshow(im)\n",
" plt.colorbar()\n", " plt.colorbar()\n",
" \n",
" if save is not None:\n",
" plt.savefig(save, bbox_inches='tight', pad_inches=1)\n",
" \n",
" plt.show()\n", " plt.show()\n",
"\n", "\n",
"def mshow(Xs, titles=None):\n", "def mshow(Xs, titles=None, im_size=1, save=None):\n",
" s = len(Xs)\n", " s = len(Xs)\n",
"\n", "\n",
" plt.figure(figsize=(16*im_size,3*im_size*s))\n", " plt.figure(figsize=(16*im_size,3*im_size*s))\n",
@ -55,7 +58,9 @@
" \n", " \n",
" plt.colorbar()\n", " plt.colorbar()\n",
" \n", " \n",
" plt.savefig('test.png', bbox_inches='tight', pad_inches=1)\n", " if save is not None:\n",
" plt.savefig(save, bbox_inches='tight', pad_inches=1)\n",
" \n",
" plt.show()" " plt.show()"
] ]
}, },
@ -128,7 +133,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"a = attributes\n", "a = attributes\n",
"i = 7\n", "i = 3\n",
"show(a[:,:,i].astype(np.float) - a[:,:,i+1])" "show(a[:,:,i].astype(np.float) - a[:,:,i+1])"
] ]
}, },
@ -145,9 +150,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"patch_size = 5\n", "def create_patches(array, patch_size=3):\n",
"\n",
"### \n",
" amp = int((patch_size - 1 ) / 2)\n", " amp = int((patch_size - 1 ) / 2)\n",
"\n", "\n",
" stack = list()\n", " stack = list()\n",
@ -158,16 +161,17 @@
" di = -ai if ai is not None else None\n", " di = -ai if ai is not None else None\n",
"\n", "\n",
" for j in range(-amp, amp+1):\n", " for j in range(-amp, amp+1):\n",
" offset = np.zeros(raster.shape)\n", " offset = np.zeros(array.shape)\n",
" aj = j if j > 0 else None\n", " aj = j if j > 0 else None\n",
" bj = j if j < 0 else None\n", " bj = j if j < 0 else None\n",
" cj = -bj if bj is not None else None\n", " cj = -bj if bj is not None else None\n",
" dj = -aj if aj is not None else None\n", " dj = -aj if aj is not None else None\n",
" print('{}:{} {}:{} - {}:{} {}:{}'.format(ai, bi, ci, di, aj, bj, cj, dj))\n", " print('{}:{} {}:{} - {}:{} {}:{}'.format(ai, bi, ci, di, aj, bj, cj, dj))\n",
" offset[ai:bi, aj:bj] = raster[ci:di, cj:dj]\n", " offset[ai:bi, aj:bj] = array[ci:di, cj:dj]\n",
" stack.append(offset)\n", " stack.append(offset)\n",
" return np.stack(stack, axis=-1)\n",
"\n", "\n",
"offset_stack = np.stack(stack, axis=2)\n", "offset_stack = create_patches(attributes, 5)\n",
"offset_stack.shape" "offset_stack.shape"
] ]
}, },
@ -190,6 +194,24 @@
"stack_std.shape" "stack_std.shape"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"figs = list()\n",
"ttls = list()\n",
"for d in range(stack_std.shape[-1]):\n",
" if d == 0:\n",
" ttls.append('Origin')\n",
" else:\n",
" ttls.append('STD 5x5 from area {}'.format(area[d-1]))\n",
" figs.append(stack_std[:,:,d])\n",
" \n",
"mshow(figs, ttls, 2)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -228,6 +250,32 @@
" ]\n", " ]\n",
"mshow(figs, ttls)" "mshow(figs, ttls)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"size = '{}x{}'.format(patch_size, patch_size)\n",
"figs = [raster,\n",
" stack_avr[:,:,-1],\n",
" stack_mean[:,:,-1],\n",
" stack_min[:,:,-1],\n",
" stack_max[:,:,-1],\n",
" stack_var[:,:,-1],\n",
" stack_std[:,:,-1]\n",
" ]\n",
"ttls = ['Origin',\n",
" 'Average ' + size,\n",
" 'Mean ' + size,\n",
" 'Minimum ' + size,\n",
" 'Maximum ' + size,\n",
" 'Variance ' + size,\n",
" 'STD ' + size\n",
" ]\n",
"mshow(figs, ttls, 2, save='mstack2.png')"
]
} }
], ],
"metadata": { "metadata": {