Skip to content

Commit

Permalink
Make a proper package out of pyfftlog (#1)
Browse files Browse the repository at this point in the history
- Converted to package
- Test and CI with Travis
- PEP8 with flake8
  • Loading branch information
prisae committed May 16, 2020
1 parent 94707c3 commit 4a4ba29
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 924 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Directories
__pycache__/

# Cython
*.so
fftlog/_fftlogmodule.c

# Pytest
.pytest_cache/

# setuptools_scm
fftlog/version.py

# Build related
.eggs/
build/
dist/
fftlog.egg-info/
MANIFEST
49 changes: 49 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
language: python

addons:
apt:
- gfortran

# Note: the `python: X.Y` is not actually used, as internally conda is used,
# which follows the `PYTHON=X.Y` var.
matrix:
include:
- python: 3.6
env: PYTHON=3.6
- python: 3.7
env: PYTHON=3.7 DEPLOY_PYPI=true
- python: 3.8
env: PYTHON=3.8

install:
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update --all
# Useful for debugging any issues with conda
- conda info -a

# Install and activate environment, install packages
- conda create -q -n test-environment python=$PYTHON $PCKGS scipy pytest pytest-cov
- source activate test-environment
- pip install setuptools_scm pytest-flake8 $INST
- pip install -e .

script:
- pytest --cov=fftlog --flake8 $TEST

deploy:
provider: pypi
user: "__token__"
password:
secure: BHN9rI3Ckz5aofGqhdpcNq9JQwqLrWQX64xlXsflY46ROQi3+jii0bbRyZgMbv3MMzkjJBOlS/L4GH1dd3da56vYBrDr4n4zCRjMRdoaFLkJRPZttNs5Il1cO2wY7yn0et8Guq7JCNivNJGppAzj5vvaJu50YfW7izaRRlMEDc8KgN5CIKaD5HOGC4AkRCwLWKOf16ly5uhOMFcVrDd/c4UvZMTxByePls2NExZzrrVxndfZZklHOIeVI0QUjuD5fc8MKxO+Lx3S01LHgFdM4xfilQPtPajAg/C6iXavcrrXk62mit0/T53reEoDBbuyQ7rtKwbJm+iN3R+qpiYjegrSpdc9l1FU2rCO3T3R7a3nNF3PzfCm6IZcgkIXjg8melUlaLROL1A7yj/DMh/ASjUPILTV2hedC5bJ/aEVsuBgjDhq7d7wH+RDuswx8vZOHkt9aKtTgLZJdvCUg0QMe0dkkmsTXq0YkLZLXcD3mEOV5lNnu50us9JEDhzunX37p1S+RhBVCWa16rptnWlfEo0W8rk42lmTywu3f6mLmsfKWFJ3zQQOo62zNya11ff1KLwdUGK9QfLw8y7wnrpVrwYU/6PU7d82gWphy2GqB50BjmpPk1lX75rkywRySHpBZug03dlMmUwzWbm9L6VTlA0RepNT3PXCS8rXBBJMzSU=
on:
branch: master
tags: true
condition: '$DEPLOY_PYPI = "true"'
distributions: "sdist"
26 changes: 26 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Changelog
#########


v0.2.0 : First packaged release
-------------------------------

**2020-05-16**

First packaged release on PyPi and conda-forge. This includes:

- Re-structuring the repo.
- Link to proper documentation, https://pyfftlog.readthedocs.io
(which is for pyfftlog), which contains as well the example.
- Add tests and CI on Travis, https://travis-ci.org/github/prisae/pyfftlog.
- Link to Zenodo, https://zenodo.org/record/3830366.
- PEP8 checking.
- Add the relevant badges to README.


v0.1.0 : Initial upload to GitHub
---------------------------------

**2016-12-05**

- Initially working version uploaded to GitHub.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
prune tests
exclude requirements.txt
exclude requirements-dev.txt
exclude .gitignore
exclude .travis.yml
97 changes: 54 additions & 43 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
`fftlog` - python wrapper FFTLog
================================
.. image:: https://travis-ci.org/prisae/fftlog.svg?branch=master
:target: https://travis-ci.org/prisae/fftlog
:alt: Travis-CI
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3830534.svg
:target: https://doi.org/10.5281/zenodo.3830534
:alt: Zenodo DOI


`fftlog` - A python wrapper for FFTLog
======================================

This is a simple `f2py`-wrapper for the logarithmic FFT code *FFTLog* as
presented in Appendix B of [Hamilton_2000]_ and published at
presented in Appendix B of [Hami00]_ and published at
`casa.colorado.edu/~ajsh/FFTLog <http://casa.colorado.edu/~ajsh/FFTLog>`_.

A pure python version (`pyfftlog`) can be found on
`github.com/prisae/pyfftlog <https://github.com/prisae/pyfftlog>`_.
Tests have shown that `fftlog` is a bit faster than `pyfftlog`, but `pyfftlog`
is easier to implement, as you only need `NumPy` and `SciPy`, without the
need to compile anything.
A pure python version (`pyfftlog`) can be found on `github.com/prisae/pyfftlog
<https://github.com/prisae/pyfftlog>`_. Tests have shown that `fftlog` is a bit
faster than `pyfftlog`, but `pyfftlog` is easier to implement, as you only need
`NumPy` and `SciPy`, without the need to compile anything.

I hope that `FFTLog` will make it into `SciPy` in the future, which will make
this project redundant.
this project redundant. (If you have the bandwidth and are willing to chip in
have a look at `SciPy PR #7310 <https://github.com/scipy/scipy/pull/7310>`_.)

Be aware that `pyfftlog` has not been tested extensively. It works fine for the
test from the original code, and my use case, which is `pyfftlog.fftl` with
`mu=0.5` (sine-transform), `q=0` (unbiased), `k=1`, `kropt=1`, and `tdir=1`
(forward). Please let me know if you encounter any issues.

Be aware that `pyfftlog` has not been tested extensively. It works fine
for the attached test, which is the test from the original code, and my use
case, which is `pyfftlog.fftl` with `mu=0.5` (sine-transform), `q=0`
(unbiased), `k=1`, `kropt=1`, and `tdir=` (forward). Please let me know if you
encounter any issues.
- **Documentation**: https://pyfftlog.readthedocs.io
- **Source Code**: https://github.com/prisae/fftlog

**Note** that the documentation is for the pure python version `pyfftlog`, but
equally applies to `fftlog`.

Description of FFTLog from the FFTLog-Website
---------------------------------------------
Expand All @@ -39,32 +51,26 @@ steps) and aliasing (periodic folding of frequencies), but under appropriate
circumstances FFTLog may approximate the results of a continuous Fourier or
Hankel transform.

The FFTLog algorithm was originally proposed by [Talman_1978]_.
The FFTLog algorithm was originally proposed by [Talm78]_.

*For the full documentation, see*
`casa.colorado.edu/~ajsh/FFTLog <http://casa.colorado.edu/~ajsh/FFTLog>`_.
*For the full documentation, see* `casa.colorado.edu/~ajsh/FFTLog
<http://casa.colorado.edu/~ajsh/FFTLog>`_.


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

To install it in your python distribution:
You can install fftlog either via **conda**:

.. code:: bash
.. code-block:: console
python setup.py install
conda install -c conda-forge fftlog
or via **pip**:

To just create the module that you can import locally:
.. code-block:: console
.. code:: bash
f2py -c fftlog.pyf src/*
You need a fortran compiler for this to work.

Check out the Jupyter Notebook `fftlogtest.ipynb` in the root directory. It is
a translation of the test-function `fftlogtest.f`, and should get you started.
pip install fftlog
Creation
Expand All @@ -89,39 +95,42 @@ command, generating only hooks for the functions `fhti`, `fttl`, `fht`, and
f2py src/* -m fftlog -h fftlog.pyf only: fhti fftl fht fhtq :
Lastly I amended the `pyf`-instructions, mainly with some :code:`intent` and
:code:`optional` statements as well as the corresponding default values.
Lastly I amended the `pyf`-instructions, mainly with some `intent` and
`optional` statements as well as the corresponding default values.


Notes
-----
1. :code:`kropt = 3` (interactive adjusting) is not possible with `fftlog`
2. :code:`wsave`-dimension is set to :code:`2*n+3*(n/2)+19`, the biggest of the
four minimum sizes described in `fftlog.f`.
'''''
1. `kropt=3` (interactive adjusting) is not possible with `fftlog`
2. `wsave`-dimension is set to `2*n+3*(n/2)+19`, the biggest of the four
minimum sizes described in `fftlog.f`.


References
----------

.. [Hamilton_2000] Hamilton, A. J. S., 2000, Uncorrelated modes of the
non-linear power spectrum: Monthly Notices of the Royal Astronomical
Society, 312, pages 257-284; DOI: `10.1046/j.1365-8711.2000.03071.x
.. [Hami00] Hamilton, A. J. S., 2000, Uncorrelated modes of the non-linear
power spectrum: Monthly Notices of the Royal Astronomical Society, 312,
pages 257-284; DOI: `10.1046/j.1365-8711.2000.03071.x
<http://dx.doi.org/10.1046/j.1365-8711.2000.03071.x>`_; Website of FFTLog:
`casa.colorado.edu/~ajsh/FFTLog <http://casa.colorado.edu/~ajsh/FFTLog>`_.
.. [Talman_1978] Talman, J. D., 1978, Numerical Fourier and Bessel transforms
in logarithmic variables: Journal of Computational Physics, 29, pages
35-48; DOI: `10.1016/0021-9991(78)90107-9
.. [Talm78] Talman, J. D., 1978, Numerical Fourier and Bessel transforms in
logarithmic variables: Journal of Computational Physics, 29, pages 35-48;
DOI: `10.1016/0021-9991(78)90107-9
<http://dx.doi.org/10.1016/0021-9991(78)90107-9>`_.
License and Credits
-------------------
License, Citation, and Credits
------------------------------

These additions to the original FFTLog-code are released to the public domain
under the `CC0 1.0 License
<http://creativecommons.org/publicdomain/zero/1.0>`_.

All releases have a Zenodo-DOI, which can be found on `10.5281/zenodo.3830364
<https://doi.org/10.5281/zenodo.3830534>`_.

Permission to distribute the original Fortran `FFTLog` code with this Python
`fftlog` package has been granted (email from Andrew Hamilton to Dieter
Werthmüller dated 28 September 2016).
Expand All @@ -141,3 +150,5 @@ The original gamerf copyright statement states::
Permission to distribute the modified gamma function code with the FFTLog
package has been granted (email from Takuya Ooura to Andrew Hamilton dated 16
March 1999).

Be kind and give credits by citing Hamilton (2000).
16 changes: 16 additions & 0 deletions fftlog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from datetime import datetime
from fftlog._fftlog import fhti, fftl, fht, fhtq

__all__ = ['fhti', 'fftl', 'fht', 'fhtq']

# Version
try:
# - Released versions just tags: 1.10.0
# - GitHub commits add .dev#+hash: 1.10.1.dev3+g973038c
# - Uncommitted changes add timestamp: 1.10.1.dev3+g973038c.d20191022
from .version import version as __version__
except ImportError:
# If it was not installed, then we don't know the version. We could throw a
# warning here, but this case *should* be rare. fftlog should be installed
# properly!
__version__ = 'unknown-'+datetime.today().strftime('%Y%m%d')
14 changes: 7 additions & 7 deletions fftlog.pyf → fftlog/fftlog.pyf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
!
! For f2py see http://cens.ioc.ee/projects/f2py2e/

python module fftlog ! in
python module _fftlog ! in
interface ! in :fftlog
subroutine fhti(n,mu,q,dlnr,kr,kropt,wsave,ok) ! in :fftlog:fftlog.f
subroutine fhti(n,mu,q,dlnr,kr,kropt,wsave,ok) ! in :fftlog:src/fftlog.f
integer intent(int) :: n
real*8 intent(in) :: mu
real*8 optional, intent(in) :: q=0
Expand All @@ -22,24 +22,24 @@ python module fftlog ! in
real*8 dimension(2*n+3*(n/2)+19), intent(out) :: wsave
logical intent(out) :: ok
end subroutine fhti
subroutine fftl(n,a,rk,dir,wsave) ! in :fftlog:fftlog.f
subroutine fftl(n,a,rk,dir,wsave) ! in :fftlog:src/fftlog.f
integer, optional, intent(hide), depend(a) :: n=len(a)
real*8 dimension(n), intent(in, out) :: a
real*8 optional, intent(in) :: rk=1
integer optional, intent(in) :: dir=1
real*8 dimension(2*n+3*(n/2)+19), intent(in) :: wsave
end subroutine fftl
subroutine fht(n,a,dir,wsave) ! in :fftlog:fftlog.f
subroutine fht(n,a,dir,wsave) ! in :fftlog:src/fftlog.f
integer, optional, intent(hide), depend(a) :: n=len(a)
real*8 dimension(n), intent(in, out) :: a
integer optional, intent(in) :: dir=1
real*8 dimension(2*n+3*(n/2)+19), intent(in) :: wsave
end subroutine fht
subroutine fhtq(n,a,dir,wsave) ! in :fftlog:fftlog.f
subroutine fhtq(n,a,dir,wsave) ! in :fftlog:src/fftlog.f
integer, optional, intent(hide), depend(a) :: n=len(a)
real*8 dimension(n), intent(in, out) :: a
integer optional, intent(in) :: dir=1
real*8 dimension(2*n+3*(n/2)+19), intent(in) :: wsave
end subroutine fhtq
end interface
end python module fftlog
end interface
end python module _fftlog
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4a4ba29

Please sign in to comment.