示例#1
0
    def test_function(self):
        """
        Test :func:`colour.continuous.multi_signals.MultiSignals.function`
        property.
        """

        attest(hasattr(self._multi_signals.function, "__call__"))
示例#2
0
def get_attribute(attribute: str) -> Any:
    """
    Return given attribute value.

    Parameters
    ----------
    attribute
        Attribute to retrieve, ``attribute`` must have a namespace module, e.g.
        *colour.models.eotf_BT2020*.

    Returns
    -------
    :class:`object`
        Retrieved attribute value.

    Examples
    --------
    >>> get_attribute('colour.models.eotf_BT2020')  # doctest: +ELLIPSIS
    <function eotf_BT2020 at 0x...>
    """

    attest("." in attribute, '"{0}" attribute has no namespace!')

    module_name, attribute = attribute.rsplit(".", 1)

    module = optional(sys.modules.get(module_name), import_module(module_name))

    attest(
        module is not None,
        f'"{module_name}" module does not exists or cannot be imported!',
    )

    return attrgetter(attribute)(module)
示例#3
0
    def header(self, value: Header_IESTM2714):
        """Setter for the **self.header** property."""

        attest(
            isinstance(value, Header_IESTM2714),
            f'"header" property: "{value}" type is not "Header_IESTM2714"!',
        )

        self._header = value
示例#4
0
    def name(self, value: str):
        """Setter for the **self.name** property."""

        attest(
            is_string(value),
            f'"name" property: "{value}" type is not "str"!',
        )

        self._name = value
示例#5
0
    def comments(self, value: Sequence[str]):
        """Setter for the **self.comments** property."""

        attest(
            is_iterable(value),
            f'"comments" property: "{value}" must be a sequence!',
        )

        self._comments = list(value)
示例#6
0
    def catalog_number(self, value: Optional[str]):
        """Setter for the **self.catalog_number** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"catalog_number" property: "{value}" type is not "str"!',
            )

        self._catalog_number = value
示例#7
0
    def extrapolator_kwargs(self, value: dict):
        """Setter for the **self.extrapolator_kwargs** property."""

        attest(
            isinstance(value, dict),
            f'"extrapolator_kwargs" property: "{value}" type is not "dict"!',
        )

        self._extrapolator_kwargs = value
        self._create_function()
示例#8
0
    def path(self, value: Optional[str]):
        """Setter for the **self.path** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"path" property: "{value}" type is not "str"!',
            )

        self._path = value
示例#9
0
    def comments(self, value: Optional[str]):
        """Setter for the **self.comments** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"comments" property: "{value}" type is not "str"!',
            )

        self._comments = value
示例#10
0
    def document_creation_date(self, value: Optional[str]):
        """Setter for the **self.document_creation_date** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"document_creation_date" property: "{value}" type is not "str"!',
            )

        self._document_creation_date = value
示例#11
0
    def report_date(self, value: Optional[str]):
        """Setter for the **self.report_date** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"report_date" property: "{value}" type is not "str"!',
            )

        self._report_date = value
示例#12
0
    def laboratory(self, value: Optional[str]):
        """Setter for the **self.measurement_equipment** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"laboratory" property: "{value}" type is not "str"!',
            )

        self._laboratory = value
示例#13
0
    def unique_identifier(self, value: Optional[str]):
        """Setter for the **self.unique_identifier** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"unique_identifier" property: "{value}" type is not "str"!',
            )

        self._unique_identifier = value
示例#14
0
    def description(self, value: Optional[str]):
        """Setter for the **self.description** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"description" property: "{value}" type is not "str"!',
            )

        self._description = value
示例#15
0
    def whitepoint_name(self, value: Optional[str]):
        """Setter for the **self.whitepoint_name** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"whitepoint_name" property: "{value}" type is not "str"!',
            )

        self._whitepoint_name = value
示例#16
0
    def manufacturer(self, value: Optional[str]):
        """Setter for the **self.manufacturer** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"manufacturer" property: "{value}" type is not "str"!',
            )

        self._manufacturer = value
示例#17
0
    def bandwidth_corrected(self, value: Optional[Boolean]):
        """Setter for the **self.bandwidth_corrected** property."""

        if value is not None:
            attest(
                isinstance(value, bool),
                f'"bandwidth_corrected" property: "{value}" type is not "bool"!',
            )

        self._bandwidth_corrected = value
示例#18
0
    def right(self, value: Optional[Number]):
        """Setter for the **self.right** property."""

        if value is not None:
            attest(
                is_numeric(value),
                f'"right" property: "{value}" is not a "number"!',
            )

            self._right = value
示例#19
0
    def use_derived_matrix_XYZ_to_RGB(self, value: Boolean):
        """Setter for the **self.use_derived_matrix_XYZ_to_RGB** property."""

        attest(
            isinstance(value, (bool, np.bool_)),
            f'"use_derived_matrix_XYZ_to_RGB" property: "{value}" is not a '
            f'"bool"!',
        )

        self._use_derived_matrix_XYZ_to_RGB = value
示例#20
0
    def cctf_decoding(self, value: Optional[Callable]):
        """Setter for the **self.cctf_decoding** property."""

        if value is not None:
            attest(
                hasattr(value, "__call__"),
                f'"cctf_decoding" property: "{value}" is not callable!',
            )

        self._cctf_decoding = value
示例#21
0
    def method(self, value: Union[Literal["Linear", "Constant"], str]):
        """Setter for the **self.method** property."""

        attest(
            is_string(value),
            f'"method" property: "{value}" type is not "str"!',
        )

        value = validate_method(value, ["Linear", "Constant"])

        self._method = value
示例#22
0
    def bandwidth_FWHM(self, value: Optional[Floating]):
        """Setter for the **self.bandwidth_FWHM** property."""

        if value is not None:
            attest(
                is_numeric(value),
                f'"bandwidth_FWHM" property: "{value}" is not a "number"!',
            )

            value = as_float_scalar(value)

        self._bandwidth_FWHM = value
示例#23
0
    def matrix_XYZ_to_RGB(self, value: Optional[ArrayLike]):
        """Setter for the **self.matrix_XYZ_to_RGB** property."""

        if value is not None:
            attest(
                isinstance(value, (tuple, list, np.ndarray, np.matrix)),
                f'"matrix_XYZ_to_RGB" property: "{value!r}" is not a "tuple", '
                f'"list", "ndarray" or "matrix" instance!',
            )

            value = as_float_array(value)

        self._matrix_XYZ_to_RGB = value
示例#24
0
    def whitepoint(self, value: ArrayLike):
        """Setter for the **self.whitepoint** property."""

        attest(
            isinstance(value, (tuple, list, np.ndarray, np.matrix)),
            f'"matrix_XYZ_to_RGB" property: "{value!r}" is not a "tuple", '
            f'"list", "ndarray" or "matrix" instance!',
        )

        value = as_float_array(value)

        self._whitepoint = value

        self._derive_transformation_matrices()
示例#25
0
    def interpolator(self, value: TypeInterpolator):
        """Setter for the **self.interpolator** property."""

        attest(
            hasattr(value, "x"),
            f'"{value}" interpolator has no "x" attribute!',
        )

        attest(
            hasattr(value, "y"),
            f'"{value}" interpolator has no "y" attribute!',
        )

        self._interpolator = value
示例#26
0
    def transmission_geometry(
        self,
        value: Optional[Literal["0:0", "di:0", "de:0", "0:di", "0:de", "d:d",
                                "other"]],
    ):
        """Setter for the **self.transmission_geometry** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"transmission_geometry" property: "{value}" type is not "str"!',
            )

        self._transmission_geometry = value
示例#27
0
def load_TCS_CIE2017(shape: SpectralShape) -> MultiSpectralDistributions:
    """
    Load the *CIE 2017 Test Colour Samples* dataset appropriate for the given
    spectral shape.

    The datasets are cached and won't be loaded again on subsequent calls to
    this definition.

    Parameters
    ----------
    shape
        Spectral shape of the tested illuminant.

    Returns
    -------
    :class:`colour.MultiSpectralDistributions`
        *CIE 2017 Test Colour Samples* dataset.

    Examples
    --------
    >>> sds_tcs = load_TCS_CIE2017(SpectralShape(380, 780, 5))
    >>> len(sds_tcs.labels)
    99
    """

    global _CACHE_TCS_CIE2017

    interval = shape.interval

    attest(
        interval in (1, 5),
        "Spectral shape interval must be either 1nm or 5nm!",
    )

    filename = f"tcs_cfi2017_{as_int_scalar(interval)}_nm.csv.gz"

    if filename in _CACHE_TCS_CIE2017:
        return _CACHE_TCS_CIE2017[filename]

    data = np.genfromtxt(str(
        os.path.join(RESOURCES_DIRECTORY_CIE2017, filename)),
                         delimiter=",")
    labels = [f"TCS{i} (CIE 2017)" for i in range(99)]

    tcs = MultiSpectralDistributions(data[:, 1:], data[:, 0], labels)

    _CACHE_TCS_CIE2017[filename] = tcs

    return tcs
示例#28
0
    def test_nan_UCS_Luo2006_to_XYZ(self):
        """
        Test :func:`colour.models.cam02_ucs.UCS_Luo2006_to_XYZ` definition nan
        support.
        """

        cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
        cases = set(permutations(cases * 3, r=3))
        for case in cases:
            Jpapbp = np.array(case)
            try:
                UCS_Luo2006_to_XYZ(Jpapbp,
                                   COEFFICIENTS_UCS_LUO2006["CAM02-LCD"])
            except ValueError as error:
                attest("CAM_Specification_CIECAM02" in str(error))
示例#29
0
    def reflection_geometry(
        self,
        value: Optional[Literal["di:8", "de:8", "8:di", "8:de", "d:d", "d:0",
                                "45a:0", "45c:0", "0:45a", "45x:0", "0:45x",
                                "other", ]],
    ):
        """Setter for the **self.reflection_geometry** property."""

        if value is not None:
            attest(
                is_string(value),
                f'"reflection_geometry" property: "{value}" type is not "str"!',
            )

        self._reflection_geometry = value
示例#30
0
    def dtype(self, value: Type[DTypeFloating]):
        """Setter for the **self.dtype** property."""

        attest(
            value in np.sctypes["float"],
            f'"dtype" must be one of the following types: '
            f"{np.sctypes['float']}",
        )

        self._dtype = value

        # The following self-assignments are written as intended and
        # triggers the rebuild of the underlying function.
        self.domain = self.domain
        self.range = self.range