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

remove dependency on opencv-python #126

Merged
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 CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies = [
'astropy >=5.0.4',
'scipy >=1.6.0',
'numpy >=1.17',
'opencv-python >=4.6.0.66',
]
dynamic = ['version']

Expand All @@ -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'
Expand Down
12 changes: 11 additions & 1 deletion src/stcal/jump/jump.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
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)

Expand Down
16 changes: 11 additions & 5 deletions tests/test_jump.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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']
Expand All @@ -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']
Expand All @@ -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")
Expand All @@ -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)