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

Install dependencies for display testing #14

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ecc0335
Install dependencies for display testing
nfahlgren Mar 28, 2024
ab4cd92
Add dependency PyQt5
nfahlgren Mar 28, 2024
97c14b8
Add dependency napari
nfahlgren Mar 28, 2024
82faaef
Add dummy test for napari viewier
nfahlgren Mar 28, 2024
ce5a3c4
Test tests
nfahlgren Mar 29, 2024
96a0f06
Drop qtbot
nfahlgren Mar 29, 2024
8093b98
make viewer with napari
nfahlgren Mar 29, 2024
885d35a
tests
maliagehan Mar 29, 2024
1800fcb
tests
maliagehan Mar 29, 2024
320c617
test
maliagehan Mar 29, 2024
08d2a1d
Refactor CI for Qt and headless testing
nfahlgren Mar 29, 2024
64b90f1
Update continuous-integration.yml
maliagehan Mar 29, 2024
01449ac
Update continuous-integration.yml
maliagehan Mar 29, 2024
75f5c96
Update continuous-integration.yml
maliagehan Mar 29, 2024
22c053e
Update pyproject.toml
maliagehan Mar 29, 2024
6911345
Update continuous-integration.yml
maliagehan Mar 29, 2024
381834e
Update continuous-integration.yml
maliagehan Mar 29, 2024
f9106a6
Create pytest.ini
maliagehan Mar 29, 2024
4970093
Update continuous-integration.yml
maliagehan Mar 29, 2024
87de749
Update pyproject.toml
maliagehan Mar 29, 2024
68ec05f
Update test_annotate.py
maliagehan Mar 29, 2024
a83d38b
Delete pytest.ini
maliagehan Mar 30, 2024
c5165f6
Update pyproject.toml
maliagehan Mar 30, 2024
7fd639b
Update continuous-integration.yml
maliagehan Mar 30, 2024
d256921
Update test_annotate.py
maliagehan Mar 30, 2024
b552235
Update test_annotate.py
maliagehan Mar 30, 2024
0b8d5d6
trying testing classes instead
maliagehan Mar 30, 2024
5b5e6af
Update test_annotate.py
maliagehan Mar 30, 2024
fd56a87
Update test_annotate.py
maliagehan Mar 30, 2024
a2bf6ce
Update napari_open.py
maliagehan Mar 30, 2024
e0ddec1
Update continuous-integration.yml
maliagehan Mar 30, 2024
a86ada8
Update pyproject.toml
maliagehan Mar 30, 2024
3491461
Update continuous-integration.yml
maliagehan Mar 30, 2024
36f965e
update import
maliagehan Mar 30, 2024
e2f444b
Update continuous-integration.yml
maliagehan Mar 30, 2024
2a15790
Update continuous-integration.yml
maliagehan Mar 30, 2024
cb71be5
Update continuous-integration.yml
maliagehan Mar 30, 2024
120bc72
Test opencv headless
nfahlgren Mar 30, 2024
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
15 changes: 11 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}

DISPLAY: ':99.0'
steps:
- uses: actions/checkout@main
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -30,19 +30,26 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install --no-install-recommends libyaml-dev libegl1-mesa libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-shape0 libxcb-cursor0 xserver-xephyr xvfb
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov ipython
pip install flake8 pytest pytest-cov pytest-qt pytest-xvfb ipython anyio
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test and generate coverage report
- uses: tlambert03/setup-qt-libs@v1
- name: Install plantcv-annotate
# Run coverage analysis on pytest tests
run: |
pip install .
py.test --cov-report=xml --cov=./
pip uninstall -y opencv-python
pip install opencv-python-headless
- name: Tests
uses: aganders3/headless-gui@v2
with:
run: pytest --cov-report=xml --cov=./
- name: Upload coverage to Deepsource
uses: deepsourcelabs/test-coverage-action@master
with:
Expand Down
5 changes: 5 additions & 0 deletions plantcv/annotate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from plantcv.annotate.napari_open import napari_open
from plantcv.annotate.napari_classes import napari_classes

__all__ = ["napari_open",
"napari_classes"]
28 changes: 28 additions & 0 deletions plantcv/annotate/napari_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Get Napari Keys

import re


def napari_classes(viewer):
"""
get names of napari keys
Inputs:
viewer = napari viewer object
Returns:
classes = napari class value names
:param viewer: napari.viewer.Viewer
:return labels: numpy.ndarray, list
"""
keylist = list(viewer.layers)
keylist = ''.join(str(keylist))
keylist = keylist.split(',')

classes = []
for x in keylist:
if re.search('Image layer', x):
pass
else:
y = x.split(" ")
classes.append(y[3].strip("\'"))

return classes
34 changes: 34 additions & 0 deletions plantcv/annotate/napari_open.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use Napari to Label

import cv2
import numpy as np
from skimage.color import label2rgb


def napari_open(img, viewer):
"""
open img in napari and label classes
Inputs:
img = img (grayimg, rgbimg, or hyperspectral image array data e.g.
hyperspectraldata.array_data)
show = if show is True the viewer is launched. This opetion is useful for
running tests without triggering the viewer.
Returns:
viewer = napari viewer object
:param img: numpy.ndarray
:return viewer: napari viewer object
"""
shape = np.shape(img)
if len(shape) == 2:
colorful = label2rgb(img)
img = (255*colorful).astype(np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if len(shape) == 3:
if shape[2] == 3:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if shape[2] > 3:
img = img.transpose(2, 0, 1)

viewer.add_image(img)

return viewer
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dynamic = ["version"]
dependencies = [
"plantcv",
"matplotlib",
"napari",
"PyQt5"
]
requires-python = ">=3.6"
authors = [
Expand All @@ -25,7 +27,11 @@ classifiers = [
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Intended Audience :: Science/Research",
]

[project.optional-dependencies]
test = [
"pytest",
"pytest-qt"
]
[project.urls]
Homepage = "https://plantcv.org"
Documentation = "https://plantcv.readthedocs.io"
Expand Down
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
import pytest
import matplotlib
import os


# Disable plotting
matplotlib.use("Template")


class TestData:
def __init__(self):
"""Initialize simple variables."""
# Test data directory
self.datadir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"testdata")
# RGB image
filename_rgb = "setaria_small_plant_rgb.png"
self.small_rgb_img = os.path.join(self.datadir, filename_rgb)
# Kmeans Clustered Gray image
filename_kmeans = "silphium_seed_labeled_example.png"
self.kmeans_seed_gray_img = os.path.join(self.datadir, filename_kmeans)
# Small Hyperspectral image
filename_hyper = "corn-kernel-hyperspectral.raw"
self.envi_sample_data = os.path.join(self.datadir, filename_hyper)


@pytest.fixture(scope="session")
def test_data():
"""Test data object for the main PlantCV package."""
return TestData()
19 changes: 15 additions & 4 deletions tests/test_annotate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from plantcv import annotate as an
import numpy as np
from plantcv.annotate.napari_classes import napari_classes


def test_annotate():
def test_napari_classes(make_napari_viewer):
"""PlantCV Test"""
assert an.__name__ == "plantcv.annotate"

img = np.zeros((100, 100, 3), dtype=np.uint8)
viewer = make_napari_viewer(show=False)
viewer.add_image(img)
coor = [(25, 25), (50, 50)]
viewer.add_image(img)
viewer.add_points(np.array(coor), symbol="o", name="total",
face_color="red", size=30)
viewer.add_points(np.array(coor), symbol="o", name="test",
face_color="red", size=30)
keys = napari_classes(viewer)

assert keys == ['total', 'test']