def right(self, value): """ Setter for the **self.right** property. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" is not a "numeric"!').format( 'right', value) self._right = value
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
def default(self, value): """ Setter for the **self.default** property. """ if value is not None: assert is_numeric(value), ( '"default" variable must be a "numeric"!') self._default = value
def absolute_tolerance(self, value): """ Setter for the **self.absolute_tolerance** property. """ if value is not None: assert is_numeric(value), ( '"absolute_tolerance" variable must be a "numeric"!') self._absolute_tolerance = value
def bandwidth_FWHM(self, value): """ Setter for the **self.bandwidth_FWHM** property. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" is not a "numeric"!'.format( 'bandwidth_FWHM', value)) self._bandwidth_FWHM = value
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
def translate_speed(self, value): """ Setter for **self._translate_speed** private attribute. Parameters ---------- value : numeric Attribute value. """ if value is not None: assert is_numeric(value), ('"{0}" is not a numeric!'.format( 'translate_speed', value)) self._translate_speed = value
def left(self, value): """ Setter for **self.__left** private attribute. Parameters ---------- value : numeric Attribute value. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" type is not "numeric"!').format( 'left', value) self.__left = value
def right(self, value): """ Setter for **self.__right** private attribute. Parameters ---------- value : numeric Attribute value. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" is not a "numeric"!').format( 'right', value) self.__right = value
def right(self, value): """ Setter for **self._right** private attribute. Parameters ---------- value : numeric Attribute value. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" is not a "numeric"!').format( 'right', value) self._right = value
def bandwidth_FWHM(self, value): """ Setter for **self.__bandwidth_FWHM** private attribute. Parameters ---------- value : numeric Attribute value. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" is not a "numeric"!'.format( 'bandwidth_FWHM', value)) self.__bandwidth_FWHM = value
def bandwidth_FWHM(self, value): """ Setter for **self._bandwidth_FWHM** private attribute. Parameters ---------- value : numeric Attribute value. """ if value is not None: assert is_numeric(value), ( '"{0}" attribute: "{1}" is not a "numeric"!'.format( 'bandwidth_FWHM', value)) self._bandwidth_FWHM = value
def test_is_numeric(self): """ Tests :func:`colour.utilities.common.is_numeric` definition. """ self.assertTrue(is_numeric(1)) self.assertTrue(is_numeric(1)) self.assertTrue(is_numeric(complex(1))) self.assertFalse(is_numeric((1, ))) self.assertFalse(is_numeric([1])) self.assertFalse(is_numeric('1'))
def __round(self, item): """ Rounds given item if numeric. Parameters ---------- item : object Attribute. Parameters ---------- item : object Attribute. Notes ----- - Reimplements the :meth:`MutableMapping.__setitem__` method. """ if is_numeric(item): return round(item, self.__key_decimals) else: return item
def corresponding_chromaticities_prediction_VonKries(experiment=1, transform='CAT02'): """ Returns the corresponding chromaticities prediction for *Von Kries* chromatic adaptation model using given transform. Parameters ---------- experiment : integer or CorrespondingColourDataset, optional {1, 2, 3, 4, 6, 8, 9, 11, 12} *Breneman (1987)* experiment number or :class:`colour.CorrespondingColourDataset` class instance. transform : unicode, optional **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild', 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco', 'Bianco PC'}**, Chromatic adaptation transform. Returns ------- tuple Corresponding chromaticities prediction. References ---------- :cite:`Breneman1987b`, :cite:`Fairchild2013t` Examples -------- >>> from pprint import pprint >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford') >>> pr = [(p.uv_m, p.uv_p) for p in pr] >>> pprint(pr) # doctest: +ELLIPSIS [(array([ 0.207, 0.486]), array([ 0.2082014..., 0.4722922...])), (array([ 0.449, 0.511]), array([ 0.4489102..., 0.5071602...])), (array([ 0.263, 0.505]), array([ 0.2643545..., 0.4959631...])), (array([ 0.322, 0.545]), array([ 0.3348730..., 0.5471220...])), (array([ 0.316, 0.537]), array([ 0.3248758..., 0.5390589...])), (array([ 0.265, 0.553]), array([ 0.2733105..., 0.5555028...])), (array([ 0.221, 0.538]), array([ 0.227148 ..., 0.5331318...)), (array([ 0.135, 0.532]), array([ 0.1442730..., 0.5226804...])), (array([ 0.145, 0.472]), array([ 0.1498745..., 0.4550785...])), (array([ 0.163, 0.331]), array([ 0.1564975..., 0.3148796...])), (array([ 0.176, 0.431]), array([ 0.1760593..., 0.4103772...])), (array([ 0.244, 0.349]), array([ 0.2259805..., 0.3465291...]))] """ experiment_results = (convert_experiment_results_Breneman1987(experiment) if is_numeric(experiment) else experiment) with domain_range_scale(1): XYZ_w, XYZ_wr = experiment_results.XYZ_t, experiment_results.XYZ_r xy_w, xy_wr = XYZ_to_xy([XYZ_w, XYZ_wr]) uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_w), xy_w) uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_wr), xy_wr) XYZ_1 = experiment_results.XYZ_ct XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform) uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr) return tuple([ CorrespondingChromaticitiesPrediction(experiment_results.name, uv_t[i], uv_m[i], uv_p[i]) for i in range(len(uv_t)) ])
def corresponding_chromaticities_prediction_CMCCAT2000(experiment=1): """ Returns the corresponding chromaticities prediction for *CMCCAT2000* chromatic adaptation model. Parameters ---------- experiment : integer or CorrespondingColourDataset, optional {1, 2, 3, 4, 6, 8, 9, 11, 12} *Breneman (1987)* experiment number or :class:`colour.CorrespondingColourDataset` class instance. Returns ------- tuple Corresponding chromaticities prediction. References ---------- :cite:`Breneman1987b`, :cite:`Li2002a`, :cite:`Westland2012k` Examples -------- >>> from pprint import pprint >>> pr = corresponding_chromaticities_prediction_CMCCAT2000(2) >>> pr = [(p.uv_m, p.uv_p) for p in pr] >>> pprint(pr) # doctest: +ELLIPSIS [(array([ 0.207, 0.486]), array([ 0.2083210..., 0.4727168...])), (array([ 0.449, 0.511]), array([ 0.4459270..., 0.5077735...])), (array([ 0.263, 0.505]), array([ 0.2640262..., 0.4955361...])), (array([ 0.322, 0.545]), array([ 0.3316884..., 0.5431580...])), (array([ 0.316, 0.537]), array([ 0.3222624..., 0.5357624...])), (array([ 0.265, 0.553]), array([ 0.2710705..., 0.5501997...])), (array([ 0.221, 0.538]), array([ 0.2261826..., 0.5294740...])), (array([ 0.135, 0.532]), array([ 0.1439693..., 0.5190984...])), (array([ 0.145, 0.472]), array([ 0.1494835..., 0.4556760...])), (array([ 0.163, 0.331]), array([ 0.1563172..., 0.3164151...])), (array([ 0.176, 0.431]), array([ 0.1763199..., 0.4127589...])), (array([ 0.244, 0.349]), array([ 0.2287638..., 0.3499324...]))] """ experiment_results = (convert_experiment_results_Breneman1987(experiment) if is_numeric(experiment) else experiment) with domain_range_scale(1): XYZ_w, XYZ_wr = experiment_results.XYZ_t, experiment_results.XYZ_r xy_w, xy_wr = XYZ_to_xy([XYZ_w, XYZ_wr]) uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_w), xy_w) uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_wr), xy_wr) L_A1 = experiment_results.Y_t L_A2 = experiment_results.Y_r XYZ_1 = experiment_results.XYZ_ct XYZ_2 = chromatic_adaptation_CMCCAT2000(XYZ_1, XYZ_w, XYZ_wr, L_A1, L_A2) uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr) return tuple([ CorrespondingChromaticitiesPrediction(experiment_results.name, uv_t[i], uv_m[i], uv_p[i]) for i in range(len(uv_t)) ])
def corresponding_chromaticities_prediction_CIE1994(experiment=1): """ Returns the corresponding chromaticities prediction for *CIE 1994* chromatic adaptation model. Parameters ---------- experiment : integer or CorrespondingColourDataset, optional {1, 2, 3, 4, 6, 8, 9, 11, 12} *Breneman (1987)* experiment number or :class:`colour.CorrespondingColourDataset` class instance. Returns ------- tuple Corresponding chromaticities prediction. References ---------- :cite:`Breneman1987b`, :cite:`CIETC1-321994b` Examples -------- >>> from pprint import pprint >>> pr = corresponding_chromaticities_prediction_CIE1994(2) >>> pr = [(p.uv_m, p.uv_p) for p in pr] >>> pprint(pr) # doctest: +ELLIPSIS [(array([ 0.207, 0.486]), array([ 0.2273130..., 0.5267609...])), (array([ 0.449, 0.511]), array([ 0.4612181..., 0.5191849...])), (array([ 0.263, 0.505]), array([ 0.2872404..., 0.5306938...])), (array([ 0.322, 0.545]), array([ 0.3489822..., 0.5454398...])), (array([ 0.316, 0.537]), array([ 0.3371612..., 0.5421567...])), (array([ 0.265, 0.553]), array([ 0.2889416..., 0.5534074...])), (array([ 0.221, 0.538]), array([ 0.2412195..., 0.5464301...])), (array([ 0.135, 0.532]), array([ 0.1530344..., 0.5488239...])), (array([ 0.145, 0.472]), array([ 0.1568709..., 0.5258835...])), (array([ 0.163, 0.331]), array([ 0.1499762..., 0.4401747...])), (array([ 0.176, 0.431]), array([ 0.1876711..., 0.5039627...])), (array([ 0.244, 0.349]), array([ 0.2560012..., 0.4546263...]))] """ experiment_results = (convert_experiment_results_Breneman1987(experiment) if is_numeric(experiment) else experiment) with domain_range_scale(1): XYZ_t, XYZ_r = experiment_results.XYZ_t, experiment_results.XYZ_r xy_o1, xy_o2 = XYZ_to_xy([XYZ_t, XYZ_r]) uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_o1), xy_o1) uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_o2), xy_o2) Y_r = experiment_results.B_r E_o1, E_o2 = experiment_results.Y_t, experiment_results.Y_r XYZ_1 = experiment_results.XYZ_ct XYZ_2 = chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_r, E_o1, E_o2) uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_o2), xy_o2) return tuple([ CorrespondingChromaticitiesPrediction(experiment_results.name, uv_t[i], uv_m[i], uv_p[i]) for i in range(len(uv_t)) ])
def corresponding_chromaticities_prediction_Fairchild1990(experiment=1): """ Returns the corresponding chromaticities prediction for *Fairchild (1990)* chromatic adaptation model. Parameters ---------- experiment : integer or CorrespondingColourDataset, optional {1, 2, 3, 4, 6, 8, 9, 11, 12} *Breneman (1987)* experiment number or :class:`colour.CorrespondingColourDataset` class instance. Returns ------- tuple Corresponding chromaticities prediction. References ---------- :cite:`Breneman1987b`, :cite:`Fairchild1991a`, :cite:`Fairchild2013s` Examples -------- >>> from pprint import pprint >>> pr = corresponding_chromaticities_prediction_Fairchild1990(2) >>> pr = [(p.uv_m, p.uv_p) for p in pr] >>> pprint(pr) # doctest: +ELLIPSIS [(array([ 0.207, 0.486]), array([ 0.2089528..., 0.4724034...])), (array([ 0.449, 0.511]), array([ 0.4375652..., 0.5121030...])), (array([ 0.263, 0.505]), array([ 0.2621362..., 0.4972538...])), (array([ 0.322, 0.545]), array([ 0.3235312..., 0.5475665...])), (array([ 0.316, 0.537]), array([ 0.3151391..., 0.5398333...])), (array([ 0.265, 0.553]), array([ 0.2634745..., 0.5544335...])), (array([ 0.221, 0.538]), array([ 0.2211595..., 0.5324470...])), (array([ 0.135, 0.532]), array([ 0.1396949..., 0.5207234...])), (array([ 0.145, 0.472]), array([ 0.1512288..., 0.4533041...])), (array([ 0.163, 0.331]), array([ 0.1715691..., 0.3026264...])), (array([ 0.176, 0.431]), array([ 0.1825792..., 0.4077892...])), (array([ 0.244, 0.349]), array([ 0.2418905..., 0.3413401...]))] """ experiment_results = (convert_experiment_results_Breneman1987(experiment) if is_numeric(experiment) else experiment) with domain_range_scale(1): XYZ_t, XYZ_r = experiment_results.XYZ_t, experiment_results.XYZ_r xy_t, xy_r = XYZ_to_xy([XYZ_t, XYZ_r]) uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_t), xy_t) uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_r), xy_r) Y_n = experiment_results.Y_t XYZ_1 = experiment_results.XYZ_ct XYZ_2 = chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_t, XYZ_r, Y_n) uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_r), xy_r) return tuple([ CorrespondingChromaticitiesPrediction(experiment_results.name, uv_t[i], uv_m[i], uv_p[i]) for i in range(len(uv_t)) ])
def plot_corresponding_chromaticities_prediction( experiment: Union[Literal[1, 2, 3, 4, 6, 8, 9, 11, 12], CorrespondingColourDataset] = 1, model: Union[Literal["CIE 1994", "CMCCAT2000", "Fairchild 1990", "Von Kries", "Zhai 2018", ], str, ] = "Von Kries", corresponding_chromaticities_prediction_kwargs: Optional[Dict] = None, **kwargs: Any, ) -> Tuple[plt.Figure, plt.Axes]: """ Plot given chromatic adaptation model corresponding chromaticities prediction. Parameters ---------- experiment *Breneman (1987)* experiment number or :class:`colour.CorrespondingColourDataset` class instance. model Corresponding chromaticities prediction model name. corresponding_chromaticities_prediction_kwargs Keyword arguments for the :func:`colour.\ corresponding_chromaticities_prediction` definition. Other Parameters ---------------- kwargs {:func:`colour.plotting.artist`, :func:`colour.plotting.diagrams.plot_chromaticity_diagram`, :func:`colour.plotting.render`}, See the documentation of the previously listed definitions. Returns ------- :class:`tuple` Current figure and axes. Examples -------- >>> plot_corresponding_chromaticities_prediction(1, 'Von Kries') ... # doctest: +ELLIPSIS (<Figure size ... with 1 Axes>, <...AxesSubplot...>) .. image:: ../_static/Plotting_\ Plot_Corresponding_Chromaticities_Prediction.png :align: center :alt: plot_corresponding_chromaticities_prediction """ if corresponding_chromaticities_prediction_kwargs is None: corresponding_chromaticities_prediction_kwargs = {} settings: Dict[str, Any] = {"uniform": True} settings.update(kwargs) _figure, axes = artist(**settings) name = ( f"Experiment {experiment}" if is_numeric(experiment) else experiment.name # type: ignore[union-attr] ) title = (f"Corresponding Chromaticities Prediction - {model} - {name} - " "CIE 1976 UCS Chromaticity Diagram") settings = {"axes": axes, "title": title} settings.update(kwargs) settings["standalone"] = False plot_chromaticity_diagram_CIE1976UCS(**settings) results = corresponding_chromaticities_prediction( experiment, model, **corresponding_chromaticities_prediction_kwargs) for result in results: _name, uv_t, uv_m, uv_p = result axes.arrow( uv_t[0], uv_t[1], uv_p[0] - uv_t[0] - 0.1 * (uv_p[0] - uv_t[0]), uv_p[1] - uv_t[1] - 0.1 * (uv_p[1] - uv_t[1]), color=CONSTANTS_COLOUR_STYLE.colour.dark, head_width=0.005, head_length=0.005, zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_annotation, ) axes.plot( uv_t[0], uv_t[1], "o", color=CONSTANTS_COLOUR_STYLE.colour.brightest, markeredgecolor=CONSTANTS_COLOUR_STYLE.colour.dark, markersize=(CONSTANTS_COLOUR_STYLE.geometry.short * 6 + CONSTANTS_COLOUR_STYLE.geometry.short * 0.75), markeredgewidth=CONSTANTS_COLOUR_STYLE.geometry.short * 0.75, zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line, ) axes.plot( uv_m[0], uv_m[1], "^", color=CONSTANTS_COLOUR_STYLE.colour.brightest, markeredgecolor=CONSTANTS_COLOUR_STYLE.colour.dark, markersize=(CONSTANTS_COLOUR_STYLE.geometry.short * 6 + CONSTANTS_COLOUR_STYLE.geometry.short * 0.75), markeredgewidth=CONSTANTS_COLOUR_STYLE.geometry.short * 0.75, zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line, ) axes.plot( uv_p[0], uv_p[1], "^", color=CONSTANTS_COLOUR_STYLE.colour.dark, zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line, ) settings.update({ "standalone": True, "bounding_box": (-0.1, 0.7, -0.1, 0.7), }) settings.update(kwargs) return render(**settings)
def plot_corresponding_chromaticities_prediction(experiment=1, model='Von Kries', transform='CAT02', **kwargs): """ Plots given chromatic adaptation model corresponding chromaticities prediction. Parameters ---------- experiment : integer or CorrespondingColourDataset, optional {1, 2, 3, 4, 6, 8, 9, 11, 12} *Breneman (1987)* experiment number or :class:`colour.CorrespondingColourDataset` class instance. model : unicode, optional Corresponding chromaticities prediction model name. transform : unicode, optional Transformation to use with *Von Kries* chromatic adaptation model. Other Parameters ---------------- \\**kwargs : dict, optional {:func:`colour.plotting.artist`, :func:`colour.plotting.diagrams.plot_chromaticity_diagram`, :func:`colour.plotting.render`}, Please refer to the documentation of the previously listed definitions. Returns ------- tuple Current figure and axes. Examples -------- >>> plot_corresponding_chromaticities_prediction(1, 'Von Kries', 'CAT02') ... # doctest: +ELLIPSIS (<Figure size ... with 1 Axes>, <...AxesSubplot...>) .. image:: ../_static/Plotting_\ Plot_Corresponding_Chromaticities_Prediction.png :align: center :alt: plot_corresponding_chromaticities_prediction """ settings = {'uniform': True} settings.update(kwargs) _figure, axes = artist(**settings) name = ('Experiment {0}'.format(experiment) if is_numeric(experiment) else experiment.name) title = (('Corresponding Chromaticities Prediction - {0} ({1}) - {2} - ' 'CIE 1976 UCS Chromaticity Diagram').format( model, transform, name) if model.lower() in ('von kries', 'vonkries') else ('Corresponding Chromaticities Prediction - {0} - {1} - ' 'CIE 1976 UCS Chromaticity Diagram').format(model, name)) settings = {'axes': axes, 'title': title} settings.update(kwargs) settings['standalone'] = False plot_chromaticity_diagram_CIE1976UCS(**settings) results = corresponding_chromaticities_prediction(experiment, transform=transform) for result in results: _name, uv_t, uv_m, uv_p = result axes.arrow(uv_t[0], uv_t[1], uv_p[0] - uv_t[0] - 0.1 * (uv_p[0] - uv_t[0]), uv_p[1] - uv_t[1] - 0.1 * (uv_p[1] - uv_t[1]), color=CONSTANTS_COLOUR_STYLE.colour.dark, head_width=0.005, head_length=0.005) axes.plot(uv_t[0], uv_t[1], 'o', color=CONSTANTS_COLOUR_STYLE.colour.brightest, markeredgecolor=CONSTANTS_COLOUR_STYLE.colour.dark, markersize=(CONSTANTS_COLOUR_STYLE.geometry.short * 6 + CONSTANTS_COLOUR_STYLE.geometry.short * 0.75), markeredgewidth=CONSTANTS_COLOUR_STYLE.geometry.short * 0.75) axes.plot(uv_m[0], uv_m[1], '^', color=CONSTANTS_COLOUR_STYLE.colour.brightest, markeredgecolor=CONSTANTS_COLOUR_STYLE.colour.dark, markersize=(CONSTANTS_COLOUR_STYLE.geometry.short * 6 + CONSTANTS_COLOUR_STYLE.geometry.short * 0.75), markeredgewidth=CONSTANTS_COLOUR_STYLE.geometry.short * 0.75) axes.plot(uv_p[0], uv_p[1], '^', color=CONSTANTS_COLOUR_STYLE.colour.dark) settings.update({ 'standalone': True, 'bounding_box': (-0.1, 0.7, -0.1, 0.7), }) settings.update(kwargs) return render(**settings)