.. _cgro-frame: .. |CgroFrame| replace:: :class:`~gdt.missions.cgro.frame.CgroFrame` .. |Quaternion| replace:: :class:`~gdt.core.coords.Quaternion` .. |BatsePhaiiMulti| replace:: :class:`~gdt.missions.cgro.batse.phaii.BatsePhaiiMulti` .. |SpacecraftAxes| replace:: :class:`~gdt.core.coords.SpacecraftAxes` ****************************************************** CGRO Spacecraft Frame (:mod:`gdt.missions.cgro.frame`) ****************************************************** The CGRO spacecraft frame, |CgroFrame|, is the frame that is aligned with the CGRO spacecraft coordinate frame, and is represented by a quaternion that defines the rotation from spacecraft coordinates to the ICRS coordinate frame. This frame takes advantage of the Astropy coordinate frame design, so we can use the FermiFrame to convert Astropy SkyCoord objects between the CGRO Frame and any celestial frame. Manually Initializing a Frame ============================= While the |CgroFrame| is typically initialized when reading from a continuous data file, such as a CONT or DISCLA file (see |BatsePhaiiMulti|) instead of manually by a user, we can manually define the frame as follows. Since the CGRO spacecraft frame is not natively specified by a quaternion, but instead the pointing of the X and Z spacecraft axes in the ICRS frame, we must specify those pointings, and the |CgroFrame| will perform the conversion into a quaternion. First, we specify the axes pointings using Astropy SkyCoord: >>> from astropy.coordinates import SkyCoord >>> x_pointing = SkyCoord(19.090958, 8.04433, unit='deg') >>> z_pointing = SkyCoord(108.162994, -6.5431795, unit='deg') Next, we create a |SpacecraftAxes| object that will enable the conversion to quaternions: >>> from gdt.core.coords import SpacecraftAxes >>> axes = SpacecraftAxes(x_pointing=x_pointing, z_pointing=z_pointing) >>> axes X axis: RA 19.090958, Dec 8.04433 Z axis: RA 108.162994, Dec -6.5431795 Finally, we initialize a |CgroFrame| with the |SpacecraftAxes| object: >>> from gdt.missions.cgro.frame import * >>> cgro_frame = CgroFrame(axes=axes) >>> cgro_frame Notice that we can also define the frame with an ``obstime``, which is useful for transforming between the |CgroFrame| and a non-inertial time-dependent frame; an ``obsgeoloc``, which can define the spacecraft location in orbit; and ``obsgeovel``, which defines the spacecraft orbital velocity. Now let us define a SkyCoord of some object of interest in RA and Dec: >>> coord = SkyCoord(100.0, -30.0, unit='deg') And we can simply rotate this into the CGRO frame with the following: >>> cgro_coord = coord.transform_to(cgro_frame) >>> (cgro_coord.az, cgro_coord.el) (, ) We can also transform from the CGRO frame to other frames. For example, we define a coordinate in the CGRO frame this way: >>> cgro_coord = SkyCoord(50.0, 25.0, frame=cgro_frame[0], unit='deg') Now we can tranform to ICRS coordinates: >>> cgro_coord.icrs or Galactic coordinates: >>> cgro_coord.galactic or any other coordinate frames provided by Astropy. Reading a CGRO Frame from a file ================================ BATSE continuous data files contain, in addition to science data, the spacecraft position and pointing history for the duration of the file. This information can be accessed by opening one of these files and extracting the spacecraft frame information. For example: >>> from gdt.core import data_path >>> from gdt.missions.cgro.batse.phaii import BatsePhaii >>> filepath = data_path / 'cgro-batse' / 'cont_08362.fits.gz' >>> phaii_multi = BatsePhaii.open(filepath) >>> phaii_multi While this is a PHAII file containing data from multiple detectors (see :ref:`BATSE PHAII data`), we can extract the spacecraft frame in the following way: >>> sc_frame = phaii_multi.get_spacecraft_frame() Notice that this |CgroFrame| object contains 4485 different frames, each defined at a particular ``obstime``. This set of frames can be used in all of the examples above. For example, we can convert our sky coordinate in ICRS to the CGRO frame for each frame in our set: >>> coord.transform_to(sc_frame).az >>> coord.transform_to(sc_frame).el We can also retrieve the spacecraft location in orbit relative to the geocenter: >>> # latitude >>> sc_frame.earth_location.lat >>> # longitude >>> sc_frame.earth_location.lon >>> # altitude >>> sc_frame.earth_location.height We can also extract a single frame or slice multiple frames: >>> sc_frame[100] >>> sc_frame[100:110] For more details about working with spacecraft frames, see :external:ref:`Spacecraft Attitude, Position, and Coordinates`. Reference/API ============= .. automodapi:: gdt.missions.cgro.frame :inherited-members: