From 4ae5426808494d70d5ebaf05dd54fceda6f60ff7 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Mon, 8 Jan 2024 14:56:18 +1300 Subject: [PATCH 01/12] Update various docstrings. --- colour_hdri/distortion/vignette.py | 4 ++-- colour_hdri/sampling/grossberg2003.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/colour_hdri/distortion/vignette.py b/colour_hdri/distortion/vignette.py index 07672d6..5afcd49 100644 --- a/colour_hdri/distortion/vignette.py +++ b/colour_hdri/distortion/vignette.py @@ -564,7 +564,7 @@ def characterise_vignette_bivariate_spline( Standard deviation of the gaussian filtering kernel applied on the resampled image at given ``samples`` count. samples - Samples count of the resampled image on the long edge. + Sample count of the resampled image on the long edge. degree Degree of the bivariate spline. @@ -1007,7 +1007,7 @@ def characterise_vignette( resampled image at given ``samples`` count. samples {:func:`colour_hdri.distortion.characterise_vignette_bivariate_spline`}, - Samples count of the resampled image on the long edge. + Sample count of the resampled image on the long edge. degree {:func:`colour_hdri.distortion.characterise_vignette_bivariate_spline`}, Degree of the bivariate spline. diff --git a/colour_hdri/sampling/grossberg2003.py b/colour_hdri/sampling/grossberg2003.py index d6be622..37441fe 100644 --- a/colour_hdri/sampling/grossberg2003.py +++ b/colour_hdri/sampling/grossberg2003.py @@ -46,7 +46,7 @@ def samples_Grossberg2003( image_stack Stack of single channel or multi-channel floating point images. samples - Samples count. + Sample count. n Histograms bins count. From c8c0258e4534cccead49a6ef28418be8d9c56f6c Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Mon, 15 Jan 2024 20:06:18 +1300 Subject: [PATCH 02/12] Update `.pre-commit-config.yaml` file. --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 054a788..161342f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,6 @@ repos: rev: "v3.1.0" hooks: - id: prettier - exclude: config-aces-reference.ocio.yaml - repo: https://github.com/pre-commit/pygrep-hooks rev: "v1.10.0" hooks: From 59992faf444750288b54b763b8444557feb6c253 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Fri, 19 Jan 2024 06:43:29 +1300 Subject: [PATCH 03/12] Update various docstrings. --- colour_hdri/recovery/tests/test_recovery.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/colour_hdri/recovery/tests/test_recovery.py b/colour_hdri/recovery/tests/test_recovery.py index 6eb60cd..c1bef04 100644 --- a/colour_hdri/recovery/tests/test_recovery.py +++ b/colour_hdri/recovery/tests/test_recovery.py @@ -68,8 +68,8 @@ class TestHighlightsRecoveryBlend(unittest.TestCase): """ - Define :func:`colour_hdri.recovery.highlights.\ -highlights_recovery_blend` definition unit tests methods. + Define :func:`colour_hdri.recovery.highlights.highlights_recovery_blend` + definition unit tests methods. """ def setUp(self): @@ -130,8 +130,8 @@ def test_highlights_recovery_blend(self): class TestHighlightsRecoveryLCHab(unittest.TestCase): """ - Define :func:`colour_hdri.recovery.highlights.\ -highlights_recovery_LCHab` definition unit tests methods. + Define :func:`colour_hdri.recovery.highlights.highlights_recovery_LCHab` + definition unit tests methods. """ def setUp(self): From 57c6f88296979cd95e074f02b35beaa7d8d62d90 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Sat, 20 Jan 2024 19:05:41 +1300 Subject: [PATCH 04/12] Unpin *Poetry* version from 1.4.0. --- .github/workflows/continuous-integration-documentation.yml | 2 -- .github/workflows/continuous-integration-quality-unit-tests.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/continuous-integration-documentation.yml b/.github/workflows/continuous-integration-documentation.yml index 6fbdda2..491660a 100644 --- a/.github/workflows/continuous-integration-documentation.yml +++ b/.github/workflows/continuous-integration-documentation.yml @@ -30,8 +30,6 @@ jobs: sudo apt-get update sudo apt-get --yes install latexmk texlive-full - name: Install Poetry - env: - POETRY_VERSION: 1.4.0 run: | curl -sSL https://install.python-poetry.org | POETRY_HOME=$HOME/.poetry python3 - echo "$HOME/.poetry/bin" >> $GITHUB_PATH diff --git a/.github/workflows/continuous-integration-quality-unit-tests.yml b/.github/workflows/continuous-integration-quality-unit-tests.yml index 580ee23..ee5f53b 100644 --- a/.github/workflows/continuous-integration-quality-unit-tests.yml +++ b/.github/workflows/continuous-integration-quality-unit-tests.yml @@ -66,8 +66,6 @@ jobs: echo "C:\Program Files\Adobe\Adobe DNG Converter" >> $GITHUB_PATH shell: bash - name: Install Poetry - env: - POETRY_VERSION: 1.4.0 run: | curl -sSL https://install.python-poetry.org | POETRY_HOME=$HOME/.poetry python3 - echo "$HOME/.poetry/bin" >> $GITHUB_PATH From 6121862af979b81128afa617e070e9624aff9887 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Wed, 24 Jan 2024 18:00:42 +1300 Subject: [PATCH 05/12] Pin `coverage` to version `>= 6, < 7`. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c7527b4..7ee44bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,7 @@ colour-demosaicing = ">= 0.2.4" matplotlib = ">= 3.5, != 3.5.0, != 3.5.1" [tool.poetry.group.dev.dependencies] -coverage = "!= 6.3" +coverage = ">= 6, < 7" coveralls = "*" invoke = "*" jupyter = "*" From a9c7681bb21ba1f0030e0ef3c5182f95d2d094b6 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Wed, 24 Jan 2024 18:05:43 +1300 Subject: [PATCH 06/12] Ensure that *coveralls.io* upload uses `Python` 3.12. --- .github/workflows/continuous-integration-quality-unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration-quality-unit-tests.yml b/.github/workflows/continuous-integration-quality-unit-tests.yml index ee5f53b..e73b4fa 100644 --- a/.github/workflows/continuous-integration-quality-unit-tests.yml +++ b/.github/workflows/continuous-integration-quality-unit-tests.yml @@ -89,6 +89,7 @@ jobs: poetry run python -W ignore -m pytest --doctest-modules --ignore=$CI_PACKAGE/examples --cov=$CI_PACKAGE $CI_PACKAGE shell: bash - name: Upload Coverage to coveralls.io + if: matrix.os == 'macOS-latest' && matrix.python-version == '3.12' run: | if [ -z "$COVERALLS_REPO_TOKEN" ]; then echo \"COVERALLS_REPO_TOKEN\" secret is undefined!; else poetry run coveralls; fi shell: bash From c9aeba9e4893cce67febbe4119afd5d03999b142 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Sat, 27 Jan 2024 14:00:38 +1300 Subject: [PATCH 07/12] Fix broken links in `README.rst` file. --- README.rst | 6 +++--- docs/installation.rst | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 7e06441..e9f87f0 100644 --- a/README.rst +++ b/README.rst @@ -12,7 +12,7 @@ Colour - HDRI :target: https://coveralls.io/r/colour-science/colour-hdri :alt: Coverage Status .. |codacy| image:: https://img.shields.io/codacy/grade/f422dc0703dd4653b2b766217c745813/develop.svg?style=flat-square - :target: https://www.codacy.com/app/colour-science/colour-hdri + :target: https://app.codacy.com/gh/colour-science/colour-hdri :alt: Code Grade .. |version| image:: https://img.shields.io/pypi/v/colour-hdri.svg?style=flat-square :target: https://pypi.org/project/colour-hdri @@ -84,8 +84,8 @@ Optional Features Dependencies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - `colour-demosaicing `__ -- `Adobe DNG Converter `__ -- `dcraw `__ +- `Adobe DNG Converter `__ +- `dcraw `__ - `ExifTool `__ - `rawpy `__ diff --git a/docs/installation.rst b/docs/installation.rst index 5a83040..fb63077 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -23,8 +23,8 @@ Optional Features Dependencies ------------------------------ - `colour-demosaicing `__ -- `Adobe DNG Converter `__ -- `dcraw `__ +- `Adobe DNG Converter `__ +- `dcraw `__ - `ExifTool `__ - `rawpy `__ From fcba9a8ef234ddfe62b42de7610b390dad03dfc5 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Mon, 29 Jan 2024 17:15:15 +1300 Subject: [PATCH 08/12] Update `pyproject.toml` file. --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 7ee44bf..e8bb6cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,6 +99,9 @@ exclude = ''' )/ ''' +[tool.codespell] +skip = 'BIBLIOGRAPHY.bib,CONTRIBUTORS.rst,*.ipynb' + [tool.flynt] line_length=999 From 0e09f8535393616bc7101d2bb6721c72c3d27c9b Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Tue, 30 Jan 2024 17:52:14 +1300 Subject: [PATCH 09/12] Use `Ruff` format. --- .pre-commit-config.yaml | 10 +-- colour_hdri/__init__.py | 12 +-- colour_hdri/calibration/debevec1997.py | 4 +- .../tests/test_absolute_luminance.py | 12 +-- .../calibration/tests/test_debevec1997.py | 16 +--- colour_hdri/distortion/tests/test_vignette.py | 4 +- colour_hdri/distortion/vignette.py | 78 ++++++------------- colour_hdri/exposure/dsc.py | 4 +- colour_hdri/exposure/tests/test_dsc.py | 4 +- colour_hdri/generation/hdri.py | 4 +- colour_hdri/generation/tests/test_hdri.py | 8 +- colour_hdri/models/dng.py | 38 +++++---- colour_hdri/models/tests/test_adobe_dng.py | 20 ++--- colour_hdri/plotting/hdri.py | 4 +- colour_hdri/plotting/tonemapping.py | 4 +- colour_hdri/process/dng.py | 31 +++----- colour_hdri/process/tests/test_dng.py | 12 +-- colour_hdri/recovery/highlights.py | 4 +- colour_hdri/recovery/tests/test_recovery.py | 28 +++---- colour_hdri/sampling/grossberg2003.py | 4 +- .../sampling/tests/test_grossberg2003.py | 8 +- .../tests/test_variance_minimization.py | 8 +- colour_hdri/sampling/variance_minimization.py | 12 +-- .../tonemapping/global_operators/operators.py | 22 ++---- colour_hdri/utilities/common.py | 4 +- colour_hdri/utilities/exif.py | 18 ++--- colour_hdri/utilities/image.py | 12 +-- colour_hdri/utilities/tests/test_common.py | 4 +- colour_hdri/utilities/tests/test_exif.py | 44 +++-------- colour_hdri/utilities/tests/test_image.py | 12 +-- pyproject.toml | 3 + tasks.py | 17 +--- utilities/export_todo.py | 4 +- 33 files changed, 139 insertions(+), 330 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 161342f..c213b30 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,18 +25,14 @@ repos: - id: flynt args: [--verbose] - repo: https://github.com/PyCQA/isort - rev: "5.12.0" + rev: "5.13.2" hooks: - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.1.6" + rev: "v0.1.14" hooks: + - id: ruff-format - id: ruff - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.11.0 - hooks: - - id: black - language_version: python3.9 - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: diff --git a/colour_hdri/__init__.py b/colour_hdri/__init__.py index 5d03f31..0e4cdc1 100644 --- a/colour_hdri/__init__.py +++ b/colour_hdri/__init__.py @@ -252,18 +252,14 @@ def __getattr__(self, attribute) -> Any: ROOT_RESOURCES_EXAMPLES: str = os.path.join( ROOT_RESOURCES, "colour-hdri-examples-datasets" ) -ROOT_RESOURCES_TESTS: str = os.path.join( - ROOT_RESOURCES, "colour-hdri-tests-datasets" -) +ROOT_RESOURCES_TESTS: str = os.path.join(ROOT_RESOURCES, "colour-hdri-tests-datasets") __application_name__ = "Colour - HDRI" __major_version__ = "0" __minor_version__ = "2" __change_version__ = "3" -__version__ = ".".join( - (__major_version__, __minor_version__, __change_version__) -) +__version__ = ".".join((__major_version__, __minor_version__, __change_version__)) try: _version: str = ( @@ -278,9 +274,7 @@ def __getattr__(self, attribute) -> Any: except Exception: _version: str = __version__ -colour.utilities.ANCILLARY_COLOUR_SCIENCE_PACKAGES[ # pyright: ignore - "colour-hdri" -] = _version +colour.utilities.ANCILLARY_COLOUR_SCIENCE_PACKAGES["colour-hdri"] = _version # pyright: ignore del _version diff --git a/colour_hdri/calibration/debevec1997.py b/colour_hdri/calibration/debevec1997.py index abfe8f8..660c21e 100644 --- a/colour_hdri/calibration/debevec1997.py +++ b/colour_hdri/calibration/debevec1997.py @@ -246,9 +246,7 @@ def camera_response_functions_Debevec1997( w = partial(weighting_function, **weighting_function_kwargs) - g_c = [ - g_solve(s_o[..., x], L_l, l_s, w, n)[0] for x in range(s_o.shape[-1]) - ] + g_c = [g_solve(s_o[..., x], L_l, l_s, w, n)[0] for x in range(s_o.shape[-1])] crfs = np.exp(tstack(np.array(g_c))) if extrapolating_function is not None: diff --git a/colour_hdri/calibration/tests/test_absolute_luminance.py b/colour_hdri/calibration/tests/test_absolute_luminance.py index e0e53a3..7055cdf 100644 --- a/colour_hdri/calibration/tests/test_absolute_luminance.py +++ b/colour_hdri/calibration/tests/test_absolute_luminance.py @@ -61,17 +61,13 @@ def test_upper_hemisphere_illuminance_Lagarde2016(self): ) np.testing.assert_allclose( - upper_hemisphere_illuminance_Lagarde2016( - np.ones((16, 32, 3)) * 10 - ), + upper_hemisphere_illuminance_Lagarde2016(np.ones((16, 32, 3)) * 10), 29.344691653426061, atol=TOLERANCE_ABSOLUTE_TESTS, ) np.testing.assert_allclose( - upper_hemisphere_illuminance_Lagarde2016( - np.ones((16, 32, 3)) * 0.1 - ), + upper_hemisphere_illuminance_Lagarde2016(np.ones((16, 32, 3)) * 0.1), 0.293446916534261, atol=TOLERANCE_ABSOLUTE_TESTS, ) @@ -170,9 +166,7 @@ def test_absolute_luminance_calibration_Lagarde2016(self): ) np.testing.assert_allclose( - absolute_luminance_calibration_Lagarde2016( - reference_exr_file, 51000 - ), + absolute_luminance_calibration_Lagarde2016(reference_exr_file, 51000), test_exr_file, rtol=0.0000001, atol=0.0000001, diff --git a/colour_hdri/calibration/tests/test_debevec1997.py b/colour_hdri/calibration/tests/test_debevec1997.py index be1cf98..8e87b3d 100644 --- a/colour_hdri/calibration/tests/test_debevec1997.py +++ b/colour_hdri/calibration/tests/test_debevec1997.py @@ -36,9 +36,7 @@ "TestCameraResponseFunctionsDebevec1997", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") ROOT_RESOURCES_CALIBRATION: str = os.path.join( ROOT_RESOURCES_TESTS, "colour_hdri", "calibration" @@ -74,9 +72,7 @@ def test_g_solve(self): np.testing.assert_allclose( g, np.load( - os.path.join( - ROOT_RESOURCES_CALIBRATION, f"test_g_solve_g_{i}.npy" - ) + os.path.join(ROOT_RESOURCES_CALIBRATION, f"test_g_solve_g_{i}.npy") ), atol=0.001, ) @@ -85,9 +81,7 @@ def test_g_solve(self): np.testing.assert_allclose( lE, np.load( - os.path.join( - ROOT_RESOURCES_CALIBRATION, f"test_g_solve_lE_{i}.npy" - ) + os.path.join(ROOT_RESOURCES_CALIBRATION, f"test_g_solve_lE_{i}.npy") ), atol=0.001, ) @@ -107,9 +101,7 @@ def test_camera_response_function_Debevec1997(self): # Lower precision for unit tests under *Github Actions*. np.testing.assert_allclose( - camera_response_functions_Debevec1997( - ImageStack.from_files(IMAGES_JPG) - ), + camera_response_functions_Debevec1997(ImageStack.from_files(IMAGES_JPG)), np.load( os.path.join( ROOT_RESOURCES_CALIBRATION, diff --git a/colour_hdri/distortion/tests/test_vignette.py b/colour_hdri/distortion/tests/test_vignette.py index 32fea8c..68a7ada 100644 --- a/colour_hdri/distortion/tests/test_vignette.py +++ b/colour_hdri/distortion/tests/test_vignette.py @@ -279,9 +279,7 @@ def test_vignette_principal_point(self): """ np.testing.assert_allclose( - vignette_principal_point( - apply_radial_gradient(np.ones([50, 70, 3])) - ), + vignette_principal_point(apply_radial_gradient(np.ones([50, 70, 3]))), np.array([0.49000000, 0.49285714]), atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_hdri/distortion/vignette.py b/colour_hdri/distortion/vignette.py index 5afcd49..c8cdffb 100644 --- a/colour_hdri/distortion/vignette.py +++ b/colour_hdri/distortion/vignette.py @@ -164,9 +164,7 @@ def apply_radial_gradient( return np.squeeze(np.nan_to_num(np.clip(image, 0, 1))) -def vignette_principal_point( - image: ArrayLike, threshold: float = 0.99 -) -> NDArrayFloat: +def vignette_principal_point(image: ArrayLike, threshold: float = 0.99) -> NDArrayFloat: """ Return the vignette principal point for given image. @@ -471,9 +469,7 @@ def characterise_vignette_2D_function( )[0] ) - return DataVignetteCharacterisation( - as_float_array(parameters), principal_point - ) + return DataVignetteCharacterisation(as_float_array(parameters), principal_point) def correct_vignette_2D_function( @@ -503,9 +499,7 @@ def correct_vignette_2D_function( -------- >>> image = apply_radial_gradient(np.ones([5, 7])) >>> characterisation_data = characterise_vignette_2D_function(image) - >>> np.around( - ... correct_vignette_2D_function(image, characterisation_data), 3 - ... ) + >>> np.around(correct_vignette_2D_function(image, characterisation_data), 3) array([[-0. , 0.122, 0.597, 0.747, 0.781, 1.08 , -0. ], [ 0. , 0.413, 0.676, 0.82 , 0.76 , 0.576, 0. ], [ 0. , 0.468, 0.759, 1.103, 0.838, 0.611, 0. ], @@ -521,9 +515,9 @@ def correct_vignette_2D_function( '"{0}" function is invalid, it must be one of {1}!', ) - vignette_characterisation_function = ( - VIGNETTE_CHARACTERISATION_2D_FUNCTIONS[function] - ) + vignette_characterisation_function = VIGNETTE_CHARACTERISATION_2D_FUNCTIONS[ + function + ] parameters, principal_point = characterisation_data.values @@ -650,9 +644,7 @@ def correct_vignette_bivariate_spline( -------- >>> image = apply_radial_gradient(np.ones([5, 7])) >>> characterisation_data = characterise_vignette_bivariate_spline(image) - >>> np.around( - ... correct_vignette_bivariate_spline(image, characterisation_data), 3 - ... ) + >>> np.around(correct_vignette_bivariate_spline(image, characterisation_data), 3) array([[ 0. , 0.345, 3.059, 4.072, 3.059, 0.345, 0. ], [ 0. , 3.624, 7.304, 9.058, 7.304, 3.624, 0. ], [ 0. , 4.936, 9.481, 14.032, 9.481, 4.936, 0. ], @@ -790,12 +782,12 @@ def vignette_sampling_coordinates( coordinates = np.vstack(samples) - coordinates[..., 0] = LinearInterpolator( - [0, 0.5, 1], [0, principal_point[0], 1] - )(coordinates[..., 0]) - coordinates[..., 1] = LinearInterpolator( - [0, 0.5, 1], [0, principal_point[1], 1] - )(coordinates[..., 1]) + coordinates[..., 0] = LinearInterpolator([0, 0.5, 1], [0, principal_point[0], 1])( + coordinates[..., 0] + ) + coordinates[..., 1] = LinearInterpolator([0, 0.5, 1], [0, principal_point[1], 1])( + coordinates[..., 1] + ) radial_samples = radial_sampling_function( samples_rho, @@ -871,14 +863,10 @@ def characterise_vignette_RBF( parameters = [] for i in range(channels): - filtered = gaussian_filter( - image[..., i], denoise_sigma, truncate=denoise_sigma - ) + filtered = gaussian_filter(image[..., i], denoise_sigma, truncate=denoise_sigma) parameters.append(filtered[x_indices, y_indices]) - return DataVignetteCharacterisation( - np.transpose(parameters), principal_point - ) + return DataVignetteCharacterisation(np.transpose(parameters), principal_point) def correct_vignette_RBF( @@ -956,9 +944,7 @@ def correct_vignette_RBF( epsilon=epsilon, ) - I_v = interpolator(tstack([y_1, x_1]).reshape([-1, 2])).reshape( - height, width - ) + I_v = interpolator(tstack([y_1, x_1]).reshape([-1, 2])).reshape(height, width) image[..., i] /= I_v @@ -1029,9 +1015,7 @@ def characterise_vignette( (180, 1) >>> principal_point # doctest: +ELLIPSIS array([ 0.4983333..., 0.49875 ]) - >>> parameters, principal_point = characterise_vignette( - ... image, method="RBF" - ... ).values + >>> parameters, principal_point = characterise_vignette(image, method="RBF").values >>> parameters.shape (180, 1) >>> principal_point # doctest: +ELLIPSIS @@ -1052,9 +1036,7 @@ def characterise_vignette( array([ 0.4983333..., 0.49875 ]) """ - method = validate_method( - method, tuple(VIGNETTE_CHARACTERISATION_METHODS.keys()) - ) + method = validate_method(method, tuple(VIGNETTE_CHARACTERISATION_METHODS.keys())) return VIGNETTE_CHARACTERISATION_METHODS[method](image, **kwargs) @@ -1125,21 +1107,15 @@ def correct_vignette( [ 0. , 0.967, 2.03 , 2.552, 2.03 , 0.967, 0. ], [ 0. , 0.091, 0.841, 1.134, 0.841, 0.091, 0. ]]) >>> characterisation_data = characterise_vignette(image, method="RBF") - >>> np.around( - ... correct_vignette(image, characterisation_data, method="RBF"), 3 - ... ) + >>> np.around(correct_vignette(image, characterisation_data, method="RBF"), 3) array([[ 0. , 0.091, 0.841, 1.134, 0.841, 0.091, 0. ], [ 0. , 0.967, 2.03 , 2.552, 2.03 , 0.967, 0. ], [ 0. , 1.323, 2.647, 3.97 , 2.647, 1.323, 0. ], [ 0. , 0.967, 2.03 , 2.552, 2.03 , 0.967, 0. ], [ 0. , 0.091, 0.841, 1.134, 0.841, 0.091, 0. ]]) - >>> characterisation_data = characterise_vignette( - ... image, method="2D Function" - ... ) + >>> characterisation_data = characterise_vignette(image, method="2D Function") >>> np.around( - ... correct_vignette( - ... image, characterisation_data, method="2D Function" - ... ), + ... correct_vignette(image, characterisation_data, method="2D Function"), ... 3, ... ) array([[-0. , 0.122, 0.597, 0.747, 0.781, 1.08 , -0. ], @@ -1147,13 +1123,9 @@ def correct_vignette( [ 0. , 0.468, 0.759, 1.103, 0.838, 0.611, 0. ], [ 0. , 0.439, 0.709, 0.858, 0.801, 0.628, -0. ], [-0. , 0.193, 0.742, 0.913, 1.049, -0.477, -0. ]]) - >>> characterisation_data = characterise_vignette( - ... image, method="Bivariate Spline" - ... ) + >>> characterisation_data = characterise_vignette(image, method="Bivariate Spline") >>> np.around( - ... correct_vignette( - ... image, characterisation_data, method="Bivariate Spline" - ... ), + ... correct_vignette(image, characterisation_data, method="Bivariate Spline"), ... 3, ... ) array([[ 0. , 0.345, 3.059, 4.072, 3.059, 0.345, 0. ], @@ -1165,6 +1137,4 @@ def correct_vignette( method = validate_method(method, tuple(VIGNETTE_CORRECTION_METHODS.keys())) - return VIGNETTE_CORRECTION_METHODS[method]( - image, characterisation_data, **kwargs - ) + return VIGNETTE_CORRECTION_METHODS[method](image, characterisation_data, **kwargs) diff --git a/colour_hdri/exposure/dsc.py b/colour_hdri/exposure/dsc.py index 04abd12..1ea46db 100644 --- a/colour_hdri/exposure/dsc.py +++ b/colour_hdri/exposure/dsc.py @@ -337,9 +337,7 @@ def exposure_index_values(H_a: ArrayLike) -> NDArrayFloat: return as_float(10 / as_float_array(H_a)) -def exposure_value_100( - N: ArrayLike, t: ArrayLike, S: ArrayLike -) -> NDArrayFloat: +def exposure_value_100(N: ArrayLike, t: ArrayLike, S: ArrayLike) -> NDArrayFloat: """ Compute the exposure value :math:`EV100` from given relative aperture *F-Number* :math:`N`, *Exposure Time* :math:`t` and *ISO* arithmetic diff --git a/colour_hdri/exposure/tests/test_dsc.py b/colour_hdri/exposure/tests/test_dsc.py index a124687..bb920e9 100644 --- a/colour_hdri/exposure/tests/test_dsc.py +++ b/colour_hdri/exposure/tests/test_dsc.py @@ -146,9 +146,7 @@ def test_exposure_index_values(self): """ np.testing.assert_allclose( - exposure_index_values( - np.array([0.16439371, 0.08810904, 0.09310904]) - ), + exposure_index_values(np.array([0.16439371, 0.08810904, 0.09310904])), np.array([60.82957797, 113.49573211, 107.40095699]), atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_hdri/generation/hdri.py b/colour_hdri/generation/hdri.py index 8b1e809..c2a290b 100644 --- a/colour_hdri/generation/hdri.py +++ b/colour_hdri/generation/hdri.py @@ -109,9 +109,7 @@ def image_stack_to_HDRI( image_data = image.data if camera_response_functions is not None: - camera_response_functions = as_float_array( - camera_response_functions - ) + camera_response_functions = as_float_array(camera_response_functions) samples = np.linspace(0, 1, camera_response_functions.shape[0]) R, G, B = tsplit(image.data) diff --git a/colour_hdri/generation/tests/test_hdri.py b/colour_hdri/generation/tests/test_hdri.py index 4e6a951..9879222 100644 --- a/colour_hdri/generation/tests/test_hdri.py +++ b/colour_hdri/generation/tests/test_hdri.py @@ -29,9 +29,7 @@ "TestImageStackToHDRI", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") ROOT_RESOURCES_GENERATION: str = os.path.join( ROOT_RESOURCES_TESTS, "colour_hdri", "generation" @@ -53,9 +51,7 @@ def test_image_stack_to_HDRI(self): """ image_stack = ImageStack.from_files(IMAGES_JPG) - image_stack.data = RGB_COLOURSPACES["sRGB"].cctf_decoding( - image_stack.data - ) + image_stack.data = RGB_COLOURSPACES["sRGB"].cctf_decoding(image_stack.data) # Lower precision for unit tests under *travis-ci*. np.testing.assert_allclose( diff --git a/colour_hdri/models/dng.py b/colour_hdri/models/dng.py index b1f62f4..5b881f0 100644 --- a/colour_hdri/models/dng.py +++ b/colour_hdri/models/dng.py @@ -508,11 +508,7 @@ def matrix_XYZ_to_camera_space( CCT, _D_uv = uv_to_CCT_Robertson1968(uv) if is_identity(M_color_matrix_1) or is_identity(M_color_matrix_2): - M_CM = ( - M_color_matrix_1 - if is_identity(M_color_matrix_2) - else M_color_matrix_2 - ) + M_CM = M_color_matrix_1 if is_identity(M_color_matrix_2) else M_color_matrix_2 else: M_CM = matrix_interpolated( CCT, @@ -546,21 +542,23 @@ def matrix_camera_space_to_XYZ( analog_balance: ArrayLike, M_forward_matrix_1: ArrayLike, M_forward_matrix_2: ArrayLike, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] - | str = "Bradford", + chromatic_adaptation_transform: ( + Literal[ + "Bianco 2010", + "Bianco PC 2010", + "Bradford", + "CAT02 Brill 2008", + "CAT02", + "CAT16", + "CMCCAT2000", + "CMCCAT97", + "Fairchild", + "Sharp", + "Von Kries", + "XYZ Scaling", + ] + | str + ) = "Bradford", ) -> NDArrayFloat: """ Return the *Camera Space* to *CIE XYZ* matrix for given *xy* white diff --git a/colour_hdri/models/tests/test_adobe_dng.py b/colour_hdri/models/tests/test_adobe_dng.py index 2b4bdb2..d6b33d1 100644 --- a/colour_hdri/models/tests/test_adobe_dng.py +++ b/colour_hdri/models/tests/test_adobe_dng.py @@ -119,41 +119,31 @@ def test_matrix_interpolated(self): ] ) np.testing.assert_allclose( - matrix_interpolated( - 5000, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2 - ), + matrix_interpolated(5000, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2), M_reference, atol=TOLERANCE_ABSOLUTE_TESTS, ) np.testing.assert_allclose( - matrix_interpolated( - 2850, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2 - ), + matrix_interpolated(2850, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2), M_COLOR_MATRIX_1, atol=TOLERANCE_ABSOLUTE_TESTS, ) np.testing.assert_allclose( - matrix_interpolated( - 1000, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2 - ), + matrix_interpolated(1000, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2), M_COLOR_MATRIX_1, atol=TOLERANCE_ABSOLUTE_TESTS, ) np.testing.assert_allclose( - matrix_interpolated( - 6500, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2 - ), + matrix_interpolated(6500, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2), M_COLOR_MATRIX_2, atol=TOLERANCE_ABSOLUTE_TESTS, ) np.testing.assert_allclose( - matrix_interpolated( - 10000, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2 - ), + matrix_interpolated(10000, 2850, 6500, M_COLOR_MATRIX_1, M_COLOR_MATRIX_2), M_COLOR_MATRIX_2, atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_hdri/plotting/hdri.py b/colour_hdri/plotting/hdri.py index 71a8e71..41dc11a 100644 --- a/colour_hdri/plotting/hdri.py +++ b/colour_hdri/plotting/hdri.py @@ -77,9 +77,7 @@ def plot_HDRI_strip( ev = i * ev_steps axis = plt.subplot(grid[i]) axis.imshow(np.clip(cctf_encoding(adjust_exposure(image, ev)), 0, 1)) - axis.text( - width * 0.05, height - height * 0.05, f"EV {ev}", color=(1, 1, 1) - ) + axis.text(width * 0.05, height - height * 0.05, f"EV {ev}", color=(1, 1, 1)) axis.set_xticks([]) axis.set_yticks([]) axis.set_aspect("equal") diff --git a/colour_hdri/plotting/tonemapping.py b/colour_hdri/plotting/tonemapping.py index b7fd4b0..f1c3845 100644 --- a/colour_hdri/plotting/tonemapping.py +++ b/colour_hdri/plotting/tonemapping.py @@ -115,8 +115,6 @@ def plot_tonemapping_operator_image( } ) plt.gca().set_xscale("log", basex=2) - plt.gca().xaxis.set_major_formatter( - matplotlib.ticker.ScalarFormatter() - ) + plt.gca().xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter()) return render(**settings) diff --git a/colour_hdri/process/dng.py b/colour_hdri/process/dng.py index ec80d36..234e7ce 100644 --- a/colour_hdri/process/dng.py +++ b/colour_hdri/process/dng.py @@ -70,13 +70,11 @@ RAW_CONVERTER_ARGUMENTS_BAYER_CFA: str = '-t 0 -D -W -4 -T "{raw_file}"' if _IS_WINDOWS_PLATFORM: - RAW_CONVERTER_ARGUMENTS_BAYER_CFA = ( - RAW_CONVERTER_ARGUMENTS_BAYER_CFA.replace('"', "") + RAW_CONVERTER_ARGUMENTS_BAYER_CFA = RAW_CONVERTER_ARGUMENTS_BAYER_CFA.replace( + '"', "" ) if is_documentation_building(): # pragma: no cover - RAW_CONVERTER_ARGUMENTS_BAYER_CFA = DocstringText( - RAW_CONVERTER_ARGUMENTS_BAYER_CFA - ) + RAW_CONVERTER_ARGUMENTS_BAYER_CFA = DocstringText(RAW_CONVERTER_ARGUMENTS_BAYER_CFA) RAW_CONVERTER_ARGUMENTS_BAYER_CFA.__doc__ = """ Arguments for the command line raw conversion application for non demosaiced linear *tiff* file format output. @@ -86,8 +84,8 @@ '-t 0 -H 1 -r 1 1 1 1 -4 -q 3 -o 0 -T "{raw_file}"' ) if _IS_WINDOWS_PLATFORM: - RAW_CONVERTER_ARGUMENTS_DEMOSAICING = ( - RAW_CONVERTER_ARGUMENTS_DEMOSAICING.replace('"', "") + RAW_CONVERTER_ARGUMENTS_DEMOSAICING = RAW_CONVERTER_ARGUMENTS_DEMOSAICING.replace( + '"', "" ) if is_documentation_building(): # pragma: no cover RAW_CONVERTER_ARGUMENTS_DEMOSAICING = DocstringText( @@ -100,8 +98,7 @@ if _IS_MACOS_PLATFORM: DNG_CONVERTER: str = ( - "/Applications/Adobe DNG Converter.app/Contents/" - "MacOS/Adobe DNG Converter" + "/Applications/Adobe DNG Converter.app/Contents/MacOS/Adobe DNG Converter" ) elif _IS_WINDOWS_PLATFORM: DNG_CONVERTER: str = "Adobe DNG Converter" @@ -257,18 +254,14 @@ def convert_raw_files_to_dng_files( """ dng_converter = optional(dng_converter, DNG_CONVERTER) - dng_converter_arguments = optional( - dng_converter_arguments, DNG_CONVERTER_ARGUMENTS - ) + dng_converter_arguments = optional(dng_converter_arguments, DNG_CONVERTER_ARGUMENTS) dng_files = [] for raw_file in raw_files: raw_file_extension = os.path.splitext(raw_file)[1] dng_file = os.path.join( output_directory, - os.path.basename( - re.sub(f"{raw_file_extension}$", ".dng", raw_file) - ), + os.path.basename(re.sub(f"{raw_file_extension}$", ".dng", raw_file)), ) if path_exists(dng_file): @@ -356,9 +349,7 @@ def convert_dng_files_to_intermediate_files( subprocess.call(command, shell=_IS_WINDOWS_PLATFORM) # noqa: S603 - tiff_file = os.path.join( - output_directory, os.path.basename(intermediate_file) - ) + tiff_file = os.path.join(output_directory, os.path.basename(intermediate_file)) if tiff_file != intermediate_file: if path_exists(tiff_file): os.remove(tiff_file) @@ -402,9 +393,7 @@ def read_dng_files_exif_tags( exif_tag = exif_tags[group].get(tag) if exif_tag is None: binding[group][tag] = ( - default - if default is None - else parser(EXIFTag(value=default)) + default if default is None else parser(EXIFTag(value=default)) ) else: binding[group][tag] = parser(exif_tag[0]) diff --git a/colour_hdri/process/tests/test_dng.py b/colour_hdri/process/tests/test_dng.py index 80b8774..1de6e4c 100644 --- a/colour_hdri/process/tests/test_dng.py +++ b/colour_hdri/process/tests/test_dng.py @@ -38,13 +38,9 @@ "TestConvertDngFilesToIntermediateFiles", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") -ROOT_PROCESS: str = os.path.join( - ROOT_RESOURCES_TESTS, "colour_hdri", "process" -) +ROOT_PROCESS: str = os.path.join(ROOT_RESOURCES_TESTS, "colour_hdri", "process") IMAGES_RAW: List[str] = filter_files(ROOT_RESOURCES_FROBISHER_001, ("CR2",)) @@ -78,9 +74,7 @@ def test_convert_raw_files_to_dng_files(self): reference_dng_files = sorted(filter_files(ROOT_PROCESS, ("dng",))) test_dng_files = sorted( - convert_raw_files_to_dng_files( - IMAGES_RAW, self._temporary_directory - ) + convert_raw_files_to_dng_files(IMAGES_RAW, self._temporary_directory) ) for test_dng_file, reference_dng_file in zip( diff --git a/colour_hdri/recovery/highlights.py b/colour_hdri/recovery/highlights.py index b24bd9e..f3a7948 100644 --- a/colour_hdri/recovery/highlights.py +++ b/colour_hdri/recovery/highlights.py @@ -147,8 +147,6 @@ def highlights_recovery_LCHab( ) return XYZ_to_RGB( - Lab_to_XYZ( - LCHab_to_Lab(tstack([L, C_c, H])), RGB_colourspace.whitepoint - ), + Lab_to_XYZ(LCHab_to_Lab(tstack([L, C_c, H])), RGB_colourspace.whitepoint), RGB_colourspace, ) diff --git a/colour_hdri/recovery/tests/test_recovery.py b/colour_hdri/recovery/tests/test_recovery.py index c1bef04..5e467f8 100644 --- a/colour_hdri/recovery/tests/test_recovery.py +++ b/colour_hdri/recovery/tests/test_recovery.py @@ -47,9 +47,7 @@ _IS_WINDOWS_PLATFORM: bool = platform.system() in ("Windows", "Microsoft") """Whether the current platform is *Windows*.""" -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") ROOT_RESOURCES_RECOVERY: str = os.path.join( ROOT_RESOURCES_TESTS, "colour_hdri", "recovery" @@ -99,18 +97,16 @@ def test_highlights_recovery_blend(self): command = [ RAW_CONVERTER, *shlex.split( - RAW_CONVERTER_ARGUMENTS_DEMOSAICING.format( - raw_file=test_raw_file - ), + RAW_CONVERTER_ARGUMENTS_DEMOSAICING.format(raw_file=test_raw_file), posix=not _IS_WINDOWS_PLATFORM, ), ] subprocess.call(command) # noqa: S603 - test_tiff_file = read_image( - str(re.sub("\\.CR2$", ".tiff", test_raw_file)) - )[::10, ::10, :] + test_tiff_file = read_image(str(re.sub("\\.CR2$", ".tiff", test_raw_file)))[ + ::10, ::10, : + ] test_tiff_file *= multipliers test_tiff_file = highlights_recovery_blend(test_tiff_file, multipliers) @@ -161,23 +157,19 @@ def test_highlights_recovery_LCHab(self): command = [ RAW_CONVERTER, *shlex.split( - RAW_CONVERTER_ARGUMENTS_DEMOSAICING.format( - raw_file=test_raw_file - ), + RAW_CONVERTER_ARGUMENTS_DEMOSAICING.format(raw_file=test_raw_file), posix=not _IS_WINDOWS_PLATFORM, ), ] subprocess.call(command) # noqa: S603 - test_tiff_file = read_image( - str(re.sub("\\.CR2$", ".tiff", test_raw_file)) - )[::10, ::10, :] + test_tiff_file = read_image(str(re.sub("\\.CR2$", ".tiff", test_raw_file)))[ + ::10, ::10, : + ] test_tiff_file *= multipliers - test_tiff_file = highlights_recovery_LCHab( - test_tiff_file, min(multipliers) - ) + test_tiff_file = highlights_recovery_LCHab(test_tiff_file, min(multipliers)) test_tiff_file = camera_space_to_sRGB( test_tiff_file, matrix_XYZ_to_camera_space ) diff --git a/colour_hdri/sampling/grossberg2003.py b/colour_hdri/sampling/grossberg2003.py index 37441fe..f92394a 100644 --- a/colour_hdri/sampling/grossberg2003.py +++ b/colour_hdri/sampling/grossberg2003.py @@ -80,8 +80,6 @@ def samples_Grossberg2003( for i in np.arange(samples): for j in np.arange(channels_c): for k, cdf in enumerate(cdf_i): - samples_cdf_i[i, k, j] = np.argmin( - np.abs(cdf[:, j] - samples_u[i]) - ) + samples_cdf_i[i, k, j] = np.argmin(np.abs(cdf[:, j] - samples_u[i])) return samples_cdf_i diff --git a/colour_hdri/sampling/tests/test_grossberg2003.py b/colour_hdri/sampling/tests/test_grossberg2003.py index 6ee4fdb..bd243f5 100644 --- a/colour_hdri/sampling/tests/test_grossberg2003.py +++ b/colour_hdri/sampling/tests/test_grossberg2003.py @@ -31,9 +31,7 @@ "TestSamplesGrossberg2003", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") ROOT_RESOURCES_SAMPLING: str = os.path.join( ROOT_RESOURCES_TESTS, "colour_hdri", "sampling" @@ -57,9 +55,7 @@ def test_samples_Grossberg2003(self): np.testing.assert_allclose( samples_Grossberg2003(ImageStack.from_files(IMAGES_JPG).data), np.load( - os.path.join( - ROOT_RESOURCES_SAMPLING, "test_samples_Grossberg2003.npy" - ) + os.path.join(ROOT_RESOURCES_SAMPLING, "test_samples_Grossberg2003.npy") ), atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_hdri/sampling/tests/test_variance_minimization.py b/colour_hdri/sampling/tests/test_variance_minimization.py index 15f15d6..0357abd 100644 --- a/colour_hdri/sampling/tests/test_variance_minimization.py +++ b/colour_hdri/sampling/tests/test_variance_minimization.py @@ -166,9 +166,7 @@ def test_highlight_regions_variance_minimization(self): ) -class TestLightProbeSamplingVarianceMinimizationViriyothai2009( - unittest.TestCase -): +class TestLightProbeSamplingVarianceMinimizationViriyothai2009(unittest.TestCase): """ Define :func:`colour_hdri.sampling.variance_minimization.\ light_probe_sampling_variance_minimization_Viriyothai2009` definition unit @@ -191,9 +189,7 @@ def test_light_probe_sampling_variance_minimization_Viriyothai2009(self): ) ) - lights = light_probe_sampling_variance_minimization_Viriyothai2009( - image - ) + lights = light_probe_sampling_variance_minimization_Viriyothai2009(image) uvs = np.array([light[0] for light in lights]) colours = np.array([light[1] for light in lights]) indexes = np.array([light[2] for light in lights]) diff --git a/colour_hdri/sampling/variance_minimization.py b/colour_hdri/sampling/variance_minimization.py index dda05be..9f5cec8 100644 --- a/colour_hdri/sampling/variance_minimization.py +++ b/colour_hdri/sampling/variance_minimization.py @@ -38,9 +38,7 @@ ] -class Light_Specification( - namedtuple("Light_Specification", ("uv", "colour", "index")) -): +class Light_Specification(namedtuple("Light_Specification", ("uv", "colour", "index"))): """ Define a light probe sampling resulting light specification. @@ -80,9 +78,7 @@ def luminance_variance(a: ArrayLike) -> float: x_centroid, y_centroid = centroid(a) - variance = np.sqrt( - np.sum(a * ((y - y_centroid) ** 2 + (x - x_centroid) ** 2)) - ) + variance = np.sqrt(np.sum(a * ((y - y_centroid) ** 2 + (x - x_centroid) ** 2))) return as_float_scalar(variance) @@ -231,9 +227,7 @@ def light_probe_sampling_variance_minimization_Viriyothai2009( f"effectively computed!" ) - Y = RGB_luminance( - light_probe, colourspace.primaries, colourspace.whitepoint - ) + Y = RGB_luminance(light_probe, colourspace.primaries, colourspace.whitepoint) regions = find_regions_variance_minimization_Viriyothai2009(Y, iterations) lights = [] diff --git a/colour_hdri/tonemapping/global_operators/operators.py b/colour_hdri/tonemapping/global_operators/operators.py index 122ee84..dfa2578 100644 --- a/colour_hdri/tonemapping/global_operators/operators.py +++ b/colour_hdri/tonemapping/global_operators/operators.py @@ -461,9 +461,7 @@ def tonemapping_operator_logarithmic_mapping( RGB_luminance(RGB, colourspace.primaries, colourspace.whitepoint) ) L_max = np.max(L) - L_d = as_float_array( - (np.log(1 + p * L) / np.log(1 + p * L_max)) ** (1 / q) - ) + L_d = as_float_array((np.log(1 + p * L) / np.log(1 + p * L_max)) ** (1 / q)) return RGB * L_d[..., None] / L[..., None] @@ -657,9 +655,7 @@ def tonemapping_operator_Tumblin1999( ) def f(x: float | NDArrayFloat) -> NDArrayFloat: - return np.where( - x > 100, 2.655, 1.855 + 0.4 * np.log10(x + 2.3 * 10**-5) - ) + return np.where(x > 100, 2.655, 1.855 + 0.4 * np.log10(x + 2.3 * 10**-5)) L_wa = np.exp(np.mean(np.log(L_w + 2.3 * 10**-5))) g_d = f(L_da) @@ -757,11 +753,7 @@ def tonemapping_operator_Reinhard2004( if m > 0 else ( 0.3 - + 0.7 - * ( - (np.log(L_max) - L_lav) - / (np.log(L_max) - np.log(L_min)) ** 1.4 - ) + + 0.7 * ((np.log(L_max) - L_lav) / (np.log(L_max) - np.log(L_min)) ** 1.4) ) ) @@ -857,12 +849,8 @@ def f( E: float, F: float, ) -> float | NDArrayFloat: - return ( - (x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F) - ) - E / F + return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F RGB = f(RGB * exposure_bias, A, B, C, D, E, F) - return cast( - NDArrayFloat, RGB * (1 / f(linear_whitepoint, A, B, C, D, E, F)) - ) + return cast(NDArrayFloat, RGB * (1 / f(linear_whitepoint, A, B, C, D, E, F))) diff --git a/colour_hdri/utilities/common.py b/colour_hdri/utilities/common.py index a8bd0f7..32aa012 100644 --- a/colour_hdri/utilities/common.py +++ b/colour_hdri/utilities/common.py @@ -72,9 +72,7 @@ def vivified_to_dict(vivified: Dict | defaultdict) -> Dict: """ if isinstance(vivified, defaultdict): - vivified = { - key: vivified_to_dict(value) for key, value in vivified.items() - } + vivified = {key: vivified_to_dict(value) for key, value in vivified.items()} return vivified diff --git a/colour_hdri/utilities/exif.py b/colour_hdri/utilities/exif.py index 7c142e2..95029c7 100644 --- a/colour_hdri/utilities/exif.py +++ b/colour_hdri/utilities/exif.py @@ -118,9 +118,7 @@ def parse_exif_string(exif_tag: EXIFTag) -> str: return str(exif_tag.value) -def parse_exif_number( - exif_tag: EXIFTag, dtype: Type[DTypeReal] | None = None -) -> Real: +def parse_exif_number(exif_tag: EXIFTag, dtype: Type[DTypeReal] | None = None) -> Real: """ Parse given EXIF tag assuming it is a number type and return its value. @@ -164,9 +162,7 @@ def parse_exif_fraction( dtype = optional(dtype, DTYPE_FLOAT_DEFAULT) value = ( - exif_tag.value - if exif_tag.value is None - else float(Fraction(exif_tag.value)) + exif_tag.value if exif_tag.value is None else float(Fraction(exif_tag.value)) ) return as_float_scalar(value, dtype) # pyright: ignore @@ -197,9 +193,7 @@ def parse_exif_array( dtype = optional(dtype, DTYPE_FLOAT_DEFAULT) - value = ( - exif_tag.value if exif_tag.value is None else exif_tag.value.split() - ) + value = exif_tag.value if exif_tag.value is None else exif_tag.value.split() return np.reshape(as_array(value, dtype), shape) # pyright: ignore @@ -309,7 +303,8 @@ def copy_exif_tags(source: str, target: str) -> bool: arguments = [EXIF_EXECUTABLE, "-overwrite_original", "-TagsFromFile"] arguments += [source, target] subprocess.check_output( - arguments, shell=_IS_WINDOWS_PLATFORM # noqa: S603 + arguments, + shell=_IS_WINDOWS_PLATFORM, # noqa: S603 ) return True @@ -429,7 +424,8 @@ def write_exif_tag(image: str, tag: str, value: str) -> bool: arguments = [EXIF_EXECUTABLE, "-overwrite_original"] arguments += [f"-{tag}={value}", image] subprocess.check_output( - arguments, shell=_IS_WINDOWS_PLATFORM # noqa: S603 + arguments, + shell=_IS_WINDOWS_PLATFORM, # noqa: S603 ) return True diff --git a/colour_hdri/utilities/image.py b/colour_hdri/utilities/image.py index 03ec45a..800106a 100644 --- a/colour_hdri/utilities/image.py +++ b/colour_hdri/utilities/image.py @@ -86,9 +86,7 @@ class Metadata(MixinDataclassArray): iso: Real | None = field(default_factory=lambda: None) black_level: NDArrayFloat | None = field(default_factory=lambda: None) white_level: NDArrayFloat | None = field(default_factory=lambda: None) - white_balance_multipliers: NDArrayFloat | None = field( - default_factory=lambda: None - ) + white_balance_multipliers: NDArrayFloat | None = field(default_factory=lambda: None) class Image: @@ -276,9 +274,7 @@ def read_metadata(self) -> Metadata: """ if self._path is not None: - logging.info( - 'Reading "{path}" image metadata.', extra={"path": self._path} - ) + logging.info('Reading "{path}" image metadata.', extra={"path": self._path}) exif_data = read_exif_tags(self._path) @@ -312,9 +308,7 @@ def read_metadata(self) -> Metadata: white_level = parse_exif_array(white_level[0]) white_level = as_float_array(white_level) / 65535 - white_balance_multipliers = exif_data["EXIF"].get( - "As Shot Neutral" - ) + white_balance_multipliers = exif_data["EXIF"].get("As Shot Neutral") if white_balance_multipliers is not None: white_balance_multipliers = parse_exif_array( white_balance_multipliers[0] diff --git a/colour_hdri/utilities/tests/test_common.py b/colour_hdri/utilities/tests/test_common.py index a359d9b..cfe8531 100644 --- a/colour_hdri/utilities/tests/test_common.py +++ b/colour_hdri/utilities/tests/test_common.py @@ -29,9 +29,7 @@ "TestFilterFiles", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") class TestVivification(unittest.TestCase): diff --git a/colour_hdri/utilities/tests/test_exif.py b/colour_hdri/utilities/tests/test_exif.py index c3fc4a7..cd40022 100644 --- a/colour_hdri/utilities/tests/test_exif.py +++ b/colour_hdri/utilities/tests/test_exif.py @@ -51,9 +51,7 @@ "TestWriteExifTag", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") class TestParseExifString(unittest.TestCase): @@ -170,9 +168,7 @@ def test_parse_exif_data(self): """Test :func:`colour_hdri.utilities.exif.parse_exif_data` definition.""" self.assertListEqual( - parse_exif_data( - "[XMP] - Description :" - ), + parse_exif_data("[XMP] - Description :"), ["XMP", "-", "Description", ""], ) @@ -200,9 +196,7 @@ class TestReadExifTags(unittest.TestCase): def test_read_exif_tags(self): """Test :func:`colour_hdri.utilities.exif.read_exif_tags` definition.""" - test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[ - 0 - ] + test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] exif_data = vivified_to_dict(read_exif_tags(test_jpg_image)) self.assertIsInstance(exif_data, type({})) @@ -224,16 +218,8 @@ def test_read_exif_tags(self): self.assertListEqual( sorted(exif_data["EXIF"].values(), key=lambda x: x[0].name), [ - [ - EXIFTag( - "EXIF", "Camera Model Name", "EOS 5D Mark II", "272" - ) - ], - [ - EXIFTag( - "EXIF", "Create Date", "2015:09:19 03:39:20", "36868" - ) - ], + [EXIFTag("EXIF", "Camera Model Name", "EOS 5D Mark II", "272")], + [EXIFTag("EXIF", "Create Date", "2015:09:19 03:39:20", "36868")], [ EXIFTag( "EXIF", @@ -279,9 +265,7 @@ def tearDown(self): def test_copy_exif_tags(self): """Test :func:`colour_hdri.utilities.exif.copy_exif_tags` definition.""" - reference_jpg_image = filter_files( - ROOT_RESOURCES_FROBISHER_001, ("jpg",) - )[0] + reference_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] test_jpg_image = os.path.join( self._temporary_directory, os.path.basename(reference_jpg_image) ) @@ -313,9 +297,7 @@ def tearDown(self): def test_update_exif_tags(self): """Test :func:`colour_hdri.utilities.exif.update_exif_tags` definition.""" - reference_jpg_images = filter_files( - ROOT_RESOURCES_FROBISHER_001, ("jpg",) - ) + reference_jpg_images = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",)) test_jpg_images = [] for reference_jpg_image in reference_jpg_images: test_jpg_image = os.path.join( @@ -351,9 +333,7 @@ def tearDown(self): def test_delete_exif_tags(self): """Test :func:`colour_hdri.utilities.exif.delete_exif_tags` definition.""" - reference_jpg_image = filter_files( - ROOT_RESOURCES_FROBISHER_001, ("jpg",) - )[0] + reference_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] test_jpg_image = os.path.join( self._temporary_directory, os.path.basename(reference_jpg_image) ) @@ -373,9 +353,7 @@ class TestReadExifTag(unittest.TestCase): def test_read_exif_tag(self): """Test :func:`colour_hdri.utilities.exif.read_exif_tag` definition.""" - test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[ - 0 - ] + test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "8.0") self.assertEqual(read_exif_tag(test_jpg_image, "ExposureTime"), "1/8") @@ -401,9 +379,7 @@ def tearDown(self): def test_write_exif_tag(self): """Test :func:`colour_hdri.utilities.exif.write_exif_tag` definition.""" - reference_jpg_image = filter_files( - ROOT_RESOURCES_FROBISHER_001, ("jpg",) - )[0] + reference_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] test_jpg_image = os.path.join( self._temporary_directory, os.path.basename(reference_jpg_image) ) diff --git a/colour_hdri/utilities/tests/test_image.py b/colour_hdri/utilities/tests/test_image.py index 0051394..54bbb96 100644 --- a/colour_hdri/utilities/tests/test_image.py +++ b/colour_hdri/utilities/tests/test_image.py @@ -24,9 +24,7 @@ "TestImageStack", ] -ROOT_RESOURCES_FROBISHER_001: str = os.path.join( - ROOT_RESOURCES_TESTS, "frobisher_001" -) +ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") class TestImage(unittest.TestCase): @@ -38,9 +36,7 @@ class TestImage(unittest.TestCase): def setUp(self): """Initialise the common tests attributes.""" - self._test_jpg_image = filter_files( - ROOT_RESOURCES_FROBISHER_001, ("jpg",) - )[0] + self._test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] def test_required_attributes(self): """Test the presence of required attributes.""" @@ -87,9 +83,7 @@ class TestImageStack(unittest.TestCase): def setUp(self): """Initialise the common tests attributes.""" - self._test_jpg_images = filter_files( - ROOT_RESOURCES_FROBISHER_001, ("jpg",) - ) + self._test_jpg_images = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",)) self._image_stack = ImageStack().from_files(self._test_jpg_images) diff --git a/pyproject.toml b/pyproject.toml index e8bb6cd..341ecce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -219,6 +219,9 @@ convention = "numpy" "utilities/*" = ["EXE001", "INP"] "utilities/unicode_to_ascii.py" = ["RUF001"] +[tool.ruff.format] +docstring-code-format = true + [build-system] requires = [ "poetry_core>=1.0.0" ] build-backend = "poetry.core.masonry.api" diff --git a/tasks.py b/tasks.py index 8471daf..5d435d5 100644 --- a/tasks.py +++ b/tasks.py @@ -135,9 +135,7 @@ def formatting( message_box('Cleaning up "BibTeX" file...') bibtex_path = BIBLIOGRAPHY_NAME with open(bibtex_path) as bibtex_file: - entries = ( - biblib.bib.Parser().parse(bibtex_file.read()).get_entries() - ) + entries = biblib.bib.Parser().parse(bibtex_file.read()).get_entries() for entry in sorted(entries.values(), key=lambda x: x.key): with contextlib.suppress(KeyError): @@ -267,9 +265,7 @@ def docs(ctx: Context, html: bool = True, pdf: bool = True): Whether to build the *PDF* documentation. """ - with ctx.prefix("export COLOUR_SCIENCE__DOCUMENTATION_BUILD=True"), ctx.cd( - "docs" - ): + with ctx.prefix("export COLOUR_SCIENCE__DOCUMENTATION_BUILD=True"), ctx.cd("docs"): if html: message_box('Building "HTML" documentation...') ctx.run("make html") @@ -368,10 +364,7 @@ def virtualise(ctx: Context, tests: bool = True): with ctx.cd(unique_name): ctx.run("poetry install") ctx.run("source $(poetry env info -p)/bin/activate") - ctx.run( - 'python -c "import imageio;' - 'imageio.plugins.freeimage.download()"' - ) + ctx.run('python -c "import imageio;imageio.plugins.freeimage.download()"') if tests: ctx.run( "poetry run pytest " @@ -422,9 +415,7 @@ def tag(ctx: Context): remote_tags = result.stdout.strip().split("\n") # pyright: ignore tags = set() for remote_tag in remote_tags: - tags.add( - remote_tag.split("refs/tags/")[1].replace("refs/tags/", "^{}") - ) + tags.add(remote_tag.split("refs/tags/")[1].replace("refs/tags/", "^{}")) version_tags = sorted(tags) if f"v{version}" in version_tags: raise RuntimeError( diff --git a/utilities/export_todo.py b/utilities/export_todo.py index 901bd30..69f3c5e 100755 --- a/utilities/export_todo.py +++ b/utilities/export_todo.py @@ -40,9 +40,7 @@ https://opensource.org/licenses/BSD-3-Clause | `https://github.com/colour-science/colour-hdri \ `__ -"""[ - 1: -] +"""[1:] def extract_todo_items(root_directory: str) -> dict: From 5a5624d4ca8f167c2bbaa2401d26e289c798b203 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Mon, 29 Jan 2024 20:14:39 +1300 Subject: [PATCH 10/12] Use `actions/checkout@v4`. --- .github/workflows/continuous-integration-documentation.yml | 2 +- .github/workflows/continuous-integration-quality-unit-tests.yml | 2 +- .../workflows/continuous-integration-static-type-checking.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration-documentation.yml b/.github/workflows/continuous-integration-documentation.yml index 491660a..d00ce7a 100644 --- a/.github/workflows/continuous-integration-documentation.yml +++ b/.github/workflows/continuous-integration-documentation.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Environment Variables run: | echo "CI_PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV diff --git a/.github/workflows/continuous-integration-quality-unit-tests.yml b/.github/workflows/continuous-integration-quality-unit-tests.yml index e73b4fa..0a436db 100644 --- a/.github/workflows/continuous-integration-quality-unit-tests.yml +++ b/.github/workflows/continuous-integration-quality-unit-tests.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 with: submodules: true - name: Environment Variables diff --git a/.github/workflows/continuous-integration-static-type-checking.yml b/.github/workflows/continuous-integration-static-type-checking.yml index 1df15e0..f903102 100644 --- a/.github/workflows/continuous-integration-static-type-checking.yml +++ b/.github/workflows/continuous-integration-static-type-checking.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Environment Variables run: | echo "CI_PACKAGE=colour_hdri" >> $GITHUB_ENV From 45de5f834c3ceba11b4146b37b8640cc8ffabc18 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Tue, 30 Jan 2024 21:23:48 +1300 Subject: [PATCH 11/12] Use `exiftool` 12.74 in CI. --- .../workflows/continuous-integration-quality-unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration-quality-unit-tests.yml b/.github/workflows/continuous-integration-quality-unit-tests.yml index 0a436db..9717d41 100644 --- a/.github/workflows/continuous-integration-quality-unit-tests.yml +++ b/.github/workflows/continuous-integration-quality-unit-tests.yml @@ -46,8 +46,8 @@ jobs: - name: Install Dependencies (Windows) if: matrix.os == 'windows-latest' run: | - curl -L https://exiftool.org/exiftool-12.51.zip -o exiftool-12.51.zip - unzip -d exiftool exiftool-12.51.zip + curl -L https://exiftool.org/exiftool-12.74.zip -o exiftool-12.74.zip + unzip -d exiftool exiftool-12.74.zip cp exiftool/exiftool\(-k\).exe exiftool/exiftool.exe echo "$PWD/exiftool" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/' >> $GITHUB_PATH curl -L https://cdn.fastpictureviewer.com/bin/dcraw.zip?v=201605100 -o dcraw.zip From 59c54326a0b952f189cb039b6b594dad0b1c4757 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Tue, 30 Jan 2024 21:43:06 +1300 Subject: [PATCH 12/12] Drop `black` settings in `pyproject.toml` file. --- pyproject.toml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 341ecce..054dc68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,16 +89,6 @@ restructuredtext-lint = "*" sphinx = "*" sphinxcontrib-bibtex = "*" -[tool.black] -line-length = 79 -exclude = ''' -/( - \.git - | build - | dist -)/ -''' - [tool.codespell] skip = 'BIBLIOGRAPHY.bib,CONTRIBUTORS.rst,*.ipynb'