Skip to content

Commit

Permalink
Fixed handling of nodata values, to remove black borders
Browse files Browse the repository at this point in the history
  • Loading branch information
jbednar committed Sep 8, 2016
1 parent 8ee071d commit 93b5049
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/landsat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@
"band10 = rio.open(path.join(data_dir, 'MERCATOR_LC80210392016114LGN00_B10.TIF'))\n",
"band11 = rio.open(path.join(data_dir, 'MERCATOR_LC80210392016114LGN00_B11.TIF'))\n",
"band12 = rio.open(path.join(data_dir, 'MERCATOR_LC80210392016114LGN00_BQA.TIF'))\n",
"\n",
"# Notice the MERCATOR prefix which indicates the data was project to Mercator CRS\n",
"\n",
"xmin = band1.bounds.left\n",
"ymin = band1.bounds.bottom\n",
"xmax = band1.bounds.right\n",
"ymax = band1.bounds.top"
"ymax = band1.bounds.top\n",
"\n",
"# Declare value used in the above files for no-data values, as bandX.nodata was not filled in\n",
"nodata=1"
]
},
{
Expand All @@ -109,7 +111,7 @@
},
"outputs": [],
"source": [
"def base_plot(tools='pan,wheel_zoom,reset',plot_width=900, plot_height=500, x_range=None, y_range=None, **plot_args):\n",
"def base_plot(tools='pan,wheel_zoom,reset',plot_width=720, plot_height=400, x_range=None, y_range=None, **plot_args):\n",
" p = Figure(tools=tools, plot_width=plot_width, plot_height=plot_height,\n",
" x_range=x_range, y_range=y_range, outline_line_color=None,\n",
" background_fill_color='black',\n",
Expand Down Expand Up @@ -141,9 +143,9 @@
"source": [
"def update_image(x_range, y_range, w, h, how='log'):\n",
" cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)\n",
" blue_img = tf.shade(cvs.raster(band2),\n",
" cmap=['black','white'],\n",
" how='linear')\n",
" agg = cvs.raster(band2)\n",
" agg.data[agg.data<nodata]=np.nan\n",
" blue_img = tf.shade(agg,cmap=['black','white'],how='linear')\n",
" return blue_img\n",
"\n",
"p = base_plot(x_range=(xmin, xmax), y_range=(ymin, ymax))\n",
Expand Down Expand Up @@ -188,11 +190,11 @@
"outputs": [],
"source": [
"def combine_bands(r, g, b):\n",
" a = (np.where(np.logical_or(np.isnan(r),r<=nodata),0,255)).astype(np.uint8) \n",
" r = (normalize_data(r)).astype(np.uint8)\n",
" g = (normalize_data(g)).astype(np.uint8)\n",
" b = (normalize_data(b)).astype(np.uint8)\n",
" col, rows = r.shape\n",
" a = (np.zeros_like(r) + 255).astype(np.uint8)\n",
" img = np.dstack([r, g, b, a]).view(np.uint32).reshape(r.shape)\n",
" return tf.Image(data=img)"
]
Expand Down

0 comments on commit 93b5049

Please sign in to comment.