difw


Namedifw JSON
Version 0.0.30 PyPI version JSON
download
home_pagehttps://github.com/imartinezl/difw
SummaryCompute one dimensional CPAB transformations in Numpy and Pytorch
upload_time2023-01-08 22:44:15
maintainerIñigo Martinez
docs_urlNone
authorIñigo Martinez
requires_python<4,>=3.6
licenseMIT license
keywords diffeomorphisms tessellations transformations continuous piecewise-affine velocity fields
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. difw documentation master file, created by
  sphinx-quickstart on Mon Jun 28 18:23:50 2021.
  You can adapt this file completely to your liking, but it should at least
  contain the root `toctree` directive.

|

.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/logo_readme.png
  :width: 400
  :align: center

|

Finite-dimensional spaces of simple, fast, and highly-expressive diffeomorphisms derived from parametric, continuously-defined, velocity fields in Numpy and Pytorch. DIFW supports one-dimensional diffeomorphic transformations. 

This repo is based on the `libcpab <https://github.com/SkafteNicki/libcpab>`_ library that supports diffeomorphic transformations in 1D (time series), 2D (images) and 3D (volumetric images).
Thanks to Nicki Skafte Detlefsen, Oren Freifeld and Ron Shapira Weber for their help and guidance. 

.. image:: https://img.shields.io/pypi/status/difw?style=flat-square
    :target: https://pypi.python.org/pypi/difw
    :alt: PyPI Status

.. image:: https://img.shields.io/pypi/v/difw?style=flat-square
    :target: https://pypi.python.org/pypi/difw
    :alt: PyPI Version

.. image:: https://img.shields.io/github/license/imartinezl/difw?style=flat-square
    :target: https://github.com/imartinezl/difw/blob/master/LICENSE
    :alt: License

.. image:: https://img.shields.io/github/workflow/status/imartinezl/difw/Workflow?style=flat-square
    :target: https://github.com/imartinezl/difw/actions
    :alt: Actions

.. image:: https://img.shields.io/pypi/dm/difw?style=flat-square
    :target: https://pepy.tech/project/difw

.. image:: https://img.shields.io/github/languages/top/imartinezl/difw?style=flat-square
    :target: https://github.com/imartinezl/difw
    :alt: Top Language

.. image:: https://img.shields.io/github/issues/imartinezl/difw?style=flat-square
    :target: https://github.com/imartinezl/difw
    :alt: Github Issues


Getting Started
---------------

The following code transforms a regular grid using a diffeomorphic curve parametrized ``theta``:

.. image:: https://mybinder.org/badge_logo.svg
    :target: https://mybinder.org/v2/gh/imartinezl/difw/HEAD

.. code-block:: python

    # Import difw library
    import difw

    # Transformation instance 
    T = difw.Cpab(tess_size=5, backend="numpy", device="cpu", zero_boundary=True, basis="qr")

    # Generate grid
    grid = T.uniform_meshgrid(100)

    # Transformation parameters
    theta = T.identity(epsilon=1)

    # Transform grid
    grid_t = T.transform_grid(grid, theta)

.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_deformgrid.png
    :align: center
    :width: 500

In this example, the tesselation is composed of 5 intervals, and the ``zero_boundary`` condition set to ``True`` constraints the velocity at the tesselation boundary (in this case, at ``x=0`` and ``x=1``). The regular grid has 100 equally spaced points. 

.. code-block:: python

    T.visualize_tesselation()

.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_tesselation.png
    :align: center
    :width: 500

The velocity field is formed by a continuous piecewise affine function defined over 5 intervals. The parameters ``theta`` represent a basis of the null space for all continuous piecewise affine functions composed of 5 intervals. In this case, we have used the QR decomposition to build the basis. See the API documentation for more details about the transformation options.

Taking into account the zero velocity constraints at the boundary, only 4 dimensions or degree of freedom are left to play with, and that indeed is the dimensionality of ``theta``, a vector of 4 values.

.. code-block:: python

    T.visualize_velocity(theta)

.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_velocity.png
    :align: center
    :width: 500

We can visualize the generated transformation based on the parameters ``theta``:

.. code-block:: python

    T.visualize_deformgrid(theta)

.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_deformgrid.png
    :align: center
    :width: 500

In addition, for optimization tasks, it is useful to obtain the gradient of the transformation with respect to parameters ``theta``. The gradient function can be obtained in closed-form solution. There are 4 different functions, one per dimension in ``theta``:

.. code-block:: python

    T.visualize_gradient(theta)

.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_gradient.png
    :align: center
    :width: 500



Installation
------------

As the compiled **difw** package is hosted on the Python Package Index (PyPI) you can easily install it with ``pip``.
To install **difw**, run this command in your terminal of choice:

.. code-block:: shell-session

    $ pip install difw

or, alternatively:

.. code-block:: shell-session

    $ python -m pip install difw

If you want to get **difw**'s latest version, you can refer to the
repository hosted at github:

.. code-block:: shell-session

    python -m pip install https://github.com/imartinezl/difw/archive/master.zip

Environment Setup
-----------------

Requirements
^^^^^^^^^^^^

**difw** builds on ``numpy``, ``torch``, ``scipy``, ``ninja``,  and ``matplotlib`` libraries.

Python 3
^^^^^^^^

To find out which version of ``python`` you have, open a terminal window and try the following command:

.. code-block:: shell-session

    $ python3 --version
    Python 3.6.9

If you have ``python3`` on your machine, then this command should respond with a version number. If you do not have ``python3`` installed, follow these `instructions <https://realpython.com/installing-python>`_.

Pip
^^^

``pip`` is the reference Python package manager. It's used to install and update packages. In case ``pip`` is not installed in your OS, follow these `procedure <https://pip.pypa.io/en/stable/installation/>`_.


Virtual Environment
^^^^^^^^^^^^^^^^^^^

``venv`` creates a “virtual” isolated Python installation and installs packages into that virtual installation. It is always recommended to use a virtual environment while developing Python applications. To create a virtual environment, go to your project’s directory and run venv.

.. code-block:: shell-session

    $ python3 -m venv env

Before you can start installing or using packages in your virtual environment you'll need to activate it. 

.. code-block:: shell-session

    $ source env/bin/activate


Source Code
-----------

difw is developed on GitHub, where the code is
`always available <https://github.com/imartinezl/difw>`_.

You can either clone the public repository:

.. code-block:: shell-session

    $ git clone git://github.com/imartinezl/difw.git

Or, download the `tarball <https://github.com/imartinezl/difw/tarball/main>`_:

.. code-block:: shell-session

    $ curl -OL https://github.com/imartinezl/difw/tarball/main
    # optionally, zipball is also available (for Windows users).

Once you have a copy of the source, you can embed it in your own Python
package, or install it into your site-packages easily:


.. code-block:: shell-session

    $ cd difw
    $ python -m pip install .


MIT License

Copyright (c) 2021 Iñigo Martínez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/imartinezl/difw",
    "name": "difw",
    "maintainer": "I\u00f1igo Martinez",
    "docs_url": null,
    "requires_python": "<4,>=3.6",
    "maintainer_email": "inigomlap@gmail.com",
    "keywords": "diffeomorphisms,tessellations,transformations,continuous piecewise-affine,velocity fields",
    "author": "I\u00f1igo Martinez",
    "author_email": "inigomlap@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f1/1c/be0a1e91d9d01ccd17740b4882be0ce10271d45fd53f0b4b7c8ccb29fe1c/difw-0.0.30.tar.gz",
    "platform": null,
    "description": ".. difw documentation master file, created by\n  sphinx-quickstart on Mon Jun 28 18:23:50 2021.\n  You can adapt this file completely to your liking, but it should at least\n  contain the root `toctree` directive.\n\n|\n\n.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/logo_readme.png\n  :width: 400\n  :align: center\n\n|\n\nFinite-dimensional spaces of simple, fast, and highly-expressive diffeomorphisms derived from parametric, continuously-defined, velocity fields in Numpy and Pytorch. DIFW supports one-dimensional diffeomorphic transformations. \n\nThis repo is based on the `libcpab <https://github.com/SkafteNicki/libcpab>`_ library that supports diffeomorphic transformations in 1D (time series), 2D (images) and 3D (volumetric images).\nThanks to Nicki Skafte Detlefsen, Oren Freifeld and Ron Shapira Weber for their help and guidance. \n\n.. image:: https://img.shields.io/pypi/status/difw?style=flat-square\n    :target: https://pypi.python.org/pypi/difw\n    :alt: PyPI Status\n\n.. image:: https://img.shields.io/pypi/v/difw?style=flat-square\n    :target: https://pypi.python.org/pypi/difw\n    :alt: PyPI Version\n\n.. image:: https://img.shields.io/github/license/imartinezl/difw?style=flat-square\n    :target: https://github.com/imartinezl/difw/blob/master/LICENSE\n    :alt: License\n\n.. image:: https://img.shields.io/github/workflow/status/imartinezl/difw/Workflow?style=flat-square\n    :target: https://github.com/imartinezl/difw/actions\n    :alt: Actions\n\n.. image:: https://img.shields.io/pypi/dm/difw?style=flat-square\n    :target: https://pepy.tech/project/difw\n\n.. image:: https://img.shields.io/github/languages/top/imartinezl/difw?style=flat-square\n    :target: https://github.com/imartinezl/difw\n    :alt: Top Language\n\n.. image:: https://img.shields.io/github/issues/imartinezl/difw?style=flat-square\n    :target: https://github.com/imartinezl/difw\n    :alt: Github Issues\n\n\nGetting Started\n---------------\n\nThe following code transforms a regular grid using a diffeomorphic curve parametrized ``theta``:\n\n.. image:: https://mybinder.org/badge_logo.svg\n    :target: https://mybinder.org/v2/gh/imartinezl/difw/HEAD\n\n.. code-block:: python\n\n    # Import difw library\n    import difw\n\n    # Transformation instance \n    T = difw.Cpab(tess_size=5, backend=\"numpy\", device=\"cpu\", zero_boundary=True, basis=\"qr\")\n\n    # Generate grid\n    grid = T.uniform_meshgrid(100)\n\n    # Transformation parameters\n    theta = T.identity(epsilon=1)\n\n    # Transform grid\n    grid_t = T.transform_grid(grid, theta)\n\n.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_deformgrid.png\n    :align: center\n    :width: 500\n\nIn this example, the tesselation is composed of 5 intervals, and the ``zero_boundary`` condition set to ``True`` constraints the velocity at the tesselation boundary (in this case, at ``x=0`` and ``x=1``). The regular grid has 100 equally spaced points. \n\n.. code-block:: python\n\n    T.visualize_tesselation()\n\n.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_tesselation.png\n    :align: center\n    :width: 500\n\nThe velocity field is formed by a continuous piecewise affine function defined over 5 intervals. The parameters ``theta`` represent a basis of the null space for all continuous piecewise affine functions composed of 5 intervals. In this case, we have used the QR decomposition to build the basis. See the API documentation for more details about the transformation options.\n\nTaking into account the zero velocity constraints at the boundary, only 4 dimensions or degree of freedom are left to play with, and that indeed is the dimensionality of ``theta``, a vector of 4 values.\n\n.. code-block:: python\n\n    T.visualize_velocity(theta)\n\n.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_velocity.png\n    :align: center\n    :width: 500\n\nWe can visualize the generated transformation based on the parameters ``theta``:\n\n.. code-block:: python\n\n    T.visualize_deformgrid(theta)\n\n.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_deformgrid.png\n    :align: center\n    :width: 500\n\nIn addition, for optimization tasks, it is useful to obtain the gradient of the transformation with respect to parameters ``theta``. The gradient function can be obtained in closed-form solution. There are 4 different functions, one per dimension in ``theta``:\n\n.. code-block:: python\n\n    T.visualize_gradient(theta)\n\n.. figure:: https://raw.githubusercontent.com/imartinezl/difw/master/docs/source/_static/figures/visualize_gradient.png\n    :align: center\n    :width: 500\n\n\n\nInstallation\n------------\n\nAs the compiled **difw** package is hosted on the Python Package Index (PyPI) you can easily install it with ``pip``.\nTo install **difw**, run this command in your terminal of choice:\n\n.. code-block:: shell-session\n\n    $ pip install difw\n\nor, alternatively:\n\n.. code-block:: shell-session\n\n    $ python -m pip install difw\n\nIf you want to get **difw**'s latest version, you can refer to the\nrepository hosted at github:\n\n.. code-block:: shell-session\n\n    python -m pip install https://github.com/imartinezl/difw/archive/master.zip\n\nEnvironment Setup\n-----------------\n\nRequirements\n^^^^^^^^^^^^\n\n**difw** builds on ``numpy``, ``torch``, ``scipy``, ``ninja``,  and ``matplotlib`` libraries.\n\nPython 3\n^^^^^^^^\n\nTo find out which version of ``python`` you have, open a terminal window and try the following command:\n\n.. code-block:: shell-session\n\n    $ python3 --version\n    Python 3.6.9\n\nIf you have ``python3`` on your machine, then this command should respond with a version number. If you do not have ``python3`` installed, follow these `instructions <https://realpython.com/installing-python>`_.\n\nPip\n^^^\n\n``pip`` is the reference Python package manager. It's used to install and update packages. In case ``pip`` is not installed in your OS, follow these `procedure <https://pip.pypa.io/en/stable/installation/>`_.\n\n\nVirtual Environment\n^^^^^^^^^^^^^^^^^^^\n\n``venv`` creates a \u201cvirtual\u201d isolated Python installation and installs packages into that virtual installation. It is always recommended to use a virtual environment while developing Python applications. To create a virtual environment, go to your project\u2019s directory and run venv.\n\n.. code-block:: shell-session\n\n    $ python3 -m venv env\n\nBefore you can start installing or using packages in your virtual environment you'll need to activate it. \n\n.. code-block:: shell-session\n\n    $ source env/bin/activate\n\n\nSource Code\n-----------\n\ndifw is developed on GitHub, where the code is\n`always available <https://github.com/imartinezl/difw>`_.\n\nYou can either clone the public repository:\n\n.. code-block:: shell-session\n\n    $ git clone git://github.com/imartinezl/difw.git\n\nOr, download the `tarball <https://github.com/imartinezl/difw/tarball/main>`_:\n\n.. code-block:: shell-session\n\n    $ curl -OL https://github.com/imartinezl/difw/tarball/main\n    # optionally, zipball is also available (for Windows users).\n\nOnce you have a copy of the source, you can embed it in your own Python\npackage, or install it into your site-packages easily:\n\n\n.. code-block:: shell-session\n\n    $ cd difw\n    $ python -m pip install .\n\n\nMIT License\n\nCopyright (c) 2021 I\u00f1igo Mart\u00ednez\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Compute one dimensional CPAB transformations in Numpy and Pytorch",
    "version": "0.0.30",
    "split_keywords": [
        "diffeomorphisms",
        "tessellations",
        "transformations",
        "continuous piecewise-affine",
        "velocity fields"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fdb4b2b903af31b45f45e69e2f29d2016417030e9e9cfbe34408c7fefc65f8af",
                "md5": "af58564c63d505c51000117766b681cc",
                "sha256": "a180c752777f1ee33c8494cc433bd61ea72acd65b2c0320784711732a04fba69"
            },
            "downloads": -1,
            "filename": "difw-0.0.30-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "af58564c63d505c51000117766b681cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.6",
            "size": 38122,
            "upload_time": "2023-01-08T22:44:13",
            "upload_time_iso_8601": "2023-01-08T22:44:13.931585Z",
            "url": "https://files.pythonhosted.org/packages/fd/b4/b2b903af31b45f45e69e2f29d2016417030e9e9cfbe34408c7fefc65f8af/difw-0.0.30-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f11cbe0a1e91d9d01ccd17740b4882be0ce10271d45fd53f0b4b7c8ccb29fe1c",
                "md5": "3c52d2e0c73450cd2a2e7debc4cead55",
                "sha256": "edaed80b82214db4ed77611dc2a1866f4eeec509b13e148d8c11439b4fdb2d94"
            },
            "downloads": -1,
            "filename": "difw-0.0.30.tar.gz",
            "has_sig": false,
            "md5_digest": "3c52d2e0c73450cd2a2e7debc4cead55",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.6",
            "size": 33127,
            "upload_time": "2023-01-08T22:44:15",
            "upload_time_iso_8601": "2023-01-08T22:44:15.227416Z",
            "url": "https://files.pythonhosted.org/packages/f1/1c/be0a1e91d9d01ccd17740b4882be0ce10271d45fd53f0b4b7c8ccb29fe1c/difw-0.0.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-08 22:44:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "imartinezl",
    "github_project": "difw",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "difw"
}
        
Elapsed time: 0.02556s