Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapbase converts crln_obs to hgln_obs if it is found in the header #2946

Merged
merged 13 commits into from Mar 13, 2019
1 change: 1 addition & 0 deletions changelog/2946.bugfix.rst
@@ -0,0 +1 @@
Mapbase now converts Carrington longitude(crln_obs) to Stonyhurst longitude(hgln_obs), if Carrington longitude(crln_obs) is found in the header.
dodoextinct marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 10 additions & 8 deletions sunpy/map/mapbase.py
Expand Up @@ -611,14 +611,16 @@ def heliographic_longitude(self):
heliographic_longitude = self.meta.get('hgln_obs', None)

if heliographic_longitude is None:
if self._default_heliographic_longitude is None:
warnings.warn_explicit(
"Missing metadata for heliographic longitude: "
"assuming longitude of 0 degrees",
Warning, __file__,
inspect.currentframe().f_back.f_lineno)
self._default_heliographic_longitude = 0
heliographic_longitude = self._default_heliographic_longitude
if self.meta.get('crln_obs', None) is not None:
heliographic_longitude = self.meta['crln_obs'] * u.deg - get_sun_L0(self.date)
else:
if self._default_heliographic_longitude is None:
warnings.warn_explicit("Missing metadata for heliographic longitude: "
"assuming longitude of 0 degrees",
Warning, __file__,
inspect.currentframe().f_back.f_lineno)
self._default_heliographic_longitude = 0
heliographic_longitude = self._default_heliographic_longitude

if isinstance(heliographic_longitude, str):
heliographic_longitude = float(heliographic_longitude)
Expand Down
9 changes: 8 additions & 1 deletion sunpy/map/tests/test_mapbase.py
Expand Up @@ -3,6 +3,7 @@
Test Generic Map
"""
import os
import glob
dodoextinct marked this conversation as resolved.
Show resolved Hide resolved
import tempfile
import warnings

Expand All @@ -27,6 +28,9 @@

testpath = sunpy.data.test.rootdir

@pytest.fixture
def HMI_file():
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
return sunpy.map.Map(glob.glob(os.path.join(testpath, "resampled_hmi.fits")))
dodoextinct marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture
def aia171_test_map():
Expand Down Expand Up @@ -194,7 +198,10 @@ def test_coordinate_frame(aia171_test_map):
assert frame.observer.lon == aia171_test_map.observer_coordinate.frame.lon
assert frame.observer.radius == aia171_test_map.observer_coordinate.frame.radius
assert frame.obstime == aia171_test_map.date


def test_heliographic_longitude_crln(HMI_file):
if HMI_file.heliographic_longitude == 0:
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
assert HMI_file.heliographic_longitude == HMI_file.carrington_longitude - sunpy.coordinates.get_sun_L0(HMI_file.date)

# ==============================================================================
# Test Rotation WCS conversion
Expand Down