Skip to content
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

unit and dimension are inconsistent for Levels #582

Open
sostock opened this issue Nov 10, 2022 · 3 comments
Open

unit and dimension are inconsistent for Levels #582

sostock opened this issue Nov 10, 2022 · 3 comments
Labels
logarithmic logarithmic scales (decibels, nepers, …)

Comments

@sostock
Copy link
Collaborator

sostock commented Nov 10, 2022

For Levels (and mixed quantities based on Levels), unit discards the logarithmic part, dimension does not:

julia> unit(5u"dBV")      # NoUnits

julia> dimension(5u"dBV") # voltage
𝐋^2 𝐌 𝐈^-1 𝐓^-3

julia> unit(5u"dBV*m")      # meters (a length)
m

julia> dimension(5u"dBV*m") # voltage * length
𝐋^3 𝐌 𝐈^-1 𝐓^-3

I think the behavior of dimension makes sense. To fix unit, there are two possibilities:

  1. Use the unit of the reflevel, i.e., unit(5u"dBV") == V
  2. Make unit(::Level) throw an error

Edit: Related: #528.

@sostock sostock added the logarithmic logarithmic scales (decibels, nepers, …) label Dec 6, 2022
@icweaver
Copy link

Sorry if this would be better as a new issue. I think I'm hitting this too over in JuliaAstro/DustExtinction.jl#58, specifically for mag support:

julia> using Unitful, UnitfulAstro

julia> x = 2u"mag"
2 mag

julia> unit(x)

Is there anything that can be done on our end?

Potentially related: #267, #265

@icweaver
Copy link

ahhh, TIL about logunit. I see this is what Plots.jl uses for their recipes, so nvm. Sorry for the noise!

@cgarling
Copy link

I would argue logunit should be documented if it's the main way to get the unit out of a logarithmic quantity. I opened #769 to add this documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logarithmic logarithmic scales (decibels, nepers, …)
Projects
None yet
Development

No branches or pull requests

3 participants