Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #358 from STBadman/main
Browse files Browse the repository at this point in the history
Allow user to specify the center of map coordinates in `pfsspy.utils.carr_cea_wcs_header`
  • Loading branch information
dstansby committed Oct 25, 2022
2 parents 35a777e + dd049b1 commit 5946af1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
35 changes: 35 additions & 0 deletions pfsspy/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

import astropy.units as u
import numpy as np
import pytest
Expand Down Expand Up @@ -115,3 +117,36 @@ def test_roll_map(gong_map):
with pytest.raises(ValueError,
match='lh_edge_lon must be in'):
utils.roll_map(adapt_map, lh_edge_lon=361 * u.deg)


def test_cea_header():
# Assert default reference pixel is at 0 deg lon
cea_default = utils.carr_cea_wcs_header(
datetime.datetime(2020, 1, 1),
[360, 180]
)
assert cea_default['crval1'] == 0.0

# Assert custom reference pixel is expected lon
cea_shift = utils.carr_cea_wcs_header(
datetime.datetime(2020, 1, 1),
[360, 180],
map_center_longitude=10.0*u.deg
)
assert cea_shift['crval1'] == 10.0

# Test reference pixel shift error handling
# 1: No units
with pytest.raises(u.UnitTypeError):
cea_default = utils.carr_cea_wcs_header(
datetime.datetime(2020, 1, 1),
[360, 180],
map_center_longitude=0.0
)
# 2: Wrong Units
with pytest.raises(u.UnitTypeError):
cea_default = utils.carr_cea_wcs_header(
datetime.datetime(2020, 1, 1),
[360, 180],
map_center_longitude=0.0*u.m
)
9 changes: 7 additions & 2 deletions pfsspy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def load_adapt(adapt_path):
return adaptMapSequence


def carr_cea_wcs_header(dtime, shape):
@u.quantity_input
def carr_cea_wcs_header(dtime, shape, *, map_center_longitude=0*u.deg):
"""
Create a Carrington WCS header for a Cylindrical Equal Area (CEA)
projection. See [1]_ for information on how this is constructed.
Expand All @@ -100,6 +101,10 @@ def carr_cea_wcs_header(dtime, shape):
shape : tuple
Map shape. The first entry should be number of points in longitude, the
second in latitude.
map_center_longitude : astropy.units.Quantity
Change the world coordinate longitude of the central image pixel to allow
for different roll angles of the Carrington map. Default to 0 deg. Must
be supplied with units of `astropy.units.deg`
References
----------
Expand All @@ -111,7 +116,7 @@ def carr_cea_wcs_header(dtime, shape):
obstime = dtime or astropy.time.Time('2000-1-1')

frame_out = coord.SkyCoord(
0 * u.deg, 0 * u.deg, const.R_sun, obstime=obstime,
map_center_longitude, 0 * u.deg, const.R_sun, obstime=obstime,
frame="heliographic_carrington", observer='self')
# Construct header
header = sunpy.map.make_fitswcs_header(
Expand Down

0 comments on commit 5946af1

Please sign in to comment.