Skip to content

Commit

Permalink
Add method to STIXMap to convert to HPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRyanIrish committed Nov 15, 2024
1 parent 8c6ec0e commit 7f57d78
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stixpy/imaging/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def estimate_stix_flare_location(cpd_sci, time_range=None, energy_range=None, su
coord = STIXImaging(0 * u.arcsec, 0 * u.arcsec, obstime=vis_tr.start, obstime_end=vis_tr.end, observer=solo)
header_bp = sunpy.map.make_fitswcs_header(bp_image, coord, telescope="STIX",

Check warning on line 78 in stixpy/imaging/tools.py

View check run for this annotation

Codecov / codecov/patch

stixpy/imaging/tools.py#L74-L78

Added lines #L74 - L78 were not covered by tests
observatory="Solar Orbiter", scale=plate_scale)
map_bp = sunpy.map.Map(bp_image, header_bp).wcs
map_bp = sunpy.map.Map(bp_image, header_bp)
wcs_bp = map_bp.wcs

Check warning on line 81 in stixpy/imaging/tools.py

View check run for this annotation

Codecov / codecov/patch

stixpy/imaging/tools.py#L80-L81

Added lines #L80 - L81 were not covered by tests
# Estimate flare location from brightest pixel in backprojection image
flare_loc = wcs_bp.array_index_to_world(*max_idx)
Expand Down
45 changes: 45 additions & 0 deletions stixpy/map/stix.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import astropy.units as u
from astropy import wcs
from sunpy.coordinates import HeliographicStonyhurst
from sunpy.map import GenericMap

import stixpy.coordinates.transforms

__all__ = ["STIXMap"]


Expand Down Expand Up @@ -72,3 +75,45 @@ def wcs(self):
# Validate the WCS here.
w2.wcs.set()
return w2

def to_hpc(self,
reference_coordinate,
reference_pixel: u.Unit('pix') = None):
"""
Return a version of the map in the Helioprojective Cartesian (HPC) coordinate frame.
This is quicker than a full reprojection, `~stixpy.coordinates.transforms.STIXImaging`
is also a helioprojective frame with a different z-axis and rotation.
Therefore, the new WCS information can be unambiguously reconstructed without
altering the data array.
Parameters
----------
reference_coordinate: `astropy.coordinates.SkyCoord`
The coordinate of the reference pixel.
Must be transformable to `sunpy.coordinates.Helioprojective`.
reference_pixel: `astropy.coordinate.Quantity` length-2 (optional)
The (x, y) pixel index of the reference pixel.
Default is center of the map's field of view.
Returns
-------
hpc_map: `sunpy.map.Map`
Map of the STIX image in the HPC coordinate frame.
"""
if reference_pixel is None:
reference_pixel = (np.array(self.data.shape)[::-1] / 2) << u.pix
roll, solo_xyz, pointing = stixpy.coordinates.transforms.get_hpc_info(

Check warning on line 106 in stixpy/map/stix.py

View check run for this annotation

Codecov / codecov/patch

stixpy/map/stix.py#L104-L106

Added lines #L104 - L106 were not covered by tests
reference_coordinate.obstime)
solo = HeliographicStonyhurst(*solo_xyz, obstime=reference_coordinate.obstime,

Check warning on line 108 in stixpy/map/stix.py

View check run for this annotation

Codecov / codecov/patch

stixpy/map/stix.py#L108

Added line #L108 was not covered by tests
representation_type="cartesian")
header = make_fitswcs_header(

Check warning on line 110 in stixpy/map/stix.py

View check run for this annotation

Codecov / codecov/patch

stixpy/map/stix.py#L110

Added line #L110 was not covered by tests
self.data,
reference_coordinate.transform_to(Helioprojective(obstime=reference_coordinate.obstime,
observer=solo)),
telescope="STIX",
observatory="Solar Orbiter",
scale=u.Quantity(self.scale),
rotation_angle=90 * u.deg + roll,)
return sunpy.map.Map(self.data, header,

Check warning on line 118 in stixpy/map/stix.py

View check run for this annotation

Codecov / codecov/patch

stixpy/map/stix.py#L118

Added line #L118 was not covered by tests
mask=self.mask, uncertainty=self.uncertainty, meta=self.meta)

0 comments on commit 7f57d78

Please sign in to comment.