|
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 1, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"data": { |
|
"text/plain": [ |
|
"'3.0.4'" |
|
] |
|
}, |
|
"execution_count": 1, |
|
"metadata": {}, |
|
"output_type": "execute_result" |
|
} |
|
], |
|
"source": [ |
|
"import astropy\n", |
|
"astropy.__version__" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 2, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"import numpy as np\n", |
|
"import astropy.units as u\n", |
|
"import astropy.coordinates as coord" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 3, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"\n", |
|
" A coordinate or frame in the ICRS system.\n", |
|
"\n", |
|
" If you're looking for \"J2000\" coordinates, and aren't sure if you want to\n", |
|
" use this or `~astropy.coordinates.FK5`, you probably want to use ICRS. It's\n", |
|
" more well-defined as a catalog coordinate and is an inertial system, and is\n", |
|
" very close (within tens of milliarcseconds) to J2000 equatorial.\n", |
|
"\n", |
|
" For more background on the ICRS and related coordinate transformations, see the\n", |
|
" references provided in the :ref:`astropy-coordinates-seealso` section of the\n", |
|
" documentation.\n", |
|
" \n", |
|
" Parameters\n", |
|
" ----------\n", |
|
" data : `BaseRepresentation` subclass instance\n", |
|
" A representation object or ``None`` to have no data (or use the\n", |
|
" coordinate component arguments, see below).\n", |
|
" \n", |
|
" ra : `Angle`, optional, must be keyword\n", |
|
" The RA for this object (``dec`` must also be given and ``representation``\n", |
|
" must be None).\n", |
|
" dec : `Angle`, optional, must be keyword\n", |
|
" The Declination for this object (``ra`` must also be given and\n", |
|
" ``representation`` must be None).\n", |
|
" distance : `~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The Distance for this object along the line-of-sight.\n", |
|
" (``representation`` must be None).\n", |
|
"\n", |
|
" pm_ra_cosdec : :class:`~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The proper motion in Right Ascension (including the ``cos(dec)`` factor)\n", |
|
" for this object (``pm_dec`` must also be given).\n", |
|
" pm_dec : :class:`~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The proper motion in Declination for this object (``pm_ra_cosdec`` must\n", |
|
" also be given).\n", |
|
" radial_velocity : :class:`~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The radial velocity of this object.\n", |
|
"\n", |
|
" representation_type : `BaseRepresentation` subclass, str, optional\n", |
|
" A representation class or string name of a representation class. This\n", |
|
" sets the expected input representation class, thereby changing the\n", |
|
" expected keyword arguments for the data passed in. For example, passing\n", |
|
" ``representation_type='cartesian'`` will make the classes expect\n", |
|
" position data with cartesian names, i.e. ``x, y, z`` in most cases.\n", |
|
" differential_type : `BaseDifferential` subclass, str, dict, optional\n", |
|
" A differential class or dictionary of differential classes (currently\n", |
|
" only a velocity differential with key 's' is supported). This sets the\n", |
|
" expected input differential class, thereby changing the expected keyword\n", |
|
" arguments of the data passed in. For example, passing\n", |
|
" ``differential_type='cartesian'`` will make the classes expect velocity\n", |
|
" data with the argument names ``v_x, v_y, v_z``.\n", |
|
" copy : bool, optional\n", |
|
" If `True` (default), make copies of the input coordinate arrays.\n", |
|
" Can only be passed in as a keyword argument.\n", |
|
" \n", |
|
"\n" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"print(coord.ICRS.__doc__)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 4, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"# ICRS cartesian initialization works as in docstring\n", |
|
"c = coord.ICRS(1,2,3, representation_type='cartesian')\n", |
|
"c = coord.ICRS(x=1,y=2,z=3, representation_type='cartesian')" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 5, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"ename": "ValueError", |
|
"evalue": "For differential object '<CartesianDifferential (d_x, d_y, d_z) [dimensionless]\n (1., 2., 3.)>', expected unit key = '' but received key = 's'", |
|
"output_type": "error", |
|
"traceback": [ |
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", |
|
"\u001b[0;32m<ipython-input-5-367a4f8fe60e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Issue: But it looks like velocities cannot be unitless and need to be at least [1 /time]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;31m# however the error message is confusing...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcoord\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mICRS\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mz\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv_x\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv_y\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv_z\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrepresentation_type\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'cartesian'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdifferential_type\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'cartesian'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
|
"\u001b[0;32m~/miniconda3/envs/research/lib/python3.7/site-packages/astropy/coordinates/baseframe.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, copy, representation_type, differential_type, *args, **kwargs)\u001b[0m\n\u001b[1;32m 557\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdifferential_data\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 558\u001b[0m self._data = representation_data.with_differentials(\n\u001b[0;32m--> 559\u001b[0;31m {'s': differential_data})\n\u001b[0m\u001b[1;32m 560\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 561\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrepresentation_data\u001b[0m \u001b[0;31m# possibly None.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
|
"\u001b[0;32m~/miniconda3/envs/research/lib/python3.7/site-packages/astropy/coordinates/representation.py\u001b[0m in \u001b[0;36mwith_differentials\u001b[0;34m(self, differentials)\u001b[0m\n\u001b[1;32m 732\u001b[0m copy=False)\n\u001b[1;32m 733\u001b[0m new_rep._differentials.update(\n\u001b[0;32m--> 734\u001b[0;31m new_rep._validate_differentials(differentials))\n\u001b[0m\u001b[1;32m 735\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 736\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mnew_rep\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
|
"\u001b[0;32m~/miniconda3/envs/research/lib/python3.7/site-packages/astropy/coordinates/representation.py\u001b[0m in \u001b[0;36m_validate_differentials\u001b[0;34m(self, differentials)\u001b[0m\n\u001b[1;32m 548\u001b[0m raise ValueError(\"For differential object '{0}', expected \"\n\u001b[1;32m 549\u001b[0m \u001b[0;34m\"unit key = '{1}' but received key = '{2}'\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 550\u001b[0;31m .format(repr(diff), expected_key, key))\n\u001b[0m\u001b[1;32m 551\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 552\u001b[0m \u001b[0;31m# For now, we are very rigid: differentials must have the same shape\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
|
"\u001b[0;31mValueError\u001b[0m: For differential object '<CartesianDifferential (d_x, d_y, d_z) [dimensionless]\n (1., 2., 3.)>', expected unit key = '' but received key = 's'" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"# Issue: But it looks like velocities cannot be unitless and need to be at least [1 /time]\n", |
|
"# however the error message is confusing...\n", |
|
"c = coord.ICRS(x=1,y=2,z=3, v_x=1, v_y=2, v_z=3, representation_type='cartesian', differential_type='cartesian')" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 6, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"name": "stdout", |
|
"output_type": "stream", |
|
"text": [ |
|
"\n", |
|
" A coordinate or frame in the Galactic coordinate system.\n", |
|
"\n", |
|
" This frame is used in a variety of Galactic contexts because it has as its\n", |
|
" x-y plane the plane of the Milky Way. The positive x direction (i.e., the\n", |
|
" l=0, b=0 direction) points to the center of the Milky Way and the z-axis\n", |
|
" points toward the North Galactic Pole (following the IAU's 1958 definition\n", |
|
" [1]_). However, unlike the `~astropy.coordinates.Galactocentric` frame, the\n", |
|
" *origin* of this frame in 3D space is the solar system barycenter, not\n", |
|
" the center of the Milky Way.\n", |
|
" \n", |
|
" Parameters\n", |
|
" ----------\n", |
|
" data : `BaseRepresentation` subclass instance\n", |
|
" A representation object or ``None`` to have no data (or use the\n", |
|
" coordinate component arguments, see below).\n", |
|
" \n", |
|
" l : `Angle`, optional, must be keyword\n", |
|
" The Galactic longitude for this object (``b`` must also be given and\n", |
|
" ``representation`` must be None).\n", |
|
" b : `Angle`, optional, must be keyword\n", |
|
" The Galactic latitude for this object (``l`` must also be given and\n", |
|
" ``representation`` must be None).\n", |
|
" distance : `~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The Distance for this object along the line-of-sight.\n", |
|
"\n", |
|
" pm_l_cosb : :class:`~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The proper motion in Galactic longitude (including the ``cos(b)`` term)\n", |
|
" for this object (``pm_b`` must also be given).\n", |
|
" pm_b : :class:`~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The proper motion in Galactic latitude for this object (``pm_l_cosb``\n", |
|
" must also be given).\n", |
|
" radial_velocity : :class:`~astropy.units.Quantity`, optional, must be keyword\n", |
|
" The radial velocity of this object.\n", |
|
"\n", |
|
" representation_type : `BaseRepresentation` subclass, str, optional\n", |
|
" A representation class or string name of a representation class. This\n", |
|
" sets the expected input representation class, thereby changing the\n", |
|
" expected keyword arguments for the data passed in. For example, passing\n", |
|
" ``representation_type='cartesian'`` will make the classes expect\n", |
|
" position data with cartesian names, i.e. ``x, y, z`` in most cases.\n", |
|
" differential_type : `BaseDifferential` subclass, str, dict, optional\n", |
|
" A differential class or dictionary of differential classes (currently\n", |
|
" only a velocity differential with key 's' is supported). This sets the\n", |
|
" expected input differential class, thereby changing the expected keyword\n", |
|
" arguments of the data passed in. For example, passing\n", |
|
" ``differential_type='cartesian'`` will make the classes expect velocity\n", |
|
" data with the argument names ``v_x, v_y, v_z``.\n", |
|
" copy : bool, optional\n", |
|
" If `True` (default), make copies of the input coordinate arrays.\n", |
|
" Can only be passed in as a keyword argument.\n", |
|
" \n", |
|
" Notes\n", |
|
" -----\n", |
|
" .. [1] Blaauw, A.; Gum, C. S.; Pawsey, J. L.; Westerhout, G. (1960), \"The\n", |
|
" new I.A.U. system of galactic coordinates (1958 revision),\"\n", |
|
" `MNRAS, Vol 121, pp.123 <http://adsabs.harvard.edu/abs/1960MNRAS.121..123B>`_.\n", |
|
"\n", |
|
"\n", |
|
"class Galactic(BaseCoordinateFrame):\n", |
|
" \"\"\"\n", |
|
" A coordinate or frame in the Galactic coordinate system.\n", |
|
"\n", |
|
" This frame is used in a variety of Galactic contexts because it has as its\n", |
|
" x-y plane the plane of the Milky Way. The positive x direction (i.e., the\n", |
|
" l=0, b=0 direction) points to the center of the Milky Way and the z-axis\n", |
|
" points toward the North Galactic Pole (following the IAU's 1958 definition\n", |
|
" [1]_). However, unlike the `~astropy.coordinates.Galactocentric` frame, the\n", |
|
" *origin* of this frame in 3D space is the solar system barycenter, not\n", |
|
" the center of the Milky Way.\n", |
|
" \"\"\"\n", |
|
"\n", |
|
" frame_specific_representation_info = {\n", |
|
" r.SphericalRepresentation: [\n", |
|
" RepresentationMapping('lon', 'l'),\n", |
|
" RepresentationMapping('lat', 'b')\n", |
|
" ],\n", |
|
" r.CartesianRepresentation: [\n", |
|
" RepresentationMapping('x', 'u'),\n", |
|
" RepresentationMapping('y', 'v'),\n", |
|
" RepresentationMapping('z', 'w')\n", |
|
" ],\n", |
|
" r.CartesianDifferential: [\n", |
|
" RepresentationMapping('d_x', 'U', u.km/u.s),\n", |
|
" RepresentationMapping('d_y', 'V', u.km/u.s),\n", |
|
" RepresentationMapping('d_z', 'W', u.km/u.s)\n", |
|
" ]\n", |
|
" }\n", |
|
"\n", |
|
" default_representation = r.SphericalRepresentation\n", |
|
" default_differential = r.SphericalCosLatDifferential\n", |
|
"\n", |
|
" # North galactic pole and zeropoint of l in FK4/FK5 coordinates. Needed for\n", |
|
" # transformations to/from FK4/5\n", |
|
"\n", |
|
" # These are from the IAU's definition of galactic coordinates\n", |
|
" _ngp_B1950 = FK4NoETerms(ra=192.25*u.degree, dec=27.4*u.degree)\n", |
|
" _lon0_B1950 = Angle(123, u.degree)\n", |
|
"\n", |
|
" # These are *not* from Reid & Brunthaler 2004 - instead, they were\n", |
|
" # derived by doing:\n", |
|
" #\n", |
|
" # >>> FK4NoETerms(ra=192.25*u.degree, dec=27.4*u.degree).transform_to(FK5)\n", |
|
" #\n", |
|
" # This gives better consistency with other codes than using the values\n", |
|
" # from Reid & Brunthaler 2004 and the best self-consistency between FK5\n", |
|
" # -> Galactic and FK5 -> FK4 -> Galactic. The lon0 angle was found by\n", |
|
" # optimizing the self-consistency.\n", |
|
" _ngp_J2000 = FK5(ra=192.8594812065348*u.degree, dec=27.12825118085622*u.degree)\n", |
|
" _lon0_J2000 = Angle(122.9319185680026, u.degree)\n", |
|
"\n" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"# The same docstring appears for coords.Galactic\n", |
|
"# because the docstring templating gets it from `basefrome.py` `base_doc`.\n", |
|
"# However, coords.Galactic cartesian coordinates are actually defined with names (u,v,w,U,V,W).\n", |
|
"\n", |
|
"print(coord.Galactic.__doc__)\n", |
|
"import inspect\n", |
|
"print(inspect.getsource(coord.Galactic))" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 7, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"# this is not an issue when representation_data are given as arguments\n", |
|
"c = coord.Galactic(1,2,3, representation_type='cartesian')" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 8, |
|
"metadata": {}, |
|
"outputs": [ |
|
{ |
|
"ename": "TypeError", |
|
"evalue": "Coordinate frame got unexpected keywords: ['x', 'y', 'z']", |
|
"output_type": "error", |
|
"traceback": [ |
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", |
|
"\u001b[0;32m<ipython-input-8-20c6f4ecd20b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# but raises error which can be cryptic given the docstring\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;31m# same problem for velocities\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcoord\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGalactic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mz\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrepresentation_type\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'cartesian'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
|
"\u001b[0;32m~/miniconda3/envs/research/lib/python3.7/site-packages/astropy/coordinates/baseframe.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, copy, representation_type, differential_type, *args, **kwargs)\u001b[0m\n\u001b[1;32m 580\u001b[0m raise TypeError(\n\u001b[1;32m 581\u001b[0m 'Coordinate frame got unexpected keywords: {0}'.format(\n\u001b[0;32m--> 582\u001b[0;31m list(kwargs)))\n\u001b[0m\u001b[1;32m 583\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 584\u001b[0m \u001b[0;31m# We do ``is None`` because self._data might evaluate to false for\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
|
"\u001b[0;31mTypeError\u001b[0m: Coordinate frame got unexpected keywords: ['x', 'y', 'z']" |
|
] |
|
} |
|
], |
|
"source": [ |
|
"# but raises error which can be cryptic given the docstring\n", |
|
"# same problem for velocities\n", |
|
"c = coord.Galactic(x=1,y=2,z=3, representation_type='cartesian')" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": 9, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"# works with correct names\n", |
|
"c = coord.Galactic(u=1,v=2,w=3, representation_type='cartesian')\n", |
|
"c = coord.Galactic(u=1,v=2,w=3, U=1/u.yr, V=1/u.yr, W=1/u.yr, representation_type='cartesian', differential_type='cartesian')" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [] |
|
} |
|
], |
|
"metadata": { |
|
"kernelspec": { |
|
"display_name": "Python 3", |
|
"language": "python", |
|
"name": "python3" |
|
}, |
|
"language_info": { |
|
"codemirror_mode": { |
|
"name": "ipython", |
|
"version": 3 |
|
}, |
|
"file_extension": ".py", |
|
"mimetype": "text/x-python", |
|
"name": "python", |
|
"nbconvert_exporter": "python", |
|
"pygments_lexer": "ipython3", |
|
"version": "3.7.0" |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 2 |
|
} |