Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various issues #587

Merged
merged 4 commits into from
May 5, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
run: |
pytest --cov=vip_hci/ --cov-report=xml --splits 3 --group ${{ matrix.group }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
8 changes: 8 additions & 0 deletions docs/source/vip_hci.psfsub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ vip\_hci.psfsub.pca\_local module
:undoc-members:
:show-inheritance:

vip\_hci.psfsub.pca\_return\_utils module
-----------------------------------------

.. automodule:: vip_hci.psfsub.pca_return_utils
:members:
:undoc-members:
:show-inheritance:

vip\_hci.psfsub.svd module
--------------------------

Expand Down
16 changes: 16 additions & 0 deletions docs/source/vip_hci.var.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ vip\_hci.var.iuwt module
:undoc-members:
:show-inheritance:

vip\_hci.var.object\_utils module
---------------------------------

.. automodule:: vip_hci.var.object_utils
:members:
:undoc-members:
:show-inheritance:

vip\_hci.var.paramenum module
-----------------------------

.. automodule:: vip_hci.var.paramenum
:members:
:undoc-members:
:show-inheritance:

vip\_hci.var.shapes module
--------------------------

Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ sphinx
pandoc
pytest
pytest-cov ~=2.6.0
codecov ~=2.0.15
pytest-split
flake8
flake8-bandit
flake8-docstrings
autopep8
sphinx-rtd-theme
StrEnum
ratelimit
56 changes: 32 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Configuration file for pytest, containing global ("session-level") fixtures.

"""
import time
import copy
import time

import numpy as np
import pytest
from astropy.utils.data import download_file

import vip_hci as vip
from .helpers import download_resource


@pytest.fixture(scope="session")
Expand All @@ -23,17 +23,19 @@ def example_dataset_adi():

Notes
-----
Astropy's ``download_file`` uses caching, so the file is downloaded at most
once per test run.
We use the helper function ``download_resource`` which handles the request
and puts it to sleep for a defined duration if too many requests are done.
They inherently call the Astropy's ``download_file`` function which uses caching,
so the file is downloaded at most once per test run.

"""
print("downloading data...")

url_prefix = "https://github.com/vortex-exoplanet/VIP_extras/raw/master/datasets"

f1 = download_file("{}/naco_betapic_cube_cen.fits".format(url_prefix), cache=True)
f2 = download_file("{}/naco_betapic_psf.fits".format(url_prefix), cache=True)
f3 = download_file("{}/naco_betapic_pa.fits".format(url_prefix), cache=True)
f1 = download_resource("{}/naco_betapic_cube_cen.fits".format(url_prefix))
f2 = download_resource("{}/naco_betapic_psf.fits".format(url_prefix))
f3 = download_resource("{}/naco_betapic_pa.fits".format(url_prefix))

# load fits
cube = vip.fits.open_fits(f1)
Expand Down Expand Up @@ -89,18 +91,20 @@ def example_dataset_ifs():

Notes
-----
Astropy's ``download_file`` uses caching, so the file is downloaded at most
once per test run.
We use the helper function ``download_resource`` which handles the request
and puts it to sleep for a defined duration if too many requests are done.
They inherently call the Astropy's ``download_file`` function which uses caching,
so the file is downloaded at most once per test run.

"""
print("downloading data...")

url_prefix = "https://github.com/vortex-exoplanet/VIP_extras/raw/master/datasets"

f1 = download_file("{}/sphere_v471tau_cube.fits".format(url_prefix), cache=True)
f2 = download_file("{}/sphere_v471tau_psf.fits".format(url_prefix), cache=True)
f3 = download_file("{}/sphere_v471tau_pa.fits".format(url_prefix), cache=True)
f4 = download_file("{}/sphere_v471tau_wl.fits".format(url_prefix), cache=True)
f1 = download_resource("{}/sphere_v471tau_cube.fits".format(url_prefix))
f2 = download_resource("{}/sphere_v471tau_psf.fits".format(url_prefix))
f3 = download_resource("{}/sphere_v471tau_pa.fits".format(url_prefix))
f4 = download_resource("{}/sphere_v471tau_wl.fits".format(url_prefix))

# load fits
cube = vip.fits.open_fits(f1)
Expand Down Expand Up @@ -139,18 +143,20 @@ def example_dataset_ifs_crop():

Notes
-----
Astropy's ``download_file`` uses caching, so the file is downloaded at most
once per test run.
We use the helper function ``download_resource`` which handles the request
and puts it to sleep for a defined duration if too many requests are done.
They inherently call the Astropy's ``download_file`` function which uses caching,
so the file is downloaded at most once per test run.

"""
print("downloading data...")

url_prefix = "https://github.com/vortex-exoplanet/VIP_extras/raw/master/datasets"

f1 = download_file("{}/sphere_v471tau_cube.fits".format(url_prefix), cache=True)
f2 = download_file("{}/sphere_v471tau_psf.fits".format(url_prefix), cache=True)
f3 = download_file("{}/sphere_v471tau_pa.fits".format(url_prefix), cache=True)
f4 = download_file("{}/sphere_v471tau_wl.fits".format(url_prefix), cache=True)
f1 = download_resource("{}/sphere_v471tau_cube.fits".format(url_prefix))
f2 = download_resource("{}/sphere_v471tau_psf.fits".format(url_prefix))
f3 = download_resource("{}/sphere_v471tau_pa.fits".format(url_prefix))
f4 = download_resource("{}/sphere_v471tau_wl.fits".format(url_prefix))

# load fits
cube = vip.fits.open_fits(f1)
Expand Down Expand Up @@ -191,17 +197,19 @@ def example_dataset_rdi():

Notes
-----
Astropy's ``download_file`` uses caching, so the file is downloaded at most
once per test run.
We use the helper function ``download_resource`` which handles the request
and puts it to sleep for a defined duration if too many requests are done.
They inherently call the Astropy's ``download_file`` function which uses caching,
so the file is downloaded at most once per test run.

"""
print("downloading data...")

url_prefix = "https://github.com/vortex-exoplanet/VIP_extras/raw/master/datasets"

f1 = download_file("{}/naco_betapic_cube_cen.fits".format(url_prefix), cache=True)
f2 = download_file("{}/naco_betapic_psf.fits".format(url_prefix), cache=True)
f3 = download_file("{}/naco_betapic_pa.fits".format(url_prefix), cache=True)
f1 = download_resource("{}/naco_betapic_cube_cen.fits".format(url_prefix))
f2 = download_resource("{}/naco_betapic_psf.fits".format(url_prefix))
f3 = download_resource("{}/naco_betapic_pa.fits".format(url_prefix))

# load fits
cube = vip.fits.open_fits(f1)
Expand Down
10 changes: 9 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

__author__ = "Thomas Bédrine, Ralf Farkas"

__all__ = ["check_detection"]
__all__ = ["check_detection", "download_resource"]

import pytest
from pytest import mark, param, raises, fixture
from ratelimit import limits, sleep_and_retry
from astropy.utils.data import download_file
import vip_hci as vip
import numpy as np

Expand Down Expand Up @@ -76,3 +78,9 @@ def verify_expcoord(vectory, vectorx, exp_yx):
)
msg = "Injected companion not recovered"
assert verify_expcoord(table.y, table.x, yx_exp), msg


@sleep_and_retry
@limits(calls=1, period=1)
def download_resource(url):
return download_file(url, cache=True)
13 changes: 8 additions & 5 deletions tests/snapshots/snapshot_invprob.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from vip_hci.fits import open_fits
from vip_hci.objects import Dataset
from vip_hci.config import VLT_NACO
from tests.helpers import download_resource

INVADI_PATH = "./tests/snapshots/invprob_adi/"
DATASET_ELEMENTS = ["cube", "angles", "psf"]
Expand All @@ -28,17 +29,19 @@ def make_dataset_adi():

Notes
-----
Astropy's ``download_file`` uses caching, so the file is downloaded at most
once per test run.
We use the helper function ``download_resource`` which handles the request
and puts it to sleep for a defined duration if too many requests are done.
They inherently call the Astropy's ``download_file`` function which uses caching,
so the file is downloaded at most once per test run.

"""
print("downloading data...")

url_prefix = "https://github.com/vortex-exoplanet/VIP_extras/raw/master/datasets"

f1 = download_file(f"{url_prefix}/naco_betapic_cube_cen.fits", cache=True)
f2 = download_file(f"{url_prefix}/naco_betapic_psf.fits", cache=True)
f3 = download_file(f"{url_prefix}/naco_betapic_pa.fits", cache=True)
f1 = download_resource(f"{url_prefix}/naco_betapic_cube_cen.fits")
f2 = download_resource(f"{url_prefix}/naco_betapic_psf.fits")
f3 = download_resource(f"{url_prefix}/naco_betapic_pa.fits")

# load fits
cube = open_fits(f1)
Expand Down
14 changes: 8 additions & 6 deletions tests/snapshots/snapshot_psfsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import numpy as np
from vip_hci.psfsub import median_sub, frame_diff, llsg, xloci, nmf, nmf_annular
from vip_hci.metrics import detection, snrmap
from astropy.utils.data import download_file
from vip_hci.fits import open_fits
from vip_hci.objects import Dataset
from vip_hci.config import VLT_NACO
from tests.helpers import download_resource

PSFADI_PATH = "./tests/snapshots/psfsub_adi/"
DATASET_ELEMENTS = ["cube", "angles", "psf"]
Expand All @@ -28,17 +28,19 @@ def make_dataset_adi():

Notes
-----
Astropy's ``download_file`` uses caching, so the file is downloaded at most
once per test run.
We use the helper function ``download_resource`` which handles the request
and puts it to sleep for a defined duration if too many requests are done.
They inherently call the Astropy's ``download_file`` function which uses caching,
so the file is downloaded at most once per test run.

"""
print("downloading data...")

url_prefix = "https://github.com/vortex-exoplanet/VIP_extras/raw/master/datasets"

f1 = download_file(f"{url_prefix}/naco_betapic_cube_cen.fits", cache=True)
f2 = download_file(f"{url_prefix}/naco_betapic_psf.fits", cache=True)
f3 = download_file(f"{url_prefix}/naco_betapic_pa.fits", cache=True)
f1 = download_resource(f"{url_prefix}/naco_betapic_cube_cen.fits")
f2 = download_resource(f"{url_prefix}/naco_betapic_psf.fits")
f3 = download_resource(f"{url_prefix}/naco_betapic_pa.fits")

# load fits
cube = open_fits(f1)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_objects_ppnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_nmf_object(injected_cube_position):
"""
Compare detections obtained through procedural and object versions of NMF.

Generate a frame with ``vip_hci.objects.ppmediansub`` and ensure its detection match
Generate a frame with ``vip_hci.objects.ppnmf`` and ensure its detection match
with its procedural counterpart. This is done by getting the snapshot of the
``vip_hci.psfsub.nmf`` function, generated preemptively with
``tests.snapshots.save_snapshots_psfsub``. Also done with
Expand Down
Loading