Skip to content

Products of scales (experimental)

Several scales as one multi-index.

scale_product

scale_product(
    *args: Any,
    name: str = "",
    desc: str = "",
    keys: Mapping[str, str] | None = None,
    joint_weights: Any = None,
    **axes: NestedScale,
) -> ScaleProduct

Combine named scales into a product: scale_product(time=cal, space=gs).

Experimental: this feature may change or be removed in a later version.

The axes are keyword arguments and their names become the axis names; name, desc, keys and joint_weights are arguments of this function, so an axis cannot have one of those names (RESERVED_AXES). Keys default to each axis's own leaf column; when two collide, the axis names.

Examples

import nestedscales as ns p = ns.scale_product(a=ns.scale_example(), b=ns.scale_example2()) p ns.product_size(p) {'axes': {'a': 7, 'b': 4}, 'total': 28}

ScaleProduct dataclass

Named axes (each a named NestedScale) and one data key column per axis.

Experimental: this feature may change or be removed in a later version.

Built with scale_product(). repr() is R's one-line format(), str() what R's print() shows, and scale_summary() R's summary(). Two products are equal when their axes, keys, joint weights and meta are.

scale_axes

scale_axes(x: ScaleProduct, axis: str | None = None)

All axes (name -> scale), or one axis.

Experimental: this feature may change or be removed in a later version.

product_size

product_size(x: ScaleProduct) -> dict[str, Any]

Leaves per axis (axes) and the size of the never materialised product (total), both whole numbers.

Experimental: this feature may change or be removed in a later version.

product_keys

product_keys(x: ScaleProduct) -> dict[str, str]

Axis -> data key column.

Experimental: this feature may change or be removed in a later version.

product_frames

product_frames(x: ScaleProduct) -> dict[str, list[str]]

Axis -> the frame names of its scale, coarsest first.

Experimental: this feature may change or be removed in a later version.

product_weights

product_weights(x: ScaleProduct) -> dict[str, list[str]]

Axis -> the weight column names of its scale (possibly none).

Experimental: this feature may change or be removed in a later version.

product_coverage

product_coverage(
    x: ScaleProduct, weight: str | None = None
) -> dict[str, float]

Axis -> the fraction of its root parent's weight that the axis still carries (scale_coverage()), 1 for an axis that was never subset.

weight names the weight column to read on every axis; None takes each axis's default weight, and an axis without weights covers 1. The joint coverage of the product is the product of the entries.

Experimental: this feature may change or be removed in a later version.