{"action":"created","comment":{"url":"https://api.github.com/repos/odlgroup/odl/pulls/comments/76202508","id":76202508,"diff_hunk":"@@ -0,0 +1,548 @@\n+# Copyright 2014-2016 The ODL development group\n+#\n+# This file is part of ODL.\n+#\n+# ODL is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# ODL 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 General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with ODL.  If not, see <http://www.gnu.org/licenses/>.\n+\n+\"\"\"Operators and functions for general and mass-preserving deformation.\"\"\"\n+\n+# Imports for common Python 2/3 codebase\n+from __future__ import print_function, division, absolute_import\n+from future import standard_library\n+standard_library.install_aliases()\n+from builtins import super\n+\n+from odl.discr import DiscreteLp, DiscreteLpVector\n+from odl.operator.operator import Operator\n+from odl.space import ProductSpaceVector, ProductSpace\n+\n+\n+__all__ = ('GeneralDeformFixedTempl', 'GeneralDeformFixedDeform',\n+           'MassPresvDeformFixedTempl', 'MassPresvDeformFixedDeform')\n+\n+\n+def _general_deform(template, deformation, out=None):\n+    \"\"\"Deform a template with a general deformation field.\n+\n+    The function maps a given template ``I`` and a given deformation\n+    field ``phi`` to the new function ``x --> I(phi(x))``.\n+\n+    Parameters\n+    ----------\n+    template : `DiscreteLpVector`\n+        Template to be deformed by a deformation field.\n+    deformation : element of power space of `DiscreteLp`\n+        The deformation field used to deform the template.\n+    out : `numpy.ndarray`, optional\n+        Array to which the function values of the deformed template\n+        are written. It must have the same shape as ``template`` and\n+        a data type compatible with ``template.dtype``.\n+\n+    Returns\n+    -------\n+    deformed_template : `numpy.ndarray`\n+        Function values of the deformed template. If ``out`` was given,\n+        the returned object is a reference to it.\n+\n+    Examples\n+    --------\n+    Create a simple 1D template and a deformation field. Where the deformation\n+    is identity, the output value is the same as the input value.\n+    In the 4-th point, the value is taken from 0.2 (one cell) to\n+    the left, i.e. 1.0.\n+\n+    >>> import odl\n+    >>> space = odl.uniform_discr(0, 1, 5, interp='nearest')\n+    >>> deform_field_space = space.vector_field_space\n+    >>> template = space.element([0, 0, 1, 0, 0])\n+    >>> deform_field = deform_field_space.element([[0.1, 0.3, 0.5, 0.5, 0.9]])\n+    >>> _general_deform(template, deform_field)\n+    array([ 0.,  0.,  1.,  1.,  0.])\n+\n+    The result depends on the chosen interpolation. With 'linear'\n+    interpolation and an offset equal to half the distance between two\n+    points, 0.1, one gets the mean of the values.\n+\n+    >>> space = odl.uniform_discr(0, 1, 5, interp='linear')\n+    >>> deform_field_space = space.vector_field_space\n+    >>> template = space.element([0, 0, 1, 0, 0])\n+    >>> deform_field = deform_field_space.element([[0.1, 0.3, 0.5, 0.6, 0.9]])\n+    >>> _general_deform(template, deform_field)\n+    array([ 0. ,  0. ,  1. ,  0.5,  0. ])\n+    \"\"\"\n+    image_pts = template.space.points()\n+    for i, vi in enumerate(deformation):\n+        image_pts[:, i] = vi.ntuple.asarray()\n+    return template.interpolation(image_pts.T, out=out, bounds_check=False)\n+\n+\n+def _mass_presv_deform(template, mass_presv_dfield, out=None):\n+    \"\"\"Deform a template with a mass-preserving deformation field.\n+\n+    The function maps a given template ``I``, a mass-preserving deformation\n+    field, i.e., a given deformation field ``phi`` and its Jacobian\n+    determinant to the new function ``x --> |Dphi(x)|I(phi(x))``.\n+\n+    Parameters\n+    ----------\n+    template : `DiscreteLpVector`\n+        Template to be deformed by a deformation field.\n+    mass_presv_dfield : element of power space of power space and `DiscreteLp`\n+        The mass-preserving deformation field used to deform the template.\n+        It contains the deformation, i.e., an element of power space\n+        of `DiscreteLp`, and the Jacobian determinant of the deformation,\n+        i.e., a `DiscreteLpVector`.\n+    out : `numpy.ndarray`, optional\n+        Array to which the function values of the deformed template\n+        are written. It must have the same shape as ``template`` and\n+        a data type compatible with ``template.dtype``.\n+\n+    Returns\n+    -------\n+    deformed_template : `numpy.ndarray`\n+        Function values of the deformed template. If ``out`` was given,\n+        the returned object is a reference to it.\n+\n+    Examples\n+    --------\n+    Create a simple 1D template ``I`` over ``[0, 1]``, a deffeomorphic\n+    deformation field and its Jacobian determinant.\n+    If the deffeomorphism ``phi`` is ``sin(x*pi/2)``, its Jacobian determinant\n+    should be ``cos(x*pi/2)*pi/2`` and the output value is\n+    ``cos(x*pi/2)*pi/2*I(sin(x*pi/2))``. A mass-preserving deformation\n+    is obtained, namely, the integration of ``I(x)`` over ``[0, 1]``\n+    equals to the integration of ``|Dphi(x)|I(phi(x))`` over ``[0, 1]``.\n+\n+\n+    >>> import odl\n+    >>> import numpy as np\n+    >>> space = odl.uniform_discr(0, 1, 5, interp='linear')\n+    >>> vspace = space.vector_field_space\n+    >>> pspace = odl.ProductSpace(vspace, space)\n+    >>> template = space.element([0, 0, 1, 0, 0])\n+    >>> deform_field = vspace.element([np.sin(space.points() * np.pi / 2.0)])\n+    >>> det = space.element(np.cos(space.points() * np.pi / 2.0) * np.pi / 2.0)\n+    >>> mass_presv_field = pspace.element()\n+    >>> mass_presv_field[0] = deform_field\n+    >>> mass_presv_field[1] = det\n+    >>> print(_mass_presv_deform(template, mass_presv_field))\n+    [0.0, 1.07761764468, 0.0, 0.0, 0.0]\n+    \"\"\"\n+    general_deform_template = _general_deform(template, mass_presv_dfield[0])\n+    return mass_presv_dfield[1] * general_deform_template\n+\n+\n+class GeneralDeformFixedTempl(Operator):","path":"odl/deform/mass_preserving.py","position":null,"original_position":146,"commit_id":"5647529d49ef77d91dacf681379acf65bdae3ff2","original_commit_id":"8ed1c21d69cd947a148facb5538e4fdcfef0aae7","user":{"login":"chongchenmath","id":19347429,"avatar_url":"https://avatars.githubusercontent.com/u/19347429?v=3","gravatar_id":"","url":"https://api.github.com/users/chongchenmath","html_url":"https://github.com/chongchenmath","followers_url":"https://api.github.com/users/chongchenmath/followers","following_url":"https://api.github.com/users/chongchenmath/following{/other_user}","gists_url":"https://api.github.com/users/chongchenmath/gists{/gist_id}","starred_url":"https://api.github.com/users/chongchenmath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chongchenmath/subscriptions","organizations_url":"https://api.github.com/users/chongchenmath/orgs","repos_url":"https://api.github.com/users/chongchenmath/repos","events_url":"https://api.github.com/users/chongchenmath/events{/privacy}","received_events_url":"https://api.github.com/users/chongchenmath/received_events","type":"User","site_admin":false},"body":"The `deformation` is generated from `vector field` based on ODE. Then we need to use this `deformation` to deform the `template`. So the `GeometricDeformFixedTempl (GeneralDeformFixedTempl)` is presented here, which is just based on `deformation`. I think using combination is too complicated or not so flexible.","created_at":"2016-08-25T08:39:56Z","updated_at":"2016-08-25T08:39:56Z","html_url":"https://github.com/odlgroup/odl/pull/518#discussion_r76202508","pull_request_url":"https://api.github.com/repos/odlgroup/odl/pulls/518","_links":{"self":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/comments/76202508"},"html":{"href":"https://github.com/odlgroup/odl/pull/518#discussion_r76202508"},"pull_request":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/518"}}},"pull_request":{"url":"https://api.github.com/repos/odlgroup/odl/pulls/518","id":82511375,"html_url":"https://github.com/odlgroup/odl/pull/518","diff_url":"https://github.com/odlgroup/odl/pull/518.diff","patch_url":"https://github.com/odlgroup/odl/pull/518.patch","issue_url":"https://api.github.com/repos/odlgroup/odl/issues/518","number":518,"state":"open","locked":false,"title":"Issue 464  deformation operators","user":{"login":"chongchenmath","id":19347429,"avatar_url":"https://avatars.githubusercontent.com/u/19347429?v=3","gravatar_id":"","url":"https://api.github.com/users/chongchenmath","html_url":"https://github.com/chongchenmath","followers_url":"https://api.github.com/users/chongchenmath/followers","following_url":"https://api.github.com/users/chongchenmath/following{/other_user}","gists_url":"https://api.github.com/users/chongchenmath/gists{/gist_id}","starred_url":"https://api.github.com/users/chongchenmath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chongchenmath/subscriptions","organizations_url":"https://api.github.com/users/chongchenmath/orgs","repos_url":"https://api.github.com/users/chongchenmath/repos","events_url":"https://api.github.com/users/chongchenmath/events{/privacy}","received_events_url":"https://api.github.com/users/chongchenmath/received_events","type":"User","site_admin":false},"body":"Operators and functions for general and mass-preserving deformation are developed.","created_at":"2016-08-24T09:42:41Z","updated_at":"2016-08-25T08:39:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"654c955a18eca35b5259eb7dbaa1f5fea1d547bf","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/odlgroup/odl/pulls/518/commits","review_comments_url":"https://api.github.com/repos/odlgroup/odl/pulls/518/comments","review_comment_url":"https://api.github.com/repos/odlgroup/odl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odlgroup/odl/issues/518/comments","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/5647529d49ef77d91dacf681379acf65bdae3ff2","head":{"label":"odlgroup:issue-464__deformation_operators","ref":"issue-464__deformation_operators","sha":"5647529d49ef77d91dacf681379acf65bdae3ff2","user":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"repo":{"id":45596393,"name":"odl","full_name":"odlgroup/odl","owner":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odlgroup/odl","description":"Operator Discretization Library","fork":false,"url":"https://api.github.com/repos/odlgroup/odl","forks_url":"https://api.github.com/repos/odlgroup/odl/forks","keys_url":"https://api.github.com/repos/odlgroup/odl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odlgroup/odl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odlgroup/odl/teams","hooks_url":"https://api.github.com/repos/odlgroup/odl/hooks","issue_events_url":"https://api.github.com/repos/odlgroup/odl/issues/events{/number}","events_url":"https://api.github.com/repos/odlgroup/odl/events","assignees_url":"https://api.github.com/repos/odlgroup/odl/assignees{/user}","branches_url":"https://api.github.com/repos/odlgroup/odl/branches{/branch}","tags_url":"https://api.github.com/repos/odlgroup/odl/tags","blobs_url":"https://api.github.com/repos/odlgroup/odl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odlgroup/odl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odlgroup/odl/git/refs{/sha}","trees_url":"https://api.github.com/repos/odlgroup/odl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/{sha}","languages_url":"https://api.github.com/repos/odlgroup/odl/languages","stargazers_url":"https://api.github.com/repos/odlgroup/odl/stargazers","contributors_url":"https://api.github.com/repos/odlgroup/odl/contributors","subscribers_url":"https://api.github.com/repos/odlgroup/odl/subscribers","subscription_url":"https://api.github.com/repos/odlgroup/odl/subscription","commits_url":"https://api.github.com/repos/odlgroup/odl/commits{/sha}","git_commits_url":"https://api.github.com/repos/odlgroup/odl/git/commits{/sha}","comments_url":"https://api.github.com/repos/odlgroup/odl/comments{/number}","issue_comment_url":"https://api.github.com/repos/odlgroup/odl/issues/comments{/number}","contents_url":"https://api.github.com/repos/odlgroup/odl/contents/{+path}","compare_url":"https://api.github.com/repos/odlgroup/odl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odlgroup/odl/merges","archive_url":"https://api.github.com/repos/odlgroup/odl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odlgroup/odl/downloads","issues_url":"https://api.github.com/repos/odlgroup/odl/issues{/number}","pulls_url":"https://api.github.com/repos/odlgroup/odl/pulls{/number}","milestones_url":"https://api.github.com/repos/odlgroup/odl/milestones{/number}","notifications_url":"https://api.github.com/repos/odlgroup/odl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odlgroup/odl/labels{/name}","releases_url":"https://api.github.com/repos/odlgroup/odl/releases{/id}","deployments_url":"https://api.github.com/repos/odlgroup/odl/deployments","created_at":"2015-11-05T07:57:55Z","updated_at":"2016-08-09T15:01:42Z","pushed_at":"2016-08-25T08:24:40Z","git_url":"git://github.com/odlgroup/odl.git","ssh_url":"git@github.com:odlgroup/odl.git","clone_url":"https://github.com/odlgroup/odl.git","svn_url":"https://github.com/odlgroup/odl","homepage":null,"size":19604,"stargazers_count":11,"watchers_count":11,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":116,"forks":6,"open_issues":116,"watchers":11,"default_branch":"master"}},"base":{"label":"odlgroup:master","ref":"master","sha":"28df4b58f500c91a9d85852142dff943f888df2a","user":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"repo":{"id":45596393,"name":"odl","full_name":"odlgroup/odl","owner":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odlgroup/odl","description":"Operator Discretization Library","fork":false,"url":"https://api.github.com/repos/odlgroup/odl","forks_url":"https://api.github.com/repos/odlgroup/odl/forks","keys_url":"https://api.github.com/repos/odlgroup/odl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odlgroup/odl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odlgroup/odl/teams","hooks_url":"https://api.github.com/repos/odlgroup/odl/hooks","issue_events_url":"https://api.github.com/repos/odlgroup/odl/issues/events{/number}","events_url":"https://api.github.com/repos/odlgroup/odl/events","assignees_url":"https://api.github.com/repos/odlgroup/odl/assignees{/user}","branches_url":"https://api.github.com/repos/odlgroup/odl/branches{/branch}","tags_url":"https://api.github.com/repos/odlgroup/odl/tags","blobs_url":"https://api.github.com/repos/odlgroup/odl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odlgroup/odl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odlgroup/odl/git/refs{/sha}","trees_url":"https://api.github.com/repos/odlgroup/odl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/{sha}","languages_url":"https://api.github.com/repos/odlgroup/odl/languages","stargazers_url":"https://api.github.com/repos/odlgroup/odl/stargazers","contributors_url":"https://api.github.com/repos/odlgroup/odl/contributors","subscribers_url":"https://api.github.com/repos/odlgroup/odl/subscribers","subscription_url":"https://api.github.com/repos/odlgroup/odl/subscription","commits_url":"https://api.github.com/repos/odlgroup/odl/commits{/sha}","git_commits_url":"https://api.github.com/repos/odlgroup/odl/git/commits{/sha}","comments_url":"https://api.github.com/repos/odlgroup/odl/comments{/number}","issue_comment_url":"https://api.github.com/repos/odlgroup/odl/issues/comments{/number}","contents_url":"https://api.github.com/repos/odlgroup/odl/contents/{+path}","compare_url":"https://api.github.com/repos/odlgroup/odl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odlgroup/odl/merges","archive_url":"https://api.github.com/repos/odlgroup/odl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odlgroup/odl/downloads","issues_url":"https://api.github.com/repos/odlgroup/odl/issues{/number}","pulls_url":"https://api.github.com/repos/odlgroup/odl/pulls{/number}","milestones_url":"https://api.github.com/repos/odlgroup/odl/milestones{/number}","notifications_url":"https://api.github.com/repos/odlgroup/odl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odlgroup/odl/labels{/name}","releases_url":"https://api.github.com/repos/odlgroup/odl/releases{/id}","deployments_url":"https://api.github.com/repos/odlgroup/odl/deployments","created_at":"2015-11-05T07:57:55Z","updated_at":"2016-08-09T15:01:42Z","pushed_at":"2016-08-25T08:24:40Z","git_url":"git://github.com/odlgroup/odl.git","ssh_url":"git@github.com:odlgroup/odl.git","clone_url":"https://github.com/odlgroup/odl.git","svn_url":"https://github.com/odlgroup/odl","homepage":null,"size":19604,"stargazers_count":11,"watchers_count":11,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":116,"forks":6,"open_issues":116,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/518"},"html":{"href":"https://github.com/odlgroup/odl/pull/518"},"issue":{"href":"https://api.github.com/repos/odlgroup/odl/issues/518"},"comments":{"href":"https://api.github.com/repos/odlgroup/odl/issues/518/comments"},"review_comments":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/518/comments"},"review_comment":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/518/commits"},"statuses":{"href":"https://api.github.com/repos/odlgroup/odl/statuses/5647529d49ef77d91dacf681379acf65bdae3ff2"}}}}
{"actor":{"display_login":"chongchenmath"}}