TargetColor

class opencsp.common.lib.target.TargetColor.TargetColor(image_width: float, image_height: float, dpm: float, initial_color: Color)

Bases: TargetAbstract

Target implementation for managing color patterns on a canvas.

__init__(image_width: float, image_height: float, dpm: float, initial_color: Color) None

Initializes the TargetColor instance with specified dimensions and initial color.

Parameters:
  • image_width (float) – The width of the image in meters.

  • image_height (float) – The height of the image in meters.

  • dpm (float) – Dots per meter for the image resolution.

  • initial_color (cl.Color) – The color to fill the canvas before adding patterns.

adjust_color_saturation(saturation_fraction: float) None

Adjusts the color saturation of each pixel in the image.

Each pixel’s vector from the origin in RGB space is adjusted to have a length equal to (saturation_fraction * max_length), where max_length is the distance from the origin to the bounding cube in RGB space defined by the maximum pixel value.

Parameters:

saturation_fraction (float) – The fraction to adjust the saturation by (0.0 to 1.0).

adjust_rgb_color_saturation(rgb, saturation_fraction, max_rgb)

Adjusts the saturation of a given RGB color.

Parameters:
  • rgb (tuple) – A tuple containing the RGB values of the color (red, green, blue).

  • saturation_fraction (float) – The fraction by which to adjust the saturation (0.0 to 1.0).

  • max_rgb (int) – The maximum RGB value (typically 255).

Returns:

A tuple containing the adjusted RGB values.

Return type:

tuple

rows_cols()

Returns the number of rows and columns in the image.

Returns:

A tuple containing the number of rows and columns in the image.

Return type:

tuple

Raises:

AssertionError – If the number of image bands is not equal to 3.

set_center_fiducial(center_fiducial_width_pix, center_fiducial_color)

Draws a center fiducial mark on the image.

Parameters:
  • center_fiducial_width_pix (int) – The width of the center fiducial in pixels; should be an odd number.

  • center_fiducial_color (cl) – The color of the center fiducial.

set_fiducial_pixel(this_row: int, this_col: int, color: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>) None

Sets a pixel in the image to the specified color.

Parameters:
  • this_row (int) – The row index of the pixel to set.

  • this_col (int) – The column index of the pixel to set.

  • color (cl) – The color to set the pixel to.

set_image_to_blue_under_red_cross_green()

Sets the image to a blue color under a red cross on a green background.

This method modifies the image to display a blue color beneath a red cross on a green background, effectively creating a specific color pattern.

set_image_to_linear_color_bar_x(color_below_min: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>, color_bar, color_above_max: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>, discrete_or_continuous: str) None

Sets the image to a linear color bar in the x direction.

Parameters:
  • color_below_min (cl) – The color to use for values below the minimum.

  • color_bar – The color bar to use for mapping values.

  • color_above_max (cl) – The color to use for values above the maximum.

  • discrete_or_continuous (str) – Specifies whether the color bar is discrete or continuous.

set_image_to_linear_color_bar_y(color_below_min: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>, color_bar, color_above_max: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>, discrete_or_continuous: str, lateral_gradient_type: str = 'saturated_to_white', saturated_to_white_exponent: float = 1.5, light_to_saturated_min: float = 0.2, light_to_saturated_max: float = 1.0) None

Sets the image to a linear color bar in the y direction.

Parameters:
  • color_below_min (cl) – The color to use for values below the minimum.

  • color_bar – The color bar to use for mapping values.

  • color_above_max (cl) – The color to use for values above the maximum.

  • discrete_or_continuous (str) – Specifies whether the color bar is discrete or continuous.

  • lateral_gradient_type (str, optional) – Defines the scheme for modulating saturation from left to right. Values: None, ‘saturated_to_white’, or ‘light_to_saturated’.

  • saturated_to_white_exponent (float, optional) – Dimensionless exponent applied if lateral_gradient_type is ‘saturated_to_white’.

  • light_to_saturated_min (float, optional) – Dimensionless minimum value applied if lateral_gradient_type is ‘light_to_saturated’.

  • light_to_saturated_max (float, optional) – Dimensionless maximum value applied if lateral_gradient_type is ‘light_to_saturated’.

set_image_to_polar_color_bar(color_below_min: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>, color_bar=[(0.0, 0.0, 255.0), (0.0, 63.75, 255.0), (0.0, 127.5, 255.0), (0.0, 191.25, 255.0), (0.0, 255.0, 255.0), (0.0, 255.0, 191.25), (0.0, 255.0, 127.5), (0.0, 255.0, 63.75), (0.0, 255.0, 0.0), (63.75, 255.0, 0.0), (127.5, 255.0, 0.0), (191.25, 255.0, 0.0), (255.0, 255.0, 0.0), (255.0, 191.25, 0.0), (255.0, 127.5, 0.0), (255.0, 63.75, 0.0), (255.0, 0.0, 0.0), (255.0, 0.0, 63.75), (255.0, 0.0, 127.5), (255.0, 0.0, 191.25), (255.0, 0.0, 255.0), (191.25, 0.0, 255.0), (127.5, 0.0, 255.0), (63.75, 0.0, 255.0), (0.0, 0.0, 255.0)], color_above_max: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>, discrete_or_continuous: str = 'continuous', pattern_boundary: str = 'image_boundary', radial_gradient_type: str = 'saturated_center_to_white', saturated_center_to_white_exponent: float = 1.5, light_center_to_saturated_saturation_min: float = 0.2, light_center_to_saturated_saturation_max: float = 1.0, draw_center_fiducial=True, center_fiducial_width_pix=3, center_fiducial_color: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>, draw_edge_fiducials=True, n_ticks_x=7, n_ticks_y=7, tick_length=0.025, tick_width_pix=3, tick_color: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>) None

Sets the image to a polar color bar based on angular values.

This method generates a polar color bar where the color is controlled by the angle, and the saturation is modulated by the radius from the center of the image.

Parameters:
  • color_below_min (cl, optional) – The color to use for values below the minimum limit of the color bar. Default is black.

  • color_bar – The color bar for angular values in the range [0, 2π). Default is a predefined color bar.

  • color_above_max (cl, optional) – The color to use for values above the maximum limit of the color bar. Default is white.

  • discrete_or_continuous (str, optional) – Specifies whether the color interpolation is ‘discrete’ or ‘continuous’. Default is ‘continuous’.

  • pattern_boundary (str, optional) – Defines the range for saturation modulation as a function of radius. Values can be ‘circle’ or ‘image_boundary’. Default is ‘image_boundary’.

  • radial_gradient_type (str, optional) – Defines the scheme for modulating saturation as a function of radius. Values can be ‘saturated_center_to_white’ or ‘light_center_to_saturated’. Default is ‘saturated_center_to_white’.

  • saturated_center_to_white_exponent (float, optional) – Dimensionless exponent applied if radial_gradient_type is ‘saturated_center_to_white’. Default is 1.5.

  • light_center_to_saturated_saturation_min (float, optional) – Dimensionless minimum saturation value applied if radial_gradient_type is ‘light_center_to_saturated’. Default is 0.2.

  • light_center_to_saturated_saturation_max (float, optional) – Dimensionless maximum saturation value applied if radial_gradient_type is ‘light_center_to_saturated’. Default is 1.0.

  • draw_center_fiducial (bool, optional) – Whether to draw a mark at the target center. Default is True.

  • center_fiducial_width_pix (int, optional) – Width of the center fiducial in pixels; should be an odd number. Default is 3.

  • center_fiducial_color (cl, optional) – Color of the center fiducial. Default is black.

  • draw_edge_fiducials (bool, optional) – Whether to draw fiducial tick marks along the target edges. Default is True.

  • n_ticks_x (int, optional) – Number of tick marks to draw along the top and bottom horizontal target edges. Default is 7.

  • n_ticks_y (int, optional) – Number of tick marks to draw along the left and right vertical target edges. Default is 7.

  • tick_length (float, optional) – Length to draw edge tick marks in meters. Default is 0.025.

  • tick_width_pix (int, optional) – Width to draw edge tick marks in pixels; should be an odd number. Default is 3.

  • tick_color (cl, optional) – Color of edge tick marks. Default is black.

Raises:

AssertionError – If an unexpected value is encountered for pattern_boundary or radial_gradient_type.

set_image_to_rgb_cube_inscribed_square(project_to_cube)

Sets the image to a square inscribed in the RGB color cube.

Parameters:

project_to_cube (bool) – If True, the square will be projected onto the RGB cube; otherwise, it will be unprojected.

set_pattern_description(description: str) None

Sets the pattern description for the target color.

Parameters:

description (str) – The description of the color pattern.

set_ticks_along_left_and_right_edges(n_ticks_y, tick_length, tick_width_pix, tick_color)

Draws tick marks along the left and right edges of the image.

Parameters:
  • n_ticks_y (int) – Number of tick marks to draw along the left and right vertical target edges.

  • tick_length (float) – Length to draw edge tick marks in meters.

  • tick_width_pix (int) – Width to draw edge tick marks in pixels; should be an odd number.

  • tick_color (cl) – Color of edge tick marks.

set_ticks_along_top_and_bottom_edges(n_ticks_x, tick_length, tick_width_pix, tick_color)

Draws tick marks along the top and bottom edges of the image.

Parameters:
  • n_ticks_x (int) – Number of tick marks to draw along the top and bottom horizontal target edges.

  • tick_length (float) – Length to draw edge tick marks in meters.

  • tick_width_pix (int) – Width to draw edge tick marks in pixels; should be an odd number.

  • tick_color (cl) – Color of edge tick marks.

opencsp.common.lib.target.TargetColor.construct_linear_color_bar_cascade(color_bar_width, color_total_height, composite_dpm, color_below_min, color_bar, color_bar_name, color_above_max, ref_color_below_min, ref_color_bar, ref_color_bar_name, ref_color_above_max, x_or_y, stack_sequence, list_of_discrete_or_continuous_lists, list_of_saturation_spec_lists, include_grey_neighbors, grey_bar_width: float, gap_between_bars_pix: int = 10, ref_gap_pix: int = 10, gap_color=<opencsp.common.lib.render.Color.Color object>) TargetColor

Constructs a cascade of linear color bars, including reference and main color bars.

Parameters:
  • color_bar_width (float) – The width of each stacked color bar in meters.

  • color_total_height (float) – The total height of the stacked color bars in meters.

  • composite_dpm (float) – The dots per meter for the image resolution.

  • color_below_min (cl.Color) – The color to use below the minimum end of the color bar.

  • color_bar (list) – A list of colors representing the color sequence for the color bar.

  • color_bar_name (str) – A terse descriptive name of the color sequence for output purposes.

  • color_above_max (cl.Color) – The color to use above the maximum end of the color bar.

  • ref_color_below_min (cl.Color) – The color to use below the minimum end of the reference color bar.

  • ref_color_bar (list) – A list of colors representing the color sequence for the reference color bar.

  • ref_color_bar_name (str) – A terse descriptive name of the reference color sequence for output purposes.

  • ref_color_above_max (cl.Color) – The color to use above the maximum end of the reference color bar.

  • x_or_y (str) – The direction of the color bar stacking (‘x’ for horizontal, ‘y’ for vertical).

  • stack_sequence (list) – A list of stack heights desired for the main color bars.

  • list_of_discrete_or_continuous_lists (list) – A list of lists of strings indicating whether to interpolate colors for each stack entry (‘discrete’ or ‘continuous’).

  • list_of_saturation_spec_lists (list) – A list of specifications for saturation adjustments for each stack entry.

  • include_grey_neighbors (bool) – Whether to include a discrete grey scale for disambiguation on either side of each stack.

  • grey_bar_width (float) – The width of grey context bars in meters, if included.

  • gap_between_bars_pix (int, optional) – The number of pixels to leave as a gap between color bar stacks. Default is 10.

  • ref_gap_pix (int, optional) – The number of pixels to leave as a gap for the reference color bar. Default is 10.

  • gap_color (cl.Color, optional) – The color to fill the gaps between color bar stacks. Default is white.

Returns:

A new instance of TargetColor representing the cascade of linear color bars.

Return type:

tc.TargetColor

Raises:

AssertionError – If the stack sequence is empty or if the lengths of the lists do not match the number of stacks.

opencsp.common.lib.target.TargetColor.construct_stacked_linear_color_bar(n_stack: int, color_bar_width, color_total_height, composite_dpm, color_below_min, color_bar, color_bar_name, color_above_max, x_or_y, discrete_or_continuous_list, saturation_spec_list, gap_color) TargetColor

Constructs a stacked linear color bar composed of multiple stacked color bars.

Parameters:
  • n_stack (int) – The number of color bars to stack vertically or horizontally.

  • color_bar_width (float) – The width of each stacked color bar in meters.

  • color_total_height (float) – The total height of the stacked color bars in meters.

  • composite_dpm (float) – The dots per meter for the image resolution.

  • color_below_min (cl.Color) – The color to use below the minimum end of the color bar.

  • color_bar (list) – A list of colors representing the color sequence for the color bar.

  • color_bar_name (str) – A terse descriptive name of the color sequence for output purposes.

  • color_above_max (cl.Color) – The color to use above the maximum end of the color bar.

  • x_or_y (str) – The direction of the color bar stacking (‘x’ for horizontal, ‘y’ for vertical).

  • discrete_or_continuous_list (list) – A list of strings indicating whether to interpolate colors for each stack entry (‘discrete’ or ‘continuous’).

  • saturation_spec_list (list) – A list of specifications for saturation adjustments for each stack entry.

  • gap_color (cl.Color) – The color to fill the gaps between stacked color bars.

Returns:

A new instance of TargetColor representing the stacked linear color bar.

Return type:

tc.TargetColor

Raises:

AssertionError – If the number of stacks is less than 1 or if the lengths of the lists do not match the number of stacks.

opencsp.common.lib.target.TargetColor.construct_target_blue_under_red_cross_green(image_width: float, image_height: float, dpm: float) TargetColor

Constructs a target with a blue color under a red cross on a green background.

Parameters:
  • image_width (float) – The width of the image in meters.

  • image_height (float) – The height of the image in meters.

  • dpm (float) – Dots per meter for the image resolution.

Returns:

An instance of TargetColor configured with the specified blue under red cross green pattern.

Return type:

TargetColor

opencsp.common.lib.target.TargetColor.construct_target_linear_color_bar(image_width: float, image_height: float, dpm: float, color_below_min: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>, color_bar, color_bar_name: str, color_above_max: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'>, x_or_y: str, discrete_or_continuous: str, lateral_gradient_type: str | None = None, saturated_to_white_exponent: float = 1.5, light_to_saturated_min: float = 0.2, light_to_saturated_max: float = 1.0) TargetColor

Constructs a linear color bar target.

Parameters:
  • image_width (float) – The width of the image in meters.

  • image_height (float) – The height of the image in meters.

  • dpm (float) – Dots per meter for the image resolution.

  • color_below_min (cl) – The color to use for values below the minimum of the color bar.

  • color_bar – The color bar mapping values to colors.

  • color_bar_name (str) – The name of the color bar for output purposes.

  • color_above_max (cl) – The color to use for values above the maximum of the color bar.

  • x_or_y (str) – The direction of color variation (‘x’ or ‘y’).

  • discrete_or_continuous (str) – Specifies whether the color interpolation is ‘discrete’ or ‘continuous’.

  • lateral_gradient_type (str, optional) – Defines the scheme for modulating saturation from left to right. Values: None, ‘saturated_to_white’, or ‘light_to_saturated’.

  • saturated_to_white_exponent (float, optional) – Dimensionless exponent applied if lateral_gradient_type is ‘saturated_to_white’.

  • light_to_saturated_min (float, optional) – Dimensionless minimum saturation value applied if lateral_gradient_type is ‘light_to_saturated’.

  • light_to_saturated_max (float, optional) – Dimensionless maximum saturation value applied if lateral_gradient_type is ‘light_to_saturated’.

Returns:

An instance of TargetColor configured with the specified linear color bar.

Return type:

TargetColor

opencsp.common.lib.target.TargetColor.construct_target_polar_color_bar(image_width: float, image_height: float, dpm: float, color_below_min: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>, color_bar=[(0.0, 0.0, 255.0), (0.0, 63.75, 255.0), (0.0, 127.5, 255.0), (0.0, 191.25, 255.0), (0.0, 255.0, 255.0), (0.0, 255.0, 191.25), (0.0, 255.0, 127.5), (0.0, 255.0, 63.75), (0.0, 255.0, 0.0), (63.75, 255.0, 0.0), (127.5, 255.0, 0.0), (191.25, 255.0, 0.0), (255.0, 255.0, 0.0), (255.0, 191.25, 0.0), (255.0, 127.5, 0.0), (255.0, 63.75, 0.0), (255.0, 0.0, 0.0), (255.0, 0.0, 63.75), (255.0, 0.0, 127.5), (255.0, 0.0, 191.25), (255.0, 0.0, 255.0), (191.25, 0.0, 255.0), (127.5, 0.0, 255.0), (63.75, 0.0, 255.0), (0.0, 0.0, 255.0)], color_bar_name: str = 'O', color_above_max: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>, discrete_or_continuous: str = 'continuous', pattern_boundary: str = 'image_boundary', radial_gradient_type: str = 'saturated_center_to_white', radial_gradient_name: str = 's2w', saturated_center_to_white_exponent: float = 1.5, light_center_to_saturated_saturation_min: float = 0.2, light_center_to_saturated_saturation_max: float = 1.0, draw_center_fiducial=True, center_fiducial_width_pix=3, center_fiducial_color: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>, draw_edge_fiducials=True, n_ticks_x=7, n_ticks_y=7, tick_length=0.01, tick_width_pix=3, tick_color: <module 'opencsp.common.lib.render.Color' from '/home/docs/checkouts/readthedocs.org/user_builds/opencsp/checkouts/latest/doc/source/../../opencsp/common/lib/render/Color.py'> = <opencsp.common.lib.render.Color.Color object>) TargetColor

Constructs a polar color bar target.

Parameters:
  • image_width (float) – The width of the image in meters.

  • image_height (float) – The height of the image in meters.

  • dpm (float) – Dots per meter for the image resolution.

  • color_below_min (cl, optional) – The color to use for values below the minimum limit of the color bar. Default is black.

  • color_bar – The color bar for angular values in the range [0, 2π).

  • color_bar_name (str, optional) – A terse name of the color bar for output filename. Default is ‘O’.

  • color_above_max (cl, optional) – The color to use for values above the maximum limit of the color bar. Default is white.

  • discrete_or_continuous (str, optional) – Indicates whether to interpolate colors between segments. Values: ‘discrete’ or ‘continuous’. Default is ‘continuous’.

  • pattern_boundary (str, optional) – Defines the range for saturation modulation as a function of radius. Values: ‘circle’ or ‘image_boundary’. Default is ‘image_boundary’.

  • radial_gradient_type (str, optional) – Defines the scheme for modulating saturation as a function of radius. Values: ‘saturated_center_to_white’ or ‘light_center_to_saturated’. Default is ‘saturated_center_to_white’.

  • radial_gradient_name (str, optional) – A terse name of the radial intensity function for output filename. Default is ‘s2w’.

  • saturated_center_to_white_exponent (float, optional) – Dimensionless exponent applied if radial_gradient_type is ‘saturated_center_to_white’. Default is 1.5.

  • light_center_to_saturated_saturation_min (float, optional) – Dimensionless minimum saturation value applied if radial_gradient_type is ‘light_center_to_saturated’. Default is 0.2.

  • light_center_to_saturated_saturation_max (float, optional) – Dimensionless maximum saturation value applied if radial_gradient_type is ‘light_center_to_saturated’. Default is 1.0.

  • draw_center_fiducial (bool, optional) – Whether to draw a mark at the target center. Default is True.

  • center_fiducial_width_pix (int, optional) – Width of the center fiducial in pixels; should be an odd number. Default is 3.

  • center_fiducial_color (cl, optional) – Color of the center fiducial. Default is white.

  • draw_edge_fiducials (bool, optional) – Whether to draw fiducial tick marks along the target edges. Default is True.

  • n_ticks_x (int, optional) – Number of tick marks to draw along the top and bottom horizontal target edges. Default is 7.

  • n_ticks_y (int, optional) – Number of tick marks to draw along the left and right vertical target edges. Default is 7.

  • tick_length (float, optional) – Length to draw edge tick marks in meters. Default is 0.010.

  • tick_width_pix (int, optional) – Width to draw edge tick marks in pixels; should be an odd number. Default is 3.

  • tick_color (cl, optional) – Color of edge tick marks. Default is black.

Returns:

An instance of TargetColor configured with the specified polar color bar.

Return type:

TargetColor

opencsp.common.lib.target.TargetColor.construct_target_rgb_cube_inscribed_square(image_width: float, image_height: float, dpm: float, project_to_cube: bool) TargetColor

Constructs a target with a square inscribed in the RGB color cube.

Parameters:
  • image_width (float) – The width of the image in meters.

  • image_height (float) – The height of the image in meters.

  • dpm (float) – Dots per meter for the image resolution.

  • project_to_cube (bool) – If True, the square will be projected onto the RGB cube; otherwise, it will be unprojected.

Returns:

An instance of TargetColor configured with the specified RGB cube inscribed square pattern.

Return type:

TargetColor

opencsp.common.lib.target.TargetColor.extend_target_all(target: TargetColor, new_pixels: int, new_color: Color, new_target_name: str | None = None) TargetColor

Constructs a new target by extending the input target with additional pixels on all sides.

Parameters:
  • target (TargetColor) – The target to extend.

  • new_pixels (int) – The number of additional pixels to extend on all sides.

  • new_color (cl.Color) – The color to fill the new pixels.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input target.

Returns:

A new instance of TargetColor with the specified extension on all sides.

Return type:

TargetColor

opencsp.common.lib.target.TargetColor.extend_target_bottom(target: TargetColor, new_pixels: int, new_color: Color, new_target_name: str | None = None) TargetColor

Constructs a new target by extending the input target with additional pixels on the bottom side.

Parameters:
  • target (TargetColor) – The target to extend.

  • new_pixels (int) – The number of additional pixels to extend on the bottom side.

  • new_color (cl.Color) – The color to fill the new pixels.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input target.

Returns:

A new instance of TargetColor with the specified extension on the bottom side.

Return type:

TargetColor

Raises:

AssertionError – If the new target dimensions do not match the expected dimensions after extension.

opencsp.common.lib.target.TargetColor.extend_target_for_splice_left_right(target: TargetColor, n_extend: int, fill_color: Color, auto_expand: str) TargetColor

Extends the input target by adding pixels either above or below based on the specified auto-expand option.

Parameters:
  • target (TargetColor) – The target to extend.

  • n_extend (int) – The number of additional pixels to add.

  • fill_color (cl.Color) – The color to fill the new pixels.

  • auto_expand (str) – Specifies how to expand the target if the heights differ. Options are: - ‘fill_top’: Extend the top. - ‘fill_bottom’: Extend the bottom. - ‘fill_even’: Extend both top and bottom evenly.

Returns:

A new instance of TargetColor with the specified extension.

Return type:

TargetColor

Raises:

AssertionError – If the auto-expand option is invalid or if both n_extend_top and n_extend_bottom are zero.

opencsp.common.lib.target.TargetColor.extend_target_left(target: TargetColor, new_pixels: int, new_color: Color, new_target_name: str | None = None) TargetColor

Constructs a new target by extending the input target with additional pixels on the left side.

Parameters:
  • target (TargetColor) – The target to extend.

  • new_pixels (int) – The number of additional pixels to extend on the left side.

  • new_color (cl.Color) – The color to fill the new pixels.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input target.

Returns:

A new instance of TargetColor with the specified extension on the left side.

Return type:

TargetColor

Raises:

AssertionError – If the new target dimensions do not match the expected dimensions after extension.

opencsp.common.lib.target.TargetColor.extend_target_right(target: TargetColor, new_pixels: int, new_color: Color, new_target_name: str | None = None) TargetColor

Constructs a new target by extending the input target with additional pixels on the right side.

Parameters:
  • target (TargetColor) – The target to extend.

  • new_pixels (int) – The number of additional pixels to extend on the right side.

  • new_color (cl.Color) – The color to fill the new pixels.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input target.

Returns:

A new instance of TargetColor with the specified extension on the right side.

Return type:

TargetColor

Raises:

AssertionError – If the new target dimensions do not match the expected dimensions after extension.

opencsp.common.lib.target.TargetColor.extend_target_top(target: TargetColor, new_pixels: int, new_color: Color, new_target_name: str | None = None) TargetColor

Constructs a new target by extending the input target with additional pixels on the top side.

Parameters:
  • target (TargetColor) – The target to extend.

  • new_pixels (int) – The number of additional pixels to extend on the top side.

  • new_color (cl.Color) – The color to fill the new pixels.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input target.

Returns:

A new instance of TargetColor with the specified extension on the top side.

Return type:

TargetColor

Raises:

AssertionError – If the new target dimensions do not match the expected dimensions after extension.

opencsp.common.lib.target.TargetColor.splice_targets_above_below(above_target: TargetColor, below_target: TargetColor, gap: int, initial_color: Color, new_target_name: str | None = None) TargetColor

Constructs a new target by placing one target above another with a specified gap.

Parameters:
  • above_target (TargetColor) – The target to place on the top side of the new target.

  • below_target (TargetColor) – The target to place on the bottom side of the new target.

  • gap (int) – The number of pixels to leave as a gap between the two targets.

  • initial_color (cl.Color) – The color to fill the canvas before adding patterns.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input targets.

Returns:

A new instance of TargetColor with the above and below targets spliced together.

Return type:

TargetColor

Raises:

AssertionError – If the targets have different widths or bands.

opencsp.common.lib.target.TargetColor.splice_targets_left_right(left_target: TargetColor, right_target: TargetColor, gap: int, initial_color: Color, auto_expand: str = 'fill_even', new_target_name: str | None = None) TargetColor

Constructs a new target by placing one target to the left of another with a specified gap.

Parameters:
  • left_target (TargetColor) – The target to place on the left side of the new target.

  • right_target (TargetColor) – The target to place on the right side of the new target.

  • gap (int) – The number of pixels to leave as a gap between the two targets.

  • initial_color (cl.Color) – The color to fill the canvas before adding patterns.

  • auto_expand (str, optional) – Specifies how to expand the smaller target if sizes don’t match. Options are: - None: No expansion. - ‘fill_top’: Extend the top of the smaller target. - ‘fill_bottom’: Extend the bottom of the smaller target. - ‘fill_even’: Extend both top and bottom evenly. Default is ‘fill_even’.

  • new_target_name (str, optional) – If provided, this will be the name of the new target; otherwise, the name will be derived from the input targets.

Returns:

A new instance of TargetColor with the left and right targets spliced together.

Return type:

TargetColor

Raises:

AssertionError – If the targets have different heights or bands, or if the auto-expand option is invalid.

opencsp.common.lib.target.TargetColor.stacked_color_bar_name(n_stack: int, color_bar_name: str) str

Constructs a name for a stacked color bar based on the number of stacks and the base color bar name.

Parameters:
  • n_stack (int) – The number of stacked color bars.

  • color_bar_name (str) – The base name of the color bar.

Returns:

The constructed name for the stacked color bar.

Return type:

str

class opencsp.common.lib.target.TargetAbstract.TargetAbstract(image_width: float, image_height: float, dpm: float)

Bases: ABC

Abstract class inherited by all target classes

NOTE – for a mirror subclass to be defined as a mirror one must be able to get the z value at a point and the surface normal at a point.

__init__(image_width: float, image_height: float, dpm: float) None
description_inch() str

Returns a string describing the target in inches.

Returns:

description – A string in the format ‘{pattern_description}__w{width}in_h{height}in_{dpi}dpi’.

Return type:

str

description_meter() str

Returns a string describing the target in meters.

Returns:

description – A string in the format ‘{pattern_description}__w{width}m_h{height}m_{dpm}dpm’.

Return type:

str

image_size_str_inch() str

Returns a string describing the image size in inches.

Returns:

size_str – A string in the format ‘w{width:.3f}in_h{height:.3f}in_{dpi:d}dpi’.

Return type:

str

image_size_str_meter() str

Returns a string describing the image size in meters.

Returns:

size_str – A string in the format ‘w{width:.3f}m_h{height:.3f}m_{dpm:.1f}dpm’.

Return type:

str

rows_cols()

Returns the number of rows and columns in the image.

Returns:

  • n_rows (int) – The number of rows in the image.

  • n_cols (int) – The number of columns in the image.

rows_cols_bands()

Returns the number of rows, columns, and (color?) bands in the image.

Returns:

  • n_rows (int) – The number of rows in the image.

  • n_cols (int) – The number of columns in the image.

  • n_bands (int) – The number of (color?) bands in the image.

set_pattern_description(description: str) None

Sets the pattern description.

For the abstract class base implementation the value “blank” is always used.

Parameters:

description (str) – The new pattern description.

Target Color 1D Gradient

Demonstrate Solar Field Plotting Routines

Target Color 2D RGB

Creates a 2D color target

opencsp.common.lib.target.target_color_2d_rgb.construct_blue_under_red_cross_green(nx, ny)

# ?? SCAFFOLDING RCB – IMPROVE THIS COMMENT

Blue underlying red cross green.

opencsp.common.lib.target.target_color_2d_rgb.construct_rgb_cube_inscribed_square_image(nx, ny, project_to_cube)

# ?? SCAFFOLDING RCB – IMPROVE THIS COMMENT

Image defined by a square inscribed in the hexagon in [R,G,B] space formed by the Red, Green, and Blue basis vectors, and their pairwise combinations to form Cyan, Magenta, and Yellow secondary vectors.

Target Color Convert

opencsp.common.lib.target.target_color_convert.O_color_bar()

Generate a color bar that moves smoothly through a sequence of colors: Blue –> Cyan –> Green –> Yellow –> Red –> Magenta –> Blue.

Returns:

A list of RGB tuples representing the color bar, where each tuple contains three floats corresponding to the red, green, and blue color channels (0-255).

Return type:

list of tuple

opencsp.common.lib.target.target_color_convert.angle_between_color_vectors(rgb_1, rgb_2)

Calculate the angle between two RGB color vectors.

Parameters:
  • rgb_1 (tuple) – The first RGB color vector (RGB tuple).

  • rgb_2 (tuple) – The second RGB color vector (RGB tuple).

Returns:

The angle in radians between the two RGB color vectors.

Return type:

float

opencsp.common.lib.target.target_color_convert.color_bar_segment_spanned_angle(idx, color_bar)

Calculate the angle spanned by a segment of the color bar between two adjacent colors.

Parameters:
  • idx (int) – The index of the color segment in the color bar.

  • color_bar (list of tuple) – The color bar to use for calculating the angle (list of RGB tuples).

Returns:

The angle in radians spanned by the color segment.

Return type:

float

opencsp.common.lib.target.target_color_convert.color_given_value(val, val_min, val_max, color_below_min, color_bar, color_above_max, discrete_or_continuous)

Lookup the color corresponding to a given value based on a specified color bar.

Parameters:
  • val (float) – The value for which to find the corresponding color.

  • val_min (float) – The minimum value of the range.

  • val_max (float) – The maximum value of the range.

  • color_below_min (tuple) – The color to return if the value is below the minimum (RGB tuple).

  • color_bar (list of tuple) – The color bar to use for mapping values to colors (list of RGB tuples).

  • color_above_max (tuple) – The color to return if the value is above the maximum (RGB tuple).

  • discrete_or_continuous (str) – Specifies whether to return a ‘discrete’ or ‘continuous’ color.

Returns:

The RGB color corresponding to the input value.

Return type:

tuple

opencsp.common.lib.target.target_color_convert.construct_color_bar_spanned_angle_list(color_bar)

Construct a list of angles spanned by each segment of the color bar.

Parameters:

color_bar (list of tuple) – The color bar to use for calculating the angles (list of RGB tuples).

Returns:

A list of angles in radians spanned by each segment of the color bar.

Return type:

list of float

opencsp.common.lib.target.target_color_convert.construct_rgb_cumulative_angle_pair_list(color_bar, first_color_idx, last_color_idx)

Construct a list of RGB colors with their corresponding cumulative angles.

Parameters:
  • color_bar (list of tuple) – The color bar to use for constructing the list (list of RGB tuples).

  • first_color_idx (int) – The index of the first color to include in the list.

  • last_color_idx (int) – The index of the last color to include in the list.

Returns:

A list of tuples where each tuple contains an RGB color and its corresponding cumulative angle.

Return type:

list of tuple

opencsp.common.lib.target.target_color_convert.corner_tour_closed_color_bar()

Generate a color bar that traverses the corners of the RGB space, excluding black and white, and returns to the starting point.

Returns:

A list of RGB tuples representing the color bar, where each tuple contains three floats corresponding to the red, green, and blue color channels (0-255).

Return type:

list of tuple

opencsp.common.lib.target.target_color_convert.interpolate_color(desired_angle, rgb_before, angle_before, rgb_after, angle_after)

Interpolate the RGB color at a specified desired angle between two RGB colors.

Parameters:
  • desired_angle (float) – The angle at which to interpolate the color.

  • rgb_before (tuple) – The RGB color before the desired angle (RGB tuple).

  • angle_before (float) – The angle corresponding to the rgb_before color.

  • rgb_after (tuple) – The RGB color after the desired angle (RGB tuple).

  • angle_after (float) – The angle corresponding to the rgb_after color.

Returns:

The interpolated RGB color as a tuple of integers (rounded).

Return type:

tuple

opencsp.common.lib.target.target_color_convert.interpolate_color_given_angle(rgb_angle_list, desired_angle)

Interpolate the RGB color corresponding to a specified desired angle using a list of RGB colors and angles.

Parameters:
  • rgb_angle_list (list of tuple) – A list of tuples where each tuple contains an RGB color and its corresponding angle.

  • desired_angle (float) – The desired angle for which to interpolate the color.

Returns:

The interpolated RGB color as a tuple of integers.

Return type:

tuple

opencsp.common.lib.target.target_color_convert.lookup_color_and_angle_after(rgb_angle_list, desired_angle)

Lookup the RGB color and angle after a specified desired angle.

Parameters:
  • rgb_angle_list (list of tuple) – A list of tuples where each tuple contains an RGB color and its corresponding angle.

  • desired_angle (float) – The desired angle for which to find the following color and angle.

Returns:

A tuple containing the RGB color and the angle after the desired angle.

Return type:

tuple

opencsp.common.lib.target.target_color_convert.lookup_color_and_angle_before(rgb_angle_list, desired_angle)

Lookup the RGB color and angle before a specified desired angle.

Parameters:
  • rgb_angle_list (list of tuple) – A list of tuples where each tuple contains an RGB color and its corresponding angle.

  • desired_angle (float) – The desired angle for which to find the preceding color and angle.

Returns:

A tuple containing the RGB color and the angle before the desired angle.

Return type:

tuple

opencsp.common.lib.target.target_color_convert.matlab_color_bar()

Generate a color bar based on manually measured slope magnitude plots from the original MATLAB SOFAST version.

Returns:

A list of RGB tuples representing the color bar, where each tuple contains three integers corresponding to the red, green, and blue color channels (0-255).

Return type:

list of tuple

opencsp.common.lib.target.target_color_convert.nikon_D3300_monitor_equal_step_color_bar()

Generate a color bar measured using an LCD monitor as a color reference on August 24, 2023.

Returns:

A list of RGB tuples representing the color bar, where each tuple contains three floats corresponding to the red, green, and blue color channels (0-255).

Return type:

list of tuple

opencsp.common.lib.target.target_color_convert.normalize_color_bar_to_equal_angles(color_bar)

Normalize a color bar to have equal angles between colors.

Parameters:

color_bar (list of tuple) – The color bar to normalize, represented as a list of RGB tuples.

Returns:

A new color bar with equal angles between colors, represented as a list of RGB tuples.

Return type:

list of tuple

opencsp.common.lib.target.target_color_convert.survey_color_bar(color_bar)

Survey the color bar to calculate the total angle spanned and the indices of the first and last non-zero angles.

Parameters:

color_bar (list of tuple) – The color bar to survey (list of RGB tuples).

Returns:

A tuple containing the total angle sum (float), the index of the first non-zero angle (int), and the index of the last non-zero angle (int).

Return type:

tuple

Target Image

opencsp.common.lib.target.target_image.construct_target_image(image_width, image_height, dpm)

Construct a target image with specified dimensions and dots per meter.

Parameters:
  • image_width (float) – The width of the image in meters.

  • image_height (float) – The height of the image in meters.

  • dpm (float) – The number of dots per meter (resolution) for the image.

Returns:

A 3D numpy array representing the constructed image, initialized to zeros (black image), with shape (image_rows, image_cols, 3) where 3 corresponds to the RGB color channels.

Return type:

numpy.ndarray

opencsp.common.lib.target.target_image.rows_cols(img)

Get the number of rows and columns in an image.

Parameters:

img (numpy.ndarray) – A 3D numpy array representing the image, expected to have shape (n_rows, n_cols, n_bands).

Returns:

A tuple containing the number of rows (int) and the number of columns (int) in the image.

Return type:

tuple

Raises:

AssertionError – If the number of bands in the image is not equal to 3.

opencsp.common.lib.target.target_image.save_image(img, output_dpm, output_dir, output_file_body, output_ext)

Save an image to a specified directory with a given resolution.

Parameters:
  • img (numpy.ndarray) – A 3D numpy array representing the image to be saved, expected to have shape (n_rows, n_cols, 3).

  • output_dpm (float) – The desired output resolution in dots per meter.

  • output_dir (str) – The directory where the image will be saved.

  • output_file_body (str) – The base name for the output file (without extension).

  • output_ext (str) – The file extension for the output image (e.g., ‘.png’, ‘.jpg’).

Returns:

The full path to the saved image file.

Return type:

str

Notes

This function creates the necessary directories if they do not exist and saves the image using the specified resolution converted to dots per inch (DPI).