{"action":"created","comment":{"url":"https://api.github.com/repos/SciTools/iris/pulls/comments/103902714","pull_request_review_id":24707444,"id":103902714,"diff_hunk":"@@ -0,0 +1,179 @@\n+# (C) British Crown Copyright 2017, Met Office\n+#\n+# This file is part of Iris.\n+#\n+# Iris is free software: you can redistribute it and/or modify it under\n+# the terms of the GNU Lesser General Public License as published by the\n+# Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# Iris is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU Lesser General Public License for more details.\n+#\n+# You should have received a copy of the GNU Lesser General Public License\n+# along with Iris.  If not, see <http://www.gnu.org/licenses/>.\n+\"\"\"\n+Routines for putting data on new strata (aka. isosurfaces), often in the\n+Z direction.\n+\n+\"\"\"\n+from __future__ import (absolute_import, division, print_function)\n+from six.moves import (filter, input, map, range, zip)  # noqa\n+\n+from functools import partial\n+\n+import numpy as np\n+import stratify\n+\n+from iris.cube import Cube\n+from iris.coords import Coord, AuxCoord, DimCoord\n+\n+\n+def _copy_coords_without_dim(cube, result, z_dim):\n+    \"\"\"\n+    Helper function to copy across non-z coordinates between cubes.\n+\n+    Parameters\n+    ----------\n+    cube : iris.cube.Cube instance\n+        Incoming cube containing the coordinates to be copied.\n+    result : iris.cube.Cube instance\n+        Incoming cube for the coordinates to be copied to.\n+    z_dim : Dimension within the cube of the z-dimension\n+        The dimension will not be copied, as the incoming z-dimension\n+        is model level_height, whilst the outgoing z-dimension is pressure.\n+\n+    Returns\n+    -------\n+    Cube\n+        A single cube with the non-z dimensions added to\n+        incoming cube.\n+\n+    \"\"\"\n+    # Copy across non-Z coordinates.\n+    for coord in cube.dim_coords:\n+        dim, = cube.coord_dims(coord)\n+        if dim != z_dim:\n+            result.add_dim_coord(coord.copy(), dim)\n+    for coord in cube.aux_coords:\n+        dims = cube.coord_dims(coord)\n+        if z_dim not in dims:\n+            result.add_aux_coord(coord.copy(), dims)\n+    for coord in cube.derived_coords:\n+        dims = cube.coord_dims(coord)\n+        if z_dim not in dims:\n+            result.add_aux_coord(coord.copy(), dims)\n+\n+\n+def relevel(phenom, level_data, target_levels, interp_direction=0,\n+            interpolator=None):\n+    \"\"\"\n+    Interpolate the given phenomenon onto the given levels of level_data.\n+\n+    For example, suppose we have two datasets `P(i,j,k)` and `H(i,j,k)`\n+    and we want ``P(i,j,H)`` we call relevel with\n+    ``phenom=P`` and ``level_data=H`` and ``target_levels`` being\n+    an array of the values of ``H`` we would like.\n+\n+    This routine is especially useful for computing isosurfaces of\n+    phenomenon that are generally monotonic in the direction of interpolation\n+    (such as height/pressure and salinity/depth).\n+\n+    Parameters\n+    ----------\n+    phenom : :class:`iris.cube.Cube`\n+        The data to be re-levelled.\n+\n+    level_data : :class:`~iris.cube.Cube` or :class:`~iris.coord.Coord`\n+        The coordinate values (cube/coord) in the same system as\n+        ``target levels``.\n+        All dimensions of ``level_data`` must be broadcastable to ``phenom``\n+\n+    target_levels : array-like\n+        The levels of ``level_data`` to pick from ``phenom``.\n+        For the default interpolator, this must be a 1d array.\n+        For a custom interpolator this may be multi-dimensional and must\n+        broadcast to phenom and level_data except in the phenomenon's\n+        ``interp_direction`` dimension.\n+\n+    interp_direction : int or :class:`~iris.coords.Coord` instance\n+        The direction of interpolation. This is necessary because\n+        level_data is rarely 1D. This is often the z dimension coordinate\n+        of ``phenom``.\n+\n+    interpolator : callable or None\n+        The interpolator to use when computing the interpolation. The function\n+        will be passed the following positional arguments::\n+\n+            (target levels, level data, phenom data, interp axis)\n+\n+        If the interpolator is None, :func:`stratify.interpolate` will be used\n+        with linear interpolation and NaN extrapolation.\n+\n+        An example of constructing an alternative interpolation scheme:\n+\n+            from functools import partial\n+            interpolator = partial(stratify.interpolate,\n+                                   interpolation=stratify.INTERPOLATE_NEAREST,\n+                                   extrapolation=stratify.EXTRAPOLATE_LINEAR)\n+\n+    \"\"\"\n+    # Identify the z-coordinate within the phenom cube\n+    if isinstance(interp_direction, Coord):","path":"lib/iris/experimental/stratify.py","position":124,"original_position":124,"commit_id":"c30fb369960e614642b1722b44d57518a1b42579","original_commit_id":"c30fb369960e614642b1722b44d57518a1b42579","user":{"login":"bjlittle","id":2051656,"avatar_url":"https://avatars1.githubusercontent.com/u/2051656?v=3","gravatar_id":"","url":"https://api.github.com/users/bjlittle","html_url":"https://github.com/bjlittle","followers_url":"https://api.github.com/users/bjlittle/followers","following_url":"https://api.github.com/users/bjlittle/following{/other_user}","gists_url":"https://api.github.com/users/bjlittle/gists{/gist_id}","starred_url":"https://api.github.com/users/bjlittle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjlittle/subscriptions","organizations_url":"https://api.github.com/users/bjlittle/orgs","repos_url":"https://api.github.com/users/bjlittle/repos","events_url":"https://api.github.com/users/bjlittle/events{/privacy}","received_events_url":"https://api.github.com/users/bjlittle/received_events","type":"User","site_admin":false},"body":"@pelson It would be handy to allow the name of the coordinate to be used as well - that aligns with other similar use patterns in iris.","created_at":"2017-03-02T11:25:29Z","updated_at":"2017-03-02T11:25:29Z","html_url":"https://github.com/SciTools/iris/pull/2320#discussion_r103902714","pull_request_url":"https://api.github.com/repos/SciTools/iris/pulls/2320","_links":{"self":{"href":"https://api.github.com/repos/SciTools/iris/pulls/comments/103902714"},"html":{"href":"https://github.com/SciTools/iris/pull/2320#discussion_r103902714"},"pull_request":{"href":"https://api.github.com/repos/SciTools/iris/pulls/2320"}}},"pull_request":{"url":"https://api.github.com/repos/SciTools/iris/pulls/2320","id":102211751,"html_url":"https://github.com/SciTools/iris/pull/2320","diff_url":"https://github.com/SciTools/iris/pull/2320.diff","patch_url":"https://github.com/SciTools/iris/pull/2320.patch","issue_url":"https://api.github.com/repos/SciTools/iris/issues/2320","number":2320,"state":"open","locked":false,"title":"Added a ruidmentary stratification/relevel/isosurface algorithm.","user":{"login":"pelson","id":810663,"avatar_url":"https://avatars0.githubusercontent.com/u/810663?v=3","gravatar_id":"","url":"https://api.github.com/users/pelson","html_url":"https://github.com/pelson","followers_url":"https://api.github.com/users/pelson/followers","following_url":"https://api.github.com/users/pelson/following{/other_user}","gists_url":"https://api.github.com/users/pelson/gists{/gist_id}","starred_url":"https://api.github.com/users/pelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelson/subscriptions","organizations_url":"https://api.github.com/users/pelson/orgs","repos_url":"https://api.github.com/users/pelson/repos","events_url":"https://api.github.com/users/pelson/events{/privacy}","received_events_url":"https://api.github.com/users/pelson/received_events","type":"User","site_admin":false},"body":"Gives Iris the ability to extract isomorphic isosurfaces. For example, this algorithm could be used to pick off a 2000m surface from data on model level data (which does not have a 1d height coordinate).\r\n\r\nI'll be more than happy to add an example to the user guide once this is in (I may even do that before it gets merged).\r\n\r\nPing @cpelley.","created_at":"2017-01-19T07:03:01Z","updated_at":"2017-03-02T11:25:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45c3c230eb8e70b93f830c2d3a9a9737585b71d3","assignee":{"login":"bjlittle","id":2051656,"avatar_url":"https://avatars1.githubusercontent.com/u/2051656?v=3","gravatar_id":"","url":"https://api.github.com/users/bjlittle","html_url":"https://github.com/bjlittle","followers_url":"https://api.github.com/users/bjlittle/followers","following_url":"https://api.github.com/users/bjlittle/following{/other_user}","gists_url":"https://api.github.com/users/bjlittle/gists{/gist_id}","starred_url":"https://api.github.com/users/bjlittle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjlittle/subscriptions","organizations_url":"https://api.github.com/users/bjlittle/orgs","repos_url":"https://api.github.com/users/bjlittle/repos","events_url":"https://api.github.com/users/bjlittle/events{/privacy}","received_events_url":"https://api.github.com/users/bjlittle/received_events","type":"User","site_admin":false},"assignees":[{"login":"bjlittle","id":2051656,"avatar_url":"https://avatars1.githubusercontent.com/u/2051656?v=3","gravatar_id":"","url":"https://api.github.com/users/bjlittle","html_url":"https://github.com/bjlittle","followers_url":"https://api.github.com/users/bjlittle/followers","following_url":"https://api.github.com/users/bjlittle/following{/other_user}","gists_url":"https://api.github.com/users/bjlittle/gists{/gist_id}","starred_url":"https://api.github.com/users/bjlittle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjlittle/subscriptions","organizations_url":"https://api.github.com/users/bjlittle/orgs","repos_url":"https://api.github.com/users/bjlittle/repos","events_url":"https://api.github.com/users/bjlittle/events{/privacy}","received_events_url":"https://api.github.com/users/bjlittle/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/SciTools/iris/pulls/2320/commits","review_comments_url":"https://api.github.com/repos/SciTools/iris/pulls/2320/comments","review_comment_url":"https://api.github.com/repos/SciTools/iris/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SciTools/iris/issues/2320/comments","statuses_url":"https://api.github.com/repos/SciTools/iris/statuses/c30fb369960e614642b1722b44d57518a1b42579","head":{"label":"pelson:stratify_interface","ref":"stratify_interface","sha":"c30fb369960e614642b1722b44d57518a1b42579","user":{"login":"pelson","id":810663,"avatar_url":"https://avatars0.githubusercontent.com/u/810663?v=3","gravatar_id":"","url":"https://api.github.com/users/pelson","html_url":"https://github.com/pelson","followers_url":"https://api.github.com/users/pelson/followers","following_url":"https://api.github.com/users/pelson/following{/other_user}","gists_url":"https://api.github.com/users/pelson/gists{/gist_id}","starred_url":"https://api.github.com/users/pelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelson/subscriptions","organizations_url":"https://api.github.com/users/pelson/orgs","repos_url":"https://api.github.com/users/pelson/repos","events_url":"https://api.github.com/users/pelson/events{/privacy}","received_events_url":"https://api.github.com/users/pelson/received_events","type":"User","site_admin":false},"repo":{"id":5312802,"name":"iris","full_name":"pelson/iris","owner":{"login":"pelson","id":810663,"avatar_url":"https://avatars0.githubusercontent.com/u/810663?v=3","gravatar_id":"","url":"https://api.github.com/users/pelson","html_url":"https://github.com/pelson","followers_url":"https://api.github.com/users/pelson/followers","following_url":"https://api.github.com/users/pelson/following{/other_user}","gists_url":"https://api.github.com/users/pelson/gists{/gist_id}","starred_url":"https://api.github.com/users/pelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelson/subscriptions","organizations_url":"https://api.github.com/users/pelson/orgs","repos_url":"https://api.github.com/users/pelson/repos","events_url":"https://api.github.com/users/pelson/events{/privacy}","received_events_url":"https://api.github.com/users/pelson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pelson/iris","description":null,"fork":true,"url":"https://api.github.com/repos/pelson/iris","forks_url":"https://api.github.com/repos/pelson/iris/forks","keys_url":"https://api.github.com/repos/pelson/iris/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pelson/iris/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pelson/iris/teams","hooks_url":"https://api.github.com/repos/pelson/iris/hooks","issue_events_url":"https://api.github.com/repos/pelson/iris/issues/events{/number}","events_url":"https://api.github.com/repos/pelson/iris/events","assignees_url":"https://api.github.com/repos/pelson/iris/assignees{/user}","branches_url":"https://api.github.com/repos/pelson/iris/branches{/branch}","tags_url":"https://api.github.com/repos/pelson/iris/tags","blobs_url":"https://api.github.com/repos/pelson/iris/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pelson/iris/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pelson/iris/git/refs{/sha}","trees_url":"https://api.github.com/repos/pelson/iris/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pelson/iris/statuses/{sha}","languages_url":"https://api.github.com/repos/pelson/iris/languages","stargazers_url":"https://api.github.com/repos/pelson/iris/stargazers","contributors_url":"https://api.github.com/repos/pelson/iris/contributors","subscribers_url":"https://api.github.com/repos/pelson/iris/subscribers","subscription_url":"https://api.github.com/repos/pelson/iris/subscription","commits_url":"https://api.github.com/repos/pelson/iris/commits{/sha}","git_commits_url":"https://api.github.com/repos/pelson/iris/git/commits{/sha}","comments_url":"https://api.github.com/repos/pelson/iris/comments{/number}","issue_comment_url":"https://api.github.com/repos/pelson/iris/issues/comments{/number}","contents_url":"https://api.github.com/repos/pelson/iris/contents/{+path}","compare_url":"https://api.github.com/repos/pelson/iris/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pelson/iris/merges","archive_url":"https://api.github.com/repos/pelson/iris/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pelson/iris/downloads","issues_url":"https://api.github.com/repos/pelson/iris/issues{/number}","pulls_url":"https://api.github.com/repos/pelson/iris/pulls{/number}","milestones_url":"https://api.github.com/repos/pelson/iris/milestones{/number}","notifications_url":"https://api.github.com/repos/pelson/iris/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pelson/iris/labels{/name}","releases_url":"https://api.github.com/repos/pelson/iris/releases{/id}","deployments_url":"https://api.github.com/repos/pelson/iris/deployments","created_at":"2012-08-06T10:25:43Z","updated_at":"2014-06-17T12:48:28Z","pushed_at":"2017-01-31T23:10:16Z","git_url":"git://github.com/pelson/iris.git","ssh_url":"git@github.com:pelson/iris.git","clone_url":"https://github.com/pelson/iris.git","svn_url":"https://github.com/pelson/iris","homepage":null,"size":111859,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"null"}},"base":{"label":"SciTools:master","ref":"master","sha":"9b40d40aa2b6df15e9b6a65ba3d6bf653a212f79","user":{"login":"SciTools","id":1391487,"avatar_url":"https://avatars0.githubusercontent.com/u/1391487?v=3","gravatar_id":"","url":"https://api.github.com/users/SciTools","html_url":"https://github.com/SciTools","followers_url":"https://api.github.com/users/SciTools/followers","following_url":"https://api.github.com/users/SciTools/following{/other_user}","gists_url":"https://api.github.com/users/SciTools/gists{/gist_id}","starred_url":"https://api.github.com/users/SciTools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciTools/subscriptions","organizations_url":"https://api.github.com/users/SciTools/orgs","repos_url":"https://api.github.com/users/SciTools/repos","events_url":"https://api.github.com/users/SciTools/events{/privacy}","received_events_url":"https://api.github.com/users/SciTools/received_events","type":"Organization","site_admin":false},"repo":{"id":5312648,"name":"iris","full_name":"SciTools/iris","owner":{"login":"SciTools","id":1391487,"avatar_url":"https://avatars0.githubusercontent.com/u/1391487?v=3","gravatar_id":"","url":"https://api.github.com/users/SciTools","html_url":"https://github.com/SciTools","followers_url":"https://api.github.com/users/SciTools/followers","following_url":"https://api.github.com/users/SciTools/following{/other_user}","gists_url":"https://api.github.com/users/SciTools/gists{/gist_id}","starred_url":"https://api.github.com/users/SciTools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciTools/subscriptions","organizations_url":"https://api.github.com/users/SciTools/orgs","repos_url":"https://api.github.com/users/SciTools/repos","events_url":"https://api.github.com/users/SciTools/events{/privacy}","received_events_url":"https://api.github.com/users/SciTools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SciTools/iris","description":"A powerful, easy to use, and community-driven Python library for analysing and visualising meteorological and oceanographic data sets.","fork":false,"url":"https://api.github.com/repos/SciTools/iris","forks_url":"https://api.github.com/repos/SciTools/iris/forks","keys_url":"https://api.github.com/repos/SciTools/iris/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SciTools/iris/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SciTools/iris/teams","hooks_url":"https://api.github.com/repos/SciTools/iris/hooks","issue_events_url":"https://api.github.com/repos/SciTools/iris/issues/events{/number}","events_url":"https://api.github.com/repos/SciTools/iris/events","assignees_url":"https://api.github.com/repos/SciTools/iris/assignees{/user}","branches_url":"https://api.github.com/repos/SciTools/iris/branches{/branch}","tags_url":"https://api.github.com/repos/SciTools/iris/tags","blobs_url":"https://api.github.com/repos/SciTools/iris/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SciTools/iris/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SciTools/iris/git/refs{/sha}","trees_url":"https://api.github.com/repos/SciTools/iris/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SciTools/iris/statuses/{sha}","languages_url":"https://api.github.com/repos/SciTools/iris/languages","stargazers_url":"https://api.github.com/repos/SciTools/iris/stargazers","contributors_url":"https://api.github.com/repos/SciTools/iris/contributors","subscribers_url":"https://api.github.com/repos/SciTools/iris/subscribers","subscription_url":"https://api.github.com/repos/SciTools/iris/subscription","commits_url":"https://api.github.com/repos/SciTools/iris/commits{/sha}","git_commits_url":"https://api.github.com/repos/SciTools/iris/git/commits{/sha}","comments_url":"https://api.github.com/repos/SciTools/iris/comments{/number}","issue_comment_url":"https://api.github.com/repos/SciTools/iris/issues/comments{/number}","contents_url":"https://api.github.com/repos/SciTools/iris/contents/{+path}","compare_url":"https://api.github.com/repos/SciTools/iris/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SciTools/iris/merges","archive_url":"https://api.github.com/repos/SciTools/iris/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SciTools/iris/downloads","issues_url":"https://api.github.com/repos/SciTools/iris/issues{/number}","pulls_url":"https://api.github.com/repos/SciTools/iris/pulls{/number}","milestones_url":"https://api.github.com/repos/SciTools/iris/milestones{/number}","notifications_url":"https://api.github.com/repos/SciTools/iris/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SciTools/iris/labels{/name}","releases_url":"https://api.github.com/repos/SciTools/iris/releases{/id}","deployments_url":"https://api.github.com/repos/SciTools/iris/deployments","created_at":"2012-08-06T10:09:14Z","updated_at":"2017-02-13T08:41:32Z","pushed_at":"2017-02-28T11:37:04Z","git_url":"git://github.com/SciTools/iris.git","ssh_url":"git@github.com:SciTools/iris.git","clone_url":"https://github.com/SciTools/iris.git","svn_url":"https://github.com/SciTools/iris","homepage":"http://scitools.org.uk/iris/","size":102722,"stargazers_count":151,"watchers_count":151,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":111,"mirror_url":null,"open_issues_count":318,"forks":111,"open_issues":318,"watchers":151,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SciTools/iris/pulls/2320"},"html":{"href":"https://github.com/SciTools/iris/pull/2320"},"issue":{"href":"https://api.github.com/repos/SciTools/iris/issues/2320"},"comments":{"href":"https://api.github.com/repos/SciTools/iris/issues/2320/comments"},"review_comments":{"href":"https://api.github.com/repos/SciTools/iris/pulls/2320/comments"},"review_comment":{"href":"https://api.github.com/repos/SciTools/iris/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SciTools/iris/pulls/2320/commits"},"statuses":{"href":"https://api.github.com/repos/SciTools/iris/statuses/c30fb369960e614642b1722b44d57518a1b42579"}}}}
{"actor":{"display_login":"bjlittle"}}