Skip to content

Commit

Permalink
Add assume_planar_screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih committed Jul 26, 2023
1 parent 15b4580 commit c7e5dd5
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 @@ -588,6 +588,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 594 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L591-L594

Added lines #L591 - L594 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L596-L597

Added lines #L596 - L597 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L600

Added line #L600 was not covered by tests

Expand Down Expand Up @@ -678,6 +686,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 710 in sunpy/coordinates/frames.py

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L709-L710

Added lines #L709 - L710 were not covered by tests

cls._assumed_screen = {

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

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L712

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

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

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L717

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

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

View check run for this annotation

Codecov / codecov/patch

sunpy/coordinates/frames.py#L719

Added line #L719 was not covered by tests


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

0 comments on commit c7e5dd5

Please sign in to comment.