Metadata-Version: 2.4
Name: pykk
Version: 0.2.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Dist: numpy>=1.21
License-File: LICENCE.txt
Summary: Fast Kramers-Kronig transform library written in Rust
Home-Page: http://github.com/Hayashi-Yudai/pykk
Requires-Python: >=3.10, <3.15
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# pykk
[![Downloads](https://pepy.tech/badge/pykk)](https://pepy.tech/project/pykk)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![PyPI version shields.io](https://img.shields.io/pypi/v/pykk.svg)](https://pypi.python.org/pypi/pykk/)
[![Test](https://github.com/Hayashi-Yudai/pykk/actions/workflows/CI.yml/badge.svg)](https://github.com/Hayashi-Yudai/pykk/actions/workflows/CI.yml)

Python library for calculating Kramers-Kronig transform written in Rust.

## Requirements

- Python >=3.10, <3.15
- NumPy >=1.21

## Install
You can install with pip command.

```bash
$ pip install pykk
```

Or build from the source.

## build

Use maturin for building.

```bash
$ uv sync
$ uv run maturin build --release
```

You can find `.whl` file in `$PROJECT_ROOT/target/wheels`. Install it by pip command.

## How to use

This library has two functions for calculating Kramers-Kronig transform, the transformation from real to imaginary part and vice versa.

```python
import numpy as np
import pykk

energy = np.linspace(1, 10, 1000)  # the values MUST have the same intervals
real = 1 / (1 + (energy - 5) ** 2)

imag = pykk.real2imag(energy, real)  # real -> imaginary part
real_kk = pykk.imag2real(energy, imag)  # imaginary -> real part
```

Both arguments accept anything `numpy.asarray` can turn into a one-dimensional array of numbers, so plain lists still work:

```python
imag = pykk.real2imag([1, 2, 3, 4], [1, 2, 3, 4])
```

The result is always a `numpy.ndarray` of `float64`, whatever the inputs were.

## Test

```bash
$ uv sync
$ uv run maturin develop
$ uv run --no-sync pytest
```

`--no-sync` matters: a bare `uv run` reinstalls pykk from its cached wheel and would replace the module `maturin develop` just built.

## Performance

Compare the performance with the code implemented by Python. The length of the data is ~ 1000 data points.

| Python 3.8 | pykk |
| ---------- | ---- |
| 37 s       | 0.4 ms |


## License
This application contains artifacts distributed under the license of the Apache License, Version 2.0.

