• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

colour-science / colour-datasets / 7853010122

10 Feb 2024 05:53AM UTC coverage: 96.225%. Remained the same
7853010122

push

github

KelSolaar
Use `np.reshape` function instead of `.reshape` method.

2243 of 2331 relevant lines covered (96.22%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/colour_datasets/loaders/ebner1998.py
1
"""
2
Constant Perceived-Hue Data - Ebner and Fairchild (1998)
3
========================================================
4

5
Defines the objects implementing support for *Ebner and Fairchild (1998)*
6
*Constant Perceived-Hue Data* dataset loading:
7

8
-   :class:`colour_datasets.loaders.DatasetLoader_Ebner1998`
9
-   :func:`colour_datasets.loaders.build_Ebner1998`
10

11
References
12
----------
13
-   :cite:`Ebner1998` : Ebner, F., & Fairchild, M. D. (1998). Finding constant
14
    hue surfaces in color space. In G. B. Beretta & R. Eschbach (Eds.), Proc.
15
    SPIE 3300, Color Imaging: Device-Independent Color, Color Hardcopy, and
16
    Graphic Arts III, (2 January 1998) (pp. 107-117). doi:10.1117/12.298269
17
"""
18

19
from __future__ import annotations
1✔
20

21
import codecs
1✔
22
import os
1✔
23
from collections import namedtuple
1✔
24

25
import numpy as np
1✔
26
from colour.hints import Dict, NDArrayFloat
1✔
27
from colour.utilities import as_float_array
1✔
28

29
from colour_datasets.loaders import AbstractDatasetLoader
1✔
30
from colour_datasets.records import datasets
1✔
31

32
__author__ = "Colour Developers"
1✔
33
__copyright__ = "Copyright 2019 Colour Developers"
1✔
34
__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
1✔
35
__maintainer__ = "Colour Developers"
1✔
36
__email__ = "colour-developers@colour-science.org"
1✔
37
__status__ = "Production"
1✔
38

39
__all__ = [
1✔
40
    "ConstantPerceivedHueColourMatches_Ebner1998",
41
    "DatasetLoader_Ebner1998",
42
    "build_Ebner1998",
43
]
44

45

46
class ConstantPerceivedHueColourMatches_Ebner1998(
1✔
47
    namedtuple(
48
        "ConstantPerceivedHueColourMatches_Ebner1998",
49
        ("name", "XYZ_r", "XYZ_cr", "XYZ_ct", "metadata"),
50
    )
51
):
52
    """
53
    Define *Ebner and Fairchild (1998)* *Constant Perceived-Hue Data*
54
    colour matches data for a given hue angle.
55

56
    Parameters
57
    ----------
58
    name
59
        *Ebner and Fairchild (1998)* *Constant Perceived-Hue Data* hue angle or
60
        name.
61
    XYZ_r
62
        *CIE XYZ* tristimulus values of the reference illuminant.
63
    XYZ_cr
64
        *CIE XYZ* tristimulus values of the reference colour under the
65
        reference illuminant.
66
    XYZ_ct
67
        *CIE XYZ* tristimulus values of the colour matches under the reference
68
        illuminant.
69
    metadata
70
        Dataset metadata.
71
    """
72

73

74
class DatasetLoader_Ebner1998(AbstractDatasetLoader):
1✔
75
    """
76
    Define the *Ebner and Fairchild (1998)* *Constant Perceived-Hue Data*
77
    dataset loader.
78

79
    Attributes
80
    ----------
81
    -   :attr:`colour_datasets.loaders.DatasetLoader_Ebner1998.ID`
82

83
    Methods
84
    -------
85
    -   :meth:`colour_datasets.loaders.DatasetLoader_Ebner1998.__init__`
86
    -   :meth:`colour_datasets.loaders.DatasetLoader_Ebner1998.load`
87

88
    References
89
    ----------
90
    :cite:`Ebner1998`
91
    """
92

93
    ID: str = "3362536"
1✔
94
    """Dataset record id, i.e. the *Zenodo* record number."""
1✔
95

96
    def __init__(self) -> None:
1✔
97
        super().__init__(datasets()[DatasetLoader_Ebner1998.ID])
1✔
98

99
    def load(
1✔
100
        self,
101
    ) -> Dict[str, Dict[int, ConstantPerceivedHueColourMatches_Ebner1998]]:
102
        """
103
        Sync, parse, convert and return the *Ebner and Fairchild (1998)*
104
        *Constant Perceived-Hue Data* dataset content.
105

106
        Returns
107
        -------
108
        :class:`dict`
109
            *Ebner and Fairchild (1998)* Constant Perceived-Hue Data* dataset
110
            content.
111

112
        Examples
113
        --------
114
        >>> from colour_datasets.utilities import suppress_stdout
115
        >>> dataset = DatasetLoader_Ebner1998()
116
        >>> with suppress_stdout():
117
        ...     dataset.load()
118
        >>> len(dataset.content.keys())
119
        1
120
        """
121

122
        super().sync()
1✔
123

124
        self._content = {"Constant Perceived-Hue Data": {}}
1✔
125

126
        datafile_path = os.path.join(
1✔
127
            self.record.repository, "dataset", "Ebner_Constant_Hue_Data.txt"
128
        )
129

130
        def _parse_float_values(data: str) -> NDArrayFloat:
1✔
131
            """Parse float values from given data."""
132

133
            values = np.reshape(
1✔
134
                as_float_array([float(x) / 100 for x in data.split("\t") if x]),
135
                (-1, 3),
136
            )
137

138
            return np.squeeze(values)
1✔
139

140
        with codecs.open(datafile_path, encoding="utf-8") as database_file:
1✔
141
            lines = filter(None, (line.strip() for line in database_file.readlines()))
1✔
142

143
            for line in lines:
1✔
144
                if line.startswith("White Point"):
1✔
145
                    XYZ_r = _parse_float_values(line.split(":")[-1])
1✔
146
                elif line.startswith("reference hue"):
1✔
147
                    line = line.replace("reference hue ", "")  # noqa: PLW2901
1✔
148
                    attribute, value = line.split("\t", 1)
1✔
149
                    hue, data = int(attribute), _parse_float_values(value)
1✔
150

151
                    self._content["Constant Perceived-Hue Data"][
1✔
152
                        hue
153
                    ] = ConstantPerceivedHueColourMatches_Ebner1998(
154
                        f"Reference Hue Angle - {hue}",
155
                        XYZ_r,
156
                        data[0],
157
                        data[1:],
158
                        {"h": hue},
159
                    )
160

161
        return self._content
1✔
162

163

164
_DATASET_LOADER_EBNER1998: DatasetLoader_Ebner1998 | None = None
1✔
165
"""
1✔
166
Singleton instance of the *Ebner and Fairchild (1998)*
167
*Constant Perceived-Hue Data* dataset loader.
168
"""
169

170

171
def build_Ebner1998(load: bool = True) -> DatasetLoader_Ebner1998:
1✔
172
    """
173
    Singleton factory that builds the *Ebner and Fairchild (1998)*
174
    *Constant Perceived-Hue Data* dataset loader.
175

176
    Parameters
177
    ----------
178
    load
179
        Whether to load the dataset upon instantiation.
180

181
    Returns
182
    -------
183
    :class:`colour_datasets.loaders.DatasetLoader_Ebner1998`
184
        Singleton instance of the *Ebner and Fairchild (1998)*
185
        *Constant Perceived-Hue Data* dataset loader.
186

187
    References
188
    ----------
189
    :cite:`Ebner1998`
190
    """
191

192
    global _DATASET_LOADER_EBNER1998  # noqa: PLW0603
193

194
    if _DATASET_LOADER_EBNER1998 is None:
1✔
195
        _DATASET_LOADER_EBNER1998 = DatasetLoader_Ebner1998()
1✔
196
        if load:
1✔
197
            _DATASET_LOADER_EBNER1998.load()
1✔
198

199
    return _DATASET_LOADER_EBNER1998
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc