Skip to content

Commit

Permalink
Replace rcond with rtol in pinv() call (#156)
Browse files Browse the repository at this point in the history
* 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`.

* 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 .`)

* Do not use NumPy 2.0

Package `python-casacore` is not (yet) compatible with NumPy 2.0. Use latest NumPy 1.x version.

* Update python.yml

Wrong tests were called.

Just invoking `pytest` should do the right thing. To be fixed in another PR.

* 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.

* Update python.yml

Use latest major version of `actions/setup-python`
  • Loading branch information
gmloose authored Jul 10, 2024
1 parent d3b1f3b commit 1f3c605
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ 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
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
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
# We cannot yet use `pytest`; requires different test file names
run: python tools/losoto_test.py
8 changes: 4 additions & 4 deletions losoto/operations/directionscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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]))
Expand Down
4 changes: 2 additions & 2 deletions losoto/operations/stationscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 1f3c605

Please sign in to comment.