Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
# needed by coveralls
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CIBW_BUILD: "cp35-* cp36-* cp37-* cp38-* cp39-*"
CIBW_BEFORE_BUILD: 'pip install "numpy<=1.19.4" "scipy<=1.5.4" "cython>=0.29.14" setuptools'
CIBW_TEST_REQUIRES: "pytest scikit-learn"
CIBW_TEST_COMMAND: "pytest -v {project}/tests"

jobs:
format_check:
name: format check
Expand Down Expand Up @@ -67,17 +59,19 @@ jobs:
pip install -r requirements_setup.txt
pip install -r requirements.txt
pip install -r requirements_test.txt
pip install coveralls>=2.0.0
pip install coveralls>=3.0.0

- name: Build sdist
run: |
python setup.py sdist -d dist
python setup.py build_ext --inplace

- name: Run tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pytest --cov pykrige --cov-report term-missing -v tests/
python -m coveralls
python -m coveralls --service=github

- uses: actions/upload-artifact@v2
with:
Expand All @@ -96,18 +90,15 @@ jobs:
with:
fetch-depth: '0'

- name: Set up Python
uses: actions\setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install cibuildwheel==1.7.0
- name: Build wheels
run: |
python -m cibuildwheel --output-dir dist
uses: joerick/[email protected]
env:
CIBW_BUILD: cp36-* cp37-* cp38-* cp39-*
CIBW_BEFORE_BUILD: pip install numpy==1.19.* scipy==1.5.* cython==0.29.* setuptools
CIBW_TEST_REQUIRES: pytest scikit-learn
CIBW_TEST_COMMAND: pytest -v {project}/tests
with:
output-dir: dist

- uses: actions/upload-artifact@v2
with:
Expand All @@ -125,7 +116,7 @@ jobs:

- name: Publish to Test PyPI
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.test_pypi_password }}
Expand All @@ -135,7 +126,7 @@ jobs:
- name: Publish to PyPI
# only if tagged
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
93 changes: 54 additions & 39 deletions benchmarks/kriging_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from time import time
import numpy as np
from pykrige.ok import OrdinaryKriging

np.random.seed(19999)

VARIOGRAM_MODELS = ['power', 'gaussian', 'spherical',
'exponential', 'linear']
BACKENDS = ['vectorized', 'loop', 'C']
VARIOGRAM_MODELS = ["power", "gaussian", "spherical", "exponential", "linear"]
BACKENDS = ["vectorized", "loop", "C"]
N_MOVING_WINDOW = [None, 10, 50, 100]


Expand Down Expand Up @@ -36,23 +36,32 @@ def make_benchark(n_train, n_test, n_dim=2):

for variogram_model in VARIOGRAM_MODELS:
tic = time()
OK = OrdinaryKriging(X_train[:, 0], X_train[:, 1], y_train,
variogram_model='linear',
verbose=False, enable_plotting=False)
res['t_train_{}'.format(variogram_model)] = time() - tic
OK = OrdinaryKriging(
X_train[:, 0],
X_train[:, 1],
y_train,
variogram_model="linear",
verbose=False,
enable_plotting=False,
)
res["t_train_{}".format(variogram_model)] = time() - tic

# All the following tests are performed with the linear variogram model
for backend in BACKENDS:
for n_closest_points in N_MOVING_WINDOW:

if backend == 'vectorized' and n_closest_points is not None:
if backend == "vectorized" and n_closest_points is not None:
continue # this is not supported

tic = time()
OK.execute('points', X_test[:, 0], X_test[:, 1],
backend=backend,
n_closest_points=n_closest_points)
res['t_test_{}_{}'.format(backend, n_closest_points)] = time() - tic
OK.execute(
"points",
X_test[:, 0],
X_test[:, 1],
backend=backend,
n_closest_points=n_closest_points,
)
res["t_test_{}_{}".format(backend, n_closest_points)] = time() - tic

return res

Expand All @@ -71,34 +80,40 @@ def print_benchmark(n_train, n_test, n_dim, res):
res : dict
a dictionary with the timing results
"""
print('='*80)
print(' '*10, 'N_dim={}, N_train={}, N_test={}'.format(n_dim,
n_train, n_test))
print('='*80)
print('\n', '# Training the model', '\n')
print('|'.join(['{:>11} '.format(el) for el in ['t_train (s)'] +
VARIOGRAM_MODELS]))
print('-' * (11 + 2) * (len(VARIOGRAM_MODELS) + 1))
print('|'.join(['{:>11} '.format('Training')] +
['{:>11.2} '.format(el) for el in
[res['t_train_{}'.format(mod)]
for mod in VARIOGRAM_MODELS]]))

print('\n', '# Predicting kriging points', '\n')
print('|'.join(['{:>11} '.format(el) for el in ['t_test (s)'] + BACKENDS]))
print('-' * (11 + 2) * (len(BACKENDS) + 1))
print("=" * 80)
print(" " * 10, "N_dim={}, N_train={}, N_test={}".format(n_dim, n_train, n_test))
print("=" * 80)
print("\n", "# Training the model", "\n")
print("|".join(["{:>11} ".format(el) for el in ["t_train (s)"] + VARIOGRAM_MODELS]))
print("-" * (11 + 2) * (len(VARIOGRAM_MODELS) + 1))
print(
"|".join(
["{:>11} ".format("Training")]
+ [
"{:>11.2} ".format(el)
for el in [res["t_train_{}".format(mod)] for mod in VARIOGRAM_MODELS]
]
)
)

print("\n", "# Predicting kriging points", "\n")
print("|".join(["{:>11} ".format(el) for el in ["t_test (s)"] + BACKENDS]))
print("-" * (11 + 2) * (len(BACKENDS) + 1))

for n_closest_points in N_MOVING_WINDOW:
timing_results = [res.get(
't_test_{}_{}'.format(mod, n_closest_points), '')
for mod in BACKENDS]
print('|'.join(['{:>11} '.format('N_nn=' + str(n_closest_points))] +
['{:>11.2} '.format(el) for el in timing_results]))


if __name__ == '__main__':
for no_train, no_test in [(400, 1000),
(400, 2000),
(800, 2000)]:
timing_results = [
res.get("t_test_{}_{}".format(mod, n_closest_points), "")
for mod in BACKENDS
]
print(
"|".join(
["{:>11} ".format("N_nn=" + str(n_closest_points))]
+ ["{:>11.2} ".format(el) for el in timing_results]
)
)


if __name__ == "__main__":
for no_train, no_test in [(400, 1000), (400, 2000), (800, 2000)]:
results = make_benchark(no_train, no_test)
print_benchmark(no_train, no_test, 2, results)
7 changes: 6 additions & 1 deletion pykrige/ok.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,12 @@ def execute(
zvalues, sigmasq = self._exec_loop_moving_window(a, bd, mask, bd_idx)
elif backend == "C":
zvalues, sigmasq = _c_exec_loop_moving_window(
a, bd, mask.astype("int8"), bd_idx, self.X_ADJUSTED.shape[0], c_pars
a,
bd,
mask.astype("int8"),
bd_idx.astype(int),
self.X_ADJUSTED.shape[0],
c_pars,
)
else:
raise ValueError(
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand All @@ -89,7 +88,7 @@
classifiers=CLASSIFIERS,
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
include_package_data=True,
python_requires=">=3.5",
python_requires=">=3.6",
use_scm_version={
"relative_to": __file__,
"write_to": "pykrige/_version.py",
Expand Down