Skip to content

Commit 7f57d78

Browse files
committed
Add method to STIXMap to convert to HPC.
1 parent 8c6ec0e commit 7f57d78

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

stixpy/imaging/tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def estimate_stix_flare_location(cpd_sci, time_range=None, energy_range=None, su
7777
coord = STIXImaging(0 * u.arcsec, 0 * u.arcsec, obstime=vis_tr.start, obstime_end=vis_tr.end, observer=solo)
7878
header_bp = sunpy.map.make_fitswcs_header(bp_image, coord, telescope="STIX",
7979
observatory="Solar Orbiter", scale=plate_scale)
80-
map_bp = sunpy.map.Map(bp_image, header_bp).wcs
80+
map_bp = sunpy.map.Map(bp_image, header_bp)
8181
wcs_bp = map_bp.wcs
8282
# Estimate flare location from brightest pixel in backprojection image
8383
flare_loc = wcs_bp.array_index_to_world(*max_idx)

stixpy/map/stix.py

+45
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import astropy.units as u
22
from astropy import wcs
3+
from sunpy.coordinates import HeliographicStonyhurst
34
from sunpy.map import GenericMap
45

6+
import stixpy.coordinates.transforms
7+
58
__all__ = ["STIXMap"]
69

710

@@ -72,3 +75,45 @@ def wcs(self):
7275
# Validate the WCS here.
7376
w2.wcs.set()
7477
return w2
78+
79+
def to_hpc(self,
80+
reference_coordinate,
81+
reference_pixel: u.Unit('pix') = None):
82+
"""
83+
Return a version of the map in the Helioprojective Cartesian (HPC) coordinate frame.
84+
85+
This is quicker than a full reprojection, `~stixpy.coordinates.transforms.STIXImaging`
86+
is also a helioprojective frame with a different z-axis and rotation.
87+
Therefore, the new WCS information can be unambiguously reconstructed without
88+
altering the data array.
89+
90+
Parameters
91+
----------
92+
reference_coordinate: `astropy.coordinates.SkyCoord`
93+
The coordinate of the reference pixel.
94+
Must be transformable to `sunpy.coordinates.Helioprojective`.
95+
reference_pixel: `astropy.coordinate.Quantity` length-2 (optional)
96+
The (x, y) pixel index of the reference pixel.
97+
Default is center of the map's field of view.
98+
99+
Returns
100+
-------
101+
hpc_map: `sunpy.map.Map`
102+
Map of the STIX image in the HPC coordinate frame.
103+
"""
104+
if reference_pixel is None:
105+
reference_pixel = (np.array(self.data.shape)[::-1] / 2) << u.pix
106+
roll, solo_xyz, pointing = stixpy.coordinates.transforms.get_hpc_info(
107+
reference_coordinate.obstime)
108+
solo = HeliographicStonyhurst(*solo_xyz, obstime=reference_coordinate.obstime,
109+
representation_type="cartesian")
110+
header = make_fitswcs_header(
111+
self.data,
112+
reference_coordinate.transform_to(Helioprojective(obstime=reference_coordinate.obstime,
113+
observer=solo)),
114+
telescope="STIX",
115+
observatory="Solar Orbiter",
116+
scale=u.Quantity(self.scale),
117+
rotation_angle=90 * u.deg + roll,)
118+
return sunpy.map.Map(self.data, header,
119+
mask=self.mask, uncertainty=self.uncertainty, meta=self.meta)

0 commit comments

Comments
 (0)