Attribute¶
This page contains the hakowan.grammar.scale.attribute module, including the
Attribute class and the norm() shorthand for vector-field magnitude.
AttributeLike = str | Attribute
module-attribute
¶
Type alias for a attribute-like objects.
- A string object will be converted to an attribute with the name set to the string.
- An attribute object will be unchanged.
Attribute
dataclass
¶
An attribute represents a scalar or vector field that is defined on the 3D geometry.
An attribute is the 3D equivalent of a column in a table. Each attribute is uniquely identified by the attribute name, which must exists in the data frame, and optionally associated with a scale.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the attribute as it is defined in the data frame. |
scale |
ScaleLike | None
|
The scale to be applied to the attribute. |
Note
The attribute object can be constructed with hakowan.attribute() function, which is an
alias of the constructor of this class.
Source code in hakowan/grammar/scale/attribute.py
norm(name, scale=None, order=2.0)
¶
Construct an attribute representing the per-element magnitude of a vector field.
This is a shorthand for Attribute(name, scale=Norm(order)) (optionally
chained with an extra scale). It turns a vector field (e.g. a velocity or
displacement field) into a derived scalar field, usable anywhere a scalar
attribute is expected, such as the size channel (arrow/tube width
proportional to magnitude) or a ScalarField texture (color by magnitude).
The two forms below are equivalent::
hkw.norm("velocity")
hkw.attribute("velocity", scale=hkw.scale.Norm())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the vector attribute in the data frame. |
required |
scale
|
ScaleLike | None
|
An optional scale applied after the norm is computed
(e.g. |
None
|
order
|
float
|
The order of the norm (e.g. |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
Attribute
|
class: |
Example
Color a vector field by its magnitude.¶
hkw.texture.ScalarField(data=hkw.norm("velocity"))
Make tube radius proportional to magnitude.¶
hkw.channel.Size(data=hkw.norm("velocity", ... scale=hkw.scale.Normalize( ... range_min=0.005, range_max=0.02)))
Source code in hakowan/grammar/scale/attribute.py
to_attribute(value)
¶
Coerce an attribute-like value into an Attribute.
This is the single coercion point for AttributeLike
values: a string is wrapped as Attribute(name=value), while an existing
Attribute is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
AttributeLike
|
A string (attribute name) or an |
required |
Returns:
| Type | Description |
|---|---|
Attribute
|
The corresponding |