From 0a3953428141c836866da4e4028df1d112ea264f Mon Sep 17 00:00:00 2001 From: Marcel Loose Date: Tue, 9 Jul 2024 22:21:44 +0200 Subject: [PATCH 1/6] Replace rcond with rtol in pinv() call The `pinv()` function deprecated the use of `rcond` in favour of `rtol`, and SciPy 1.14.0 removed the keyword option `rcond` completely from `pinv()`. Replaced all occurrences of `rcond` in calls to `pinv()` with `rtol`. --- losoto/operations/directionscreen.py | 8 ++++---- losoto/operations/stationscreen.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/losoto/operations/directionscreen.py b/losoto/operations/directionscreen.py index 3f2db68..47a42ca 100644 --- a/losoto/operations/directionscreen.py +++ b/losoto/operations/directionscreen.py @@ -248,9 +248,9 @@ def _fit_phase_screen(station_names, source_names, pp, airmass, rr, weights, tim D = np.transpose(D, (1, 0, 2)) - D D2 = np.sum(D**2, axis=2) C = -(D2 / r_0**2)**(beta / 2.0) / 2.0 - pinvC = pinv(C, rcond=1e-3) + pinvC = pinv(C, rtol=1e-3) U, S, V = svd(C) - invU = pinv(np.dot(np.transpose(U[:, :order]), np.dot(weights[:, :, k], U[:, :order])), rcond=1e-3) + invU = pinv(np.dot(np.transpose(U[:, :order]), np.dot(weights[:, :, k], U[:, :order])), rtol=1e-3) # Calculate real screen rr1 = np.dot(np.transpose(U[:, :order]), np.dot(weights[:, :, k], rr_real[:, k])) @@ -337,9 +337,9 @@ def _fit_tec_screen(station_names, source_names, pp, airmass, rr, weights, times D = np.transpose(D, (1, 0, 2)) - D D2 = np.sum(D**2, axis=2) C = -(D2 / r_0**2)**(beta / 2.0) / 2.0 - pinvC = pinv(C, rcond=1e-3) + pinvC = pinv(C, rtol=1e-3) U, S, V = svd(C) - invU = pinv(np.dot(np.transpose(U[:, :order]), np.dot(weights[:, :, k], U[:, :order])), rcond=1e-3) + invU = pinv(np.dot(np.transpose(U[:, :order]), np.dot(weights[:, :, k], U[:, :order])), rtol=1e-3) # Calculate screen rr1 = np.dot(np.transpose(U[:, :order]), np.dot(weights[:, :, k], rr[:, k])) diff --git a/losoto/operations/stationscreen.py b/losoto/operations/stationscreen.py index ca47790..2b7d91e 100644 --- a/losoto/operations/stationscreen.py +++ b/losoto/operations/stationscreen.py @@ -375,7 +375,7 @@ def _calculate_svd(pp, r_0, beta, N_piercepoints): D = np.transpose(D, (1, 0, 2)) - D D2 = np.sum(D**2, axis=2) C = -(D2 / r_0**2)**(beta / 2.0) / 2.0 - pinvC = pinv(C, rcond=1e-3) + pinvC = pinv(C, rtol=1e-3) U, S, V = svd(C) return C, pinvC, U @@ -439,7 +439,7 @@ def _fit_screen(source_names, full_matrices, pp, rr, weights, order, r_0, beta, else: # Recalculate for unflagged directions C, pinvC, U = _calculate_svd(pp, r_0, beta, N_piercepoints) - invU = pinv(np.dot(np.transpose(U[:, :order]), np.dot(w, U)[:, :order]), rcond=1e-3) + invU = pinv(np.dot(np.transpose(U[:, :order]), np.dot(w, U)[:, :order]), rtol=1e-3) # Fit screen to unflagged directions if screen_type == 'phase': From ddb9b1f7703494ac6e6890e01b2490a7938d2444 Mon Sep 17 00:00:00 2001 From: Marcel Loose Date: Tue, 9 Jul 2024 22:36:35 +0200 Subject: [PATCH 2/6] Update python.yml Need to fix workflow as well, since it still used the old-fashioned way of installing (i.e. `python setup.py install`, instead of `pip install .`) --- .github/workflows/python.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8474f99..c351d98 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -21,6 +21,6 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest - name: Install - run: python setup.py install + run: pip install . - name: Test - run: python setup.py test + run: pytest From fb99eb4f2a568640dd4f0499b3d0b8c02ac81c20 Mon Sep 17 00:00:00 2001 From: Marcel Loose Date: Tue, 9 Jul 2024 22:38:56 +0200 Subject: [PATCH 3/6] Do not use NumPy 2.0 Package `python-casacore` is not (yet) compatible with NumPy 2.0. Use latest NumPy 1.x version. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 105fae2..7d6693b 100755 --- a/setup.py +++ b/setup.py @@ -71,7 +71,7 @@ def run(self): 'Topic :: Software Development :: Libraries :: Python Modules', ], tests_require=['pytest'], - install_requires=['numpy>=1.9', 'cython', 'tables>=3.4', 'configparser', + install_requires=['numpy>=1.9,<2.0', 'cython', 'tables>=3.4', 'configparser', 'scipy', 'matplotlib', 'python-casacore>=3.0'], scripts=['bin/losoto', 'bin/H5parm_split.py', 'bin/H5parm2parmdb.py', 'bin/parmdb2H5parm.py', 'bin/killMS2H5parm.py', From 2aa950b19662d20bccf3bdd66d19d3914009e4f1 Mon Sep 17 00:00:00 2001 From: Marcel Loose Date: Tue, 9 Jul 2024 22:47:24 +0200 Subject: [PATCH 4/6] Update python.yml Wrong tests were called. Just invoking `pytest` should do the right thing. To be fixed in another PR. --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c351d98..019ad23 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -23,4 +23,4 @@ jobs: - name: Install run: pip install . - name: Test - run: pytest + run: pytest -sv tools/losoto_test.py From 0599fb9de5d7f07ff4e3e0e6b932dc9cb1f349ef Mon Sep 17 00:00:00 2001 From: Marcel Loose Date: Tue, 9 Jul 2024 22:55:56 +0200 Subject: [PATCH 5/6] We cannot yet use PyTest The name of the (single) test script doesn't adhere to `pytest` standards, so it is not found. At the same time, there are a few Python files named "test*.py" that contain currently failing tests. This needs to be fixed in a different PR. --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 019ad23..7e987f3 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -23,4 +23,5 @@ jobs: - name: Install run: pip install . - name: Test - run: pytest -sv tools/losoto_test.py + # We cannot yet use `pytest`; requires different test file names + run: python tools/losoto_test.py From 77f6a08457fb3af16a400d3b793842a7d89adae4 Mon Sep 17 00:00:00 2001 From: Marcel Loose Date: Wed, 10 Jul 2024 10:49:19 +0200 Subject: [PATCH 6/6] Update python.yml Use latest major version of `actions/setup-python` --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7e987f3..723693f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies