Skip to content

Commit

Permalink
Add assume_planar_screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih authored and wtbarnes committed Mar 28, 2024
1 parent aa8d36f commit b814eac
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions sunpy/coordinates/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ def make_3d(self):
with np.errstate(invalid='ignore'):
dd = ((-1*b) + np.sqrt(b**2 - 4*c)) / 2 # use the "far" solution

elif self._assumed_screen['type'] == 'planar':
direction = self._assumed_screen['vantage_point'].transform_to(self).cartesian
direction = CartesianRepresentation(1, 0, 0) * self.observer.radius - direction
direction /= direction.norm()

Check warning on line 585 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L582-L585

Added lines #L582 - L585 were not covered by tests

d_from_plane = self.observer.radius * direction.x
dd = d_from_plane / rep.dot(direction)

Check warning on line 588 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L587-L588

Added lines #L587 - L588 were not covered by tests

else:
raise ValueError(f"Unknown screen type: {self._assumed_screen['type']}")

Check warning on line 591 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L591

Added line #L591 was not covered by tests

Expand Down Expand Up @@ -748,6 +756,38 @@ def assume_spherical_screen(cls, center, only_off_disk=False):
finally:
cls._assumed_screen = old_assumed_screen

@classmethod
@contextmanager
def assume_planar_screen(cls, vantage_point, only_off_disk=False):
"""
Context manager to interpret 2D coordinates as being on the inside of a planar screen.
The plane goes through Sun center and is perpendicular to the vector between the
specified vantage point and Sun center.
This replaces the default assumption where 2D coordinates are mapped onto the surface of the
Sun.
Parameters
----------
vantage_point : `~astropy.coordinates.SkyCoord`
The vantage point that defines the orientation of the plane.
only_off_disk : `bool`, optional
If `True`, apply this assumption only to off-disk coordinates, with on-disk coordinates
still mapped onto the surface of the Sun. Defaults to `False`.
"""
try:
old_assumed_screen = cls._assumed_screen # nominally None

Check warning on line 780 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L779-L780

Added lines #L779 - L780 were not covered by tests

cls._assumed_screen = {

Check warning on line 782 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L782

Added line #L782 was not covered by tests
'type': 'planar',
'vantage_point': vantage_point,
'only_off_disk': only_off_disk
}
yield

Check warning on line 787 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L787

Added line #L787 was not covered by tests
finally:
cls._assumed_screen = old_assumed_screen

Check warning on line 789 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L789

Added line #L789 was not covered by tests


@add_common_docstring(**_frame_parameters())
class HeliocentricEarthEcliptic(SunPyBaseCoordinateFrame):
Expand Down

0 comments on commit b814eac

Please sign in to comment.