yunruse / Noether

Just another units package
MIT License
9 stars 0 forks source link

Decibels - logarithmic units #51

Closed yunruse closed 1 year ago

yunruse commented 1 year ago

c.f. https://en.wikipedia.org/wiki/Decibel

Support for e.g. dBf, dBZ units, where instead of being relative to 1, it is relative to a specific unit.

Implementation detail

A LogarithmicScale for dB which functions as a unit, holding how it scales.

Meanwhile, a dimensionless LogarithmicMeasure(log_value, scale, relative_to=1) can handle e.g. dB(Z). Perhaps internally the should store the actual value, and take as input (and give as display) the "decibel" value.

yunruse commented 1 year ago

LogarithmicScale should have a .from_ratio, too.

Other logarithmic units: A lovely amount, actually!

In the SI system the non SI modifier decibel (dB) is not permitted for use directly alongside SI units so the dBW is not directly permitted but 10 dBW may be written 10 dB (1 watt).

Some optional info_log_scales could e.g. give info on pH, Richter scales.

yunruse commented 1 year ago

To make a point about the interfacing – and this needs noting down properly in documentation - that * is always multiplication, and unit(value) may be within-scale, just like with AffineUnit. (Recall that in the CLI e.g. 3dB -> dB(3))

Therefore we should see

>>> dB(3)  # 10^0.3
1.99526231
>>> dB * 3  # 3 * 10^0.1
3.77677624

To clarify, dB(10) == 10; we will use power scale throughout.

yunruse commented 1 year ago

Oh, and also: