{"action":"created","comment":{"url":"https://api.github.com/repos/ARM-DOE/pyart/pulls/comments/57746290","id":57746290,"diff_hunk":"@@ -0,0 +1,246 @@\n+from __future__ import print_function, division\n+import numpy as np\n+import matplotlib.pyplot as plt\n+import matplotlib.colors as colors\n+import os\n+try:\n+    from osgeo import gdal\n+    IMPORT_FLAG = True\n+except ImportError:\n+    IMPORT_FLAG = False\n+\n+\n+def write_grid_geotiff(filename, grid, field=None, rgb=False, level=None,\n+                       cmap='viridis', vmin=0, vmax=75, color_levels=None,\n+                       warp=False, sld=False):\n+    \"\"\"\n+    Write a Py-ART Grid object to a GeoTIFF file. The GeoTIFF can be the\n+    standard Azimuthal Equidistant projection used in Py-ART, or a lat/lon\n+    projection on a WGS84 sphere. The latter is typically more usable in web\n+    mapping applications. The GeoTIFF can contain a single float-point raster\n+    band, or three RGB byte raster bands. The former will require an SLD file\n+    for colorful display using standard GIS or web mapping software, while the\n+    latter will show colors \"out-of-the-box\" but lack actual data values. The\n+    function also can output an SLD file based on the user-specified inputs.\n+    User can specify the 2D vertical level to be output. If this is not\n+    specified, a 2D composite is created. User also can specify the field\n+    to output.\n+\n+    This function requires GDAL Python libraries to be installed. These are\n+    available via conda; e.g., 'conda install gdal'\n+\n+    Parameters\n+    ----------\n+    filename : str\n+        Filename to save grid to\n+    grid : Grid\n+        Grid object to write\n+    rbg : Boolean\n+        True - Output 3-band RGB GeoTIFF\n+        False - Output single-channel, float-valued GeoTIFF. For display,\n+                likely will need an SLD file to provide a color table.\n+    level: int\n+        Index for z-axis plane to output. None gives composite values\n+        (i.e., max in column)\n+    cmap : str or matplotlib colormap object\n+        Colormap to use for RGB output or SLD file\n+    vmin : int or float\n+        Minimum value to color for RGB output or SLD file\n+    vmax : int or float\n+        Maximum value to color for RGB output or SLD file\n+    color_levels : int\n+        Number of color levels in cmap. Useful for categorical colormaps\n+        with steps << 255 (e.g., hydrometeor ID).\n+    warp : Boolean\n+        True - Use gdalwarp (called from command line using os.system)\n+               to warp to a lat/lon WGS84 grid\n+        False - No warping will be performed. Output will be Az. Equidistant.\n+    sld : Boolean\n+        True - Create a Style Layer Descriptor file (SLD) mapped to vmin/vmax\n+               and cmap. File is named same as output TIFF, except for .sld\n+               extension.\n+        False - Don't do this\n+    \"\"\"\n+    if not IMPORT_FLAG:\n+        print('GDAL not detected, GeoTIFF output failure!')\n+        return\n+\n+    # Allow the user to swap filename/grid position in call\n+    if type(filename) is not str:\n+        fname = grid\n+        gridvol = filename\n+    else:\n+        fname = filename\n+        gridvol = grid\n+    name, end = fname.split('.')\n+\n+    f_flag = False\n+    for f, field_dic in gridvol.fields.iteritems():\n+        if f == field:\n+            f_flag = True\n+            ofile = name + \"_\" + f + \".\" + end\n+            nz, ny, nx = gridvol.fields[field]['data'].shape\n+            rcells = ny * 0.5\n+            dist = max(gridvol.axes['x_disp']['data'])","path":"pyart/io/output_to_geotiff.py","position":84,"original_position":84,"commit_id":"79e56667a7ddd9f0d89480eaafc57e05db1d9555","original_commit_id":"79e56667a7ddd9f0d89480eaafc57e05db1d9555","user":{"login":"jjhelmus","id":1050278,"avatar_url":"https://avatars.githubusercontent.com/u/1050278?v=3","gravatar_id":"","url":"https://api.github.com/users/jjhelmus","html_url":"https://github.com/jjhelmus","followers_url":"https://api.github.com/users/jjhelmus/followers","following_url":"https://api.github.com/users/jjhelmus/following{/other_user}","gists_url":"https://api.github.com/users/jjhelmus/gists{/gist_id}","starred_url":"https://api.github.com/users/jjhelmus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jjhelmus/subscriptions","organizations_url":"https://api.github.com/users/jjhelmus/orgs","repos_url":"https://api.github.com/users/jjhelmus/repos","events_url":"https://api.github.com/users/jjhelmus/events{/privacy}","received_events_url":"https://api.github.com/users/jjhelmus/received_events","type":"User","site_admin":false},"body":"axes is deprecated, use grid.x['data']","created_at":"2016-03-29T15:42:48Z","updated_at":"2016-03-29T15:42:48Z","html_url":"https://github.com/ARM-DOE/pyart/pull/511#discussion_r57746290","pull_request_url":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511","_links":{"self":{"href":"https://api.github.com/repos/ARM-DOE/pyart/pulls/comments/57746290"},"html":{"href":"https://github.com/ARM-DOE/pyart/pull/511#discussion_r57746290"},"pull_request":{"href":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511"}}},"pull_request":{"url":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511","id":63957948,"html_url":"https://github.com/ARM-DOE/pyart/pull/511","diff_url":"https://github.com/ARM-DOE/pyart/pull/511.diff","patch_url":"https://github.com/ARM-DOE/pyart/pull/511.patch","issue_url":"https://api.github.com/repos/ARM-DOE/pyart/issues/511","number":511,"state":"open","locked":false,"title":"GeoTIFF output","user":{"login":"tjlang","id":3036387,"avatar_url":"https://avatars.githubusercontent.com/u/3036387?v=3","gravatar_id":"","url":"https://api.github.com/users/tjlang","html_url":"https://github.com/tjlang","followers_url":"https://api.github.com/users/tjlang/followers","following_url":"https://api.github.com/users/tjlang/following{/other_user}","gists_url":"https://api.github.com/users/tjlang/gists{/gist_id}","starred_url":"https://api.github.com/users/tjlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjlang/subscriptions","organizations_url":"https://api.github.com/users/tjlang/orgs","repos_url":"https://api.github.com/users/tjlang/repos","events_url":"https://api.github.com/users/tjlang/events{/privacy}","received_events_url":"https://api.github.com/users/tjlang/received_events","type":"User","site_admin":false},"body":"Added GeoTIFF output capabilities to `pyart.io` module. New function is `pyart.io.write_grid_geotiff`, and it accepts Py-ART `Grid` objects. New functionality adds `gdal` as an optional dependency. If not installed, the function will complain and not work.\r\n\r\nExample usage:\r\n```\r\npyart.io.write_grid_geotiff(\r\n    'test_radar_fp.tiff', grid, field='ZC', cmap='pyart_NWSRef',\r\n    rgb=True, vmin=0, vmax=75, warp=True, sld=False)\r\n```\r\n\r\nThis creates a simple 3-channel RGB GeoTIFF of composite reflectivity (ZC field), warped to a WGS84 lat/lon grid, using the `pyart_NWSRef` color table with min/max set at (0, 75). Here is what the output looks like in GIS software:\r\n<img width=\"1042\" alt=\"screen shot 2016-03-23 at 4 04 35 pm\" src=\"https://cloud.githubusercontent.com/assets/3036387/14001550/78ca2d5c-f114-11e5-89ba-f486e6164f3a.png\">\r\n\r\nOne can also output single-channel floating point data to the GeoTIFF, and create an ancillary Style Layer Descriptor (SLD) file containing color table info.\r\n\r\nExample usage:\r\n```\r\nimport dualpol\r\nhidcolor = dualpol.HidColors()\r\npyart.io.write_grid_geotiff(\r\n    'test_radar.tiff', grid, field='FH', level=4, cmap=hidcolor.cmaphid,\r\n    rgb=False, vmin=0, vmax=10, color_levels=10, warp=True, sld=True)\r\n```\r\n\r\nThis creates a GeoTIFF with HID index values following the `dualpol` paradigm (https://github.com/nasa/DualPol). The SLD file that is created contains the default `dualpol` HID colormap, which is categorical and has 10 entries. The output is valid for vertical level 4 in the Py-ART `Grid` object (2.5 km MSL in this case).\r\n\r\nWhat it looks like in GIS software:\r\n<img width=\"1042\" alt=\"screen shot 2016-03-23 at 4 36 50 pm\" src=\"https://cloud.githubusercontent.com/assets/3036387/14001740/9f71b10e-f115-11e5-917b-ceb8f6f50df8.png\">\r\n","created_at":"2016-03-23T21:44:30Z","updated_at":"2016-03-29T15:42:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75359074a719b4f12c5f772603f483c9f830b06e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511/commits","review_comments_url":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511/comments","review_comment_url":"https://api.github.com/repos/ARM-DOE/pyart/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ARM-DOE/pyart/issues/511/comments","statuses_url":"https://api.github.com/repos/ARM-DOE/pyart/statuses/79e56667a7ddd9f0d89480eaafc57e05db1d9555","head":{"label":"tjlang:master","ref":"master","sha":"79e56667a7ddd9f0d89480eaafc57e05db1d9555","user":{"login":"tjlang","id":3036387,"avatar_url":"https://avatars.githubusercontent.com/u/3036387?v=3","gravatar_id":"","url":"https://api.github.com/users/tjlang","html_url":"https://github.com/tjlang","followers_url":"https://api.github.com/users/tjlang/followers","following_url":"https://api.github.com/users/tjlang/following{/other_user}","gists_url":"https://api.github.com/users/tjlang/gists{/gist_id}","starred_url":"https://api.github.com/users/tjlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjlang/subscriptions","organizations_url":"https://api.github.com/users/tjlang/orgs","repos_url":"https://api.github.com/users/tjlang/repos","events_url":"https://api.github.com/users/tjlang/events{/privacy}","received_events_url":"https://api.github.com/users/tjlang/received_events","type":"User","site_admin":false},"repo":{"id":33682303,"name":"pyart","full_name":"tjlang/pyart","owner":{"login":"tjlang","id":3036387,"avatar_url":"https://avatars.githubusercontent.com/u/3036387?v=3","gravatar_id":"","url":"https://api.github.com/users/tjlang","html_url":"https://github.com/tjlang","followers_url":"https://api.github.com/users/tjlang/followers","following_url":"https://api.github.com/users/tjlang/following{/other_user}","gists_url":"https://api.github.com/users/tjlang/gists{/gist_id}","starred_url":"https://api.github.com/users/tjlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjlang/subscriptions","organizations_url":"https://api.github.com/users/tjlang/orgs","repos_url":"https://api.github.com/users/tjlang/repos","events_url":"https://api.github.com/users/tjlang/events{/privacy}","received_events_url":"https://api.github.com/users/tjlang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tjlang/pyart","description":"The Python-ARM Radar Toolkit. An data model driven interactive toolkit for working with weather radar data. ","fork":true,"url":"https://api.github.com/repos/tjlang/pyart","forks_url":"https://api.github.com/repos/tjlang/pyart/forks","keys_url":"https://api.github.com/repos/tjlang/pyart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tjlang/pyart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tjlang/pyart/teams","hooks_url":"https://api.github.com/repos/tjlang/pyart/hooks","issue_events_url":"https://api.github.com/repos/tjlang/pyart/issues/events{/number}","events_url":"https://api.github.com/repos/tjlang/pyart/events","assignees_url":"https://api.github.com/repos/tjlang/pyart/assignees{/user}","branches_url":"https://api.github.com/repos/tjlang/pyart/branches{/branch}","tags_url":"https://api.github.com/repos/tjlang/pyart/tags","blobs_url":"https://api.github.com/repos/tjlang/pyart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tjlang/pyart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tjlang/pyart/git/refs{/sha}","trees_url":"https://api.github.com/repos/tjlang/pyart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tjlang/pyart/statuses/{sha}","languages_url":"https://api.github.com/repos/tjlang/pyart/languages","stargazers_url":"https://api.github.com/repos/tjlang/pyart/stargazers","contributors_url":"https://api.github.com/repos/tjlang/pyart/contributors","subscribers_url":"https://api.github.com/repos/tjlang/pyart/subscribers","subscription_url":"https://api.github.com/repos/tjlang/pyart/subscription","commits_url":"https://api.github.com/repos/tjlang/pyart/commits{/sha}","git_commits_url":"https://api.github.com/repos/tjlang/pyart/git/commits{/sha}","comments_url":"https://api.github.com/repos/tjlang/pyart/comments{/number}","issue_comment_url":"https://api.github.com/repos/tjlang/pyart/issues/comments{/number}","contents_url":"https://api.github.com/repos/tjlang/pyart/contents/{+path}","compare_url":"https://api.github.com/repos/tjlang/pyart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tjlang/pyart/merges","archive_url":"https://api.github.com/repos/tjlang/pyart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tjlang/pyart/downloads","issues_url":"https://api.github.com/repos/tjlang/pyart/issues{/number}","pulls_url":"https://api.github.com/repos/tjlang/pyart/pulls{/number}","milestones_url":"https://api.github.com/repos/tjlang/pyart/milestones{/number}","notifications_url":"https://api.github.com/repos/tjlang/pyart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tjlang/pyart/labels{/name}","releases_url":"https://api.github.com/repos/tjlang/pyart/releases{/id}","deployments_url":"https://api.github.com/repos/tjlang/pyart/deployments","created_at":"2015-04-09T17:18:52Z","updated_at":"2016-03-23T19:45:34Z","pushed_at":"2016-03-23T21:26:48Z","git_url":"git://github.com/tjlang/pyart.git","ssh_url":"git@github.com:tjlang/pyart.git","clone_url":"https://github.com/tjlang/pyart.git","svn_url":"https://github.com/tjlang/pyart","homepage":"http://arm-doe.github.io/pyart/","size":51301,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ARM-DOE:master","ref":"master","sha":"e5d771c8db5b3b23f54d4e9ce0e2fc5528b2bc28","user":{"login":"ARM-DOE","id":2540600,"avatar_url":"https://avatars.githubusercontent.com/u/2540600?v=3","gravatar_id":"","url":"https://api.github.com/users/ARM-DOE","html_url":"https://github.com/ARM-DOE","followers_url":"https://api.github.com/users/ARM-DOE/followers","following_url":"https://api.github.com/users/ARM-DOE/following{/other_user}","gists_url":"https://api.github.com/users/ARM-DOE/gists{/gist_id}","starred_url":"https://api.github.com/users/ARM-DOE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARM-DOE/subscriptions","organizations_url":"https://api.github.com/users/ARM-DOE/orgs","repos_url":"https://api.github.com/users/ARM-DOE/repos","events_url":"https://api.github.com/users/ARM-DOE/events{/privacy}","received_events_url":"https://api.github.com/users/ARM-DOE/received_events","type":"Organization","site_admin":false},"repo":{"id":6248645,"name":"pyart","full_name":"ARM-DOE/pyart","owner":{"login":"ARM-DOE","id":2540600,"avatar_url":"https://avatars.githubusercontent.com/u/2540600?v=3","gravatar_id":"","url":"https://api.github.com/users/ARM-DOE","html_url":"https://github.com/ARM-DOE","followers_url":"https://api.github.com/users/ARM-DOE/followers","following_url":"https://api.github.com/users/ARM-DOE/following{/other_user}","gists_url":"https://api.github.com/users/ARM-DOE/gists{/gist_id}","starred_url":"https://api.github.com/users/ARM-DOE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARM-DOE/subscriptions","organizations_url":"https://api.github.com/users/ARM-DOE/orgs","repos_url":"https://api.github.com/users/ARM-DOE/repos","events_url":"https://api.github.com/users/ARM-DOE/events{/privacy}","received_events_url":"https://api.github.com/users/ARM-DOE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ARM-DOE/pyart","description":"The Python-ARM Radar Toolkit. An data model driven interactive toolkit for working with weather radar data. ","fork":false,"url":"https://api.github.com/repos/ARM-DOE/pyart","forks_url":"https://api.github.com/repos/ARM-DOE/pyart/forks","keys_url":"https://api.github.com/repos/ARM-DOE/pyart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ARM-DOE/pyart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ARM-DOE/pyart/teams","hooks_url":"https://api.github.com/repos/ARM-DOE/pyart/hooks","issue_events_url":"https://api.github.com/repos/ARM-DOE/pyart/issues/events{/number}","events_url":"https://api.github.com/repos/ARM-DOE/pyart/events","assignees_url":"https://api.github.com/repos/ARM-DOE/pyart/assignees{/user}","branches_url":"https://api.github.com/repos/ARM-DOE/pyart/branches{/branch}","tags_url":"https://api.github.com/repos/ARM-DOE/pyart/tags","blobs_url":"https://api.github.com/repos/ARM-DOE/pyart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ARM-DOE/pyart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ARM-DOE/pyart/git/refs{/sha}","trees_url":"https://api.github.com/repos/ARM-DOE/pyart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ARM-DOE/pyart/statuses/{sha}","languages_url":"https://api.github.com/repos/ARM-DOE/pyart/languages","stargazers_url":"https://api.github.com/repos/ARM-DOE/pyart/stargazers","contributors_url":"https://api.github.com/repos/ARM-DOE/pyart/contributors","subscribers_url":"https://api.github.com/repos/ARM-DOE/pyart/subscribers","subscription_url":"https://api.github.com/repos/ARM-DOE/pyart/subscription","commits_url":"https://api.github.com/repos/ARM-DOE/pyart/commits{/sha}","git_commits_url":"https://api.github.com/repos/ARM-DOE/pyart/git/commits{/sha}","comments_url":"https://api.github.com/repos/ARM-DOE/pyart/comments{/number}","issue_comment_url":"https://api.github.com/repos/ARM-DOE/pyart/issues/comments{/number}","contents_url":"https://api.github.com/repos/ARM-DOE/pyart/contents/{+path}","compare_url":"https://api.github.com/repos/ARM-DOE/pyart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ARM-DOE/pyart/merges","archive_url":"https://api.github.com/repos/ARM-DOE/pyart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ARM-DOE/pyart/downloads","issues_url":"https://api.github.com/repos/ARM-DOE/pyart/issues{/number}","pulls_url":"https://api.github.com/repos/ARM-DOE/pyart/pulls{/number}","milestones_url":"https://api.github.com/repos/ARM-DOE/pyart/milestones{/number}","notifications_url":"https://api.github.com/repos/ARM-DOE/pyart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ARM-DOE/pyart/labels{/name}","releases_url":"https://api.github.com/repos/ARM-DOE/pyart/releases{/id}","deployments_url":"https://api.github.com/repos/ARM-DOE/pyart/deployments","created_at":"2012-10-16T17:51:30Z","updated_at":"2016-03-17T16:54:26Z","pushed_at":"2016-03-27T21:39:15Z","git_url":"git://github.com/ARM-DOE/pyart.git","ssh_url":"git@github.com:ARM-DOE/pyart.git","clone_url":"https://github.com/ARM-DOE/pyart.git","svn_url":"https://github.com/ARM-DOE/pyart","homepage":"http://arm-doe.github.io/pyart/","size":69367,"stargazers_count":58,"watchers_count":58,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":53,"mirror_url":null,"open_issues_count":46,"forks":53,"open_issues":46,"watchers":58,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511"},"html":{"href":"https://github.com/ARM-DOE/pyart/pull/511"},"issue":{"href":"https://api.github.com/repos/ARM-DOE/pyart/issues/511"},"comments":{"href":"https://api.github.com/repos/ARM-DOE/pyart/issues/511/comments"},"review_comments":{"href":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511/comments"},"review_comment":{"href":"https://api.github.com/repos/ARM-DOE/pyart/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ARM-DOE/pyart/pulls/511/commits"},"statuses":{"href":"https://api.github.com/repos/ARM-DOE/pyart/statuses/79e56667a7ddd9f0d89480eaafc57e05db1d9555"}}}}