From 864fabd13ad0cfd9979ccbcaea1143dac8991a58 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Fri, 13 Aug 2021 15:21:15 +0200 Subject: [PATCH 1/7] fix deramp residual and optimizer --- xdem/coreg.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xdem/coreg.py b/xdem/coreg.py index 983ae6ef..02614465 100644 --- a/xdem/coreg.py +++ b/xdem/coreg.py @@ -1033,7 +1033,8 @@ def poly2d(x_coordinates: np.ndarray, y_coordinates: np.ndarray, return estimated_values # type: ignore def residuals(coefs: np.ndarray, x_coords: np.ndarray, y_coords: np.ndarray, targets: np.ndarray): - return np.median(np.abs(targets - poly2d(x_coords, y_coords, coefs))) + res = targets - poly2d(x_coords, y_coords, coefs) + return res[np.isfinite(res)] if verbose: print("Estimating deramp function...") @@ -1055,15 +1056,14 @@ def residuals(coefs: np.ndarray, x_coords: np.ndarray, y_coords: np.ndarray, tar ddem = ddem[indices] # Optimize polynomial parameters - coefs = scipy.optimize.fmin( + coefs = scipy.optimize.leastsq( func=residuals, x0=np.zeros(shape=((self.degree + 1) * (self.degree + 2) // 2)), - args=(x_coords, y_coords, ddem), - disp=verbose + args=(x_coords, y_coords, ddem) ) - self._meta["coefficients"] = coefs - self._meta["func"] = lambda x, y: poly2d(x, y, coefs) + self._meta["coefficients"] = coefs[0] + self._meta["func"] = lambda x, y: poly2d(x, y, coefs[0]) def _apply_func(self, dem: np.ndarray, transform: rio.transform.Affine) -> np.ndarray: """Apply the deramp function to a DEM.""" From 40257fe0a8b0c6fa72f7e2849fba6ed90b7cb3c4 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Fri, 12 Aug 2022 12:02:56 +0200 Subject: [PATCH 2/7] Add coveralls GitHub Actions routine --- .github/workflows/python-package.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 7271ad70..acecaa8e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -57,3 +57,20 @@ jobs: - name: Test with pytest run: | pytest -ra -n=auto + + - name: Coverall coverage + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + flag-name: run-${{ matrix.test_number }} + parallel: true + + finish: + needs: test + runs-on: ubuntu-latest + steps: + - name: Coveralls finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true From 6af4b35a35925fefcbdffec73df25fdbf2274457 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Fri, 12 Aug 2022 12:07:53 +0200 Subject: [PATCH 3/7] Rename job build into test for coveralls --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index acecaa8e..c63c7e36 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -10,7 +10,7 @@ on: branches: [ main ] jobs: - build: + test: name: ${{ matrix.os }}, python ${{ matrix.python-version}} runs-on: ${{ matrix.os }} From 883900e69c36f40fb2a7f7d38fe4d9315ba26ddf Mon Sep 17 00:00:00 2001 From: rhugonne Date: Fri, 12 Aug 2022 12:53:22 +0200 Subject: [PATCH 4/7] Generate coverage output with pytest --- .github/workflows/python-package.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c63c7e36..618376ab 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -56,7 +56,8 @@ jobs: python -c "from xdem.examples import *; download_longyearbyen_examples(overwrite=False)" - name: Test with pytest run: | - pytest -ra -n=auto + pip install pytest-cov coveralls + pytest -ra -n=auto --cov=xdem/ - name: Coverall coverage uses: coverallsapp/github-action@master From cc4354ee33c0633867822af6442d15c8ea38768f Mon Sep 17 00:00:00 2001 From: rhugonne Date: Fri, 12 Aug 2022 13:15:11 +0200 Subject: [PATCH 5/7] Specify path to pytest coverage file --- .github/workflows/python-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 618376ab..c340b042 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -64,6 +64,7 @@ jobs: with: github-token: ${{ secrets.github_token }} flag-name: run-${{ matrix.test_number }} + path-to-lcov: .coverage parallel: true finish: From f26d3e1660199f24e9ccbd1f42480a3da4b1c949 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Wed, 17 Aug 2022 16:14:45 +0200 Subject: [PATCH 6/7] Convert coverage file to lcov format --- .github/workflows/python-package.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c340b042..6119892c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -59,19 +59,26 @@ jobs: pip install pytest-cov coveralls pytest -ra -n=auto --cov=xdem/ - - name: Coverall coverage + # We can skip the conversion step once this PR of pytest is merged: https://github.com/pytest-dev/pytest-cov/pull/536 + # and replace pytest argument by --cov-report=lcov + - name: Converting coverage to LCOV format + run: | + pip install coveragepy-lcov + coveragepy-lcov --data_file_path .coverage --output_file_path coverage.info + + - name: Upload coverage to Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.github_token }} flag-name: run-${{ matrix.test_number }} - path-to-lcov: .coverage + path-to-lcov: coverage.info parallel: true finish: needs: test runs-on: ubuntu-latest steps: - - name: Coveralls finished + - name: Upload to Coveralls finished uses: coverallsapp/github-action@master with: github-token: ${{ secrets.github_token }} From d19af18daa2b016c5ddcf11f4df75300aff6d049 Mon Sep 17 00:00:00 2001 From: rhugonne Date: Wed, 17 Aug 2022 16:39:41 +0200 Subject: [PATCH 7/7] Add coverage badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5c2494c1..e698699f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ More documentation to come! [![Conda Version](https://img.shields.io/conda/vn/conda-forge/xdem.svg)](https://anaconda.org/conda-forge/xdem) [![Conda Platforms](https://img.shields.io/conda/pn/conda-forge/xdem.svg)](https://anaconda.org/conda-forge/xdem) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/xdem.svg)](https://anaconda.org/conda-forge/xdem) +[![Coverage Status](https://coveralls.io/repos/github/GlacioHack/xdem/badge.svg?branch=main)](https://coveralls.io/github/GlacioHack/xdem?branch=main) To cite this package: [![Zenodo](https://zenodo.org/badge/doi/10.5281/zenodo.4809697.svg)](https://zenodo.org/record/4809698)