From f1de96abf5a0980d46354746a8c57e2cb1a4d091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 12:46:12 +0200 Subject: [PATCH 01/12] move to src/ based package structure --- .gitignore | 4 +++- {pykrige => src/pykrige}/__init__.py | 0 {pykrige => src/pykrige}/ck.py | 0 {pykrige => src/pykrige}/compat.py | 0 {pykrige => src/pykrige}/core.py | 0 {pykrige => src/pykrige}/kriging_tools.py | 0 {pykrige => src/pykrige}/lib/__init__.py | 0 {pykrige => src/pykrige}/lib/cok.pyx | 0 {pykrige => src/pykrige}/lib/variogram_models.pxd | 0 {pykrige => src/pykrige}/lib/variogram_models.pyx | 0 {pykrige => src/pykrige}/ok.py | 0 {pykrige => src/pykrige}/ok3d.py | 0 {pykrige => src/pykrige}/rk.py | 0 {pykrige => src/pykrige}/uk.py | 0 {pykrige => src/pykrige}/uk3d.py | 0 {pykrige => src/pykrige}/variogram_models.py | 0 16 files changed, 3 insertions(+), 1 deletion(-) rename {pykrige => src/pykrige}/__init__.py (100%) rename {pykrige => src/pykrige}/ck.py (100%) rename {pykrige => src/pykrige}/compat.py (100%) rename {pykrige => src/pykrige}/core.py (100%) rename {pykrige => src/pykrige}/kriging_tools.py (100%) rename {pykrige => src/pykrige}/lib/__init__.py (100%) rename {pykrige => src/pykrige}/lib/cok.pyx (100%) rename {pykrige => src/pykrige}/lib/variogram_models.pxd (100%) rename {pykrige => src/pykrige}/lib/variogram_models.pyx (100%) rename {pykrige => src/pykrige}/ok.py (100%) rename {pykrige => src/pykrige}/ok3d.py (100%) rename {pykrige => src/pykrige}/rk.py (100%) rename {pykrige => src/pykrige}/uk.py (100%) rename {pykrige => src/pykrige}/uk3d.py (100%) rename {pykrige => src/pykrige}/variogram_models.py (100%) diff --git a/.gitignore b/.gitignore index 9a5248a..d4587a5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ downloads/ eggs/ .eggs/ lib/ +!src/pykrige/lib/ lib64/ parts/ sdist/ @@ -108,7 +109,8 @@ tags # own stuff info/ -pykrige/_version.py +src/pykrige/_version.py +.vscode/ # Cython generated C code *.c diff --git a/pykrige/__init__.py b/src/pykrige/__init__.py similarity index 100% rename from pykrige/__init__.py rename to src/pykrige/__init__.py diff --git a/pykrige/ck.py b/src/pykrige/ck.py similarity index 100% rename from pykrige/ck.py rename to src/pykrige/ck.py diff --git a/pykrige/compat.py b/src/pykrige/compat.py similarity index 100% rename from pykrige/compat.py rename to src/pykrige/compat.py diff --git a/pykrige/core.py b/src/pykrige/core.py similarity index 100% rename from pykrige/core.py rename to src/pykrige/core.py diff --git a/pykrige/kriging_tools.py b/src/pykrige/kriging_tools.py similarity index 100% rename from pykrige/kriging_tools.py rename to src/pykrige/kriging_tools.py diff --git a/pykrige/lib/__init__.py b/src/pykrige/lib/__init__.py similarity index 100% rename from pykrige/lib/__init__.py rename to src/pykrige/lib/__init__.py diff --git a/pykrige/lib/cok.pyx b/src/pykrige/lib/cok.pyx similarity index 100% rename from pykrige/lib/cok.pyx rename to src/pykrige/lib/cok.pyx diff --git a/pykrige/lib/variogram_models.pxd b/src/pykrige/lib/variogram_models.pxd similarity index 100% rename from pykrige/lib/variogram_models.pxd rename to src/pykrige/lib/variogram_models.pxd diff --git a/pykrige/lib/variogram_models.pyx b/src/pykrige/lib/variogram_models.pyx similarity index 100% rename from pykrige/lib/variogram_models.pyx rename to src/pykrige/lib/variogram_models.pyx diff --git a/pykrige/ok.py b/src/pykrige/ok.py similarity index 100% rename from pykrige/ok.py rename to src/pykrige/ok.py diff --git a/pykrige/ok3d.py b/src/pykrige/ok3d.py similarity index 100% rename from pykrige/ok3d.py rename to src/pykrige/ok3d.py diff --git a/pykrige/rk.py b/src/pykrige/rk.py similarity index 100% rename from pykrige/rk.py rename to src/pykrige/rk.py diff --git a/pykrige/uk.py b/src/pykrige/uk.py similarity index 100% rename from pykrige/uk.py rename to src/pykrige/uk.py diff --git a/pykrige/uk3d.py b/src/pykrige/uk3d.py similarity index 100% rename from pykrige/uk3d.py rename to src/pykrige/uk3d.py diff --git a/pykrige/variogram_models.py b/src/pykrige/variogram_models.py similarity index 100% rename from pykrige/variogram_models.py rename to src/pykrige/variogram_models.py From b91607ea114ec2805d48afd8db6fb4b589c4c72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:16:23 +0200 Subject: [PATCH 02/12] move setup.cfg content to pyproject.toml --- LICENSE | 2 +- pyproject.toml | 76 ++++++++++++++++++++++++++++++++++++++++++++-- setup.cfg | 82 -------------------------------------------------- setup.py | 36 ++++++++-------------- 4 files changed, 87 insertions(+), 109 deletions(-) delete mode 100755 setup.cfg diff --git a/LICENSE b/LICENSE index 1ce79b7..3811878 100755 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015-2021, PyKrige Developers +Copyright (c) 2015-2022, PyKrige Developers All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/pyproject.toml b/pyproject.toml index b66af3d..9717c89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,86 @@ [build-system] requires = [ - "setuptools>=42", + "setuptools>=62", "wheel", - "setuptools_scm[toml]>=3.5", + "setuptools_scm[toml]>=6.4", "oldest-supported-numpy", "scipy>=1.1.0,<2", "Cython>=0.28.3,<3.0", ] build-backend = "setuptools.build_meta" +[project] +requires-python = ">=3.7" +name = "PyKrige" +description = "Kriging Toolkit for Python." +authors = [ + {name = "Benjamin S. Murphy"}, + {name = "Sebastian Müller", email = "info@geostat-framework.org"}, +] +maintainers = [ + {name = "Sebastian Müller", email = "info@geostat-framework.org"}, + {name = "Roman Yurchak"}, +] +readme = "README.md" +license = {file = "LICENSE"} +dynamic = ["version"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Operating System :: Unix", + "Operating System :: Microsoft", + "Operating System :: MacOS", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: GIS", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Physics", + "Topic :: Utilities", +] +dependencies = [ + "numpy>=1.14.5,<2", + "scipy>=1.1.0,<2", +] + +[project.optional-dependencies] +doc = [ + "gstools>=1.3,<2", + "pillow", + "scikit-learn>=0.19", + "m2r2>=0.2.8", + "matplotlib>=3", + "meshzoo>=0.7,<1", + "numpydoc>=1.1,<2", + "sphinx>=3,<4", + "sphinx-gallery>=0.8,<1", + "sphinx-rtd-theme>=0.5,<1", + "sphinxcontrib-napoleon", +] +plot = ["matplotlib>=3,<4"] +sklearn = ["scikit-learn>=0.19"] +test = [ + "pytest-cov>=3", + "gstools>=1.3,<2", + "scikit-learn>=0.19", +] + +[project.urls] +Changelog = "https://github.com/GeoStat-Framework/PyKrige/blob/main/CHANGELOG.md" +Conda-Forge = "https://anaconda.org/conda-forge/pykrige" +Documentation = "https://pykrige.readthedocs.io" +Homepage = "https://github.com/GeoStat-Framework/PyKrige" +Source = "https://github.com/GeoStat-Framework/PyKrige" +Tracker = "https://github.com/GeoStat-Framework/PyKrige/issues" + [tool.setuptools_scm] write_to = "pykrige/_version.py" write_to_template = "__version__ = '{version}'" diff --git a/setup.cfg b/setup.cfg deleted file mode 100755 index 23eeda0..0000000 --- a/setup.cfg +++ /dev/null @@ -1,82 +0,0 @@ -[metadata] -name = PyKrige -description = Kriging Toolkit for Python. -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/GeoStat-Framework/PyKrige -author = Benjamin S. Murphy, Sebastian Müller -author_email = info@geostat-framework.org -maintainer = Sebastian Mueller, Roman Yurchak -maintainer_email = info@geostat-framework.org -license = BSD-3-Clause -license_file = LICENSE -platforms = any -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - Intended Audience :: End Users/Desktop - Intended Audience :: Science/Research - License :: OSI Approved :: BSD License - Natural Language :: English - Operating System :: MacOS - Operating System :: MacOS :: MacOS X - Operating System :: Microsoft - Operating System :: Microsoft :: Windows - Operating System :: POSIX - Operating System :: Unix - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Topic :: Scientific/Engineering - Topic :: Scientific/Engineering :: GIS - Topic :: Utilities -project_urls = - Documentation = https://pykrige.readthedocs.io - Source = https://github.com/GeoStat-Framework/PyKrige - Tracker = https://github.com/GeoStat-Framework/PyKrige/issues - Changelog = https://github.com/GeoStat-Framework/PyKrige/blob/main/CHANGELOG.md - Conda-Forge = https://anaconda.org/conda-forge/pykrige - -[options] -packages = find: -install_requires = - numpy>=1.14.5,<2 - scipy>=1.1.0,<2 -python_requires = >=3.6 -include_package_data = True -zip_safe = False - -[options.packages.find] -exclude = - tests* - docs* - -[options.extras_require] -doc = - gstools>=1.1.1,<2 - pillow - scikit-learn>=0.19 - m2r2>=0.2.8,<1 - matplotlib>=3,<4 - meshzoo>=0.7,<1 - numpydoc>=1.1,<2 - pykrige>=1.5,<2 - pyvista>=0.31,<1 - sphinx>=3,<4 - sphinx-gallery>=0.8,<1 - sphinx-rtd-theme>=0.5,<1 - sphinxcontrib-napoleon -plot = - matplotlib>=3,<4 -sklearn = - scikit-learn>=0.19 -test = - coverage[toml]>=5.2.1,<6 - pytest>=6.0,<7 - pytest-cov>=2.11.0,<3 - gstools>=1.1.1,<2 - scikit-learn>=0.19 diff --git a/setup.py b/setup.py index 2741f23..0247e8d 100755 --- a/setup.py +++ b/setup.py @@ -1,33 +1,21 @@ # -*- coding: utf-8 -*- """Kriging Toolkit for Python.""" import os -from setuptools import setup, Extension -from Cython.Build import cythonize -import numpy as np -# cython extensions ########################################################### +import numpy as np +from Cython.Build import cythonize +from setuptools import Extension, setup -CY_MODULES = [] -CY_MODULES.append( +# cython extensions +CY_MODULES = [ Extension( - "pykrige.lib.cok", - [os.path.join("pykrige", "lib", "cok.pyx")], + name=f"pykrige.{ext}", + sources=[os.path.join("src", "pykrige", *ext.split(".")) + ".pyx"], include_dirs=[np.get_include()], + define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")], ) -) -CY_MODULES.append( - Extension( - "pykrige.lib.variogram_models", - [os.path.join("pykrige", "lib", "variogram_models.pyx")], - include_dirs=[np.get_include()], - ) -) -EXT_MODULES = cythonize(CY_MODULES) # annotate=True - -# embed signatures for sphinx -for ext_m in EXT_MODULES: - ext_m.cython_directives = {"embedsignature": True} - -# setup ####################################################################### + for ext in ["lib.cok", "lib.variogram_models"] +] -setup(ext_modules=EXT_MODULES, include_dirs=[np.get_include()]) +# setup - do not include package data to ignore .pyx files in wheels +setup(ext_modules=cythonize(CY_MODULES), include_package_data=False) From e7bacac638cea0fe499e548800bb29c7df70a3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:19:24 +0200 Subject: [PATCH 03/12] apply black --- docs/source/conf.py | 2 +- src/pykrige/core.py | 4 ++-- src/pykrige/variogram_models.py | 6 +++--- tests/test_core.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 9ddd224..2ecb618 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -326,7 +326,7 @@ # The following is used by sphinx.ext.linkcode to provide links to github linkcode_resolve = make_linkcode_resolve( "pykrige", - u"https://github.com/GeoStat-Framework/" + "https://github.com/GeoStat-Framework/" "PyKrige/blob/{revision}/" "{package}/{path}#L{lineno}", ) diff --git a/src/pykrige/core.py b/src/pykrige/core.py index e7f61b5..c11e203 100755 --- a/src/pykrige/core.py +++ b/src/pykrige/core.py @@ -869,9 +869,9 @@ def calcQ1(epsilon): def calcQ2(epsilon): """Returns the Q2 statistic for the variogram fit (see [1]).""" - return np.sum(epsilon ** 2) / (epsilon.shape[0] - 1) + return np.sum(epsilon**2) / (epsilon.shape[0] - 1) def calc_cR(Q2, sigma): """Returns the cR statistic for the variogram fit (see [1]).""" - return Q2 * np.exp(np.sum(np.log(sigma ** 2)) / sigma.shape[0]) + return Q2 * np.exp(np.sum(np.log(sigma**2)) / sigma.shape[0]) diff --git a/src/pykrige/variogram_models.py b/src/pykrige/variogram_models.py index 5aa46ba..a056bdf 100755 --- a/src/pykrige/variogram_models.py +++ b/src/pykrige/variogram_models.py @@ -34,7 +34,7 @@ def power_variogram_model(m, d): scale = float(m[0]) exponent = float(m[1]) nugget = float(m[2]) - return scale * d ** exponent + nugget + return scale * d**exponent + nugget def gaussian_variogram_model(m, d): @@ -42,7 +42,7 @@ def gaussian_variogram_model(m, d): psill = float(m[0]) range_ = float(m[1]) nugget = float(m[2]) - return psill * (1.0 - np.exp(-(d ** 2.0) / (range_ * 4.0 / 7.0) ** 2.0)) + nugget + return psill * (1.0 - np.exp(-(d**2.0) / (range_ * 4.0 / 7.0) ** 2.0)) + nugget def exponential_variogram_model(m, d): @@ -63,7 +63,7 @@ def spherical_variogram_model(m, d): [d <= range_, d > range_], [ lambda x: psill - * ((3.0 * x) / (2.0 * range_) - (x ** 3.0) / (2.0 * range_ ** 3.0)) + * ((3.0 * x) / (2.0 * range_) - (x**3.0) / (2.0 * range_**3.0)) + nugget, psill + nugget, ], diff --git a/tests/test_core.py b/tests/test_core.py index a7670e0..94986d8 100755 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2779,7 +2779,7 @@ def test_geometric_code(): dz = np.sin(np.pi / 180.0 * lat) - np.sin(np.pi / 180.0 * lat_ref[i]) assert_allclose( core.great_circle_distance(lon_ref[i], lat_ref[i], lon, lat), - core.euclid3_to_great_circle(np.sqrt(dx ** 2 + dy ** 2 + dz ** 2)), + core.euclid3_to_great_circle(np.sqrt(dx**2 + dy**2 + dz**2)), rtol=1e-5, ) From 8ea1025e27a89e76ba82edc98c6f9192705f9af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:22:38 +0200 Subject: [PATCH 04/12] CI: update cibuildwheel workflow --- .github/workflows/main.yml | 59 +++++++++++++++++++++----------------- pyproject.toml | 13 +++++++++ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f8fd77b..699d455 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,38 @@ jobs: - name: black check run: | - python -m black --check --diff --color pykrige/ examples/ tests/ + python -m black --check --diff --color . + + build_wheels: + name: wheels for ${{ matrix.cfg.os }} / ${{ matrix.cfg.arch }} + runs-on: ${{ matrix.cfg.os }} + strategy: + fail-fast: false + matrix: + cfg: + - { os: ubuntu-latest, arch: x86_64 } + - { os: ubuntu-latest, arch: i686 } + - { os: windows-latest, arch: AMD64 } + - { os: windows-latest, arch: x86 } + - { os: macos-latest, arch: x86_64 } + - { os: macos-latest, arch: arm64 } + - { os: macos-latest, arch: universal2 } + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + + - name: Build wheels + uses: pypa/cibuildwheel@v2.8.1 + env: + CIBW_ARCHS: ${{ matrix.cfg.arch }} + with: + output-dir: dist + + - uses: actions/upload-artifact@v2 + with: + path: ./dist/*.whl build_sdist: name: sdist and coveralls @@ -74,32 +105,6 @@ jobs: with: path: dist/*.tar.gz - build_wheels: - name: wheels on ${{matrix.os}} - runs-on: ${{matrix.os}} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: '0' - - - name: Build wheels - uses: pypa/cibuildwheel@v2.1.1 - env: - CIBW_BUILD: cp36-* cp37-* cp38-* cp39-* - CIBW_TEST_EXTRAS: test - CIBW_TEST_COMMAND: pytest -v {project}/tests - with: - output-dir: dist - - - uses: actions/upload-artifact@v2 - with: - path: ./dist/*.whl - upload_to_pypi: needs: [build_wheels, build_sdist] runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 9717c89..a931645 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,3 +133,16 @@ target-version = [ max-statements = 80 max-attributes = 25 max-public-methods = 75 + +[tool.cibuildwheel] +# Switch to using build +build-frontend = "build" +# Disable building PyPy wheels on all platforms, 32bit for py3.10 and musllinux builds, py3.6 +skip = ["cp36-*", "pp*", "cp310-win32", "cp310-manylinux_i686", "*-musllinux_*"] +# Run the package tests using `pytest` +test-extras = "test" +test-command = "pytest -v {package}/tests" +# Skip trying to test arm64 builds on Intel Macs +test-skip = "*-macosx_arm64 *-macosx_universal2:arm64" +# no wheels for linux-32bit anymore for numpy>=1.22 +environment = "PIP_PREFER_BINARY=1" From 344c4e81959dba4af63cd7e1dfb964d58ecae442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:24:34 +0200 Subject: [PATCH 05/12] version: fix path --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a931645..c3f1688 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ Source = "https://github.com/GeoStat-Framework/PyKrige" Tracker = "https://github.com/GeoStat-Framework/PyKrige/issues" [tool.setuptools_scm] -write_to = "pykrige/_version.py" +write_to = "src/pykrige/_version.py" write_to_template = "__version__ = '{version}'" local_scheme = "no-local-version" fallback_version = "0.0.0.dev0" From 2340d99dcaeca6d8a663632583e2966d79dd41de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:29:10 +0200 Subject: [PATCH 06/12] CI: verbose editable installs --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 699d455..7fc7fbb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -87,7 +87,7 @@ jobs: run: | python -m pip install --upgrade pip pip install build coveralls>=3.0.0 - pip install --editable .[test] + pip install -v --editable .[test] - name: Run tests env: From d998fdbcd22a06f1e2f55dc363b9bdd5ff92a885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:29:29 +0200 Subject: [PATCH 07/12] update MANIFEST --- MANIFEST.in | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index bb11063..78512d8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,4 @@ -prune * -graft tests -recursive-include pykrige *.py *.pyx *.pxd -recursive-exclude pykrige *.c *.cpp -include LICENSE README.md pyproject.toml setup.py setup.cfg -exclude CHANGELOG.md -global-exclude __pycache__ *.py[cod] .* +prune ** +recursive-include tests *.py *.txt *.asc +recursive-include src/pykrige *.py *.pyx *.pxd +include LICENSE README.md pyproject.toml setup.py From 54fdc31c9996e334b450323782b7817831789536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:32:53 +0200 Subject: [PATCH 08/12] doc: remove unneeded dep --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c3f1688..23f4260 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,6 @@ doc = [ "scikit-learn>=0.19", "m2r2>=0.2.8", "matplotlib>=3", - "meshzoo>=0.7,<1", "numpydoc>=1.1,<2", "sphinx>=3,<4", "sphinx-gallery>=0.8,<1", From 81b86647a2a8e20b3e560949f59feab9dbda5cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:38:14 +0200 Subject: [PATCH 09/12] apply isort and add check to CI --- .github/workflows/main.yml | 6 +++++- benchmarks/kriging_benchmarks.py | 2 ++ docs/source/conf.py | 8 +++++--- docs/source/sphinxext/github_link.py | 4 ++-- examples/00_ordinary.py | 4 ++-- examples/01_universal.py | 4 ++-- examples/02_kriging3D.py | 4 ++-- examples/03_gstools_covmodel.py | 5 +++-- examples/04_krige_geometric.py | 2 +- examples/05_kriging_1D.py | 3 ++- examples/06_exact_values_example_1D.py | 3 ++- examples/07_regression_kriging2d.py | 4 ++-- examples/08_krige_cv.py | 2 +- examples/10_classification_kriging2d.py | 6 +++--- pyproject.toml | 4 ++++ src/pykrige/__init__.py | 2 +- src/pykrige/ck.py | 7 ++++--- src/pykrige/compat.py | 6 +++--- src/pykrige/core.py | 5 ++--- src/pykrige/kriging_tools.py | 7 ++++--- src/pykrige/lib/cok.pyx | 4 ++++ src/pykrige/ok.py | 11 ++++++----- src/pykrige/ok3d.py | 11 ++++++----- src/pykrige/rk.py | 2 +- src/pykrige/uk.py | 11 ++++++----- src/pykrige/uk3d.py | 11 ++++++----- tests/test_api.py | 3 +-- tests/test_classification_krige.py | 6 +++--- tests/test_core.py | 8 ++++---- tests/test_regression_krige.py | 7 +++---- 30 files changed, 92 insertions(+), 70 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7fc7fbb..07b2199 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,12 +30,16 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install black + pip install black 'isort[colors]<6' - name: black check run: | python -m black --check --diff --color . + - name: isort check + run: | + python -m isort --check --diff --color . + build_wheels: name: wheels for ${{ matrix.cfg.os }} / ${{ matrix.cfg.arch }} runs-on: ${{ matrix.cfg.os }} diff --git a/benchmarks/kriging_benchmarks.py b/benchmarks/kriging_benchmarks.py index 927c333..ed0cf84 100644 --- a/benchmarks/kriging_benchmarks.py +++ b/benchmarks/kriging_benchmarks.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- """Benchmarks.""" from time import time + import numpy as np + from pykrige.ok import OrdinaryKriging np.random.seed(19999) diff --git a/docs/source/conf.py b/docs/source/conf.py index 2ecb618..1d7ebc2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,11 +13,12 @@ # All configuration values have a default; values that are commented out # serve to show the default. import datetime -import sys import os import shlex -import sphinx_rtd_theme +import sys + import matplotlib +import sphinx_rtd_theme matplotlib.use("Agg") @@ -28,9 +29,10 @@ # sys.path.insert(0, os.path.abspath("../../")) sys.path.insert(0, os.path.abspath("sphinxext")) -import pykrige from github_link import make_linkcode_resolve +import pykrige + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. diff --git a/docs/source/sphinxext/github_link.py b/docs/source/sphinxext/github_link.py index 9ce0e9c..97507c7 100644 --- a/docs/source/sphinxext/github_link.py +++ b/docs/source/sphinxext/github_link.py @@ -1,11 +1,11 @@ # Adapted from scikit learn -from operator import attrgetter import inspect -import subprocess import os +import subprocess import sys from functools import partial +from operator import attrgetter REVISION_CMD = "git rev-parse --short HEAD" diff --git a/examples/00_ordinary.py b/examples/00_ordinary.py index de15d1d..b35e923 100755 --- a/examples/00_ordinary.py +++ b/examples/00_ordinary.py @@ -6,11 +6,11 @@ """ +import matplotlib.pyplot as plt import numpy as np + import pykrige.kriging_tools as kt from pykrige.ok import OrdinaryKriging -import matplotlib.pyplot as plt - data = np.array( [ diff --git a/examples/01_universal.py b/examples/01_universal.py index 3b5ba01..326b61d 100755 --- a/examples/01_universal.py +++ b/examples/01_universal.py @@ -6,10 +6,10 @@ """ -from pykrige.uk import UniversalKriging -import numpy as np import matplotlib.pyplot as plt +import numpy as np +from pykrige.uk import UniversalKriging data = np.array( [ diff --git a/examples/02_kriging3D.py b/examples/02_kriging3D.py index 09438db..7f4b9f8 100755 --- a/examples/02_kriging3D.py +++ b/examples/02_kriging3D.py @@ -4,11 +4,11 @@ """ -from pykrige.ok3d import OrdinaryKriging3D -from pykrige.uk3d import UniversalKriging3D import numpy as np from matplotlib import pyplot as plt +from pykrige.ok3d import OrdinaryKriging3D +from pykrige.uk3d import UniversalKriging3D data = np.array( [ diff --git a/examples/03_gstools_covmodel.py b/examples/03_gstools_covmodel.py index 6d1508b..ccf46f2 100644 --- a/examples/03_gstools_covmodel.py +++ b/examples/03_gstools_covmodel.py @@ -5,10 +5,11 @@ Example how to use the PyKrige routines with a GSTools CovModel. """ +import gstools as gs import numpy as np -from pykrige.ok import OrdinaryKriging from matplotlib import pyplot as plt -import gstools as gs + +from pykrige.ok import OrdinaryKriging # conditioning data data = np.array( diff --git a/examples/04_krige_geometric.py b/examples/04_krige_geometric.py index f641ff4..e033a2e 100644 --- a/examples/04_krige_geometric.py +++ b/examples/04_krige_geometric.py @@ -7,10 +7,10 @@ for ordinary kriging on a sphere. """ -from pykrige.ok import OrdinaryKriging import numpy as np from matplotlib import pyplot as plt +from pykrige.ok import OrdinaryKriging # Make this example reproducible: np.random.seed(89239413) diff --git a/examples/05_kriging_1D.py b/examples/05_kriging_1D.py index dc21d1a..0f083f5 100644 --- a/examples/05_kriging_1D.py +++ b/examples/05_kriging_1D.py @@ -4,8 +4,9 @@ An example of 1D kriging with PyKrige """ -import numpy as np import matplotlib.pyplot as plt +import numpy as np + from pykrige import OrdinaryKriging plt.style.use("ggplot") diff --git a/examples/06_exact_values_example_1D.py b/examples/06_exact_values_example_1D.py index 715ac85..404b07d 100644 --- a/examples/06_exact_values_example_1D.py +++ b/examples/06_exact_values_example_1D.py @@ -7,10 +7,11 @@ as a non-exact interpolator in 1D. """ -from pykrige.ok import OrdinaryKriging import matplotlib.pyplot as plt import numpy as np +from pykrige.ok import OrdinaryKriging + plt.style.use("ggplot") np.random.seed(42) diff --git a/examples/07_regression_kriging2d.py b/examples/07_regression_kriging2d.py index 3716412..33fc558 100644 --- a/examples/07_regression_kriging2d.py +++ b/examples/07_regression_kriging2d.py @@ -7,11 +7,11 @@ import sys -from sklearn.svm import SVR +from sklearn.datasets import fetch_california_housing from sklearn.ensemble import RandomForestRegressor from sklearn.linear_model import LinearRegression -from sklearn.datasets import fetch_california_housing from sklearn.model_selection import train_test_split +from sklearn.svm import SVR from pykrige.rk import RegressionKriging diff --git a/examples/08_krige_cv.py b/examples/08_krige_cv.py index ece8fd8..f4cf7ff 100644 --- a/examples/08_krige_cv.py +++ b/examples/08_krige_cv.py @@ -7,9 +7,9 @@ """ import numpy as np -from pykrige.rk import Krige from sklearn.model_selection import GridSearchCV +from pykrige.rk import Krige # 2D Kring param opt diff --git a/examples/10_classification_kriging2d.py b/examples/10_classification_kriging2d.py index c625754..ce31a63 100644 --- a/examples/10_classification_kriging2d.py +++ b/examples/10_classification_kriging2d.py @@ -7,12 +7,12 @@ import sys -from sklearn.svm import SVC +from sklearn.datasets import fetch_california_housing from sklearn.ensemble import RandomForestClassifier from sklearn.linear_model import LogisticRegression -from sklearn.datasets import fetch_california_housing -from sklearn.preprocessing import KBinsDiscretizer from sklearn.model_selection import train_test_split +from sklearn.preprocessing import KBinsDiscretizer +from sklearn.svm import SVC from pykrige.ck import ClassificationKriging diff --git a/pyproject.toml b/pyproject.toml index 23f4260..8f600a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,6 +86,10 @@ write_to_template = "__version__ = '{version}'" local_scheme = "no-local-version" fallback_version = "0.0.0.dev0" +[tool.isort] +profile = "black" +multi_line_output = 3 + [tool.black] target-version = [ "py36", diff --git a/src/pykrige/__init__.py b/src/pykrige/__init__.py index 6a5be84..162acb8 100755 --- a/src/pykrige/__init__.py +++ b/src/pykrige/__init__.py @@ -43,8 +43,8 @@ from . import kriging_tools as kt # noqa from .ok import OrdinaryKriging # noqa -from .uk import UniversalKriging # noqa from .ok3d import OrdinaryKriging3D # noqa +from .uk import UniversalKriging # noqa from .uk3d import UniversalKriging3D # noqa try: diff --git a/src/pykrige/ck.py b/src/pykrige/ck.py index ea9ea50..4199c87 100644 --- a/src/pykrige/ck.py +++ b/src/pykrige/ck.py @@ -1,14 +1,15 @@ # coding: utf-8 """Classification Kriging.""" import numpy as np -from pykrige.compat import Krige, validate_sklearn, check_sklearn_model + +from pykrige.compat import Krige, check_sklearn_model, validate_sklearn validate_sklearn() +from scipy.linalg import helmert from sklearn.metrics import accuracy_score -from sklearn.svm import SVC from sklearn.preprocessing import OneHotEncoder -from scipy.linalg import helmert +from sklearn.svm import SVC class ClassificationKriging: diff --git a/src/pykrige/compat.py b/src/pykrige/compat.py index d092606..d0ca37c 100644 --- a/src/pykrige/compat.py +++ b/src/pykrige/compat.py @@ -1,16 +1,16 @@ # coding: utf-8 # pylint: disable= invalid-name, unused-import """For compatibility.""" -from pykrige.uk3d import UniversalKriging3D +from pykrige.ok import OrdinaryKriging from pykrige.ok3d import OrdinaryKriging3D from pykrige.uk import UniversalKriging -from pykrige.ok import OrdinaryKriging +from pykrige.uk3d import UniversalKriging3D # sklearn try: # keep train_test_split here for backward compatibility + from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin from sklearn.model_selection import train_test_split - from sklearn.base import RegressorMixin, ClassifierMixin, BaseEstimator SKLEARN_INSTALLED = True diff --git a/src/pykrige/core.py b/src/pykrige/core.py index c11e203..0a01c36 100755 --- a/src/pykrige/core.py +++ b/src/pykrige/core.py @@ -23,10 +23,9 @@ """ import numpy as np -from scipy.spatial.distance import pdist, squareform, cdist -from scipy.optimize import least_squares import scipy.linalg as spl - +from scipy.optimize import least_squares +from scipy.spatial.distance import cdist, pdist, squareform eps = 1.0e-10 # Cutoff for comparison to zero diff --git a/src/pykrige/kriging_tools.py b/src/pykrige/kriging_tools.py index 4f6dd1a..496dad8 100755 --- a/src/pykrige/kriging_tools.py +++ b/src/pykrige/kriging_tools.py @@ -12,11 +12,12 @@ Copyright (c) 2015-2020, PyKrige Developers """ -import numpy as np -import warnings -import io import datetime +import io import os +import warnings + +import numpy as np def write_asc_grid(x, y, z, filename="output.asc", no_data=-999.0, style=1): diff --git a/src/pykrige/lib/cok.pyx b/src/pykrige/lib/cok.pyx index 9044c01..558fb2c 100644 --- a/src/pykrige/lib/cok.pyx +++ b/src/pykrige/lib/cok.pyx @@ -1,11 +1,15 @@ #cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True # -*- coding: utf-8 -*- import numpy as np + cimport numpy as np from libc.math cimport sqrt + import scipy.linalg + from scipy.linalg.cython_blas cimport dgemv from scipy.linalg.cython_lapack cimport dgesv + from .variogram_models cimport get_variogram_model diff --git a/src/pykrige/ok.py b/src/pykrige/ok.py index e7ce37d..cbcfeb6 100644 --- a/src/pykrige/ok.py +++ b/src/pykrige/ok.py @@ -21,19 +21,20 @@ Copyright (c) 2015-2020, PyKrige Developers """ +import warnings + import numpy as np import scipy.linalg from scipy.spatial.distance import cdist -from . import variogram_models -from . import core + +from . import core, variogram_models from .core import ( + P_INV, _adjust_for_anisotropy, + _find_statistics, _initialize_variogram_model, _make_variogram_parameter_list, - _find_statistics, - P_INV, ) -import warnings class OrdinaryKriging: diff --git a/src/pykrige/ok3d.py b/src/pykrige/ok3d.py index a143168..14c2656 100644 --- a/src/pykrige/ok3d.py +++ b/src/pykrige/ok3d.py @@ -20,19 +20,20 @@ Copyright (c) 2015-2020, PyKrige Developers """ +import warnings + import numpy as np import scipy.linalg from scipy.spatial.distance import cdist -from . import variogram_models -from . import core + +from . import core, variogram_models from .core import ( + P_INV, _adjust_for_anisotropy, + _find_statistics, _initialize_variogram_model, _make_variogram_parameter_list, - _find_statistics, - P_INV, ) -import warnings class OrdinaryKriging3D: diff --git a/src/pykrige/rk.py b/src/pykrige/rk.py index 70fcc14..5feb97c 100644 --- a/src/pykrige/rk.py +++ b/src/pykrige/rk.py @@ -1,6 +1,6 @@ # coding: utf-8 """Regression Kriging.""" -from pykrige.compat import Krige, validate_sklearn, check_sklearn_model +from pykrige.compat import Krige, check_sklearn_model, validate_sklearn validate_sklearn() diff --git a/src/pykrige/uk.py b/src/pykrige/uk.py index 9819534..2202b99 100644 --- a/src/pykrige/uk.py +++ b/src/pykrige/uk.py @@ -19,19 +19,20 @@ (Wiley Series in Probability and Statistics, 1993) 137 p. Copyright (c) 2015-2020, PyKrige Developers """ +import warnings + import numpy as np import scipy.linalg from scipy.spatial.distance import cdist -from . import variogram_models -from . import core + +from . import core, variogram_models from .core import ( + P_INV, _adjust_for_anisotropy, + _find_statistics, _initialize_variogram_model, _make_variogram_parameter_list, - _find_statistics, - P_INV, ) -import warnings class UniversalKriging: diff --git a/src/pykrige/uk3d.py b/src/pykrige/uk3d.py index 7f8ee01..2cf86be 100644 --- a/src/pykrige/uk3d.py +++ b/src/pykrige/uk3d.py @@ -19,19 +19,20 @@ Copyright (c) 2015-2020, PyKrige Developers """ +import warnings + import numpy as np import scipy.linalg from scipy.spatial.distance import cdist -from . import variogram_models -from . import core + +from . import core, variogram_models from .core import ( + P_INV, _adjust_for_anisotropy, + _find_statistics, _initialize_variogram_model, _make_variogram_parameter_list, - _find_statistics, - P_INV, ) -import warnings class UniversalKriging3D: diff --git a/tests/test_api.py b/tests/test_api.py index 6c033ca..df24464 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,8 +3,7 @@ import numpy as np import pytest -from pykrige.compat import Krige -from pykrige.compat import threed_krige +from pykrige.compat import Krige, threed_krige def _method_and_vergiogram(): diff --git a/tests/test_classification_krige.py b/tests/test_classification_krige.py index 3e5e93a..8d389f5 100644 --- a/tests/test_classification_krige.py +++ b/tests/test_classification_krige.py @@ -1,16 +1,16 @@ from itertools import product -import pytest import numpy as np +import pytest from pykrige.ck import ClassificationKriging try: - from sklearn.svm import SVC from sklearn.datasets import fetch_california_housing from sklearn.ensemble import RandomForestClassifier - from sklearn.preprocessing import KBinsDiscretizer from sklearn.model_selection import train_test_split + from sklearn.preprocessing import KBinsDiscretizer + from sklearn.svm import SVC SKLEARN_INSTALLED = True except ImportError: diff --git a/tests/test_core.py b/tests/test_core.py index 94986d8..9e197a8 100755 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2,21 +2,21 @@ Testing code. Updated BSM February 2017 """ -import sys import os +import sys import numpy as np import pytest -from pytest import approx from numpy.testing import assert_allclose +from pytest import approx from scipy.spatial.distance import cdist -from pykrige import kriging_tools as kt from pykrige import core +from pykrige import kriging_tools as kt from pykrige import variogram_models from pykrige.ok import OrdinaryKriging -from pykrige.uk import UniversalKriging from pykrige.ok3d import OrdinaryKriging3D +from pykrige.uk import UniversalKriging from pykrige.uk3d import UniversalKriging3D BASE_DIR = os.path.abspath(os.path.dirname(__file__)) diff --git a/tests/test_regression_krige.py b/tests/test_regression_krige.py index 631af56..a222d51 100644 --- a/tests/test_regression_krige.py +++ b/tests/test_regression_krige.py @@ -1,17 +1,16 @@ from itertools import product -import pytest import numpy as np +import pytest from pykrige.rk import RegressionKriging try: - from sklearn.svm import SVR from sklearn.datasets import fetch_california_housing - from sklearn.linear_model import ElasticNet, Lasso from sklearn.ensemble import RandomForestRegressor - from sklearn.linear_model import LinearRegression + from sklearn.linear_model import ElasticNet, Lasso, LinearRegression from sklearn.model_selection import train_test_split + from sklearn.svm import SVR SKLEARN_INSTALLED = True except ImportError: From c3e9fd83adf4d3b810348340bb9f893042fb5589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:42:54 +0200 Subject: [PATCH 10/12] fix old typo --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07b2199..1dc0d97 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v2 - name: Set up Python 3.8 - uses: actions\setup-python@v2 + uses: actions/setup-python@v2 with: python-version: 3.8 @@ -83,7 +83,7 @@ jobs: fetch-depth: '0' - name: Set up Python 3.8 - uses: actions\setup-python@v2 + uses: actions/setup-python@v2 with: python-version: 3.8 From 734912ce41dbbbd7451dbe405db7c26b63e31875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 13:47:22 +0200 Subject: [PATCH 11/12] tests: skip gstools for now due to pinv2 bug --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8f600a6..604faad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,8 +68,8 @@ plot = ["matplotlib>=3,<4"] sklearn = ["scikit-learn>=0.19"] test = [ "pytest-cov>=3", - "gstools>=1.3,<2", "scikit-learn>=0.19", + # "gstools>=1.3,<2", ] [project.urls] From 4ca31ee6934e1f679eea57eb891edce66941cd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Wed, 10 Aug 2022 14:14:01 +0200 Subject: [PATCH 12/12] doc fixes --- docs/source/_templates/layout.html | 26 ++++++++++++++++---------- docs/source/conf.py | 25 +++++++++++++++++++++---- pyproject.toml | 9 +++++---- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/docs/source/_templates/layout.html b/docs/source/_templates/layout.html index eccaa77..118bec8 100644 --- a/docs/source/_templates/layout.html +++ b/docs/source/_templates/layout.html @@ -4,17 +4,23 @@ {{ super() }}
- PyKrige GitHub - PyKrige Zenodo DOI - PyKrige PyPI +
- GeoStat Website - GeoStat Github - GeoStat ReadTheDocs - GeoStat PyPI +

- Index - Sitemap - {% endblock %} + + {% endblock %} diff --git a/docs/source/conf.py b/docs/source/conf.py index 1d7ebc2..0e576d6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -47,17 +47,34 @@ "sphinx.ext.mathjax", "sphinx.ext.autodoc", "sphinx.ext.autosummary", - "sphinxcontrib.napoleon", + "sphinx.ext.napoleon", # parameters look better than with numpydoc only + "numpydoc", "sphinx_gallery.gen_gallery", "sphinx.ext.linkcode", "m2r2", ] - -autosummary_generate = True - autodoc_default_flags = ["members", "inherited-members"] +# autosummaries from source-files +autosummary_generate = True +# dont show __init__ docstring +autoclass_content = "class" +# sort class members +autodoc_member_order = "groupwise" +# autodoc_member_order = 'bysource' + +# Notes in boxes +napoleon_use_admonition_for_notes = True +# Attributes like parameters +# napoleon_use_ivar = True +# this is a nice class-doc layout +numpydoc_show_class_members = True +# class members have no separate file, so they are not in a toctree +numpydoc_class_members_toctree = False +# for the covmodels alot of classmembers show up... +# maybe switch off with: :no-inherited-members: +numpydoc_show_inherited_class_members = True # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] diff --git a/pyproject.toml b/pyproject.toml index 604faad..2e4703c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,14 +54,15 @@ dependencies = [ [project.optional-dependencies] doc = [ "gstools>=1.3,<2", + "scipy<1.9", "pillow", "scikit-learn>=0.19", "m2r2>=0.2.8", "matplotlib>=3", - "numpydoc>=1.1,<2", - "sphinx>=3,<4", - "sphinx-gallery>=0.8,<1", - "sphinx-rtd-theme>=0.5,<1", + "numpydoc>=1.1", + "sphinx>=4", + "sphinx-gallery>=0.8", + "sphinx-rtd-theme>=1", "sphinxcontrib-napoleon", ] plot = ["matplotlib>=3,<4"]