def from_geodetic(cls, lon, lat, height=0., ellipsoid=None): """ Location on Earth, initialized from geodetic coordinates. Parameters ---------- lon : `~astropy.coordinates.Longitude` or float Earth East longitude. Can be anything that initialises an `~astropy.coordinates.Angle` object (if float, in degrees). lat : `~astropy.coordinates.Latitude` or float Earth latitude. Can be anything that initialises an `~astropy.coordinates.Latitude` object (if float, in degrees). height : `~astropy.units.Quantity` or float, optional Height above reference ellipsoid (if float, in meters; default: 0). ellipsoid : str, optional Name of the reference ellipsoid to use (default: 'WGS84'). Available ellipsoids are: 'WGS84', 'GRS80', 'WGS72'. Raises ------ astropy.units.UnitsError If the units on ``lon`` and ``lat`` are inconsistent with angular ones, or that on ``height`` with a length. ValueError If ``lon``, ``lat``, and ``height`` do not have the same shape, or if ``ellipsoid`` is not recognized as among the ones implemented. Notes ----- For the conversion to geocentric coordinates, the ERFA routine ``gd2gc`` is used. See https://github.com/liberfa/erfa """ ellipsoid = _check_ellipsoid(ellipsoid, default=cls._ellipsoid) # We use Angle here since there is no need to wrap the longitude - # gd2gc will just take cos/sin anyway. And wrapping might fail # on readonly input. lon = Angle(lon, u.degree, copy=False) lat = Latitude(lat, u.degree, copy=False) # don't convert to m by default, so we can use the height unit below. if not isinstance(height, u.Quantity): height = u.Quantity(height, u.m, copy=False) # get geocentric coordinates. Have to give one-dimensional array. xyz = erfa.gd2gc(getattr(erfa, ellipsoid), lon.to_value(u.radian), lat.to_value(u.radian), height.to_value(u.m)) self = xyz.ravel().view(cls._location_dtype, cls).reshape(xyz.shape[:-1]) self._unit = u.meter self._ellipsoid = ellipsoid return self.to(height.unit)
def lla2itrs(lla): """ uses ERFA's geodetic to geocentric function and the WGS84 ellipsoid parameters Input: lla is assumed to be a numpy array of dimension [3] or [n,3], where 3 is the lon (radians),lat (radians), height (meters) of the geodetic coordinates of n different sets of coordinates Output: xyz is assumed to be a numpy array of dimension [3] or [n,3], where 3 is the x,z,y cartesian coordinates in meters of n different sets of coordinates """ lla = np.atleast_2d(lla) xyz = np.array(gd2gc(1, lla[:, 0], lla[:, 1], lla[:, 2]), dtype=np.float64) if xyz.size == 3: xyz = xyz[0] return xyz
def from_geodetic(cls, lon, lat, height=0., ellipsoid=None): """ Location on Earth, initialized from geodetic coordinates. Parameters ---------- lon : `~astropy.coordinates.Longitude` or float Earth East longitude. Can be anything that initialises an `~astropy.coordinates.Angle` object (if float, in degrees). lat : `~astropy.coordinates.Latitude` or float Earth latitude. Can be anything that initialises an `~astropy.coordinates.Latitude` object (if float, in degrees). height : `~astropy.units.Quantity` or float, optional Height above reference ellipsoid (if float, in meters; default: 0). ellipsoid : str, optional Name of the reference ellipsoid to use (default: 'WGS84'). Available ellipsoids are: 'WGS84', 'GRS80', 'WGS72'. Raises ------ astropy.units.UnitsError If the units on ``lon`` and ``lat`` are inconsistent with angular ones, or that on ``height`` with a length. ValueError If ``lon``, ``lat``, and ``height`` do not have the same shape, or if ``ellipsoid`` is not recognized as among the ones implemented. Notes ----- For the conversion to geocentric coordinates, the ERFA routine ``gd2gc`` is used. See https://github.com/liberfa/erfa """ ellipsoid = _check_ellipsoid(ellipsoid, default=cls._ellipsoid) lon = Longitude(lon, u.degree, wrap_angle=180*u.degree, copy=False) lat = Latitude(lat, u.degree, copy=False) # don't convert to m by default, so we can use the height unit below. if not isinstance(height, u.Quantity): height = u.Quantity(height, u.m, copy=False) # get geocentric coordinates. Have to give one-dimensional array. xyz = erfa.gd2gc(getattr(erfa, ellipsoid), lon.to_value(u.radian), lat.to_value(u.radian), height.to_value(u.m)) self = xyz.ravel().view(cls._location_dtype, cls).reshape(xyz.shape[:-1]) self._unit = u.meter self._ellipsoid = ellipsoid return self.to(height.unit)
def site_location(elong, phi, height): """ Return site position vector in cartesian coordintate in ITRS system, based on WGS84 reference ellipsoid Parameter: ========== elong, phi, height: double arrays of sites' geodetic cooradinates Return: ======= location: double array """ n = 1 # WGS84 # n = 2 GRS80 # n = 3 # WGS72 return erfa.gd2gc(n, elong, phi, height)