Skip to content

Commit

Permalink
Merge pull request #62 from mkelley/afrho-from_fluxd-sun-units
Browse files Browse the repository at this point in the history
Fix Afrho initialization crash when solar flux density is not provided.
  • Loading branch information
mkelley committed Sep 13, 2018
2 parents 8d3efc1 + 97ecd16 commit ccb94d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 1 addition & 5 deletions sbpy/activity/dust.py
Expand Up @@ -249,10 +249,6 @@ def from_fluxd(cls, wave_or_freq, fluxd, aper, eph, phasecor=False,
default solar spectrum will be used via
`~sbpy.spectroscopy.sun.default_sun`.
unit : `~astropy.units.Unit`, optional
The spectral unit for the output, ignored if `S` is
provided.
Examples
--------
Expand All @@ -269,7 +265,7 @@ def from_fluxd(cls, wave_or_freq, fluxd, aper, eph, phasecor=False,
"""

fluxd1cm = Afrho(1 * u.cm).fluxd(wave_or_freq, aper, eph=eph, S=S,
unit=unit)
unit=fluxd.unit)

afrho = Afrho((fluxd / fluxd1cm).decompose() * u.cm)
if phasecor:
Expand Down
16 changes: 13 additions & 3 deletions sbpy/activity/tests/test_dust.py
Expand Up @@ -4,11 +4,13 @@
import astropy.units as u
from ..dust import *


def test_phase_HalleyMarcus():
assert np.isclose(phase_HalleyMarcus(0 * u.deg), 1.0)
assert np.isclose(phase_HalleyMarcus(15 * u.deg), 5.8720e-01)
assert np.isclose(phase_HalleyMarcus(14.5 * u.deg), 0.5959274462322928)


class TestAfrho:
def test_init(self):
afrho = Afrho(1000 * u.cm)
Expand All @@ -34,6 +36,14 @@ def test_from_flam(self):
afrho = Afrho.from_fluxd(None, fluxd, aper, eph, S=S)
assert np.isclose(afrho.cm, 1000)

def test_from_flam_with_synphot(self):
wave = 0.55 * u.um
fluxd = 6.764172537310662e-14 * u.W / u.m**2 / u.um
aper = 1 * u.arcsec
eph = dict(rh=1.5 * u.au, delta=1.0 * u.au)
afrho = Afrho.from_fluxd(wave, fluxd, aper, eph)
assert np.isclose(afrho.cm, 1000)

def test_from_fnu(self):
fluxd = 6.161081515869728 * u.mJy
nu = 2.998e14 / 11.7 * u.Hz
Expand Down Expand Up @@ -73,7 +83,8 @@ def test_fluxd_with_freq(self):
def test_to_phase(self):
afrho = Afrho(10 * u.cm).to_phase(15 * u.deg, 0 * u.deg)
assert np.isclose(afrho.cm, 5.8720)



class TestEfrho:
def test_init(self):
efrho = Efrho(1000 * u.cm)
Expand Down Expand Up @@ -115,7 +126,7 @@ def test_fluxd(self):
eph = dict(rh=1.5 * u.au, delta=1.0 * u.au)
fluxd = efrho.fluxd(wave, aper, eph)
assert np.isclose(fluxd.value, 1e-16)

def test_fluxd_unit(self):
efrho = Efrho(100, 'cm')
wave = 5 * u.um
Expand All @@ -124,4 +135,3 @@ def test_fluxd_unit(self):
Tscale = 1.1
fluxd = efrho.fluxd(wave, aper, eph, Tscale=Tscale, unit='mJy')
assert np.isclose(fluxd.value, 0.3197891693353106)

0 comments on commit ccb94d0

Please sign in to comment.