Skip to content

Add documentation for logunit #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cgarling
Copy link

logunit is exported but not documented. This function is useful and documenting it would be beneficial (it recently came up in #582). This PR adds a docstring to logunit and adds it to the API documentation in the logarithm.md file.

@icweaver
Copy link

icweaver commented Mar 7, 2025

Thanks for getting this going, Chris! To my surprise, it seems that logarithmic quantities are not actually subtypes of Quantity, but are their own thing it seems (Gain and Level), which are both subtypes of the unexported Unitful.LogScale

This bit me in MakieOrg/Makie.jl#4801, so just wanted to give a heads up in case things like

Returns the units associated with a logarithmic `Quantity`, a logarithmically-scaled
`Quantity` type, or a `Quantity` type with mixed logarithmic / linear scaling.

need to be clarified

Valid arguments to logunit are technically not `Quantity` so be more careful about wording
@cgarling
Copy link
Author

cgarling commented Mar 7, 2025

Good point -- I updated the docstring in the PR, let me know if it looks better

@icweaver
Copy link

icweaver commented Mar 7, 2025

ugh, I forgot about Unitful.MixedUnits. Thanks for including that too! I don't have a lot of experience with this type system stuff, so will defer to Sebastian 👍🏾

@cgarling
Copy link
Author

This is just an addition to the docs and should be ready to merge if someone can have a look.

dB

julia> logunit(u"dB")
dB
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an additional example for MixedUnits, since they are already mentioned in the docstring?

julia> logunit(u"dBm/s")
dBm

src/logarithm.jl Outdated
"""
logunit(x::LogScaled)
logunit(x::Union{Type{<:LogScaled}, MixedUnits})
Returns the units associated with a `LogScaled` instance, a `LogScaled` type,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns the units associated with a `LogScaled` instance, a `LogScaled` type,
Returns the logarithmic "units" associated with a `LogScaled` instance, a `LogScaled` type,

The manual refers to these as logarithmic "units". I think this might be less confusing, especially in the case of MixedUnits.

julia> logunit(u"dB")
dB
```
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reference to the unit docstring might be useful, e.g.

See also: [`unit`](@ref).

(A reference from unit to logunit could be added as well.)

@cgarling
Copy link
Author

Thanks @sostock, I have implemented your feedback in the above two commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants