class Heliocentric(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Heliocentric system. - The origin is the centre of the Sun - The z-axis points from the centre of the Sun to the observer. - The y-axis is perpendicular to the z-axis, and lies in the plane that contains the z-axis and the solar rotation axis, pointing towards the Sun's north pole. This frame may either be specified in Cartesian or cylindrical representation. Cylindrical representation replaces (``x``, ``y``) with (``rho``, ``psi``) where ``rho`` is the impact parameter and ``psi`` is the position angle. ``psi`` is measured relative to the west limb, rather than solar north, so is shifted by 90 degrees compared to the convention of the Heliocentric Radial system. If the ``data`` parameter is given, the positional parameters for the coordinate frame (``x``, ``y``, ``z``) do not need to be given. A new instance can be created using the following signatures (note that ``obstime`` and ``representation_type`` must be supplied as keywords):: Heliocentric(x, y, z, obstime) Heliocentric(rho, psi, z, obstime, representation_type='cylindrical') Parameters ---------- data : `~astropy.coordinates.BaseRepresentation` or None A representation object. If specified, other parameters must be in keyword form and if x, y and z are specified, it must be None. x : `~astropy.units.Quantity`, optional X-axis coordinate. Not needed if ``data`` is given. y : `~astropy.units.Quantity`, optional Y-axis coordinate. Not needed if ''data'' is given. z : `~astropy.units.Quantity`, optional Z-axis coordinate. Not needed if ``data`` is given. observer : `~sunpy.coordinates.frames.HeliographicStonyhurst`, str The coordinate of the observer in the solar system. If you supply a string, it must be a solar system body that can be parsed by `~sunpy.coordinates.ephemeris.get_body_heliographic_stonyhurst`. Defaults to the Earth. obstime : {parse_time_types} The date and time of the observation. Examples -------- >>> from astropy.coordinates import SkyCoord, CartesianRepresentation >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(CartesianRepresentation(10*u.km, 1*u.km, 2*u.km), ... obstime="2011/01/05T00:00:50", frame="heliocentric") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-05T00:00:50.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in km (10., 1., 2.)> >>> sc = SkyCoord([1,2]*u.km, [3,4]*u.m, [5,6]*u.cm, frame="heliocentric", obstime="2011/01/01T00:00:54") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-01T00:00:54.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in (km, m, cm) [(1., 3., 5.), (2., 4., 6.)]> >>> sc = SkyCoord(CylindricalRepresentation(10*u.km, 60*u.deg, 10*u.km), ... obstime="2011/01/05T00:00:50", ... frame="heliocentric") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-05T00:00:50.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in km (5., 8.66025404, 10.)> """ default_representation = CartesianRepresentation _frame_specific_representation_info = { CylindricalRepresentation: [RepresentationMapping('phi', 'psi', u.deg)] } obstime = TimeFrameAttributeSunPy() observer = ObserverCoordinateAttribute(HeliographicStonyhurst, default="earth")
class Helioprojective(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Helioprojective (Cartesian) system. This is a projective coordinate system centered around the observer. It is a full spherical coordinate system with position given as longitude theta_x and latitude theta_y. If the ``data`` parameter is given, the positional parameters for the coordinate frame (``Tx``, ``Ty``, ``distance``) do not need to be given. Parameters ---------- data : `~astropy.coordinates.BaseRepresentation` or None A representation object. If specified, other parameters must be in keyword form. Tx : `~astropy.coordinates.Angle` or `~astropy.units.Quantity` Theta_x coordinate. Not needed if ``data`` is given. Ty : `~astropy.coordinates.Angle` or `~astropy.units.Quantity` Theta_y coordinate. Not needed if ``data`` is given. distance : `~astropy.units.Quantity` The radial distance from the observer to the coordinate point. Not needed if ``data`` is given. obstime : {parse_time_types} The date and time of the observation. observer : `~sunpy.coordinates.frames.HeliographicStonyhurst`, str The coordinate of the observer in the solar system. If you supply a string, it must be a solar system body that can be parsed by `~sunpy.coordinates.ephemeris.get_body_heliographic_stonyhurst`. Defaults to the Earth. rsun : `~astropy.units.Quantity` The physical (length) radius of the Sun. Used to calculate the position of the limb for calculating distance from the observer to the coordinate. Defaults to the solar radius. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km, obstime="2010/01/01T00:00:00", ... frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2010-01-01T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, km) (0., 0., 5.)> >>> sc = SkyCoord(0*u.deg, 0*u.deg, obstime="2010/01/01T00:00:00", frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2010-01-01T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty) in arcsec (0., 0.)> >>> sc = SkyCoord(CartesianRepresentation(1*u.AU, 1e5*u.km, -2e5*u.km), ... obstime="2011/01/05T00:00:50", ... frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2011-01-05T00:00:50.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, AU) (137.87948623, -275.75878762, 1.00000112)> """ default_representation = SphericalRepresentation frame_specific_representation_info = { SphericalRepresentation: [ RepresentationMapping(reprname='lon', framename='Tx', defaultunit=u.arcsec), RepresentationMapping(reprname='lat', framename='Ty', defaultunit=u.arcsec), RepresentationMapping(reprname='distance', framename='distance', defaultunit=None) ], UnitSphericalRepresentation: [ RepresentationMapping(reprname='lon', framename='Tx', defaultunit=u.arcsec), RepresentationMapping(reprname='lat', framename='Ty', defaultunit=u.arcsec) ], } obstime = TimeFrameAttributeSunPy() rsun = Attribute(default=_RSUN.to(u.km)) observer = ObserverCoordinateAttribute(HeliographicStonyhurst, default="earth") def calculate_distance(self): """ This method calculates the third coordinate of the Helioprojective frame. It assumes that the coordinate point is on the disk of the Sun at the rsun radius. If a point in the frame is off limb then NaN will be returned. Returns ------- new_frame : `~sunpy.coordinates.frames.HelioProjective` A new frame instance with all the attributes of the original but now with a third coordinate. """ # Skip if we already are 3D distance = self.spherical.distance if not (distance.unit is u.one and u.allclose(distance, 1 * u.one)): return self if not isinstance(self.observer, BaseCoordinateFrame): raise ConvertError("Cannot calculate distance to the solar disk " "for observer '{}' " "without `obstime` being specified.".format( self.observer)) rep = self.represent_as(UnitSphericalRepresentation) lat, lon = rep.lat, rep.lon alpha = np.arccos(np.cos(lat) * np.cos(lon)).to(lat.unit) c = self.observer.radius**2 - self.rsun**2 b = -2 * self.observer.radius * np.cos(alpha) # Ingore sqrt of NaNs with np.errstate(invalid='ignore'): d = ((-1 * b) - np.sqrt(b**2 - 4 * c)) / 2 return self.realize_frame( SphericalRepresentation(lon=lon, lat=lat, distance=d))
class Helioprojective(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Helioprojective Cartesian (HPC) system, which is observer-based. - The origin is the location of the observer. - ``Tx`` (aka "theta_x") is the angle relative to the plane containing the Sun-observer line and the Sun's rotation axis, with positive values in the direction of the Sun's west limb. - ``Ty`` (aka "theta_y") is the angle relative to the Sun's equatorial plane, with positive values in the direction of the Sun's north pole. - ``distance`` is the Sun-observer distance. This system is frequently used in a projective form without ``distance`` specified. For observations looking very close to the center of the Sun, where the small-angle approximation is appropriate, ``Tx`` and ``Ty`` can be approximated as Cartesian components. A new instance can be created using the following signatures (note that if supplied, ``obstime`` and ``observer`` must be keyword arguments):: Helioprojective(Tx, Ty, obstime=obstime, observer=observer) Helioprojective(Tx, Ty, distance, obstime=obstime, observer=observer) Parameters ---------- {data} Tx : `~astropy.coordinates.Angle` or `~astropy.units.Quantity` The theta_x coordinate for this object. Not needed if ``data`` is given. Ty : `~astropy.coordinates.Angle` or `~astropy.units.Quantity` The theta_y coordinate for this object. Not needed if ``data`` is given. distance : `~astropy.units.Quantity` The distance coordinate from the observer for this object. Not needed if ``data`` is given. {observer} {rsun} {common} Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km, ... obstime="2010/01/01T00:00:00", observer="earth", frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2010-01-01T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, km) (0., 0., 5.)> >>> sc = SkyCoord(0*u.deg, 0*u.deg, ... obstime="2010/01/01T00:00:00", observer="earth", frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2010-01-01T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty) in arcsec (0., 0.)> >>> sc = SkyCoord(CartesianRepresentation(1*u.AU, 1e5*u.km, -2e5*u.km), ... obstime="2011/01/05T00:00:50", observer="earth", frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2011-01-05T00:00:50.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, AU) (137.87948623, -275.75878762, 1.00000112)> """ frame_specific_representation_info = { SphericalRepresentation: [ RepresentationMapping('lon', 'Tx', u.arcsec), RepresentationMapping('lat', 'Ty', u.arcsec), RepresentationMapping('distance', 'distance', None) ], SphericalDifferential: [ RepresentationMapping('d_lon', 'd_Tx', u.arcsec / u.s), RepresentationMapping('d_lat', 'd_Ty', u.arcsec / u.s), RepresentationMapping('d_distance', 'd_distance', u.km / u.s) ], UnitSphericalRepresentation: [ RepresentationMapping('lon', 'Tx', u.arcsec), RepresentationMapping('lat', 'Ty', u.arcsec) ], } rsun = QuantityAttribute(default=_RSUN, unit=u.km) observer = ObserverCoordinateAttribute(HeliographicStonyhurst) @property def angular_radius(self): """ Angular radius of the Sun as seen by the observer. The ``rsun`` frame attribute is the radius of the Sun in length units. The tangent vector from the observer to the edge of the Sun forms a right-angle triangle with the radius of the Sun as the far side and the Sun-observer distance as the hypotenuse. Thus, the sine of the angular radius of the Sun is ratio of these two distances. """ from sunpy.coordinates.sun import _angular_radius # avoiding a circular import if not isinstance(self.observer, HeliographicStonyhurst): if self.observer is None: raise ValueError("The observer must be defined, not `None`.") raise ValueError( "The observer must be fully defined by specifying `obstime`.") return _angular_radius(self.rsun, self.observer.radius) def make_3d(self): """ This method calculates the third coordinate of the Helioprojective frame. It assumes that the coordinate point is on the surface of the Sun. If a point in the frame is off limb then NaN will be returned. Returns ------- new_frame : `~sunpy.coordinates.frames.Helioprojective` A new frame instance with all the attributes of the original but now with a third coordinate. """ # Skip if we already are 3D if not self._is_2d: return self if not isinstance(self.observer, BaseCoordinateFrame): raise ConvertError("Cannot calculate distance to the Sun " f"for observer '{self.observer}' " "without `obstime` being specified.") rep = self.represent_as(UnitSphericalRepresentation) lat, lon = rep.lat, rep.lon # Check for the use of floats with lower precision than the native Python float if not set([lon.dtype.type, lat.dtype.type]).issubset( [float, np.float64, np.longdouble]): warn_user( "The Helioprojective component values appear to be lower " "precision than the native Python float: " f"Tx is {lon.dtype.name}, and Ty is {lat.dtype.name}. " "To minimize precision loss, you may want to cast the values to " "`float` or `numpy.float64` via the NumPy method `.astype()`.") # Calculate the distance to the surface of the Sun using the law of cosines cos_alpha = np.cos(lat) * np.cos(lon) c = self.observer.radius**2 - self.rsun**2 b = -2 * self.observer.radius * cos_alpha # Ignore sqrt of NaNs with np.errstate(invalid='ignore'): d = ((-1 * b) - np.sqrt(b**2 - 4 * c)) / 2 # use the "near" solution if self._spherical_screen: sphere_center = self._spherical_screen['center'].transform_to( self).cartesian c = sphere_center.norm()**2 - self._spherical_screen['radius']**2 b = -2 * sphere_center.dot(rep) # Ignore sqrt of NaNs with np.errstate(invalid='ignore'): dd = ((-1 * b) + np.sqrt(b**2 - 4 * c)) / 2 # use the "far" solution d = np.fmin(d, dd) if self._spherical_screen['only_off_disk'] else dd return self.realize_frame( SphericalRepresentation(lon=lon, lat=lat, distance=d)) _spherical_screen = None @classmethod @contextmanager def assume_spherical_screen(cls, center, only_off_disk=False): """ Context manager to interpret 2D coordinates as being on the inside of a spherical screen. The radius of the screen is the distance between the specified ``center`` and Sun center. This ``center`` does not have to be the same as the observer location for the coordinate frame. If they are the same, then this context manager is equivalent to assuming that the helioprojective "zeta" component is zero. This replaces the default assumption where 2D coordinates are mapped onto the surface of the Sun. Parameters ---------- center : `~astropy.coordinates.SkyCoord` The center of the spherical screen 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`. Examples -------- .. minigallery:: sunpy.coordinates.Helioprojective.assume_spherical_screen >>> import astropy.units as u >>> from sunpy.coordinates import Helioprojective >>> h = Helioprojective(range(7)*u.arcsec*319, [0]*7*u.arcsec, ... observer='earth', obstime='2020-04-08') >>> print(h.make_3d()) <Helioprojective Coordinate (obstime=2020-04-08T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, AU) [( 0., 0., 0.99660825), ( 319., 0., 0.99687244), ( 638., 0., 0.99778472), ( 957., 0., 1.00103285), (1276., 0., nan), (1595., 0., nan), (1914., 0., nan)]> >>> with Helioprojective.assume_spherical_screen(h.observer): ... print(h.make_3d()) <Helioprojective Coordinate (obstime=2020-04-08T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, AU) [( 0., 0., 1.00125872), ( 319., 0., 1.00125872), ( 638., 0., 1.00125872), ( 957., 0., 1.00125872), (1276., 0., 1.00125872), (1595., 0., 1.00125872), (1914., 0., 1.00125872)]> >>> with Helioprojective.assume_spherical_screen(h.observer, only_off_disk=True): ... print(h.make_3d()) <Helioprojective Coordinate (obstime=2020-04-08T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, AU) [( 0., 0., 0.99660825), ( 319., 0., 0.99687244), ( 638., 0., 0.99778472), ( 957., 0., 1.00103285), (1276., 0., 1.00125872), (1595., 0., 1.00125872), (1914., 0., 1.00125872)]> """ try: old_spherical_screen = cls._spherical_screen # nominally None center_hgs = center.transform_to( HeliographicStonyhurst(obstime=center.obstime)) cls._spherical_screen = { 'center': center, 'radius': center_hgs.radius, 'only_off_disk': only_off_disk } yield finally: cls._spherical_screen = old_spherical_screen
class HeliographicCarrington(HeliographicStonyhurst): """ A coordinate or frame in the Carrington Heliographic system. - The origin is the centre of the Sun - The z-axis is aligned with the Sun's north pole - The x and y axes rotate with a period of 25.38 days. This frame differs from the Stonyhurst version in the definition of the longitude, which is defined using the time-dependent offset described above. If the ``data`` parameter is given, the positional parameters for the coordinate frame (``lon``, ``lat``, ``radius``) do not need to be given. Parameters ---------- data : `~astropy.coordinates.BaseRepresentation` or None A representation object or None to have no data. lon : `~astropy.coordinates.Angle`, optional The longitude for this object (``lat`` must also be given and ``data`` must be None). Not needed if ``data`` is given. lat : `~astropy.coordinates.Angle`, optional The latitude for this object (``lon`` must also be given and ``data`` must be None). Not needed if ``data`` is given. radius : `~astropy.units.Quantity`, optional The radial distance for this object. Defaults to the solar radius. Not needed if ``data`` is given. obstime : {parse_time_types} The date and time of the observation. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(1*u.deg, 2*u.deg, 3*u.km, ... frame="heliographic_carrington", ... obstime="2010/01/01T00:00:30") >>> sc <SkyCoord (HeliographicCarrington: obstime=2010-01-01T00:00:30.000): (lon, lat, radius) in (deg, deg, km) (1., 2., 3.)> >>> sc = SkyCoord([1,2,3]*u.deg, [4,5,6]*u.deg, [5,6,7]*u.km, ... obstime="2010/01/01T00:00:45", frame="heliographic_carrington") >>> sc <SkyCoord (HeliographicCarrington: obstime=2010-01-01T00:00:45.000): (lon, lat, radius) in (deg, deg, km) [(1., 4., 5.), (2., 5., 6.), (3., 6., 7.)]> >>> sc = SkyCoord(CartesianRepresentation(0*u.km, 45*u.km, 2*u.km), ... obstime="2011/01/05T00:00:50", ... frame="heliographic_carrington") >>> sc <SkyCoord (HeliographicCarrington: obstime=2011-01-05T00:00:50.000): (lon, lat, radius) in (deg, deg, km) (90., 2.54480438, 45.04442252)> """ name = "heliographic_carrington" default_representation = SphericalRepresentation frame_specific_representation_info = { SphericalRepresentation: [ RepresentationMapping(reprname='lon', framename='lon', defaultunit=u.deg), RepresentationMapping(reprname='lat', framename='lat', defaultunit=u.deg), RepresentationMapping(reprname='distance', framename='radius', defaultunit=None) ], UnitSphericalRepresentation: [ RepresentationMapping(reprname='lon', framename='lon', defaultunit=u.deg), RepresentationMapping(reprname='lat', framename='lat', defaultunit=u.deg) ], } _wrap_angle = 360 * u.deg obstime = TimeFrameAttributeSunPy()
class SunPyBaseCoordinateFrame(BaseCoordinateFrame): """ Base class for sunpy coordinate frames. This class is not intended to be used directly and has no transformations defined. * Defines the frame attribute ``obstime`` for observation time. * Defines a default wrap angle of 180 degrees for longitude in spherical coordinates, which can be overridden via the class variable ``_wrap_angle``. * Inject a nice way of representing the object which the coordinate represents. """ obstime = TimeFrameAttributeSunPy() default_representation = SphericalRepresentation default_differential = SphericalDifferential frame_specific_representation_info = { SphericalDifferential: [ RepresentationMapping('d_lon', 'd_lon', u.arcsec / u.s), RepresentationMapping('d_lat', 'd_lat', u.arcsec / u.s), RepresentationMapping('d_distance', 'd_distance', u.km / u.s) ], } _wrap_angle = 180 * u.deg # for longitude in spherical coordinates def __init__(self, *args, **kwargs): self.object_name = None # If wrap_longitude=False is passed in, do not impose a specific wrap angle for the frame if not kwargs.pop('wrap_longitude', True): self._wrap_angle = None super().__init__(*args, **kwargs) # If obstime is specified, treat the default observer (None) as explicitly set if self.obstime is not None and self.is_frame_attr_default('observer'): self._attr_names_with_defaults.remove('observer') return def represent_as(self, base, s='base', in_frame_units=False): data = super().represent_as(base, s, in_frame_units=in_frame_units) # If a frame wrap angle is set, use that wrap angle for any spherical representations. if self._wrap_angle is not None and \ isinstance(data, (UnitSphericalRepresentation, SphericalRepresentation)): data.lon.wrap_angle = self._wrap_angle return data def __str__(self): # We override this here so that when you print a SkyCoord it shows the # observer as the string and not the whole massive coordinate. if getattr(self, "object_name", None): return f"<{self.__class__.__name__} Coordinate for '{self.object_name}'>" else: return super().__str__() @property def _is_2d(self): return (self._data is not None and self._data.norm().unit is u.one and u.allclose(self._data.norm(), 1 * u.one)) def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs) # TODO: Remove this after the minimum Astropy dependency includes astropy/astropy#12005 cls._fix_property_docstrings() @classmethod def _fix_property_docstrings(cls): # This class method adds docstrings to properties dynamically created by # BaseCoordinateFrame.__init_subclass__(). Accordingly, this method needs to itself be # called from SunPyBaseCoordinateFrame.__init_subclass__() to work for our subclasses. property_docstrings = { 'default_representation': "Default representation for position data", 'default_differential': "Default representation for differential data", 'frame_specific_representation_info': "Mapping for frame-specific component names", } for prop, docstring in property_docstrings.items(): if getattr(cls, prop).__doc__ is None: setattr(getattr(cls, prop), '__doc__', docstring)
class Heliocentric(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Heliocentric system, which is observer-based. - The origin is the center of the Sun. - The Z-axis is aligned with the Sun-observer line. - The Y-axis is aligned with the component of the vector to the Sun's north pole that is perpendicular to the Z-axis. This frame defaults to a Cartesian component representation, which is known as Heliocentric Cartesian (HCC). This frame can also be represented using cylindrical components, where where ``rho`` is the impact parameter and ``psi`` is the position angle. ``psi`` is measured relative to the west limb, rather than solar north, so is shifted by 90 degrees compared to the convention of the Heliocentric Radial (HCR) system. A new instance can be created using the following signatures (note that if supplied, ``obstime``, ``observer``, and ``representation_type`` must be keyword arguments):: Heliocentric(x, y, z, obstime=obstime, observer=observer) Heliocentric(rho, psi, z, representation_type='cylindrical', obstime=obstime, observer=observer) Parameters ---------- {data} {xyz} {observer} {common} Examples -------- >>> from astropy.coordinates import SkyCoord, CartesianRepresentation >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(CartesianRepresentation(10*u.km, 1*u.km, 2*u.km), ... obstime="2011/01/05T00:00:50", observer="earth", frame="heliocentric") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-05T00:00:50.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in km (10., 1., 2.)> >>> sc = SkyCoord([1,2]*u.km, [3,4]*u.m, [5,6]*u.cm, ... obstime="2011/01/01T00:00:54", observer="earth", frame="heliocentric") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-01T00:00:54.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in (km, m, cm) [(1., 3., 5.), (2., 4., 6.)]> >>> sc = SkyCoord(CylindricalRepresentation(10*u.km, 60*u.deg, 10*u.km), ... obstime="2011/01/05T00:00:50", observer="earth", frame="heliocentric") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-05T00:00:50.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in km (5., 8.66025404, 10.)> """ default_representation = CartesianRepresentation default_differential = CartesianDifferential frame_specific_representation_info = { CylindricalRepresentation: [RepresentationMapping('phi', 'psi', u.deg)] } observer = ObserverCoordinateAttribute(HeliographicStonyhurst) def represent_as(self, base, s='base', in_frame_units=False): data = super().represent_as(base, s, in_frame_units=in_frame_units) # For cylindrical representations, wrap the `psi` component (natively `phi`) at 360 deg if isinstance(data, CylindricalRepresentation): data.phi.wrap_at(360 * u.deg, inplace=True) return data
class Heliocentric(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Heliocentric system. - The origin is the centre of the Sun - The z-axis points from the centre of the Sun to the observer. - The y-axis is perpendicular to the z-axis, and lies in the plane that contains the z-axis and the solar rotation axis, pointing towards the Sun's north pole. This frame may either be specified in Cartesian or cylindrical representation. Cylindrical representation replaces (x, y) with (rho, psi) where rho is the impact parameter and psi is the position angle in degrees. Parameters ---------- representation: `~astropy.coordinates.BaseRepresentation` or None. A representation object. If specified, other parameters must be in keyword form and if x, y and z are specified, it must be None. x: `Quantity` object. X-axis coordinate, optional, must be keyword. y: `Quantity` object. Y-axis coordinate, optional, must be keyword. z: `Quantity` object. Shared by both representations. Z-axis coordinate, optional, must be keyword. observer: `~sunpy.coordinates.frames.HeliographicStonyhurst`, optional The coordinate of the observer in the solar system. Defaults to the Earth. obstime: SunPy Time The date and time of the observation, used to convert to heliographic carrington coordinates. Examples -------- >>> from astropy.coordinates import SkyCoord, CartesianRepresentation >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(CartesianRepresentation(10*u.km, 1*u.km, 2*u.km), ... obstime="2011/01/05T00:00:50", frame="heliocentric") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-05T00:00:50.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in km (10., 1., 2.)> >>> sc = SkyCoord([1,2]*u.km, [3,4]*u.m, [5,6]*u.cm, frame="heliocentric", obstime="2011/01/01T00:00:54") >>> sc <SkyCoord (Heliocentric: obstime=2011-01-01T00:00:54.000, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (x, y, z) in (km, m, cm) [(1., 3., 5.), (2., 4., 6.)]> """ default_representation = CartesianRepresentation _frame_specific_representation_info = { CylindricalRepresentation: [RepresentationMapping('phi', 'psi', u.deg)] } obstime = TimeFrameAttributeSunPy() observer = ObserverCoordinateAttribute(HeliographicStonyhurst, default="earth")
class HeliographicStonyhurst(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Stonyhurst Heliographic system. In a cartesian representation this is also known as the Heliocentric Earth Equatorial (HEEQ) system. This frame has its origin at the solar centre and the north pole above the solar north pole, and the zero line on longitude pointing towards the Earth. A new instance can be created using the following signatures (note that all the arguments must be supplied as keywords):: HeliographicStonyhurst(lon, lat, obstime) HeliographicStonyhurst(lon, lat, radius, obstime) HeliographicStonyhurst(x, y, z, obstime, representation_type='cartesian') Parameters ---------- representation : `~astropy.coordinates.BaseRepresentation` or `None` A representation object or None to have no data. lon : `~astropy.coordinates.Angle`, optional The longitude for this object (``lat`` must also be given and ``representation`` must be None). lat : `~astropy.coordinates.Angle`, optional The latitude for this object (``lon`` must also be given and ``representation`` must be None). radius : `~astropy.units.Quantity`, optional This quantity holds the radial distance. If not specified, it is, by default, the radius of the photosphere. x : `~astropy.units.Quantity`, optional x coordinate. y : `~astropy.units.Quantity`, optional y coordinate. z : `~astropy.units.Quantity`, optional z coordinate. obstime: `~sunpy.time.Time` The date and time of the observation, used to convert to heliographic carrington coordinates. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(1*u.deg, 1*u.deg, 2*u.km, ... frame="heliographic_stonyhurst", ... obstime="2010/01/01T00:00:45") >>> sc <SkyCoord (HeliographicStonyhurst: obstime=2010-01-01T00:00:45.000): (lon, lat, radius) in (deg, deg, km) (1., 1., 2.)> >>> sc.frame <HeliographicStonyhurst Coordinate (obstime=2010-01-01T00:00:45.000): (lon, lat, radius) in (deg, deg, km) (1., 1., 2.)> >>> sc = SkyCoord(HeliographicStonyhurst(-10*u.deg, 2*u.deg)) >>> sc <SkyCoord (HeliographicStonyhurst: obstime=None): (lon, lat, radius) in (deg, deg, km) (-10., 2., 695700.)> Notes ----- This frame will always be converted a 3D frame where the radius defaults to rsun. """ name = "heliographic_stonyhurst" default_representation = SphericalRepresentation frame_specific_representation_info = { SphericalRepresentation: [RepresentationMapping(reprname='lon', framename='lon', defaultunit=u.deg), RepresentationMapping(reprname='lat', framename='lat', defaultunit=u.deg), RepresentationMapping(reprname='distance', framename='radius', defaultunit=None)], CartesianRepresentation: [RepresentationMapping(reprname='x', framename='x'), RepresentationMapping(reprname='y', framename='y'), RepresentationMapping(reprname='z', framename='z')] } obstime = TimeFrameAttributeSunPy() def __init__(self, *args, **kwargs): _rep_kwarg = kwargs.get('representation_type', None) super().__init__(*args, **kwargs) # Make 3D if specified as 2D # If representation was explicitly passed, do not change the rep. if not _rep_kwarg: if isinstance(self._data, UnitSphericalRepresentation): self._data = self.spherical def represent_as(self, base, s='base', in_frame_units=False): """ Unless the requested representation is UnitSphericalRepresentation, scale a coordinate with dimensionless length so that it has the length of the solar radius. """ data = super().represent_as(base, s, in_frame_units=in_frame_units) if not isinstance(data, UnitSphericalRepresentation) and \ data.norm().unit is u.one and u.allclose(data.norm(), 1*u.one): data *= _RSUN.to(u.km) return data
class Pointing(BaseCoordinateFrame): """ Written by Joshua G. Albert - [email protected] A coordinate or frame in the Pointing system. This frame has the following frame attributes, which are necessary for transforming from Pointing to some other system: * ``obstime`` The time at which the observation is taken. Used for determining the position and orientation of the Earth. * ``location`` The location on the Earth. This can be specified either as an `~astropy.coordinates.EarthLocation` object or as anything that can be transformed to an `~astropy.coordinates.ITRS` frame. * ``phaseDir`` The phase tracking center of the frame. This can be specified either as an (ra,dec) `~astropy.units.Qunatity` or as anything that can be transformed to an `~astropy.coordinates.ICRS` frame. * ``fixtime`` The time at which the frame is fixed. Used for determining the position and orientation of the Earth. Parameters ---------- representation : `BaseRepresentation` or None A representation object or None to have no data (or use the other keywords) u : :class:`~astropy.units.Quantity`, optional, must be keyword The u coordinate for this object (``v`` and ``w`` must also be given and ``representation`` must be None). v : :class:`~astropy.units.Quantity`, optional, must be keyword The v coordinate for this object (``u`` and ``w`` must also be given and ``representation`` must be None). w : :class:`~astropy.units.Quantity`, optional, must be keyword The w coordinate for this object (``u`` and ``v`` must also be given and ``representation`` must be None). Notes ----- This is useful for radio astronomy. """ frame_specific_representation_info = { 'cartesian': [ RepresentationMapping('x', 'u'), RepresentationMapping('y', 'v'), RepresentationMapping('z', 'w') ], } default_representation = CartesianRepresentation obstime = TimeAttribute(default=None) location = EarthLocationAttribute(default=None) phase = CoordinateAttribute(ICRS, default=None) fixtime = TimeAttribute(default=None) def __init__(self, *args, **kwargs): super(Pointing, self).__init__(*args, **kwargs) @property def elevation(self): """ Elevation above the horizon of the direction, in degree """ return self.phase.transform_to( AltAz(location=self.location, obstime=self.obstime)).alt
class HeliographicCarrington(HeliographicStonyhurst): """ A coordinate or frame in the Carrington Heliographic system. - The origin is the centre of the Sun - The z-axis is aligned with the Sun's north pole - The x and y axes rotate with a period of 25.38 days. The line of zero longitude passed through the disk centre as seen from Earth at 21:36 on 9th Nov 1853. This frame differs from the Stonyhurst version in the definition of the longitude, which is defined using the time-dependant offset described above. Parameters ---------- representation: `~astropy.coordinates.BaseRepresentation` or None. A representation object. If specified, other parameters must be in keyword form. lon: `Angle` object. The longitude for this object (``lat`` must also be given and ``representation`` must be None). lat: `Angle` object. The latitude for this object (``lon`` must also be given and ``representation`` must be None). radius: `astropy.units.Quantity` object, optional, must be keyword. This quantity holds the radial distance. Defaults to the solar radius. obstime: SunPy Time The date and time of the observation, used to convert to heliographic carrington coordinates. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(1*u.deg, 2*u.deg, 3*u.km, ... frame="heliographic_carrington", ... obstime="2010/01/01T00:00:30") >>> sc <SkyCoord (HeliographicCarrington: obstime=2010-01-01T00:00:30.000): (lon, lat, radius) in (deg, deg, km) (1., 2., 3.)> >>> sc = SkyCoord([1,2,3]*u.deg, [4,5,6]*u.deg, [5,6,7]*u.km, ... obstime="2010/01/01T00:00:45", frame="heliographic_carrington") >>> sc <SkyCoord (HeliographicCarrington: obstime=2010-01-01T00:00:45.000): (lon, lat, radius) in (deg, deg, km) [(1., 4., 5.), (2., 5., 6.), (3., 6., 7.)]> """ name = "heliographic_carrington" default_representation = SphericalRepresentation frame_specific_representation_info = { SphericalRepresentation: [RepresentationMapping(reprname='lon', framename='lon', defaultunit=u.deg), RepresentationMapping(reprname='lat', framename='lat', defaultunit=u.deg), RepresentationMapping(reprname='distance', framename='radius', defaultunit=None)], UnitSphericalRepresentation: [RepresentationMapping(reprname='lon', framename='lon', defaultunit=u.deg), RepresentationMapping(reprname='lat', framename='lat', defaultunit=u.deg)], } _wrap_angle = 360*u.deg obstime = TimeFrameAttributeSunPy()
class HeliographicStonyhurst(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Stonyhurst Heliographic system. In a cartesian representation this is also known as the Heliocentric Earth Equatorial (HEEQ) system. This frame has its origin at the solar centre and the north pole above the solar north pole, and the zero line on longitude pointing towards the Earth. A new instance can be created using the following signatures (note that all the arguments must be supplied as keywords):: HeliographicStonyhurst(lon, lat, obstime) HeliographicStonyhurst(lon, lat, radius, obstime) HeliographicStonyhurst(x, y, z, obstime, representation='cartesian') Parameters ---------- representation : `~astropy.coordinates.BaseRepresentation` or `None` A representation object or None to have no data. lon : `~astropy.coordinates.Angle`, optional The longitude for this object (``lat`` must also be given and ``representation`` must be None). lat : `~astropy.coordinates.Angle`, optional The latitude for this object (``lon`` must also be given and ``representation`` must be None). radius : `~astropy.units.Quantity`, optional This quantity holds the radial distance. If not specified, it is, by default, the radius of the photosphere. x : `~astropy.units.Quantity`, optional x coordinate. y : `~astropy.units.Quantity`, optional y coordinate. z : `~astropy.units.Quantity`, optional z coordinate. obstime: `~sunpy.time.Time` The date and time of the observation, used to convert to heliographic carrington coordinates. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(1*u.deg, 1*u.deg, 2*u.km, ... frame="heliographic_stonyhurst", ... obstime="2010/01/01T00:00:45") >>> sc <SkyCoord (HeliographicStonyhurst: obstime=2010-01-01 00:00:45): (lon, lat, radius) in (deg, deg, km) (1., 1., 2.)> >>> sc.frame <HeliographicStonyhurst Coordinate (obstime=2010-01-01 00:00:45): (lon, lat, radius) in (deg, deg, km) (1., 1., 2.)> >>> sc = SkyCoord(HeliographicStonyhurst(-10*u.deg, 2*u.deg)) >>> sc <SkyCoord (HeliographicStonyhurst: obstime=None): (lon, lat, radius) in (deg, deg, km) (-10., 2., 695508.)> Notes ----- This frame will always be converted a 3D frame where the radius defaults to rsun. """ name = "heliographic_stonyhurst" default_representation = SphericalRepresentation frame_specific_representation_info = { SphericalRepresentation: [RepresentationMapping(reprname='lon', framename='lon', defaultunit=u.deg), RepresentationMapping(reprname='lat', framename='lat', defaultunit=u.deg), RepresentationMapping(reprname='distance', framename='radius', defaultunit=None)], CartesianRepresentation: [RepresentationMapping(reprname='x', framename='x'), RepresentationMapping(reprname='y', framename='y'), RepresentationMapping(reprname='z', framename='z')] } obstime = TimeFrameAttributeSunPy() _default_wrap_angle = 180*u.deg def __init__(self, *args, **kwargs): _rep_kwarg = kwargs.get('representation', None) wrap = kwargs.pop('wrap_longitude', True) if ('radius' in kwargs and kwargs['radius'].unit is u.one and quantity_allclose(kwargs['radius'], 1*u.one)): kwargs['radius'] = RSUN_METERS.to(u.km) super(HeliographicStonyhurst, self).__init__(*args, **kwargs) # Make 3D if specified as 2D # If representation was explicitly passed, do not change the rep. if not _rep_kwarg: # If we were passed a 3D rep extract the distance, otherwise # calculate it from RSUN. if isinstance(self._data, UnitSphericalRepresentation): distance = RSUN_METERS.to(u.km) self._data = SphericalRepresentation(lat=self._data.lat, lon=self._data.lon, distance=distance) if wrap and isinstance(self._data, (UnitSphericalRepresentation, SphericalRepresentation)): self._data.lon.wrap_angle = self._default_wrap_angle
class Helioprojective(SunPyBaseCoordinateFrame): """ A coordinate or frame in the Helioprojective (Cartesian) system. This is a projective coordinate system centered around the observer. It is a full spherical coordinate system with position given as longitude theta_x and latitude theta_y. Parameters ---------- representation: `~astropy.coordinates.BaseRepresentation` or None. A representation object. If specified, other parameters must be in keyword form. Tx: `~astropy.coordinates.Angle` or `~astropy.units.Quantity` X-axis coordinate. Ty: `~astropy.coordinates.Angle` or `~astropy.units.Quantity` Y-axis coordinate. distance: `~astropy.units.Quantity` The radial distance from the observer to the coordinate point. obstime: SunPy Time The date and time of the observation, used to convert to heliographic carrington coordinates. observer: `~sunpy.coordinates.frames.HeliographicStonyhurst` The coordinate of the observer in the solar system. rsun: `~astropy.units.Quantity` The physical (length) radius of the Sun. Used to calculate the position of the limb for calculating distance from the observer to the coordinate. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km, obstime="2010/01/01T00:00:00", ... frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2010-01-01 00:00:00, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, km) (0., 0., 5.)> >>> sc = SkyCoord(0*u.deg, 0*u.deg, obstime="2010/01/01T00:00:00", frame="helioprojective") >>> sc <SkyCoord (Helioprojective: obstime=2010-01-01 00:00:00, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty) in arcsec (0., 0.)> """ default_representation = SphericalRepresentation frame_specific_representation_info = { SphericalRepresentation: [RepresentationMapping(reprname='lon', framename='Tx', defaultunit=u.arcsec), RepresentationMapping(reprname='lat', framename='Ty', defaultunit=u.arcsec), RepresentationMapping(reprname='distance', framename='distance', defaultunit=None)], UnitSphericalRepresentation: [RepresentationMapping(reprname='lon', framename='Tx', defaultunit=u.arcsec), RepresentationMapping(reprname='lat', framename='Ty', defaultunit=u.arcsec)], } obstime = TimeFrameAttributeSunPy() rsun = Attribute(default=RSUN_METERS.to(u.km)) observer = ObserverCoordinateAttribute(HeliographicStonyhurst, default="earth") def __init__(self, *args, **kwargs): wrap = kwargs.pop('wrap_longitude', True) BaseCoordinateFrame.__init__(self, *args, **kwargs) if wrap and isinstance(self._data, (UnitSphericalRepresentation, SphericalRepresentation)): self._data.lon.wrap_angle = 180*u.deg def calculate_distance(self): """ This method calculates the third coordinate of the Helioprojective frame. It assumes that the coordinate point is on the disk of the Sun at the rsun radius. If a point in the frame is off limb then NaN will be returned. Returns ------- new_frame : `~sunpy.coordinates.frames.HelioProjective` A new frame instance with all the attributes of the original but now with a third coordinate. """ # Skip if we already are 3D if (isinstance(self._data, SphericalRepresentation) and not (self.distance.unit is u.one and quantity_allclose(self.distance, 1*u.one))): return self if not isinstance(self.observer, BaseCoordinateFrame): raise ConvertError("Cannot calculate distance to the solar disk " "for observer '{}' " "without `obstime` being specified.".format(self.observer)) rep = self.represent_as(UnitSphericalRepresentation) lat, lon = rep.lat, rep.lon alpha = np.arccos(np.cos(lat) * np.cos(lon)).to(lat.unit) c = self.observer.radius**2 - self.rsun**2 b = -2 * self.observer.radius * np.cos(alpha) d = ((-1*b) - np.sqrt(b**2 - 4*c)) / 2 return self.realize_frame(SphericalRepresentation(lon=lon, lat=lat, distance=d))
class HeliographicStonyhurst(BaseCoordinateFrame): """ A coordinate or frame in the Stonyhurst Heliographic system. This frame has its origin at the solar centre and the north pole above the solar north pole, and the zero line on longitude pointing towards the Earth. Parameters ---------- representation: `~astropy.coordinates.BaseRepresentation` or `None` A representation object or None to have no data. lon: `Angle` object. The longitude for this object (``lat`` must also be given and ``representation`` must be None). lat: `Angle` object. The latitude for this object (``lon`` must also be given and ``representation`` must be None). radius: `astropy.units.Quantity` object. This quantity holds the radial distance. If not specified, it is, by default, the radius of the photosphere. Optional. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(1*u.deg, 1*u.deg, 2*u.km, ... frame="heliographic_stonyhurst", ... dateobs="2010/01/01T00:00:45") >>> sc <SkyCoord (HelioGraphicStonyhurst): dateobs=2010-01-01 00:00:45, lon=1.0 deg, lat=1.0 deg, rad=2.0 km> >>> sc.frame <HelioGraphicStonyhurst Coordinate: dateobs=2010-01-01 00:00:45, lon=1.0 deg, lat=1.0 deg, rad=2.0 km> >>> sc = SkyCoord(HelioGraphicStonyhurst(-10*u.deg, 2*u.deg)) >>> sc <SkyCoord (HelioGraphicStonyhurst): dateobs=None, lon=-10.0 deg, lat=2.0 deg, rad=695508.0 km> Notes ----- This frame will always be converted a 3D frame where the radius defaults to rsun. """ name = "heliographic_stonyhurst" default_representation = SphericalWrap180Representation _frame_specific_representation_info = { 'spherical': [ RepresentationMapping('lon', 'lon', 'recommended'), RepresentationMapping('lat', 'lat', 'recommended'), RepresentationMapping('distance', 'radius', 'recommended') ], 'sphericalwrap180': [ RepresentationMapping('lon', 'lon', 'recommended'), RepresentationMapping('lat', 'lat', 'recommended'), RepresentationMapping('distance', 'radius', 'recommended') ] } dateobs = TimeFrameAttributeSunPy() def __init__(self, *args, **kwargs): _rep_kwarg = kwargs.get('representation', None) super(HeliographicStonyhurst, self).__init__(*args, **kwargs) # Make 3D if specified as 2D # If representation was explicitly passed, do not change the rep. if not _rep_kwarg: # If we were passed a 3D rep extract the distance, otherwise # calculate it from RSUN. distance = None if isinstance(self._data, SphericalRepresentation): distance = self._data.distance elif isinstance(self._data, UnitSphericalRepresentation): distance = RSUN_METERS.to(u.km) if distance: self._data = self.default_representation(lat=self._data.lat, lon=self._data.lon, distance=distance)
class Helioprojective(BaseCoordinateFrame): """ A coordinate or frame in the Helioprojective (Cartesian) system. This is a projective coordinate system centered around the observer. It is a full spherical coordinate system with position given as longitude theta_x and latitude theta_y. Parameters ---------- representation: `~astropy.coordinates.BaseRepresentation` or None. A representation object. If specified, other parameters must be in keyword form. Tx: `~astropy.coordinates.Angle` or `~astropy.units.Quantity` X-axis coordinate. Ty: `~astropy.coordinates.Angle` or `~astropy.units.Quantity` Y-axis coordinate. distance: `~astropy.units.Quantity` The radial distance from the observer to the coordinate point. L0: `~astropy.coordinates.Angle` The Heliographic (Stonyhurst) Longitude of the observer. B0: `~astropy.coordinates.Angle` or `~astropy.units.Quantity` The Heliographic (Stonyhurst) Latitude of the observer. D0: `Quantity` object. Represents the distance between observer and solar center. **Defaults to 1 AU**. Examples -------- >>> from astropy.coordinates import SkyCoord >>> import sunpy.coordinates >>> import astropy.units as u >>> sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km, dateobs="2010/01/01T00:00:00", ... frame="helioprojective") >>> sc <SkyCoord (HelioProjective): dateobs=2010-01-01 00:00:00, D0=149597870.7 km , Tx=0.0 arcsec, Ty=0.0 arcsec, distance=5.0 km> >>> sc = SkyCoord(0*u.deg, 0*u.deg, dateobs="2010/01/01T00:00:00", frame="helioprojective") >>> sc <SkyCoord (HelioProjective): dateobs=2010-01-01 00:00:00, D0=149597870.7 km , Tx=0.0 arcsec, Ty=0.0 arcsec, distance=149597870.7 km> """ default_representation = SphericalWrap180Representation _frame_specific_representation_info = { 'spherical': [ RepresentationMapping('lon', 'Tx', u.arcsec), RepresentationMapping('lat', 'Ty', u.arcsec), RepresentationMapping('distance', 'distance', u.km) ], 'sphericalwrap180': [ RepresentationMapping('lon', 'Tx', u.arcsec), RepresentationMapping('lat', 'Ty', u.arcsec), RepresentationMapping('distance', 'distance', u.km) ], 'unitspherical': [ RepresentationMapping('lon', 'Tx', u.arcsec), RepresentationMapping('lat', 'Ty', u.arcsec) ], 'unitsphericalwrap180': [ RepresentationMapping('lon', 'Tx', u.arcsec), RepresentationMapping('lat', 'Ty', u.arcsec) ] } D0 = FrameAttribute(default=(1 * u.au).to(u.km)) dateobs = TimeFrameAttributeSunPy() L0 = FrameAttribute(default=0 * u.deg) B0 = FrameAttribute(default=0 * u.deg) rsun = FrameAttribute(default=RSUN_METERS.to(u.km)) def __init__(self, *args, **kwargs): _rep_kwarg = kwargs.get('representation', None) BaseCoordinateFrame.__init__(self, *args, **kwargs) # Convert from Spherical to SphericalWrap180 # If representation was explicitly passed, do not change the rep. if not _rep_kwarg: # The base __init__ will make this a UnitSphericalRepresentation # This makes it Wrap180 instead if isinstance(self._data, UnitSphericalRepresentation): self._data = UnitSphericalWrap180Representation( lat=self._data.lat, lon=self._data.lon) self.representation = UnitSphericalWrap180Representation # Make a Spherical Wrap180 instead elif isinstance(self._data, SphericalRepresentation): self._data = SphericalWrap180Representation( lat=self._data.lat, lon=self._data.lon, distance=self._data.distance) self.representation = SphericalWrap180Representation def calculate_distance(self): """ This method calculates the third coordnate of the Helioprojective frame. It assumes that the coordinate point is on the disk of the Sun at the rsun radius. If a point in the frame is off limb then NaN will be returned. Returns ------- new_frame : `~sunpy.coordinates.frames.HelioProjective` A new frame instance with all the attributes of the original but now with a third coordinate. """ # Skip if we already are 3D if isinstance(self._data, SphericalRepresentation): return self rep = self.represent_as(UnitSphericalWrap180Representation) lat, lon = rep.lat, rep.lon alpha = np.arccos(np.cos(lat) * np.cos(lon)).to(lat.unit) c = self.D0**2 - self.rsun**2 b = -2 * self.D0.to(u.m) * np.cos(alpha) d = ((-1 * b) - np.sqrt(b**2 - 4 * c)) / 2 return self.realize_frame( SphericalWrap180Representation(lon=lon, lat=lat, distance=d))
class FakeICRS(ICRS): frame_specific_representation_info = { 'spherical': [RepresentationMapping('lon', 'ra', u.hourangle), RepresentationMapping('lat', 'dec', None), RepresentationMapping('distance', 'distance')] # should fall back to default of None unit }