fast-barnes-py


Namefast-barnes-py JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/MeteoSwiss/fast-barnes-py/
SummaryFast Barnes Interpolation
upload_time2023-02-17 22:11:38
maintainer
docs_urlNone
authorBruno Zürcher
requires_python>=3.8
licenseBSD 3-Clause License
keywords python interpolation gridding
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Fast Barnes Interpolation
This Python package provides an implementation of the formal algorithms for fast Barnes interpolation as presented in the corresponding paper ([preprint available at GMD](https://gmd.copernicus.org/preprints/gmd-2022-116/gmd-2022-116.pdf)).

Barnes interpolation is a method that is widely used in geospatial sciences like meteorology to remodel data values recorded at irregularly distributed points into a representative analytical field.

Naive computation of Barnes interpolation leads to an algorithmic complexity of O(N x W x H), where N is the number of sample points and W x H the size of the underlying grid.  
As shown in the paper, a good approximation of Barnes interpolation with a drastically reduced algorithmic complexity O(N + W x H) can be obtained by calculating a convolutional expression.

### Example

The code below demonstrates how Barnes interpolation can be computed given a few sample points of mean sea level pressure values located over the British islands.

```
import numpy as np

# definition of 50 sample points with longitude, latitude and mean sea level pressure QFF
input_data = np.asarray([
    [-3.73,56.33,995.1], [2.64,47.05,1012.5], [-8.40,47.50,1011.3], [2.94,54.33,1006.0], [-2.90,49.90,1006.3],
    [-8.98,53.72,1002.1], [1.20,58.60,1002.6], [1.60,50.73,1009.1], [-7.38,57.36,997.7], [-1.25,53.01,1000.4],
    [-4.74,52.79,998.4], [-0.61,47.48,1013.0], [-6.10,50.10,1004.3], [-6.46,54.87,996.4], [-3.22,47.29,1012.8],
    [-1.60,55.42,996.6], [2.30,56.60,1004.5], [1.12,52.95,1003.6], [-0.90,57.80,999.9], [-7.90,51.40,1002.6],
    [-0.70,50.10,1007.5], [2.53,49.02,1010.8], [-5.06,48.47,1008.5], [-3.10,53.60,997.5], [-5.63,57.86,997.8],
    [-6.90,52.85,1000.9], [-4.15,51.09,1002.6], [-1.99,51.50,1002.7], [1.21,47.68,1011.7], [-5.70,56.30,995.5],
    [-1.98,53.13,998.5], [1.09,49.93,1009.0], [1.72,58.42,1002.9], [-6.30,52.30,999.4], [0.70,57.70,1001.9],
    [-3.50,53.60,995.9], [1.38,48.06,1011.6], [-4.37,51.71,1001.1], [-3.09,58.45,998.5], [2.00,56.40,1003.9],
    [1.90,57.00,1003.3], [0.45,51.90,1004.9], [-8.25,51.80,1002.5], [-1.87,53.81,997.4], [-2.38,55.71,995.1],
    [-4.01,54.80,992.1], [0.88,53.37,1002.6], [-1.69,51.86,1002.1], [-4.57,52.14,999.6], [-0.20,58.40,1001.1],
])

lon_lat_data = input_data[:, 0:2]
qff_values = input_data[:, 2]
```

The target grid has to be specified and then the data and the grid are passed with the Gaussian width parameter to the `interpolation.barnes()` method, which returns a representative gridded field. 

```
# definition of a 12° x 12° grid starting at 9°W / 47°N
resolution = 32.0
step = 1.0 / resolution
x0 = np.asarray([-9.0, 47.0], dtype=np.float64)
size = (int(12.0 / step), int(12.0 / step))

# calculate Barnes interpolation
from fastbarnes import interpolation
sigma = 1.0
field = interpolation.barnes(lon_lat_data, qff_values, sigma, x0, step, size)
```

The resulting field can then be further processed, for instance visualized by a matplotlib contour plot.

```
# draw graphic with labeled contours and scattered sample points
import matplotlib.pyplot as plt
plt.figure(figsize=(5, 5))

gridX = np.arange(x0[0], x0[0]+size[1]*step, step)
gridY = np.arange(x0[1], x0[1]+size[0]*step, step)
levels = np.arange(976, 1026, 2)
cs = plt.contour(gridX, gridY, field, levels)
plt.clabel(cs, levels[::2], fmt='%d', fontsize=9)

plt.scatter(lon_lat_data[:, 0], lon_lat_data[:, 1], color='red', s=20, marker='.')

plt.show()
```

Note that due to the just-in-time compilation of the underlying code, the first execution of Barnes interpolation takes considerable more time than the succeeding ones.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MeteoSwiss/fast-barnes-py/",
    "name": "fast-barnes-py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "python,interpolation,gridding",
    "author": "Bruno Z\u00fcrcher",
    "author_email": "bruno.zuercher@meteoswiss.ch",
    "download_url": "https://files.pythonhosted.org/packages/33/52/84251abe475360e6e6e33edc4eb0a6e3072f4d500dcb9eabf80479d33299/fast-barnes-py-1.0.0.tar.gz",
    "platform": null,
    "description": "# Fast Barnes Interpolation\r\nThis Python package provides an implementation of the formal algorithms for fast Barnes interpolation as presented in the corresponding paper ([preprint available at GMD](https://gmd.copernicus.org/preprints/gmd-2022-116/gmd-2022-116.pdf)).\r\n\r\nBarnes interpolation is a method that is widely used in geospatial sciences like meteorology to remodel data values recorded at irregularly distributed points into a representative analytical field.\r\n\r\nNaive computation of Barnes interpolation leads to an algorithmic complexity of O(N x W x H), where N is the number of sample points and W x H the size of the underlying grid.  \r\nAs shown in the paper, a good approximation of Barnes interpolation with a drastically reduced algorithmic complexity O(N + W x H) can be obtained by calculating a convolutional expression.\r\n\r\n### Example\r\n\r\nThe code below demonstrates how Barnes interpolation can be computed given a few sample points of mean sea level pressure values located over the British islands.\r\n\r\n```\r\nimport numpy as np\r\n\r\n# definition of 50 sample points with longitude, latitude and mean sea level pressure QFF\r\ninput_data = np.asarray([\r\n    [-3.73,56.33,995.1], [2.64,47.05,1012.5], [-8.40,47.50,1011.3], [2.94,54.33,1006.0], [-2.90,49.90,1006.3],\r\n    [-8.98,53.72,1002.1], [1.20,58.60,1002.6], [1.60,50.73,1009.1], [-7.38,57.36,997.7], [-1.25,53.01,1000.4],\r\n    [-4.74,52.79,998.4], [-0.61,47.48,1013.0], [-6.10,50.10,1004.3], [-6.46,54.87,996.4], [-3.22,47.29,1012.8],\r\n    [-1.60,55.42,996.6], [2.30,56.60,1004.5], [1.12,52.95,1003.6], [-0.90,57.80,999.9], [-7.90,51.40,1002.6],\r\n    [-0.70,50.10,1007.5], [2.53,49.02,1010.8], [-5.06,48.47,1008.5], [-3.10,53.60,997.5], [-5.63,57.86,997.8],\r\n    [-6.90,52.85,1000.9], [-4.15,51.09,1002.6], [-1.99,51.50,1002.7], [1.21,47.68,1011.7], [-5.70,56.30,995.5],\r\n    [-1.98,53.13,998.5], [1.09,49.93,1009.0], [1.72,58.42,1002.9], [-6.30,52.30,999.4], [0.70,57.70,1001.9],\r\n    [-3.50,53.60,995.9], [1.38,48.06,1011.6], [-4.37,51.71,1001.1], [-3.09,58.45,998.5], [2.00,56.40,1003.9],\r\n    [1.90,57.00,1003.3], [0.45,51.90,1004.9], [-8.25,51.80,1002.5], [-1.87,53.81,997.4], [-2.38,55.71,995.1],\r\n    [-4.01,54.80,992.1], [0.88,53.37,1002.6], [-1.69,51.86,1002.1], [-4.57,52.14,999.6], [-0.20,58.40,1001.1],\r\n])\r\n\r\nlon_lat_data = input_data[:, 0:2]\r\nqff_values = input_data[:, 2]\r\n```\r\n\r\nThe target grid has to be specified and then the data and the grid are passed with the Gaussian width parameter to the `interpolation.barnes()` method, which returns a representative gridded field. \r\n\r\n```\r\n# definition of a 12\u00c2\u00b0 x 12\u00c2\u00b0 grid starting at 9\u00c2\u00b0W / 47\u00c2\u00b0N\r\nresolution = 32.0\r\nstep = 1.0 / resolution\r\nx0 = np.asarray([-9.0, 47.0], dtype=np.float64)\r\nsize = (int(12.0 / step), int(12.0 / step))\r\n\r\n# calculate Barnes interpolation\r\nfrom fastbarnes import interpolation\r\nsigma = 1.0\r\nfield = interpolation.barnes(lon_lat_data, qff_values, sigma, x0, step, size)\r\n```\r\n\r\nThe resulting field can then be further processed, for instance visualized by a matplotlib contour plot.\r\n\r\n```\r\n# draw graphic with labeled contours and scattered sample points\r\nimport matplotlib.pyplot as plt\r\nplt.figure(figsize=(5, 5))\r\n\r\ngridX = np.arange(x0[0], x0[0]+size[1]*step, step)\r\ngridY = np.arange(x0[1], x0[1]+size[0]*step, step)\r\nlevels = np.arange(976, 1026, 2)\r\ncs = plt.contour(gridX, gridY, field, levels)\r\nplt.clabel(cs, levels[::2], fmt='%d', fontsize=9)\r\n\r\nplt.scatter(lon_lat_data[:, 0], lon_lat_data[:, 1], color='red', s=20, marker='.')\r\n\r\nplt.show()\r\n```\r\n\r\nNote that due to the just-in-time compilation of the underlying code, the first execution of Barnes interpolation takes considerable more time than the succeeding ones.\r\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Fast Barnes Interpolation",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/MeteoSwiss/fast-barnes-py/"
    },
    "split_keywords": [
        "python",
        "interpolation",
        "gridding"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "444f3b6196d5538d35904f6f8afbbaed6c00efe5e9920b1337dd5945b9c24d50",
                "md5": "1f46b0c9bb2498cd9962dc9881522dd5",
                "sha256": "5c0fd6d8813b9cebd6564eff47b0fd9329763452454d0d14424b6610f07c4279"
            },
            "downloads": -1,
            "filename": "fast_barnes_py-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1f46b0c9bb2498cd9962dc9881522dd5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18166,
            "upload_time": "2023-02-17T22:11:37",
            "upload_time_iso_8601": "2023-02-17T22:11:37.387248Z",
            "url": "https://files.pythonhosted.org/packages/44/4f/3b6196d5538d35904f6f8afbbaed6c00efe5e9920b1337dd5945b9c24d50/fast_barnes_py-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "335284251abe475360e6e6e33edc4eb0a6e3072f4d500dcb9eabf80479d33299",
                "md5": "a75c4d28f45cfa50402e3d510f79f1ee",
                "sha256": "1273f85ba85cd9620f6110404fd0f5f5084367e4da75b278688232c9d61be314"
            },
            "downloads": -1,
            "filename": "fast-barnes-py-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a75c4d28f45cfa50402e3d510f79f1ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15214,
            "upload_time": "2023-02-17T22:11:38",
            "upload_time_iso_8601": "2023-02-17T22:11:38.713381Z",
            "url": "https://files.pythonhosted.org/packages/33/52/84251abe475360e6e6e33edc4eb0a6e3072f4d500dcb9eabf80479d33299/fast-barnes-py-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-17 22:11:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MeteoSwiss",
    "github_project": "fast-barnes-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "fast-barnes-py"
}
        
Elapsed time: 0.19498s