Skip to content

Commit

Permalink
Merge pull request #1309 from DanRyanIrish/goes_xraylum_mean_au
Browse files Browse the repository at this point in the history
Fix for Issue #1307
  • Loading branch information
Cadair committed Mar 8, 2015
2 parents 96390ce + cd241be commit 43f7a03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
14 changes: 8 additions & 6 deletions sunpy/instr/goes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from sunpy import config
from sunpy import lightcurve
from sunpy.util.net import check_download_file
from sunpy.sun import sun
from sunpy import sun

__all__ = ['get_goes_event_list', 'calculate_temperature_em',
'calculate_radiative_loss_rate', 'calculate_xray_luminosity']
Expand Down Expand Up @@ -1095,7 +1095,9 @@ def _goes_lx(longflux, shortflux, obstime=None, date=None):
were taken simultaneously.
date : (optional) datetime object or valid date string.
Date at which measurements were taken.
Date at which measurements were taken. This is used to
calculate the Sun-Earth distance.
Default=None implies Sun-Earth distance is set to 1AU.
Returns
-------
Expand Down Expand Up @@ -1211,8 +1213,8 @@ def _calc_xraylum(flux, date=None):
date : (optional) datetime object or valid date string
Used to calculate a more accurate Sun-Earth distance based on
Earth's orbit at that date. If date is not set, standard value
for 1AU used.
Earth's orbit at that date. If date is None, Sun-Earth
distance is set to 1AU.
Returns
-------
Expand All @@ -1231,7 +1233,7 @@ def _calc_xraylum(flux, date=None):
"""
if date is not None:
date = parse_time(date)
xraylum = 4 * np.pi * sun.sunearth_distance(t=date).to("m")**2 * flux
xraylum = 4 * np.pi * sun.sun.sunearth_distance(t=date).to("m")**2 * flux
else:
xraylum = 4 * np.pi * sun.sunearth_distance().to("m")**2 * flux
xraylum = 4 * np.pi * sun.constants.au.to("m")**2 * flux
return xraylum
26 changes: 13 additions & 13 deletions sunpy/instr/tests/test_goes.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ def test_goes_lx_nokwargs():
shortflux = Quantity([7e-7, 7e-7, 7e-7, 7e-7, 7e-7, 7e-7], unit="W/m**2")
# Test output when no kwargs are set.
lx_test = goes._goes_lx(longflux[:2], shortflux[:2])
lx_expected = {"longlum": Quantity([1.91013779e+18, 1.91013779e+18],
lx_expected = {"longlum": Quantity([1.98649103e+18, 1.98649103e+18],
unit="W"),
"shortlum": Quantity([1.91013779e+17, 1.91013779e+17],
unit="W")}
"shortlum": Quantity([1.98649103e+17, 1.98649103e+17],
unit="W")}
assert sorted(lx_test.keys()) == sorted(lx_expected.keys())
assert np.allclose(lx_test["longlum"], lx_expected["longlum"], rtol=0.01)
assert np.allclose(lx_test["shortlum"], lx_expected["shortlum"],
Expand Down Expand Up @@ -414,16 +414,16 @@ def test_goes_lx_obstime():
# Test output when obstime and cumulative kwargs are set.
lx_test = goes._goes_lx(longflux, shortflux, obstime)
lx_expected = {
"longlum": 1.91013779e+18 * Quantity(np.ones(6), unit='W'),
"shortlum": 1.91013779e+17 * Quantity(np.ones(6), unit='W'),
"longlum_int": Quantity([1.9101360630079373e+19], unit="J"),
"shortlum_int": Quantity([1.9101360630079373e+18], unit="J"),
"longlum_cumul": Quantity([3.82027213e+18, 7.64054425e+18,
1.14608164e+19, 1.52810885e+19,
1.91013606e+19], unit="J"),
"shortlum_cumul": Quantity([3.82027213e+17, 7.64054425e+17,
1.14608164e+18, 1.52810885e+18,
1.91013606e+18], unit="J")}
"longlum": 1.96860565e+18 * Quantity(np.ones(6), unit='W'),
"shortlum": 1.96860565e+17 * Quantity(np.ones(6), unit='W'),
"longlum_int": Quantity([1.96860565e+19], unit="J"),
"shortlum_int": Quantity([1.96860565e+18], unit="J"),
"longlum_cumul": Quantity([3.93721131e+18, 7.87442262e+18,
1.18116339e+19, 1.57488452e+19,
1.96860565e+19], unit="J"),
"shortlum_cumul": Quantity([3.93721131e+17, 7.87442262e+17,
1.18116339e+18, 1.57488452e+18,
1.96860565e+18], unit="J")}
assert sorted(lx_test.keys()) == sorted(lx_expected.keys())
assert np.allclose(lx_test["longlum"], lx_expected["longlum"], rtol=0.01)
assert np.allclose(lx_test["shortlum"], lx_expected["shortlum"],
Expand Down

0 comments on commit 43f7a03

Please sign in to comment.