astropy: astropy units for blackbody_lambda does not do proper si conversion
If I run the following code, it correctly converts the unit “bar” to SI:
from astropy import units as u
test = 1 * u.bar
print(test)
print(test.si)
# 1.0 bar
# 100000.0 N / m2
But for blackbody_lambda
, it fails to convert the result to correct si unit:
from astropy import units as u
from astropy.modeling.blackbody import blackbody_lambda
testB = blackbody_lambda(1 * u.um, 100 * u.K)
print(testB)
print(testB.si)
print(testB.to('N/s/m^2/sr'))
# 3.8960173143757327e-56 erg / (Angstrom cm2 s sr)
# 3.896017314375732e-54 bar / (rad2 s)
# 3.896017314375732e-49 N / (m2 s sr)
That is, astropy does not convert bar
to N/m^2
(which gives factor of 10^5 difference).
I tested with some other complicated combinations, e.g., test = 1 * u.cm * u.bar / u.sr * u.erg
, but the SI conversion worked just fine.
Maybe the failure is only for blackbody_lambda
…?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (14 by maintainers)
I don’t think this is a bug in blackbody per se. The SI conversion maps
J / m3
toPa
(andbar
is1e5 * Pa
). When we’re talking about flux, it makes more sense to havetestB.si
return something likeJ / (m3 rad2 s)
, no? For now, you can force this manually:p.s. Astronomer calculating flux in SI units? That’s crazy talk!
Very much so. Though
bar/rad2
just doesn’t make sense! If someone has the time, I’d do the swap of power and pressure insi.py
and see if that helps…Hi, I am triaging and noticed that some level of closure might have been reached… Should this issue be closed for now and a new issue be opened should a similar problem arise?
I second @pllim’s observation: This does not look like a bug to me, but rather some kind of rigidity in the default units adopted in the
.si
units conversion mechanism. Maybe in the future some sort of flexibility could be introduced to the overarching scheme of unit conversion to suit the user’s needs better? But that would be a separate issue.@MSeifert04 Oh, sorry. I am using version 3.1.1: