From a0316fdf54d369b17c533f2120868126b17ed846 Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Mon, 21 Nov 2022 11:40:49 -0500 Subject: [PATCH 1/4] remove dependency on `opencv-python` --- src/stcal/jump/jump.py | 11 ++++++++++- tests/test_jump.py | 16 +++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/stcal/jump/jump.py b/src/stcal/jump/jump.py index 267169b3..0f2ab332 100644 --- a/src/stcal/jump/jump.py +++ b/src/stcal/jump/jump.py @@ -1,12 +1,21 @@ import time import logging +import warnings + import numpy as np -import cv2 as cv from . import twopoint_difference as twopt from . import constants import multiprocessing +try: + import cv2 as cv + + OPENCV_INSTALLED = True +except ImportError: + OPENCV_INSTALLED = False + warnings.warn('Could not import `opencv-python`; certain snowball detection and usage of ellipses will be inoperable') + log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) diff --git a/tests/test_jump.py b/tests/test_jump.py index 615f0a23..500dd7f4 100644 --- a/tests/test_jump.py +++ b/tests/test_jump.py @@ -1,17 +1,21 @@ -import pytest import numpy as np +import pytest from astropy.io import fits from stcal.jump.jump import flag_large_events, find_circles, find_ellipses +DQFLAGS = {'JUMP_DET': 4, 'SATURATED': 2, 'DO_NOT_USE': 1} +try: + import cv2 as cv -DQFLAGS = {'JUMP_DET': 4, 'SATURATED': 2, 'DO_NOT_USE': 1} + OPENCV_INSTALLED = True +except ImportError: + OPENCV_INSTALLED = False @pytest.fixture(scope='function') def setup_cube(): - def _cube(ngroups, readnoise=10): nints = 1 nrows = 204 @@ -27,6 +31,7 @@ def _cube(ngroups, readnoise=10): return _cube +@pytest.mark.skipif(not OPENCV_INSTALLED, reason="`opencv-python` not installed") def test_find_simple_circle(): plane = np.zeros(shape=(5, 5), dtype=np.uint8) plane[2, 2] = DQFLAGS['JUMP_DET'] @@ -38,6 +43,7 @@ def test_find_simple_circle(): assert circle[0][1] == pytest.approx(1.0, 1e-3) +@pytest.mark.skipif(not OPENCV_INSTALLED, reason="`opencv-python` not installed") def test_find_simple_ellipse(): plane = np.zeros(shape=(5, 5), dtype=np.uint8) plane[2, 2] = DQFLAGS['JUMP_DET'] @@ -49,9 +55,10 @@ def test_find_simple_ellipse(): plane[2, 4] = DQFLAGS['JUMP_DET'] plane[3, 3] = DQFLAGS['JUMP_DET'] ellipse = find_ellipses(plane, DQFLAGS['JUMP_DET'], 1) - assert ellipse[0][2] == pytest.approx(45.0, 1e-3) # 90 degree rotation + assert ellipse[0][2] == pytest.approx(45.0, 1e-3) # 90 degree rotation assert ellipse[0][0] == pytest.approx((2.5, 2.0)) # center + @pytest.mark.skip(reason="only for local testing") def test_single_group(): inplane = fits.getdata("jumppix.fits") @@ -61,4 +68,3 @@ def test_single_group(): min_jump_area=15, max_offset=1, expand_factor=1.1, use_ellipses=True, sat_required_snowball=False) fits.writeto("jumppix_expand.fits", indq, overwrite=True) - From 3fb0da24225ecc766965906f9fb81d9b63579690 Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Mon, 21 Nov 2022 11:55:01 -0500 Subject: [PATCH 2/4] apply `flake8` fixes --- src/stcal/jump/jump.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stcal/jump/jump.py b/src/stcal/jump/jump.py index 0f2ab332..1ab252b2 100644 --- a/src/stcal/jump/jump.py +++ b/src/stcal/jump/jump.py @@ -14,7 +14,8 @@ OPENCV_INSTALLED = True except ImportError: OPENCV_INSTALLED = False - warnings.warn('Could not import `opencv-python`; certain snowball detection and usage of ellipses will be inoperable') + warnings.warn('Could not import `opencv-python`; ' + 'certain snowball detection and usage of ellipses will be inoperable') log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) From e64dd34c2b7b73c7cba8f65064714db9edd95d27 Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Mon, 21 Nov 2022 13:10:33 -0500 Subject: [PATCH 3/4] add change log entry --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index fbc1baff..f20255ec 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ General ------- - Moved build configuration from ``setup.cfg`` to ``pyproject.toml`` to support PEP621 [#95] - +- made dependency on ``opencv-python`` conditional [#126] ramp_fitting ~~~~~~~~~~~~ From 593e8b908ffff6638d68cc98fa88d2341ce8a975 Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Tue, 22 Nov 2022 09:58:39 -0500 Subject: [PATCH 4/4] update dependencies --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 109a2a8a..069e5bef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,6 @@ dependencies = [ 'astropy >=5.0.4', 'scipy >=1.6.0', 'numpy >=1.17', - 'opencv-python >=4.6.0.66', ] dynamic = ['version'] @@ -36,6 +35,9 @@ test = [ 'pytest-doctestplus', 'pytest-openfiles >=0.5.0', ] +opencv = [ + 'opencv-python >=4.6.0.66', +] [project.urls] 'repository' = 'https://github.com/spacetelescope/stcal'