class LSR(BaseRADecFrame): r"""A coordinate or frame in the Local Standard of Rest (LSR). This coordinate frame is axis-aligned and co-spatial with `ICRS`, but has a velocity offset relative to the solar system barycenter to remove the peculiar motion of the sun relative to the LSR. Roughly, the LSR is the mean velocity of the stars in the solar neighborhood, but the precise definition of which depends on the study. As defined in Schönrich et al. (2010): "The LSR is the rest frame at the location of the Sun of a star that would be on a circular orbit in the gravitational potential one would obtain by azimuthally averaging away non-axisymmetric features in the actual Galactic potential." No such orbit truly exists, but it is still a commonly used velocity frame. We use default values from Schönrich et al. (2010) for the barycentric velocity relative to the LSR, which is defined in Galactic (right-handed) cartesian velocity components :math:`(U, V, W) = (11.1, 12.24, 7.25)~{{\rm km}}~{{\rm s}}^{{-1}}`. These values are customizable via the ``v_bary`` argument which specifies the velocity of the solar system barycenter with respect to the LSR. The frame attributes are listed under **Other Parameters**. """ # frame attributes: v_bary = DifferentialAttribute(default=v_bary_Schoenrich2010, allowed_classes=[r.CartesianDifferential])
class ExternalGalaxyFrame(BaseCoordinateFrame): """Astropy coordinate frame centered on an external galaxy. The frame is defined by sky coordinate, heliocentric distance and velocity, and inclination and position angle. Modeled on astropy's Galactocentric class, but without that class's defaults-setting mechanism. x, y, and z are defined such that with inclination and position angle both 0, x points along RA, y along dec, and z into sky. With nonzero inclination y will still point within the plane of the sky, while x and z rotate about the y axis. Keyword Arguments: gal_coord: Scalar SkyCoord or Frame object Contains sky position of galaxy gal_distance: Quantity (units of length, e.g. u.kpc) Distance to galaxy galvel_heliocentric: CartesianDifferential, units of velocity 3-d heliocentric velocity of galaxy, in the sky-aligned cartesian frame pointing to galaxy (x=East, y=North, z=distance) inclination: Quantity (units of angle) PA: Quantity (units of angle) """ default_representation = r.CartesianRepresentation default_differential = r.CartesianDifferential # frame attributes # notes: apparently you can't call something "distance"? # also, ipython reload insufficient to reset attributes - have to quit out and restart python? gal_coord = CoordinateAttribute(frame=ICRS) # PA defined relative to ICRS ra/dec gal_distance = QuantityAttribute(unit=u.kpc) galvel_heliocentric = DifferentialAttribute( allowed_classes=[r.CartesianDifferential]) inclination = QuantityAttribute(unit=u.deg) PA = QuantityAttribute(unit=u.deg) def __init__(self, *args, skyalign=False, **kwargs): # left some example code for subclasses in here default_params = { 'gal_coord': ICRS(ra=10.68470833 * u.degree, dec=41.26875 * u.degree), "gal_distance": 780.0 * u.kpc, "galvel_heliocentric": r.CartesianDifferential([125.2, -73.8, -300.] * (u.km / u.s)), "inclination": (-77.) * u.degree, "PA": 37. * u.degree, } kwds = dict() kwds.update(default_params) if skyalign: kwds['inclination'] = 0. * u.deg kwds['PA'] = 0. * u.deg kwds.update(kwargs) super().__init__(*args, **kwds)
class TestFrame2(BaseCoordinateFrame): attrtest = DifferentialAttribute(default=dif, allowed_classes=[ r.CartesianDifferential, r.CylindricalDifferential ])
class Galactocentric(BaseCoordinateFrame): r""" A coordinate or frame in the Galactocentric system. This frame allows specifying the Sun-Galactic center distance, the height of the Sun above the Galactic midplane, and the solar motion relative to the Galactic center. However, as there is no modern standard definition of a Galactocentric reference frame, it is important to pay attention to the default values used in this class if precision is important in your code. The default values of the parameters of this frame are taken from the original definition of the frame in 2014. As such, the defaults are somewhat out of date relative to recent measurements made possible by, e.g., Gaia. The defaults can, however, be changed at runtime by setting the parameter set name in `~astropy.coordinates.galactocentric_frame_defaults`. The current default parameter set is ``"pre-v4.0"``, indicating that the parameters were adopted before ``astropy`` version 4.0. A regularly-updated parameter set can instead be used by setting ``galactocentric_frame_defaults.set ('latest')``, and other parameter set names may be added in future versions. To find out the scientific papers that the current default parameters are derived from, use ``galcen.frame_attribute_references`` (where ``galcen`` is an instance of this frame), which will update even if the default parameter set is changed. The position of the Sun is assumed to be on the x axis of the final, right-handed system. That is, the x axis points from the position of the Sun projected to the Galactic midplane to the Galactic center -- roughly towards :math:`(l,b) = (0^\circ,0^\circ)`. For the default transformation (:math:`{\rm roll}=0^\circ`), the y axis points roughly towards Galactic longitude :math:`l=90^\circ`, and the z axis points roughly towards the North Galactic Pole (:math:`b=90^\circ`). For a more detailed look at the math behind this transformation, see the document :ref:`astropy:coordinates-galactocentric`. The frame attributes are listed under **Other Parameters**. """ default_representation = r.CartesianRepresentation default_differential = r.CartesianDifferential # frame attributes galcen_coord = CoordinateAttribute(frame=ICRS) galcen_distance = QuantityAttribute(unit=u.kpc) galcen_v_sun = DifferentialAttribute( allowed_classes=[r.CartesianDifferential]) z_sun = QuantityAttribute(unit=u.pc) roll = QuantityAttribute(unit=u.deg) def __init__(self, *args, **kwargs): # Set default frame attribute values based on the ScienceState instance # for the solar parameters defined above default_params = galactocentric_frame_defaults.get() self.frame_attribute_references = \ galactocentric_frame_defaults.references.copy() for k in default_params: if k in kwargs: # If a frame attribute is set by the user, remove its reference self.frame_attribute_references.pop(k, None) # Keep the frame attribute if it is set by the user, otherwise use # the default value kwargs[k] = kwargs.get(k, default_params[k]) super().__init__(*args, **kwargs) @classmethod def get_roll0(cls): """ The additional roll angle (about the final x axis) necessary to align the final z axis to match the Galactic yz-plane. Setting the ``roll`` frame attribute to -this method's return value removes this rotation, allowing the use of the `Galactocentric` frame in more general contexts. """ # note that the actual value is defined at the module level. We make at # a property here because this module isn't actually part of the public # API, so it's better for it to be accessable from Galactocentric return _ROLL0
class Galactocentric(BaseCoordinateFrame): r""" A coordinate or frame in the Galactocentric system. This frame requires specifying the Sun-Galactic center distance, and optionally the height of the Sun above the Galactic midplane. The position of the Sun is assumed to be on the x axis of the final, right-handed system. That is, the x axis points from the position of the Sun projected to the Galactic midplane to the Galactic center -- roughly towards :math:`(l,b) = (0^\circ,0^\circ)`. For the default transformation (:math:`{\rm roll}=0^\circ`), the y axis points roughly towards Galactic longitude :math:`l=90^\circ`, and the z axis points roughly towards the North Galactic Pole (:math:`b=90^\circ`). The default position of the Galactic Center in ICRS coordinates is taken from Reid et al. 2004, http://adsabs.harvard.edu/abs/2004ApJ...616..872R. .. math:: {\rm RA} = 17:45:37.224~{\rm hr}\\ {\rm Dec} = -28:56:10.23~{\rm deg} The default distance to the Galactic Center is 8.3 kpc, e.g., Gillessen et al. (2009), https://ui.adsabs.harvard.edu/#abs/2009ApJ...692.1075G/abstract The default height of the Sun above the Galactic midplane is taken to be 27 pc, as measured by Chen et al. (2001), https://ui.adsabs.harvard.edu/#abs/2001ApJ...553..184C/abstract The default solar motion relative to the Galactic center is taken from a combination of Schönrich et al. (2010) [for the peculiar velocity] and Bovy (2015) [for the circular velocity at the solar radius], https://ui.adsabs.harvard.edu/#abs/2010MNRAS.403.1829S/abstract https://ui.adsabs.harvard.edu/#abs/2015ApJS..216...29B/abstract For a more detailed look at the math behind this transformation, see the document :ref:`coordinates-galactocentric`. The frame attributes are listed under **Other Parameters**. """ default_representation = r.CartesianRepresentation default_differential = r.CartesianDifferential # frame attributes galcen_coord = CoordinateAttribute(default=ICRS(ra=266.4051 * u.degree, dec=-28.936175 * u.degree), frame=ICRS) galcen_distance = QuantityAttribute(default=8.3 * u.kpc) galcen_v_sun = DifferentialAttribute( default=r.CartesianDifferential([11.1, 220 + 12.24, 7.25] * u.km / u.s), allowed_classes=[r.CartesianDifferential]) z_sun = QuantityAttribute(default=27. * u.pc) roll = QuantityAttribute(default=0. * u.deg) def __init__(self, *args, **kwargs): # backwards-compatibility if ('galcen_ra' in kwargs or 'galcen_dec' in kwargs): warnings.warn( "The arguments 'galcen_ra', and 'galcen_dec' are " "deprecated in favor of specifying the sky coordinate" " as a CoordinateAttribute using the 'galcen_coord' " "argument", AstropyDeprecationWarning) galcen_kw = dict() galcen_kw['ra'] = kwargs.pop('galcen_ra', self.galcen_coord.ra) galcen_kw['dec'] = kwargs.pop('galcen_dec', self.galcen_coord.dec) kwargs['galcen_coord'] = ICRS(**galcen_kw) super().__init__(*args, **kwargs) @property def galcen_ra(self): warnings.warn( "The attribute 'galcen_ra' is deprecated. Use " "'.galcen_coord.ra' instead.", AstropyDeprecationWarning) return self.galcen_coord.ra @property def galcen_dec(self): warnings.warn( "The attribute 'galcen_dec' is deprecated. Use " "'.galcen_coord.dec' instead.", AstropyDeprecationWarning) return self.galcen_coord.dec @classmethod def get_roll0(cls): """ The additional roll angle (about the final x axis) necessary to align the final z axis to match the Galactic yz-plane. Setting the ``roll`` frame attribute to -this method's return value removes this rotation, allowing the use of the `Galactocentric` frame in more general contexts. """ # note that the actual value is defined at the module level. We make at # a property here because this module isn't actually part of the public # API, so it's better for it to be accessable from Galactocentric return _ROLL0
class Galactocentric(BaseCoordinateFrame): r""" A coordinate or frame in the Galactocentric system. This frame allows specifying the Sun-Galactic center distance, the height of the Sun above the Galactic midplane, and the solar motion relative to the Galactic center. However, as there is no modern standard definition of a Galactocentric reference frame, it is important to pay attention to the default values used in this class if precision is important in your code. The default values of the parameters of this frame are taken from the original definition of the frame in 2014. As such, the defaults are somewhat out of date relative to recent measurements made possible by, e.g., Gaia. The defaults can, however, be changed at runtime by setting the parameter set name in `~astropy.coordinates.galactocentric_frame_defaults`. The current default parameter set is ``"pre-v4.0"``, indicating that the parameters were adopted before ``astropy`` version 4.0. A regularly-updated parameter set can instead be used by setting ``galactocentric_frame_defaults.set ('latest')``, and other parameter set names may be added in future versions. To find out the scientific papers that the current default parameters are derived from, use ``galcen.frame_attribute_references`` (where ``galcen`` is an instance of this frame), which will update even if the default parameter set is changed. The position of the Sun is assumed to be on the x axis of the final, right-handed system. That is, the x axis points from the position of the Sun projected to the Galactic midplane to the Galactic center -- roughly towards :math:`(l,b) = (0^\circ,0^\circ)`. For the default transformation (:math:`{\rm roll}=0^\circ`), the y axis points roughly towards Galactic longitude :math:`l=90^\circ`, and the z axis points roughly towards the North Galactic Pole (:math:`b=90^\circ`). For a more detailed look at the math behind this transformation, see the document :ref:`coordinates-galactocentric`. The frame attributes are listed under **Other Parameters**. """ default_representation = r.CartesianRepresentation default_differential = r.CartesianDifferential # frame attributes galcen_coord = CoordinateAttribute(frame=ICRS) galcen_distance = QuantityAttribute(unit=u.kpc) galcen_v_sun = DifferentialAttribute( allowed_classes=[r.CartesianDifferential]) z_sun = QuantityAttribute(unit=u.pc) roll = QuantityAttribute(unit=u.deg) def __init__(self, *args, **kwargs): # Set default frame attribute values based on the ScienceState instance # for the solar parameters defined above default_params = galactocentric_frame_defaults.get() self.frame_attribute_references = \ galactocentric_frame_defaults._references.copy() warn = False for k in default_params: # If a frame attribute is set by the user, remove its reference self.frame_attribute_references.pop(k, None) # If a parameter is read from the defaults, we might want to warn # the user that the defaults will change (see below) if k not in kwargs: warn = True # Keep the frame attribute if it is set by the user, otherwise use # the default value kwargs[k] = kwargs.get(k, default_params[k]) # If the frame defaults have not been updated with the ScienceState # class, and the user uses any default parameter value, raise a # deprecation warning to inform them that the defaults will change in # the future: if galactocentric_frame_defaults._value == 'pre-v4.0' and warn: docs_link = 'http://docs.astropy.org/en/latest/coordinates/galactocentric.html' warnings.warn( 'In v4.1 and later versions, the Galactocentric ' 'frame will adopt default parameters that may update ' 'with time. An updated default parameter set is ' 'already available through the ' 'astropy.coordinates.galactocentric_frame_defaults ' 'ScienceState object, as described in but the ' 'default is currently still set to the pre-v4.0 ' 'parameter defaults. The safest way to guard against ' 'changing default parameters in the future is to ' 'either (1) specify all Galactocentric frame ' 'attributes explicitly when using the frame, ' 'or (2) set the galactocentric_frame_defaults ' f'parameter set name explicitly. See {docs_link} for more ' 'information.', AstropyDeprecationWarning) super().__init__(*args, **kwargs) @classmethod def get_roll0(cls): """ The additional roll angle (about the final x axis) necessary to align the final z axis to match the Galactic yz-plane. Setting the ``roll`` frame attribute to -this method's return value removes this rotation, allowing the use of the `Galactocentric` frame in more general contexts. """ # note that the actual value is defined at the module level. We make at # a property here because this module isn't actually part of the public # API, so it's better for it to be accessable from Galactocentric return _ROLL0