# CustomScaling

## class CustomScaling( to_physical_fn: Callable[[int], float], to_raw_fn: Callable[[float], int] | None = None, )[source]

Bases: [`ScalingFunction`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.types.ScalingFunction.md#instro.i2c.types.ScalingFunction "instro.i2c.types.ScalingFunction")

User-defined scaling. `to_raw_fn` is optional; `to_raw` raises `NotImplementedError` without it.

Example

```
>>> CustomScaling(
...     to_physical_fn=lambda x: x / 4095 * 5.0 * 7.2,
...     to_raw_fn=lambda v: int(v / 7.2 / 5.0 * 4095),
... )
```

Methods

| [`to_physical`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.types.CustomScaling.md#instro.i2c.types.CustomScaling.to_physical "instro.i2c.types.CustomScaling.to_physical") | Raw register value → physical units. |
| --- | --- |
| [`to_raw`](https://dev.nominal.io/instro/ref/instruments/instro.i2c.types.CustomScaling.md#instro.i2c.types.CustomScaling.to_raw "instro.i2c.types.CustomScaling.to_raw") | Physical value → raw integer. |

### to_physical(raw: int) → float[source]

Raw register value → physical units.

### to_raw(physical: float) → int[source]

Physical value → raw integer. May raise `NotImplementedError` if inverse is not supported.
