def test_is_within_mesh_volume(self): """Test :func:`colour.volume.mesh.is_within_mesh_volume` definition.""" self.assertTrue( is_within_mesh_volume( np.array([0.0005, 0.0031, 0.0010]), self._mesh ) ) self.assertFalse( is_within_mesh_volume( np.array([0.3205, 0.4131, 0.5100]), self._mesh ) ) self.assertTrue( is_within_mesh_volume( np.array([0.0025, 0.0088, 0.0340]), self._mesh ) ) self.assertFalse( is_within_mesh_volume( np.array([0.4325, 0.3788, 0.1034]), self._mesh ) )
def test_nan_is_within_mesh_volume(self): """ Tests :func:`colour.volume.mesh.is_within_mesh_volume` 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: is_within_mesh_volume(case, self.__mesh)
def is_within_pointer_gamut(XYZ, tolerance=None): """ Returns if given *CIE XYZ* tristimulus values are within Pointer's Gamut volume. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. tolerance : numeric, optional Tolerance allowed in the inside-triangle check. Returns ------- bool Is within Pointer's Gamut. Notes ----- - Input *CIE XYZ* tristimulus values are in domain [0, 1]. Examples -------- >>> import numpy as np >>> is_within_pointer_gamut(np.array([0.3205, 0.4131, 0.5100])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.5100], [0.0005, 0.0031, 0.0010]]) >>> is_within_pointer_gamut(a) array([ True, False], dtype=bool) """ XYZ_p = Lab_to_XYZ( LCHab_to_Lab(POINTER_GAMUT_DATA), POINTER_GAMUT_ILLUMINANT) return is_within_mesh_volume(XYZ, XYZ_p, tolerance)
def test_n_dimensional_is_within_mesh_volume(self): """ Tests :func:`colour.volume.mesh.is_within_mesh_volume` definition n-dimensional arrays support. """ a = np.array([0.0005, 0.0031, 0.0010]) b = is_within_mesh_volume(a, self._mesh) a = np.tile(a, (6, 1)) b = np.tile(b, 6) np.testing.assert_almost_equal(is_within_mesh_volume(a, self._mesh), b) a = np.reshape(a, (2, 3, 3)) b = np.reshape(b, (2, 3)) np.testing.assert_almost_equal(is_within_mesh_volume(a, self._mesh), b)
def is_within_visible_spectrum( XYZ, interval=10, cmfs=STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'], illuminant=sd_ones( STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer']. shape), tolerance=None): """ Returns if given *CIE XYZ* tristimulus values are within visible spectrum volume / given colour matching functions volume. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. interval : int, optional Wavelength :math:`\\lambda_{i}` range interval used to compute the pulse waves for the *CIE XYZ* colourspace outer surface. cmfs : XYZ_ColourMatchingFunctions, optional Standard observer colour matching functions. illuminant : SpectralDistribution, optional Illuminant spectral distribution. tolerance : numeric, optional Tolerance allowed in the inside-triangle check. Returns ------- bool Is within visible spectrum. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``XYZ`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ Examples -------- >>> import numpy as np >>> is_within_visible_spectrum(np.array([0.3205, 0.4131, 0.51])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.51], ... [-0.0005, 0.0031, 0.001]]) >>> is_within_visible_spectrum(a) array([ True, False], dtype=bool) """ key = (interval, hash(cmfs), hash(illuminant)) vertices = _XYZ_OUTER_SURFACE_POINTS_CACHE.get(key) if vertices is None: _XYZ_OUTER_SURFACE_POINTS_CACHE[key] = vertices = (XYZ_outer_surface( interval, STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'], illuminant)) return is_within_mesh_volume(XYZ, vertices, tolerance)
def is_within_visible_spectrum( XYZ, interval=10, cmfs=STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'], illuminant=sd_ones(STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'].shape), tolerance=None): """ Returns if given *CIE XYZ* tristimulus values are within visible spectrum volume / given colour matching functions volume. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. interval : int, optional Wavelength :math:`\\lambda_{i}` range interval used to compute the pulse waves for the *CIE XYZ* colourspace outer surface. cmfs : XYZ_ColourMatchingFunctions, optional Standard observer colour matching functions. illuminant : SpectralDistribution, optional Illuminant spectral distribution. tolerance : numeric, optional Tolerance allowed in the inside-triangle check. Returns ------- bool Is within visible spectrum. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``XYZ`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ Examples -------- >>> import numpy as np >>> is_within_visible_spectrum(np.array([0.3205, 0.4131, 0.51])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.51], ... [-0.0005, 0.0031, 0.001]]) >>> is_within_visible_spectrum(a) array([ True, False], dtype=bool) """ key = (interval, hash(cmfs), hash(illuminant)) vertices = _XYZ_OUTER_SURFACE_POINTS_CACHE.get(key) if vertices is None: _XYZ_OUTER_SURFACE_POINTS_CACHE[key] = vertices = (XYZ_outer_surface( interval, STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'], illuminant)) return is_within_mesh_volume(XYZ, vertices, tolerance)
def test_is_within_mesh_volume(self): """ Tests :func:`colour.volume.mesh.is_within_mesh_volume` definition. """ self.assertTrue( is_within_mesh_volume(np.array([0.0005, 0.0031, 0.0010]), self.__mesh)) self.assertFalse( is_within_mesh_volume(np.array([0.3205, 0.4131, 0.5100]), self.__mesh)) self.assertTrue( is_within_mesh_volume(np.array([0.0025, 0.0088, 0.0340]), self.__mesh)) self.assertFalse( is_within_mesh_volume(np.array([0.4325, 0.3788, 0.1034]), self.__mesh))
def is_within_pointer_gamut(XYZ: ArrayLike, tolerance: Optional[Floating] = None) -> NDArray: """ Return whether given *CIE XYZ* tristimulus values are within Pointer's Gamut volume. Parameters ---------- XYZ *CIE XYZ* tristimulus values. tolerance Tolerance allowed in the inside-triangle check. Returns ------- :class:`numpy.ndarray` Wether given *CIE XYZ* tristimulus values are within Pointer's Gamut volume. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``XYZ`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ Examples -------- >>> import numpy as np >>> is_within_pointer_gamut(np.array([0.3205, 0.4131, 0.5100])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.5100], [0.0005, 0.0031, 0.0010]]) >>> is_within_pointer_gamut(a) array([ True, False], dtype=bool) """ XYZ_p = Lab_to_XYZ(LCHab_to_Lab(DATA_POINTER_GAMUT_VOLUME), CCS_ILLUMINANT_POINTER_GAMUT) return is_within_mesh_volume(XYZ, XYZ_p, tolerance)
def is_within_visible_spectrum(XYZ, cmfs=STANDARD_OBSERVERS_CMFS.get( 'CIE 1931 2 Degree Standard Observer'), tolerance=None): """ Returns if given *CIE XYZ* tristimulus values are within visible spectrum volume / given colour matching functions volume. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. cmfs : XYZ_ColourMatchingFunctions Standard observer colour matching functions. tolerance : numeric, optional Tolerance allowed in the inside-triangle check. Returns ------- bool Is within visible spectrum. Notes ----- - Input *CIE XYZ* tristimulus values are in domain [0, 1]. - This definition requires *scipy* to be installed. Examples -------- >>> import numpy as np >>> is_within_visible_spectrum(np.array([0.3205, 0.4131, 0.51])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.51], ... [-0.0005, 0.0031, 0.001]]) >>> is_within_visible_spectrum(a) array([ True, False], dtype=bool) """ return is_within_mesh_volume(XYZ, cmfs.values, tolerance)
def is_within_pointer_gamut(XYZ, tolerance=None): """ Returns if given *CIE XYZ* tristimulus values are within Pointer's Gamut volume. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. tolerance : numeric, optional Tolerance allowed in the inside-triangle check. Returns ------- bool Is within Pointer's Gamut. Notes ----- - Input *CIE XYZ* tristimulus values are in domain [0, 1]. Examples -------- >>> import numpy as np >>> is_within_pointer_gamut(np.array([0.3205, 0.4131, 0.5100])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.5100], ... [0.0005, 0.0031, 0.0010]]) >>> is_within_pointer_gamut(a) array([ True, False], dtype=bool) """ XYZ_p = Lab_to_XYZ(LCHab_to_Lab(POINTER_GAMUT_DATA), POINTER_GAMUT_ILLUMINANT) return is_within_mesh_volume(XYZ, XYZ_p, tolerance)
def is_within_visible_spectrum( XYZ, cmfs=MSDS_CMFS['CIE 1931 2 Degree Standard Observer'].copy().align( SPECTRAL_SHAPE_OUTER_SURFACE_XYZ), illuminant=sd_ones(SPECTRAL_SHAPE_OUTER_SURFACE_XYZ), tolerance=None, **kwargs): """ Returns if given *CIE XYZ* tristimulus values are within visible spectrum volume / given colour matching functions volume. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. cmfs : XYZ_ColourMatchingFunctions, optional Standard observer colour matching functions. illuminant : SpectralDistribution, optional Illuminant spectral distribution. tolerance : numeric, optional Tolerance allowed in the inside-triangle check. Other Parameters ---------------- \\**kwargs : dict, optional {:func:`colour.msds_to_XYZ`}, Please refer to the documentation of the previously listed definition. Returns ------- bool Is within visible spectrum. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``XYZ`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ Examples -------- >>> import numpy as np >>> is_within_visible_spectrum(np.array([0.3205, 0.4131, 0.51])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.51], ... [-0.0005, 0.0031, 0.001]]) >>> is_within_visible_spectrum(a) array([ True, False], dtype=bool) """ key = (hash(cmfs), hash(illuminant), six.text_type(kwargs)) vertices = _CACHE_OUTER_SURFACE_XYZ_POINTS.get(key) if vertices is None: _CACHE_OUTER_SURFACE_XYZ_POINTS[key] = vertices = (XYZ_outer_surface( cmfs, illuminant, **kwargs)) return is_within_mesh_volume(XYZ, vertices, tolerance)
def is_within_visible_spectrum( XYZ: ArrayLike, cmfs: Optional[MultiSpectralDistributions] = None, illuminant: Optional[SpectralDistribution] = None, tolerance: Optional[Floating] = None, **kwargs: Any, ) -> NDArray: """ Return whether given *CIE XYZ* tristimulus values are within the visible spectrum volume, i.e. *Rösch-MacAdam* colour solid, for given colour matching functions and illuminant. Parameters ---------- XYZ *CIE XYZ* tristimulus values. cmfs Standard observer colour matching functions, default to the *CIE 1931 2 Degree Standard Observer*. illuminant Illuminant spectral distribution, default to *CIE Illuminant E*. tolerance Tolerance allowed in the inside-triangle check. Other Parameters ---------------- kwargs {:func:`colour.msds_to_XYZ`}, See the documentation of the previously listed definition. Returns ------- :class:`numpy.ndarray` Are *CIE XYZ* tristimulus values within the visible spectrum volume, i.e. *Rösch-MacAdam* colour solid. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``XYZ`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ Examples -------- >>> import numpy as np >>> is_within_visible_spectrum(np.array([0.3205, 0.4131, 0.51])) array(True, dtype=bool) >>> a = np.array([[0.3205, 0.4131, 0.51], ... [-0.0005, 0.0031, 0.001]]) >>> is_within_visible_spectrum(a) array([ True, False], dtype=bool) """ cmfs, illuminant = handle_spectral_arguments( cmfs, illuminant, "CIE 1931 2 Degree Standard Observer", "E", SPECTRAL_SHAPE_OUTER_SURFACE_XYZ, ) key = (hash(cmfs), hash(illuminant), str(kwargs)) vertices = _CACHE_OUTER_SURFACE_XYZ_POINTS.get(key) if vertices is None: _CACHE_OUTER_SURFACE_XYZ_POINTS[key] = vertices = solid_RoschMacAdam( cmfs, illuminant, **kwargs) return is_within_mesh_volume(XYZ, vertices, tolerance)