Attribute¶
In Hakowan, an attribute specifies a specific "column" of the data (i.e. mesh attribute) that will be used to encode various visual channels and textures. Each attribute consists of a name, optional physical unit, and scale. The name identifies the mesh attribute; the scale defines a column-specific transformation before visual encoding. Units are semantic metadata used by automatic legends and observation manifests.
Creating Attributes¶
The hkw.attribute() function is a convenient alias for creating Attribute objects:
# To specify an attribute from name alone.
# By default, scale is identity.
attr = hkw.attribute(name="normal")
# To specify an attribute from both name and scale.
attr = hkw.attribute(name="normal", scale=hkw.scale.Uniform(factor=2))
# hkw.attribute() is equivalent to hkw.scale.Attribute()
attr = hkw.scale.Attribute(name="normal", scale=hkw.scale.Uniform(factor=2))
temperature = hkw.attribute("temperature", unit="°C")
pressure = hkw.attribute("pressure", unit="Pa", scale=hkw.scale.Log())
The norm() shorthand¶
hkw.norm() creates an Attribute with a leading Norm
scale, converting a vector field into a scalar magnitude. Its unit metadata
is preserved for legends and observation manifests. Use the result wherever
scalar attributes are accepted, such as the size channel
or a ScalarField texture.
# Equivalent forms:
attr = hkw.norm("velocity")
attr = hkw.attribute("velocity", scale=hkw.scale.Norm())
# Color a surface by vector magnitude.
mat = hkw.material.Diffuse(
reflectance=hkw.texture.ScalarField(data=hkw.norm("velocity"))
)
Attribute-Like Objects¶
Many Hakowan functions accept "attribute-like" objects, which can be either:
- A string: Automatically converted to an
Attributewith the given name - An
Attributeobject: Used directly
This allows for convenient shorthand notation: