astropy units for blackbody_lambda does not do proper si conversion
See original GitHub issueIf 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
…?
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (14 by maintainers)
Top Results From Across the Web
Units and Quantities (astropy.units) — Astropy v5.2
The most convenient way to create a Quantity is to multiply or divide a value by one of the built-in units. It works...
Read more >Equivalencies — Astropy v5.2
The parallax() function handles conversions between parallax angles and length. In general, you should not be able to change units of length into...
Read more >Low-Level Unit Conversion — Astropy v5.2
Conversion of quantities from one unit to another is handled using the Quantity.to() method. This page describes some low-level features for handling unit...
Read more >Decomposing and Composing Units — Astropy v5.2
A unit or quantity can be decomposed into its irreducible parts using the Unit.decompose() or Quantity.decompose() methods.
Read more >Quantity — Astropy v5.2
Quantity objects are converted to float by default. Furthermore, any data passed in are copied, which for large arrays may not be optimal....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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…