def _tag_to_frame(tag): """ Extract the frame name from the tag. """ tag = tag[tag.rfind('/')+1:] tag = tag[:tag.rfind('-')] return frame_transform_graph.lookup_name(tag)
def _tag_to_frame(tag): """ Extract the frame name from the tag. """ tag = tag[tag.rfind('/')+1:] tag = tag[:tag.rfind('-')] return frame_transform_graph.lookup_name(tag)
def with_observer_stationary_relative_to(self, frame, velocity=None, preserve_observer_frame=False): """ A new `SpectralCoord` with the velocity of the observer altered, but not the position. If a coordinate frame is specified, the observer velocities will be modified to be stationary in the specified frame. If a coordinate instance is specified, optionally with non-zero velocities, the observer velocities will be updated so that the observer is co-moving with the specified coordinates. Parameters ---------- frame : str, `~astropy.coordinates.BaseCoordinateFrame` or `~astropy.coordinates.SkyCoord` The observation frame in which the observer will be stationary. This can be the name of a frame (e.g. 'icrs'), a frame class, frame instance with no data, or instance with data. This can optionally include velocities. velocity : `~astropy.units.Quantity` or `~astropy.coordinates.CartesianDifferential`, optional If ``frame`` does not contain velocities, these can be specified as a 3-element `~astropy.units.Quantity`. In the case where this is also not specified, the velocities default to zero. preserve_observer_frame : bool If `True`, the final observer frame class will be the same as the original one, and if `False` it will be the frame of the velocity reference class. Returns ------- new_coord : `SpectralCoord` The new coordinate object representing the spectral data transformed based on the observer's new velocity frame. """ if self.observer is None or self.target is None: raise ValueError("This method can only be used if both observer " "and target are defined on the SpectralCoord.") # Start off by extracting frame if a SkyCoord was passed in if isinstance(frame, SkyCoord): frame = frame.frame if isinstance(frame, BaseCoordinateFrame): if not frame.has_data: frame = frame.realize_frame( CartesianRepresentation(0 * u.km, 0 * u.km, 0 * u.km)) if frame.data.differentials: if velocity is not None: raise ValueError( 'frame already has differentials, cannot also specify velocity' ) # otherwise frame is ready to go else: if velocity is None: differentials = ZERO_VELOCITIES else: differentials = CartesianDifferential(velocity) frame = frame.realize_frame( frame.data.with_differentials(differentials)) if isinstance(frame, (type, str)): if isinstance(frame, type): frame_cls = frame elif isinstance(frame, str): frame_cls = frame_transform_graph.lookup_name(frame) if velocity is None: velocity = 0 * u.m / u.s, 0 * u.m / u.s, 0 * u.m / u.s elif velocity.shape != (3, ): raise ValueError( 'velocity should be a Quantity vector with 3 elements') frame = frame_cls(0 * u.m, 0 * u.m, 0 * u.m, *velocity, representation_type='cartesian', differential_type='cartesian') observer = update_differentials_to_match( self.observer, frame, preserve_observer_frame=preserve_observer_frame) # Calculate the initial and final los velocity init_obs_vel = self._calculate_radial_velocity(self.observer, self.target, as_scalar=True) fin_obs_vel = self._calculate_radial_velocity(observer, self.target, as_scalar=True) # Apply transformation to data new_data = _apply_relativistic_doppler_shift( self, fin_obs_vel - init_obs_vel) new_coord = self.replicate(value=new_data, observer=observer) return new_coord