question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

astropy units for blackbody_lambda does not do proper si conversion

See original GitHub issue

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…?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
pllimcommented, Feb 6, 2019

I don’t think this is a bug in blackbody per se. The SI conversion maps J / m3 to Pa (and bar is 1e5 * Pa). When we’re talking about flux, it makes more sense to have testB.si return something like J / (m3 rad2 s), no? For now, you can force this manually:

>>> testB.to(u.J / (u.m ** 3 * u.s * u.rad ** 2))
<Quantity 3.89601731e-49 J / (m3 rad2 s)>

p.s. Astronomer calculating flux in SI units? That’s crazy talk!

2reactions
mhvkcommented, Mar 11, 2019

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 in si.py and see if that helps…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found