Skip to content

Commit

Permalink
Use colour checks configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Dec 23, 2024
1 parent 642cee8 commit b30dd12
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 125 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ sigterm = True
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
if TYPE_CHECKING:
pass
4 changes: 2 additions & 2 deletions colour_demosaicing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
__major_version__ = "0"
__minor_version__ = "2"
__change_version__ = "6"
__version__ = ".".join((__major_version__, __minor_version__, __change_version__))
__version__ = f"{__major_version__}.{__minor_version__}.{__change_version__}"

try:
_version: str = (
Expand All @@ -72,7 +72,7 @@
.strip()
.decode("utf-8")
)
except Exception:
except Exception: # noqa: BLE001
_version: str = __version__

colour.utilities.ANCILLARY_COLOUR_SCIENCE_PACKAGES["colour-demosaicing"] = _version # pyright: ignore
Expand Down
7 changes: 6 additions & 1 deletion colour_demosaicing/bayer/demosaicing/bilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

from __future__ import annotations

import typing

import numpy as np
from colour.hints import ArrayLike, Literal, NDArrayFloat

if typing.TYPE_CHECKING:
from colour.hints import ArrayLike, Literal, NDArrayFloat

from colour.utilities import as_float_array, tstack
from scipy.ndimage.filters import convolve

Expand Down
15 changes: 10 additions & 5 deletions colour_demosaicing/bayer/demosaicing/malvar2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from colour.hints import ArrayLike, Literal, NDArrayFloat

if TYPE_CHECKING:
from colour.hints import ArrayLike, Literal, NDArrayFloat

from colour.utilities import as_float_array, ones, tstack
from scipy.ndimage.filters import convolve

Expand Down Expand Up @@ -162,13 +167,13 @@ def demosaicing_CFA_Bayer_Malvar2004(
del GR_GB, Rg_RB_Bg_BR, Rg_BR_Bg_RB, Rb_BB_Br_RR

# Red rows.
R_r = np.transpose(np.any(R_m == 1, axis=1)[None]) * ones(R.shape)
R_r = np.transpose(np.any(R_m == 1, axis=1)[None]) * ones(R.shape) # pyright: ignore
# Red columns.
R_c = np.any(R_m == 1, axis=0)[None] * ones(R.shape)
R_c = np.any(R_m == 1, axis=0)[None] * ones(R.shape) # pyright: ignore
# Blue rows.
B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * ones(B.shape)
B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * ones(B.shape) # pyright: ignore
# Blue columns
B_c = np.any(B_m == 1, axis=0)[None] * ones(B.shape)
B_c = np.any(B_m == 1, axis=0)[None] * ones(B.shape) # pyright: ignore

del R_m, B_m

Expand Down
21 changes: 13 additions & 8 deletions colour_demosaicing/bayer/demosaicing/menon2007.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from colour.hints import ArrayLike, Literal, NDArrayFloat

if TYPE_CHECKING:
from colour.hints import ArrayLike, Literal, NDArrayFloat

from colour.utilities import as_float_array, ones, tsplit, tstack
from scipy.ndimage.filters import convolve, convolve1d

Expand Down Expand Up @@ -51,7 +56,7 @@ def demosaicing_CFA_Bayer_Menon2007(
CFA: ArrayLike,
pattern: Literal["RGGB", "BGGR", "GRBG", "GBRG"] | str = "RGGB",
refining_step: bool = True,
):
) -> NDArrayFloat:
"""
Return the demosaiced *RGB* colourspace array from given *Bayer* CFA using
DDFAPD - *Menon (2007)* demosaicing algorithm.
Expand Down Expand Up @@ -165,9 +170,9 @@ def demosaicing_CFA_Bayer_Menon2007(
del d_H, d_V, G_H, G_V

# Red rows.
R_r = np.transpose(np.any(R_m == 1, axis=1)[None]) * ones(R.shape)
R_r = np.transpose(np.any(R_m == 1, axis=1)[None]) * ones(R.shape) # pyright: ignore
# Blue rows.
B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * ones(B.shape)
B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * ones(B.shape) # pyright: ignore

k_b = as_float_array([0.5, 0, 0.5])

Expand Down Expand Up @@ -317,13 +322,13 @@ def refining_step_Menon2007(

# Updating of the red and blue components in the green locations.
# Red rows.
R_r = np.transpose(np.any(R_m == 1, axis=1)[None]) * ones(R.shape)
R_r = np.transpose(np.any(R_m == 1, axis=1)[None]) * ones(R.shape) # pyright: ignore
# Red columns.
R_c = np.any(R_m == 1, axis=0)[None] * ones(R.shape)
R_c = np.any(R_m == 1, axis=0)[None] * ones(R.shape) # pyright: ignore
# Blue rows.
B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * ones(B.shape)
B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * ones(B.shape) # pyright: ignore
# Blue columns.
B_c = np.any(B_m == 1, axis=0)[None] * ones(B.shape)
B_c = np.any(B_m == 1, axis=0)[None] * ones(B.shape) # pyright: ignore

R_G = R - G
B_G = B - G
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestDemosaicing_CFA_Bayer_bilinear:
demosaicing_CFA_Bayer_bilinear` definition unit tests methods.
"""

def test_demosaicing_CFA_Bayer_bilinear(self):
def test_demosaicing_CFA_Bayer_bilinear(self) -> None:
"""
Test :func:`colour_demosaicing.bayer.demosaicing.bilinear.\
demosaicing_CFA_Bayer_bilinear` definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestDemosaicing_CFA_Bayer_Malvar2004:
demosaicing_CFA_Bayer_Malvar2004` definition unit tests methods.
"""

def test_demosaicing_CFA_Bayer_Malvar2004(self):
def test_demosaicing_CFA_Bayer_Malvar2004(self) -> None:
"""
Test :func:`colour_demosaicing.bayer.demosaicing.malvar2004.\
demosaicing_CFA_Bayer_Malvar2004` definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestDemosaicing_CFA_Bayer_Menon2007:
demosaicing_CFA_Bayer_Menon2007` definition unit tests methods.
"""

def test_demosaicing_CFA_Bayer_Menon2007(self):
def test_demosaicing_CFA_Bayer_Menon2007(self) -> None:
"""
Test :func:`colour_demosaicing.bayer.demosaicing.menon2007.\
demosaicing_CFA_Bayer_Menon2007` definition.
Expand Down
9 changes: 7 additions & 2 deletions colour_demosaicing/bayer/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from colour.hints import Literal, NDArray, Tuple

if TYPE_CHECKING:
from colour.hints import Literal, NDArray, Tuple

from colour.utilities import validate_method

__author__ = "Colour Developers"
Expand Down Expand Up @@ -75,7 +80,7 @@ def masks_CFA_Bayer(
).upper()

channels = {channel: np.zeros(shape, dtype="bool") for channel in "RGB"}
for channel, (y, x) in zip(pattern, [(0, 0), (0, 1), (1, 0), (1, 1)]):
for channel, (y, x) in zip(pattern, [(0, 0), (0, 1), (1, 0), (1, 1)], strict=False):
channels[channel][y::2, x::2] = 1

return tuple(channels.values())
10 changes: 6 additions & 4 deletions colour_demosaicing/bayer/mosaicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

from __future__ import annotations

from colour.hints import ArrayLike, Literal, NDArray
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from colour.hints import ArrayLike, Literal, NDArray

from colour.utilities import as_float_array, tsplit

from colour_demosaicing.bayer import masks_CFA_Bayer
Expand Down Expand Up @@ -60,6 +64,4 @@ def mosaicing_CFA_Bayer(
R, G, B = tsplit(RGB)
R_m, G_m, B_m = masks_CFA_Bayer(RGB.shape[0:2], pattern)

CFA = R * R_m + G * G_m + B * B_m

return CFA
return R * R_m + G * G_m + B * B_m
2 changes: 1 addition & 1 deletion colour_demosaicing/bayer/tests/test_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestMasks_CFA_Bayer:
unit tests methods.
"""

def test_masks_CFA_Bayer(self):
def test_masks_CFA_Bayer(self) -> None:
"""
Test :func:`colour_demosaicing.bayer.masks.masks_CFA_Bayer`
definition.
Expand Down
2 changes: 1 addition & 1 deletion colour_demosaicing/bayer/tests/test_mosaicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestMosaicing_CFA_Bayer:
definition unit tests methods.
"""

def test_mosaicing_CFA_Bayer(self):
def test_mosaicing_CFA_Bayer(self) -> None:
"""
Test :func:`colour_demosaicing.bayer.mosaicing.mosaicing_CFA_Bayer`
definition.
Expand Down
114 changes: 37 additions & 77 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,91 +133,51 @@ addopts = "-n auto --dist=loadscope --durations=5"
[tool.ruff]
target-version = "py310"
line-length = 88
select = [
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
# "ANN", # flake8-annotations
"B", # flake8-bugbear
# "BLE", # flake8-blind-except
"C4", # flake8-comprehensions
# "C90", # mccabe
# "COM", # flake8-commas
"DTZ", # flake8-datetimez
"D", # pydocstyle
"E", # pydocstyle
# "ERA", # eradicate
# "EM", # flake8-errmsg
"EXE", # flake8-executable
"F", # flake8
# "FBT", # flake8-boolean-trap
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
# "PD", # pandas-vet
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"PL", # pylint
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib [Enable]
"Q", # flake8-quotes
"RET", # flake8-return
"RUF", # Ruff
"S", # flake8-bandit
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
# "TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pydocstyle
"YTT" # flake8-2020
]
select = ["ALL"]
ignore = [
"B008",
"B905",
"D104",
"D200",
"D202",
"D205",
"D301",
"D400",
"I001",
"N801",
"N802",
"N803",
"N806",
"N813",
"N815",
"N816",
"PGH003",
"PIE804",
"PLE0605",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0915",
"PLR2004",
"RET504",
"RET505",
"RET506",
"RET507",
"RET508",
"RUF022",
"TRY003",
"TRY300",
"UP038",
"C", # Pylint - Convention
"C90", # mccabe
"COM", # flake8-commas
"ERA", # eradicate
"FBT", # flake8-boolean-trap
"FIX", # flake8-fixme
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib [Enable]
"TD", # flake8-todos
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
"D200", # One-line docstring should fit on one line
"D202", # No blank lines allowed after function docstring
"D205", # 1 blank line required between summary line and description
"D301", # Use `r"""` if any backslashes in a docstring
"D400", # First line should end with a period
"I001", # Import block is un-sorted or un-formatted
"N801", # Class name `.*` should use CapWords convention
"N802", # Function name `.*` should be lowercase
"N803", # Argument name `.*` should be lowercase
"N806", # Variable `.*` in function should be lowercase
"N813", # Camelcase `.*` imported as lowercase `.*`
"N815", # Variable `.*` in class scope should not be mixedCase
"N816", # Variable `.*` in global scope should not be mixedCase
"NPY002", # Replace legacy `np.random.random` call with `np.random.Generator`
"PGH003", # Use specific rule codes when ignoring type issues
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements
"PLR2004", # Magic value used in comparison, consider replacing `.*` with a constant variable
"PYI036", # Star-args in `.*` should be annotated with `object`
"PYI051", # `Literal[".*"]` is redundant in a union with `str`
"PYI056", # Calling `.append()` on `__all__` may not be supported by all type checkers (use `+=` instead)
"RUF022", # [*] `__all__` is not sorted
"TRY003", # Avoid specifying long messages outside the exception class
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
]
typing-modules = ["colour.hints"]
fixable = ["B", "C", "E", "F", "PIE", "RUF", "SIM", "UP", "W"]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.ruff.per-file-ignores]
"__init__.py" = ["D104"]
"colour_demosaicing/examples/*" = ["INP", "T201", "T203"]
"docs/*" = ["INP"]
"tasks.py" = ["INP"]
Expand Down
Loading

0 comments on commit b30dd12

Please sign in to comment.