Skip to content

Instantly share code, notes, and snippets.

@rutj3
Last active December 31, 2015 05:29
Show Gist options
  • Save rutj3/7941518 to your computer and use it in GitHub Desktop.
Save rutj3/7941518 to your computer and use it in GitHub Desktop.
Blockserver
{
"metadata": {
"name": "Blockserver_example"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "import BlockServer\n%cd 'D:\\'",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "D:\\\n"
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": "L8_1 = r'LC81970242013202LGN00.vrt'\nL8_2 = r'LC81970242013346NSG00.vrt'",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": "# define inputs and outputs\ninputs = {'scene1': L8_1,\n 'scene2': L8_2}\n\noutputs = {'ndvi_change': 'ndvi_diff.tif',\n 'albedo_change': 'albedo_diff.tif'}\n\n# options are GDAL driver options\nobj = BlockServer(inputs=inputs, outputs=outputs,\n options=[\"COMPRESS=PACKBITS\", \"TILED=YES\", \"BLOCKXSIZE=128\", \"BLOCKYSIZE=128\"])\n\n# iterate over the blocks\nfor num in obj.GetBlockIDs():\n \n # returns a dict with arrays of each input\n blck = obj.GetBlock(num) \n \n # do something with the data\n sc1 = blck['scene1']\n ndvi1 = (sc1[5,:,:] - sc1[4,:,:]) / (sc1[5,:,:] + sc1[4,:,:])\n albe1 = np.average(sc1, axis=0)\n\n sc2 = blck['scene2']\n ndvi2 = (sc2[5,:,:] - sc2[4,:,:]) / (sc2[5,:,:] + sc2[4,:,:])\n albe2 = np.average(sc2, axis=0)\n \n ndvi_diff = ndvi1 - ndvi2\n albe_diff = albe1 - albe2\n \n # write the results, the dict must match the\n # earlier 'outputs' dict\n obj.WriteBlock(num, {'ndvi_change': ndvi_diff,\n 'albedo_change': albe_diff})\n\nobj.Close()",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": "-c:20: RuntimeWarning: divide by zero encountered in divide\n-c:24: RuntimeWarning: divide by zero encountered in divide\n"
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment