Unitful.jl
Unitful.jl copied to clipboard
dBW missing, attempts to define it fail.
In RF, we use dBW sometimes and not just dBm. Attempting to define it fails as follows:
julia> @logscale dBW "dBW" dBW 30u"dBm" 10 false ERROR: invalid redefinition of constant dBW
I also tried the following and got an even weirder message:
julia> @unit dBW "dBW" dBW 30u"dBm" false ERROR: DimensionError: mW² and 1000.0 mW are not dimensionally compatible.
The way to do this is with @logunit
, see src/pkgdefaults: https://github.com/PainterQubits/Unitful.jl/blob/ebad4497360693722c9dae0a6d6f28b5647ad4a6/src/pkgdefaults.jl#L673-L681
For dBW
, this would be
@logunit dBW "dBW" Unitful.Decibel 1u"W"
Maybe we should just add dBW
to Unitful?
Thanks. It would be great if dBW was added to the list.
Actually, that doesn't fully work. It lets me use the constant dBW, but not the text u"dBW", and that is necessary for the compound units like dBW/m^2/MHz.
julia> using Unitful julia> @logunit dBW "dBW" Unitful.Decibel 1u"W" julia> power = -100u"dBW" ERROR: LoadError: ArgumentError: Symbol dBW could not be found in unit modules Module[Unitful]
To use a unit with the u"…"
macro, you need to register the module that defines the unit:
Unitful.register(YourModule)
If you define the unit in the REPL, YourModule
would be Main
.
If you define the unit in a package, you should call Unitful.register
in the module’s __init__()
function:
function __init__()
Unitful.register(YourModule)
end