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

Astronomical Magnitudes #265

Closed
mileslucas opened this issue Sep 1, 2019 · 1 comment · Fixed by #267
Closed

Astronomical Magnitudes #265

mileslucas opened this issue Sep 1, 2019 · 1 comment · Fixed by #267

Comments

@mileslucas
Copy link
Contributor

mileslucas commented Sep 1, 2019

Hello, I have a somewhat niche unit problem.

Over at UnitfulAstro there's been an implementation of astronomical magnitudes (Lines 89-149). There's a few flavors, but the basic interaction is that it is a logarithmic scale with a conversion like

f * 10 ^ (-0.4 * lambda_m)

where f is a flux value and lambda_m is the magnitude.

What I've noticed is an issue of undefined behavior when using some of the densities of fluxes. For instance, when looking at the brightness of stars, we can measure them and get a power value, or energy per second (energy for us is flux) eg erg/s. Furthermore, we might have a flux density, or a solid angle in which the energy is absorbed (like the aperture of a telescope) eg erg/s/cm^2. Even further, we could disperse the light and obtain a spectrum that is dependent on wavelength eg erg/s/cm^2/cm.

Any one of these values ought to be able to be affected by this magnitude, but only the following cases work:

julia> using Unitful, UnitfulAstro

julia> flux = 10u"erg"
10 erg

julia> λ_m = 1u"mag"
1 mag

julia> flux * λ_m
ERROR: undefined behavior. Please file an issue with the code needed to reproduce.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] isrootpower_dim(::Unitful.Dimensions{(Unitful.Dimension{:Length}(2//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-2//1))}) at /Users/miles/.julia/packages/Unitful/dPidf/src/logarithm.jl:167
 [3] isrootpower(::Quantity{Int64,𝐋^2*𝐌*𝐓^-2,Unitful.FreeUnits{(erg,),𝐋^2*𝐌*𝐓^-2,nothing}}) at /Users/miles/.julia/packages/Unitful/dPidf/src/logarithm.jl:166
 [4] *(::Quantity{Int64,𝐋^2*𝐌*𝐓^-2,Unitful.FreeUnits{(erg,),𝐋^2*𝐌*𝐓^-2,nothing}}, ::Gain{Unitful.LogInfo{:Magnitude,10,-2.5},:?,Int64}) at /Users/miles/.julia/packages/Unitful/dPidf/src/logarithm.jl:213
 [5] top-level scope at none:0

jjulia> flux = 10u"erg/s"
10 erg s^-1

julia> flux * λ_m
3.981071705534972 erg s^-1

julia> flux = 10u"erg/s/cm^2"
10 erg cm^-2 s^-1

julia> flux * λ_m
3.981071705534972 erg cm^-2 s^-1

julia> flux = 10u"erg/s/cm^2/cm"
10 erg cm^-3 s^-1

julia> flux * λ_m
ERROR: undefined behavior. Please file an issue with the code needed to reproduce.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] isrootpower_dim(::Unitful.Dimensions{(Unitful.Dimension{:Length}(-1//1), Unitful.Dimension{:Mass}(1//1), Unitful.Dimension{:Time}(-3//1))}) at /Users/miles/.julia/packages/Unitful/dPidf/src/logarithm.jl:167
 [3] isrootpower(::Quantity{Int64,𝐌*𝐋^-1*𝐓^-3,Unitful.FreeUnits{(erg, cm^-3, s^-1),𝐌*𝐋^-1*𝐓^-3,nothing}}) at /Users/miles/.julia/packages/Unitful/dPidf/src/logarithm.jl:166
 [4] *(::Quantity{Int64,𝐌*𝐋^-1*𝐓^-3,Unitful.FreeUnits{(erg, cm^-3, s^-1),𝐌*𝐋^-1*𝐓^-3,nothing}}, ::Gain{Unitful.LogInfo{:Magnitude,10,-2.5},:?,Int64}) at /Users/miles/.julia/packages/Unitful/dPidf/src/logarithm.jl:213
 [5] top-level scope at none:0

Any tips?

@ajkeller34
Copy link
Collaborator

Thanks for the report and your interest in the package. I'm pretty sure #267 should resolve your issues. This sort of error happens whenever someone tries to multiply a quantity of some dimension by a gain for the first time; you need to decide if the behavior should be more like watts (10dB = 10x) or volts (20dB = 10x).

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 a pull request may close this issue.

2 participants