Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

attribute.normalize

Normalize a numeric attribute column to 0..1 by its own min and max or by rank, into a new column. "minmax" scales the range linearly; "rank" and "percentile" place a value at its position in the sorted order, tied runs sharing the average of the positions they span, so a threshold of 0.8 selects the top fifth by count. A column whose values are all the same normalizes to 0.

Inputs

  • geometry (Geometry). Whose column is normalized, and the population the range is taken over. A copy carrying both the source column and the new one comes out.
  • class (one of detail, edge, point, primitive, vertex). Default "point". Which rows are normalized: the class the column lives on, and where the new column is written.
  • name (String). Default "". Which column to normalize. It has to be a one-number-per-element column; a name the class does not carry is refused.
  • as (String). Default "". What the normalized column is called. Left empty, it is the source name with _norm after it.
  • mode (one of minmax, percentile, rank). Default "minmax". How the values are spread over 0 to 1: "minmax" keeps the shape of the distribution, "rank" and "percentile" spread it evenly. "rank" and "percentile" give the same values.

Outputs

  • geometry: the geometry with the Float column of normalized values under as (or <name>_norm) on class.

Example

local points = g.points.grid({ countX = 4, countZ = 1, spacing = 1 })
local numbered = g.attribute.number({ geometry = points, class = "point", name = "n" })
local spread = g.attribute.normalize({ geometry = numbered, name = "n" })

n_norm holds 0, 1/3, 2/3, 1. With mode = "rank", values 0, 0, 1, 1 normalize to 1/6, 1/6, 5/6, 5/6.