wm_utils

Holds various utilities used by wafer_map.

class wafer_map.wm_utils.BeizerGradient(initial_color, arc_color, dest_color)[source]

Beizer curve gradient between 3 colors.

Not implemented.

get_color(value)[source]

Get a color.

class wafer_map.wm_utils.Gradient[source]

Base class for all gradients.

Currently does nothing.

class wafer_map.wm_utils.LinearGradient(initial_color, dest_color)[source]

Linear gradient between two colors.

Parameters:
  • initial_color – The starting color for the linear gradient.
  • dest_color – sdfsd
self.initial_color

asad

self.dest_color

asdads

get_color(self, value) :

Returns a color that is value between self.initial_color and self.final_color

get_color(value)[source]

Get a color along the gradient. Value = 0 to 1 inclusive.

class wafer_map.wm_utils.PolylinearGradient(*colors)[source]

Polylinear Gradient between n colors.

Acts as a LinearGradient if n == 2.

Parameters:colors (iterable) – A list or tuple of RGB or RGBa tuples (or wx.Colour objects). Each color in this list is a vertex of the polylinear gradient.
self.colors

iterable – The list of colors (or wx.Colour objects) which are the verticies of the poly gradient.

self.initial_color

tuple or wx.Colour object – The starting color of the gradient.

self.dest_color

tuple or wx.Colour object – The final color of the gradient.

get_color(self, value):

Returns a color that is value along the gradient.

get_color(value)[source]

Get a color value.

wafer_map.wm_utils._GradientFillLinear(rect, intial_color, dest_color, direction)[source]

Reimplement the wxDCImpl::DoGradientFillLinear algorithm.

This algorithm can be found in wxWidgets-3.0.2/src/common/dcbase.cpp, line 862.

wxWidgets uses the native MS Windows (msw) function if it can:
wxMSIMG32DLL.GetSymbol(wxT(“GradientFill”)

See function wxMSWDCImpl::DoGradientFillLinear in wxWidgets-3.0.2/src/msw/dc.cpp, line 2870

Allows user to put in a value from 0 (intial_color) to 1 (dest_color).

What will this function return? I do not know yet.

There’s not really a struct for a “continuous gradient”…

I think that perhaps this function will just calculate the color for a given 0-1 value between initial_color and dest_color on the fly.

I’m an idiot! This is just linear algebra, I can solve this!

wafer_map.wm_utils.beizer_gradient(initial_color, arc_color, dest_color, value)[source]

Calculate the color value along a Beizer Curve.

The Beizer Curve’s control colors are defined by initial_color, arc_color, and final_color.

wafer_map.wm_utils.coord_to_grid(coord, die_size, grid_center)[source]

Convert a panel coordinate to a grid value.

Parameters:
  • coord (tuple) – A 2-tuple of (x, y) floating point values for the panel coordinate
  • die_size (tuple) – A 2-tuple of (x, y) floating point values for the die size
  • grid_center (tuple) – A 2-tuple of (grid_x, grid_y) values that represents the origin of the wafer in grid coordinates.
Returns:

(grid_x, grid_y) – The grid coordinates. Also known as (column, row).

Return type:

tuple

wafer_map.wm_utils.frange(start, stop, step)[source]

Generator that creates an arbitrary-stepsize range.

wafer_map.wm_utils.grid_to_rect_coord(grid, die_size, grid_center)[source]

Convert a die’s grid value to the origin point of the rectangle to draw.

Adjusts for the fact that the grid falls on the center of a die by subtracting die_size/2 from the coordinate.

Adjusts for the fact that Grid +y is down while panel +y is up by taking grid_center - grid rather than grid - grid_center as is done in the X case.

wafer_map.wm_utils.linear_gradient(initial_color, dest_color, value)[source]

Find the color that is value between initial_color and dest_color.

Parameters:
  • initial_color (tuple) – A 3- or 4-tuple of RGB or RGBa values representing the starting color for the gradient. Each color channel should be in the range 0-255 inclusive.
  • dest_color (tuple) – A 3- or 4-tuple of RGB or RGBa values representing the ending color for the gradient. Each color channel should be in the range 0-255.
  • value (float) – A floating point number from 0 to 1 inclusive that determines how far along the color gradient the returned color should be. A value of 0 returns initial_color while a value of 1 returns dest_color.
Returns:

  • (r, g, b) (tuple) – A 3-tuple representing the color that is value * 100 percent along the gradient. Each color channel is 0-255 inclusive.
  • Implementation Details
  • ———————-
  • All of this package works in the RGB colorspace. However, as is seen in
  • https (//www.youtube.com/watch?v=LKnqECcg6Gw and)
  • https (//www.youtube.com/watch?v=sPiWg5jSoZI, the RGB color space does)
  • not blend correctly with standard averaging, which is what I do here.
  • I haven’t found any source for this, but experimentation has shown that
  • the HSL colorspace *does blend correctly with linear averaging. So*
  • I use the colour module to convert RGB to HSL. After converting, I
  • take the linear average of my two colors (via rescale) and then
  • convert back to RGB.

Examples

Halfway between Red and Green is Yellow. This really should return (255, 255, 0), but it’s close enough for now.

>>> linear_gradient((255, 0, 0), (0, 255, 0), 0.5)
(254, 255, 0)

Red and Blue mix to make green. Standard Rainbow

>>> linear_gradient((255, 0, 0), (0, 0, 255), 0.5)
(0, 255, 0)

75% of the from Red to Green is Orange.

>>> linear_gradient((255, 0, 0), (0, 255, 0), 0.75)
(127, 255, 0)
wafer_map.wm_utils.max_dist_sqrd(center, size)[source]

Calculate the squared distnace to the furthest corner of a rectangle.

Assumes that the origin is (0, 0).

Does not take the square of the distance for the sake of speed.

If the rectangle’s center is in the Q1, then the upper-right corner is the farthest away from the origin. If in Q2, then the upper-left corner is farthest away. Etc.

Returns the magnitude of the largest distance.

Used primarily for calculating if a die has any part outside of wafer’s edge exclusion.

Parameters:
  • center (tuple of length 2, numerics) – (x, y) tuple defining the rectangle’s center coordinates
  • size (tuple of length 2) – (x, y) tuple that defines the size of the rectangle.
Returns:

dist – The distance from the origin (0, 0) to the farthest corner of the rectangle.

Return type:

numeric

See also

max_dist()
Calculates the distance from the orgin (0, 0) to the farthest corner of a rectangle.
wafer_map.wm_utils.nanpercentile(a, percentile)[source]

Perform numpy.percentile(a, percentile) while ignoring NaN values.

Only works on a 1D array.

wafer_map.wm_utils.polylinear_gradient(colors, value)[source]

Create a gradient.

colors is a list or tuple of length 2 or more. If length 2, then it’s the same as LinearGradient Value is the 0-1 value between colors[0] and colors[-1]. Assumes uniform spacing between all colors.

wafer_map.wm_utils.rescale(x, orig_scale, new_scale=(0, 1))[source]

Rescale x to run over a new range.

Rescales x (which was part of scale original_min to original_max) to run over a range new_min to new_max such that the value x maintains position on the new scale new_min to new_max. If x is outside of xRange, then y will be outside of yRange.

Default new scale range is 0 to 1 inclusive.

Parameters:
  • x (numeric) – The value to rescale.
  • orig_scale (sequence of numerics, length 2) – The (min, max) value that x typically ranges over.
  • new_scale (sequence of numerics, length 2, optional) – The new (min, max) value that the rescaled x should reference
Returns:

result – The rescaled x value

Return type:

float

Examples

>>> rescale(5, (10, 20), (0, 1))
-0.5
>>> rescale(27, (0, 200), (0, 5))
0.675
>>> rescale(1.5, (0, 1), (0, 10))
15.0
wafer_map.wm_utils.rescale_clip(x, orig_scale, new_scale=(0, 1))[source]

Rescale and clip x to run over a new range.

Same as rescale, but also clips the new data. Any result that is below new_min or above new_max is listed as new_min or new_max, respectively

Examples

>>> rescale_clip(5, (10, 20), (0, 1))
0
>>> rescale_clip(15, (10, 20), (0, 1))
0.5
>>> rescale_clip(25, (10, 20), (0, 1))
1