|
1 | 1 | import astropy.units as u
|
2 | 2 | from astropy import wcs
|
| 3 | +from sunpy.coordinates import HeliographicStonyhurst |
3 | 4 | from sunpy.map import GenericMap
|
4 | 5 |
|
| 6 | +import stixpy.coordinates.transforms |
| 7 | + |
5 | 8 | __all__ = ["STIXMap"]
|
6 | 9 |
|
7 | 10 |
|
@@ -72,3 +75,45 @@ def wcs(self):
|
72 | 75 | # Validate the WCS here.
|
73 | 76 | w2.wcs.set()
|
74 | 77 | 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