skipi


Nameskipi JSON
Version 0.1.8 PyPI version JSON
download
home_pagehttps://github.com/TUM-E21-ThinFilms/skipi
SummaryIntuitive package to easily work with mathematical functions
upload_time2023-01-19 16:08:19
maintainer
docs_urlNone
authorAlexander Book
requires_python
licenseMIT
keywords scientific mathematical transforms
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # skipi
skipi is a library to easily define mathematical functions and apply various transforms on it. 

A function always consists of a domain and a map. Usually the domain is ommited since it's clear for the human what the domain is, however, not for the computer. 

This library aims to combine the domain and the map into one Function object and offer multiple convenient operations on it.

## Examples
### Algebraic operations
Supported features are: Addition, Subtraction, Multiplication, Division, Exponentiation, Composition
```python
import numpy as np
from skipi.function import Function

f = Function(np.linspace(0, 10, 100), lambda x: 2+x)
g = Function(f.get_domain(), lambda x: np.sin(x))
h1, h2, h3, h4, h5, h6 = f+g, f-g, f*g, g/f, f.composeWith(g), f**g
``` 

### Plotting
A function is plotted using matplotlib calling plot(). If you want to plot multiple functions into one graph, simply use
```python
g.plot()  # does not draw the graph yet
f.plot(show=True) # draws it
```

### Remeshing
If you want to re-mesh a function on a different domain/grid, you can use `remesh` or `vremesh`. 
The method `remesh` assigns a new mesh, independent of the previous one.
```python
f = Function(np.linspace(0, 10, 10), lambda x: np.sin(x))
f.remesh(np.linspace(0, 20, 1000))
```
However, if you want to restrict the domain, you can use `vremesh` which has a similar syntax as `slice` except that instead of indices we use values and it allows multiple slicing:
```python
f = Function(np.linspace(0, 10, 1000), lambda x: np.sin(x))
f.vremesh((np.pi, 2*np.pi)) # domain is now restricted to [pi, 2pi]
f.vremesh((None, 2*np.pi)) # domain is now restricted to [0, 2pi]
f.vremesh((np.pi, None)) # domain is now restricted to [pi, 10]
f.vremesh((0.5, 1.5), (2.0, 2.5)) # domain is now restricted to [0.5, 1.5] union [2.0, 2.5]
```
### Creating functions from data
If you don't have an analytical formulation of `y = f(x)`, but rather have y_i and x_i values, then you can create a function by interpolation. By default, linear interpolation is used.
```python
x_i = np.linspace(0, 10, 100)
y_i = np.sin(x_i)

f = Function.to_function(x_i, y_i)
print(f(0.1234)) # linearly interpolated, not sin(0.1234)!
```

### Integration
Calculate the integral function of `f(x) = 5x`

```python
import numpy as np
from skipi.function import Function, Integral

f = Function(np.linspace(0, 10, 100), lambda x: 5*x)
F = Integral.from_function(f) # Integral function
F.plot(show=True)
```

### Fourier transform
Calculate the fourier transform (analytical fourier transform, not fft) of f(x) = exp(-x^2)

```python
from skipi.fourier import FourierTransform, InverseFourierTransform

t_space, freq_space = np.linspace(-5, 5, 100), np.linspace(-10, 10, 100)
f = Function(t_space, lambda x: np.exp(-x**2))
F = FourierTransform.from_function(freq_space, f)
f2 = InverseFourierTransform.from_function(t_space, F)

# f2 should be equal to f
(f-f2).plot(show=True)
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TUM-E21-ThinFilms/skipi",
    "name": "skipi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "scientific,mathematical transforms",
    "author": "Alexander Book",
    "author_email": "alexander.book@frm2.tum.de",
    "download_url": "https://files.pythonhosted.org/packages/13/23/4b22c18a176a899ad59344aa8f1b2262c16faf720f396f04671c953cd45f/skipi-0.1.8.tar.gz",
    "platform": null,
    "description": "# skipi\nskipi is a library to easily define mathematical functions and apply various transforms on it. \n\nA function always consists of a domain and a map. Usually the domain is ommited since it's clear for the human what the domain is, however, not for the computer. \n\nThis library aims to combine the domain and the map into one Function object and offer multiple convenient operations on it.\n\n## Examples\n### Algebraic operations\nSupported features are: Addition, Subtraction, Multiplication, Division, Exponentiation, Composition\n```python\nimport numpy as np\nfrom skipi.function import Function\n\nf = Function(np.linspace(0, 10, 100), lambda x: 2+x)\ng = Function(f.get_domain(), lambda x: np.sin(x))\nh1, h2, h3, h4, h5, h6 = f+g, f-g, f*g, g/f, f.composeWith(g), f**g\n``` \n\n### Plotting\nA function is plotted using matplotlib calling plot(). If you want to plot multiple functions into one graph, simply use\n```python\ng.plot()  # does not draw the graph yet\nf.plot(show=True) # draws it\n```\n\n### Remeshing\nIf you want to re-mesh a function on a different domain/grid, you can use `remesh` or `vremesh`. \nThe method `remesh` assigns a new mesh, independent of the previous one.\n```python\nf = Function(np.linspace(0, 10, 10), lambda x: np.sin(x))\nf.remesh(np.linspace(0, 20, 1000))\n```\nHowever, if you want to restrict the domain, you can use `vremesh` which has a similar syntax as `slice` except that instead of indices we use values and it allows multiple slicing:\n```python\nf = Function(np.linspace(0, 10, 1000), lambda x: np.sin(x))\nf.vremesh((np.pi, 2*np.pi)) # domain is now restricted to [pi, 2pi]\nf.vremesh((None, 2*np.pi)) # domain is now restricted to [0, 2pi]\nf.vremesh((np.pi, None)) # domain is now restricted to [pi, 10]\nf.vremesh((0.5, 1.5), (2.0, 2.5)) # domain is now restricted to [0.5, 1.5] union [2.0, 2.5]\n```\n### Creating functions from data\nIf you don't have an analytical formulation of `y = f(x)`, but rather have y_i and x_i values, then you can create a function by interpolation. By default, linear interpolation is used.\n```python\nx_i = np.linspace(0, 10, 100)\ny_i = np.sin(x_i)\n\nf = Function.to_function(x_i, y_i)\nprint(f(0.1234)) # linearly interpolated, not sin(0.1234)!\n```\n\n### Integration\nCalculate the integral function of `f(x) = 5x`\n\n```python\nimport numpy as np\nfrom skipi.function import Function, Integral\n\nf = Function(np.linspace(0, 10, 100), lambda x: 5*x)\nF = Integral.from_function(f) # Integral function\nF.plot(show=True)\n```\n\n### Fourier transform\nCalculate the fourier transform (analytical fourier transform, not fft) of f(x) = exp(-x^2)\n\n```python\nfrom skipi.fourier import FourierTransform, InverseFourierTransform\n\nt_space, freq_space = np.linspace(-5, 5, 100), np.linspace(-10, 10, 100)\nf = Function(t_space, lambda x: np.exp(-x**2))\nF = FourierTransform.from_function(freq_space, f)\nf2 = InverseFourierTransform.from_function(t_space, F)\n\n# f2 should be equal to f\n(f-f2).plot(show=True)\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Intuitive package to easily work with mathematical functions",
    "version": "0.1.8",
    "split_keywords": [
        "scientific",
        "mathematical transforms"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13234b22c18a176a899ad59344aa8f1b2262c16faf720f396f04671c953cd45f",
                "md5": "3de89416db3f5308b661e1b460b82166",
                "sha256": "c0fbd641655a39d49dd2d47a23308c955210b200866ef6204855c217df28072e"
            },
            "downloads": -1,
            "filename": "skipi-0.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "3de89416db3f5308b661e1b460b82166",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24525,
            "upload_time": "2023-01-19T16:08:19",
            "upload_time_iso_8601": "2023-01-19T16:08:19.802967Z",
            "url": "https://files.pythonhosted.org/packages/13/23/4b22c18a176a899ad59344aa8f1b2262c16faf720f396f04671c953cd45f/skipi-0.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-19 16:08:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "TUM-E21-ThinFilms",
    "github_project": "skipi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "skipi"
}
        
Elapsed time: 0.02739s