diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8892d946..ed31d85f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -# This workflow will install Python depe:ndencies, run tests and lint with a variety of Python versions +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: ci @@ -15,8 +15,20 @@ env: COVERAGE_CORE: sysmon jobs: - no_object_checks: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: "3.14" + - name: Run pre-commit + run: | + pip install pre-commit + pre-commit run --files src/**/*.py + no_object_checks: + needs: pre-commit runs-on: ubuntu-latest strategy: fail-fast: false @@ -29,37 +41,25 @@ jobs: group: [1, 2, 3] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} + cache: pip - name: Install dependencies run: | python -m pip install --upgrade pip pip install --editable . --group dev - # Uncomment below when ready to deal with a lot of PEP8 formatting changes - - name: Verify files with pre-commit - run: | - # Setup pre-commit hooks - pre-commit clean - pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks - pre-commit install --hook-type pre-merge-commit - pre-commit install --hook-type pre-push - pre-commit install --hook-type post-rewrite - pre-commit install-hooks - pre-commit install - # Run pre-commit hooks - pre-commit run --files src/**/*.py - name: Test with pytest run: | coverage run --source src -m pytest tests/pre_3_10 --splits 3 --group ${{ matrix.group }} coverage xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v6 objects_check: - + needs: pre-commit runs-on: ubuntu-latest strategy: fail-fast: false @@ -67,30 +67,19 @@ jobs: python-version: ["3.11", "3.12", "3.13", "3.14"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} + cache: pip - name: Install dependencies run: | python -m pip install --upgrade pip pip install --editable . --group dev - - name: Verify files with pre-commit - run: | - # Setup pre-commit hooks - pre-commit clean - pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks - pre-commit install --hook-type pre-merge-commit - pre-commit install --hook-type pre-push - pre-commit install --hook-type post-rewrite - pre-commit install-hooks - pre-commit install - # Run pre-commit hooks - pre-commit run --files src/vip_hci/objects/*.py - name: Test with pytest run: | coverage run --source=src/vip_hci/objects/ -m pytest tests/post_3_10 coverage xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v6 diff --git a/.github/workflows/draft-pdf.yml b/.github/workflows/draft-pdf.yml index cce545f2..6f6d14ea 100644 --- a/.github/workflows/draft-pdf.yml +++ b/.github/workflows/draft-pdf.yml @@ -6,7 +6,7 @@ jobs: name: Paper Draft steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Build draft PDF uses: openjournals/openjournals-draft-action@master with: @@ -14,7 +14,7 @@ jobs: # This should be the path to the paper within your repo. paper-path: paper.md - name: Upload - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: paper # This is the output path where Pandoc will write the compiled diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 91a09a0e..3ba88f61 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 089dbffb..00000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: python - -sudo: required -dist: xenial # no 3.7 on 14.04 Trusty - -python: - - 3.7 - - 3.8 - - 3.9 - -# command to install dependencies -install: - - pip install -e . - -# command to run tests + coverage -script: - - pytest -v - -after_success: - - codecov diff --git a/readthedocs_full_compilation_timeout_error.yml b/readthedocs_full_compilation_timeout_error.yml deleted file mode 100644 index 0ca52ca0..00000000 --- a/readthedocs_full_compilation_timeout_error.yml +++ /dev/null @@ -1,15 +0,0 @@ -# .readthedocs_timeout_error.yml - -version: 2 - -build: - os: ubuntu-22.04 - tools: - python: "3.10" - -python: - install: - - requirements: docs/requirements.txt - -sphinx: - configuration: docs/source/conf.py diff --git a/src/vip_hci/preproc/derotation.py b/src/vip_hci/preproc/derotation.py index 83749f86..610c8ad6 100644 --- a/src/vip_hci/preproc/derotation.py +++ b/src/vip_hci/preproc/derotation.py @@ -219,7 +219,7 @@ def frame_rotate(array, angle, imlib='vip-fft', interpolation='lanczos4', array_prep = array.copy() # residual (non-interp) nans should be set to 0 to avoid bug in rotation - array_prep[np.where(np.isnan(array_prep))] = 0 + array_prep[np.isnan(array_prep)] = 0 y, x = array_prep.shape @@ -604,9 +604,8 @@ def rotate_fft(array, angle): ori_y, ori_x = array_in.shape cy, cx = frame_center(array) - arr_xy = np.mgrid[0:ori_y, 0:ori_x] - arr_y = arr_xy[0]-cy - arr_x = arr_xy[1]-cx + arr_y = np.broadcast_to((np.arange(ori_y) - cy)[:, np.newaxis], (ori_y, ori_x)) + arr_x = np.broadcast_to((np.arange(ori_x) - cx)[np.newaxis, :], (ori_y, ori_x)) # TODO: make FFT padding work for other option than '0'. s_x = _fft_shear(array_in, arr_x, a, ax=1, pad=0) diff --git a/src/vip_hci/psfsub/pca_fullfr.py b/src/vip_hci/psfsub/pca_fullfr.py index 877520e4..10dda4ae 100644 --- a/src/vip_hci/psfsub/pca_fullfr.py +++ b/src/vip_hci/psfsub/pca_fullfr.py @@ -1428,22 +1428,38 @@ def _adimsdi_doublepca( for frame in range(n): ind = _find_indices_adi(angle_list, frame, pa_thr, truncate=truncate, max_frames=max_fr) - - res_result = _project_subtract( - res_cube_channels[:n], - res_cube_channels[n:], - ncomp_adi, - scaling[1], - mask_center_px, - svd_mode, - verbose, - False, - ind, - frame, - cube_sig=cube_sig, - left_eigv=left_eigv, - min_frames_pca=min_frames_pca, - ) + if 'A' in ref_strategy or cube_ref is None: + res_result = _project_subtract( + res_cube_channels[:n], + None, + ncomp_adi, + scaling[1], + mask_center_px, + svd_mode, + verbose, + False, + ind, + frame, + cube_sig=cube_sig, + left_eigv=left_eigv, + min_frames_pca=min_frames_pca, + ) + else: + res_result = _project_subtract( + res_cube_channels[:n], + res_cube_channels[n:], # ref cube + ncomp_adi, + scaling[1], + mask_center_px, + svd_mode, + verbose, + False, + ind, + frame, + cube_sig=cube_sig, + left_eigv=left_eigv, + min_frames_pca=min_frames_pca, + ) res_ifs_adi[frame] = res_result[-1].reshape((y_in, x_in)) if verbose: diff --git a/src/vip_hci/stats/__init__.py b/src/vip_hci/stats/__init__.py index 4b6e7bd2..6ac11bc6 100644 --- a/src/vip_hci/stats/__init__.py +++ b/src/vip_hci/stats/__init__.py @@ -9,6 +9,7 @@ - distance (correlation) between a cube and a reference frame. """ +from .bkg_proba import * from .clip_sigma import * from .distances import * from .im_stats import * diff --git a/src/vip_hci/stats/bkg_proba.py b/src/vip_hci/stats/bkg_proba.py index e4611d58..968a9e6b 100644 --- a/src/vip_hci/stats/bkg_proba.py +++ b/src/vip_hci/stats/bkg_proba.py @@ -11,9 +11,10 @@ import numpy as np -def bkg_star_proba(n_dens, sep, n_bkg=1, verbose=True, full_output=False): +def bkg_star_proba(n_dens, sep, n_bkg=1, unit="deg", verbose=True, + full_output=False): """ Given an input density of background star brighter than a certain - magnitude (obtained e.g. from the Besancon model or TRILEGAL), and the + magnitude (obtained e.g. from the Besançon model or TRILEGAL), and the separation of n_bkg point source, estimate the probability of having n_bkg or more background stars in a disk with radius equal to the largest separation. @@ -23,12 +24,15 @@ def bkg_star_proba(n_dens, sep, n_bkg=1, verbose=True, full_output=False): ---------- n_dens : float Number density of background stars in the direction of the object of - interest, in arcsec^-2. + interest. Units are set by the ``unit`` parameter. sep : float or numpy 1d array Separation of the point sources with respect to central star, in arcsec. n_bkg : int, opt Number of point sources in the field, and for which the separation is provided. + unit : str, opt + Unit of ``n_dens``. Either ``"deg"`` for deg^-2 (default, e.g. from + the Besançon model) or ``"arcsec"`` for arcsec^-2. verbose: bool, opt Whether to print the probabilities for 0 to n_bkg point sources. full_output: bool, opt @@ -46,6 +50,16 @@ def bkg_star_proba(n_dens, sep, n_bkg=1, verbose=True, full_output=False): if n_bkg < 1 or not isinstance(n_bkg, int): raise TypeError("n_bkg should be a strictly positive integer.") + if unit == "deg": + if verbose: + print("Input n_dens unit: deg^-2") + n_dens = n_dens / 3600**2 + elif unit == "arcsec": + if verbose: + print("Input n_dens unit: arcsec^-2") + else: + raise ValueError("unit must be 'deg' or 'arcsec'.") + if not isinstance(sep, float): if isinstance(sep, np.ndarray): if sep.ndim != 1 or sep.shape[0] != n_bkg: @@ -61,14 +75,14 @@ def bkg_star_proba(n_dens, sep, n_bkg=1, verbose=True, full_output=False): probas[i] = np.exp(-n_dens*B)*(n_dens*B)**i/float(factorial(i)) if verbose: msg = "Proba of having {:.0f} bkg star in a disk of " - msg += "{:.1}'' radius: {:.1f}%" - print(msg.format(i, sep, probas[i])) + msg += "{:.2g}'' radius: {:.4g}%" + print(msg.format(i, sep, probas[i]*100)) proba = 1-np.sum(probas) if verbose: msg = "Proba of having {:.0f} bkg star or more in a disk of " - msg += "{:.1}'' radius: {:.1f}%" - print(msg.format(n_bkg, sep, proba)) + msg += "{:.2g}'' radius: {:.4g}%" + print(msg.format(n_bkg, sep, proba*100)) if full_output: return proba, probas