Main Page
PHSRM Remote Sensing Hands-On Lesson (MATLAB)

Table of Contents

   PHSRM Remote Sensing Hands-On Lesson (MATLAB)
      Overview
      Note About HTML Links
      References
         Tutorials
         Required Readings
         The Permuted Index
         Mice API Documentation
      Kernels Used
      Mice Modules Used
   Time Conversion (convtm)
      Task Statement
      Learning Goals
      Approach
      Solution
         Solution Meta-Kernel
         Solution Source Code
         Solution Sample Output
   Obtaining Target States and Positions (getsta)
      Task Statement
      Learning Goals
      Approach
      Solution
         Solution Meta-Kernel
         Solution Source Code
         Solution Sample Output
   Spacecraft Orientation and Reference Frames (xform)
      Task Statement
      Learning Goals
      Approach
      Solution
         Solution Meta-Kernel
         Solution Source Code
         Solution Sample Output
   Computing Sub-spacecraft and Sub-solar Points (subpts)
      Task Statement
      Learning Goals
      Approach
      Solution
         Solution Meta-Kernel
         Solution Source Code
         Solution Sample Output
   Intersecting Vectors with a Triaxial Ellipsoid (fovint)
      Task Statement
      Learning Goals
      Approach
      Solution
         Solution Meta-Kernel
         Solution Source Code
         Solution Sample Output




Top

PHSRM Remote Sensing Hands-On Lesson (MATLAB)





July 19, 2011



Top

Overview




In this lesson you will develop a series of simple programs that demonstrate the usage of Mice to compute a variety of different geometric quantities applicable to experiments carried out by a remote sensing instrument flown on an interplanetary spacecraft. This particular lesson focuses on a framing camera flying on the PHSRM spacecraft, but many of the concepts are easily extended and generalized to other scenarios.



Top

Note About HTML Links




The HTML version of this lesson contains links pointing to various HTML documents provided with the Toolkit. All of these links are relative and, in order to function, require this document to be in a certain location in the Toolkit HTML documentation directory tree.

In order for the links to be resolved, create a subdirectory called ``lessons'' under the ``doc/html'' directory of the Toolkit tree and copy this document to that subdirectory before loading it into a Web browser.



Top

References






Top

Tutorials



The following SPICE tutorials are referred to by the discussions in this lesson:

   Name             Lesson steps/functions it describes
   ---------------  -----------------------------------------
   Time             Time Conversion
   SCLK and LSK     Time Conversion
   SPK              Obtaining Ephemeris Data
   Frames           Reference Frames
   Using Frames     Reference Frames
   PCK              Planetary Constants Data
   CK               Spacecraft Orientation Data
These tutorials are available from the NAIF ftp server at JPL:

   http://naif.jpl.nasa.gov/naif/tutorials.html


Top

Required Readings



The Required Reading documents are provided with the Toolkit and are located under the ``mice/doc'' directory in the MATLAB installation tree.

   Name             Lesson steps/functions that it describes
   ---------------  -----------------------------------------
   time.req         Time Conversion
   sclk.req         SCLK Time Conversion
   spk.req          Obtaining Ephemeris Data
   frames.req       Using Reference Frames
   pck.req          Obtaining Planetary Constants Data
   ck.req           Obtaining Spacecraft Orientation Data
   naif_ids.req     Determining Body ID Codes


Top

The Permuted Index



Another useful document distributed with the Toolkit is the permuted index. This is located under the ``mice/doc'' directory in the MATLAB installation tree.

This text document provides a simple mechanism to discover what Mice functions perform a particular function of interest as well as the name of the source module that contains the function.



Top

Mice API Documentation



A Mice routine's specification is found in the API documentation page located under ``mice/doc/html/mice''.

For example, the document

   mice/doc/html/mice/cspice_str2et.html
describes the cspice_str2et routine.



Top

Kernels Used




The following kernels are used in examples provided in this lesson:

   #  FILE NAME                 TYPE  DESCRIPTION
   -- ------------------------------- ----  ------------------------
   1  naif0009.tls                         LSK   Generic LSK
   2  phsrm_201008031645.tsc               SCLK  PHSRM SCLK
   3  de421xs.bsp                          SPK   Solar System Ephemeris
   4  phobos_kiam_101231_v00.bsp           SPK   Phobos Ephemeris
   5  phsrm_130114_130114_130214_nom2.bsp  SPK   PHSRM Spacecraft SPK
   6  phsrm_v00.tf                         FK    PHSRM FK
   7  phsrm_sc_test2_111108_130214_v00.bc  CK    PHSRM Spacecraft CK
   8  pck00009.tpc                         PCK   Generic PCK
   9  phsrm_tsns_v00.ti                    IK    PHSRM TSNS IK
These SPICE kernels are included in the lesson package available from the PHSRM server at IKI:

   http://spice.ikiweb.ru/PHSRM/kernels


Top

Mice Modules Used




This section provides a complete summary of the functions, and the kernels that are suggested for usage in each of the exercises in this tutorial. (You may wish to not look at this list unless/until you ``get stuck'' while working on your own.)

   CHAPTER EXERCISE   FUNCTIONS      NON-VOID       KERNELS
   ------- ---------  -------------  ---------      -------
     1     convtm     cspice_furnsh                 1,2
                      cspice_str2et
                      cspice_etcal
                      cspice_timout
                      cspice_sce2c
                      cspice_sce2s
 
     2     getsta     cspice_furnsh                 1,3-6
                      cspice_str2et
                      cspice_spkezr
                      cspice_spkpos
                      cspice_convrt
 
     3     xform      cspice_furnsh  cspice_vsep    1-8
                      cspice_str2et
                      cspice_spkezr
                      cspice_sxform
                      cspice_spkpos
                      cspice_pxform
                      cspice_convrt
 
     4     subpts     cspice_furnsh                 1,3-6,8
                      cspice_str2et
                      cspice_subpt
                      cspice_subsol
 
     5     fovint     cspice_furnsh  cspice_dpr     1-9
                      cspice_str2et
                      cspice_bodn2c
                      cspice_getfov
                      cspice_sincpt
                      cspice_reclat
                      cspice_ilumin
                      cspice_et2lst
Refer to the headers of the various functions listed above, as detailed interface specifications are provided with the source code.



Top

Time Conversion (convtm)







Top

Task Statement




Write a program that prompts the user for an input UTC time string, converts it to the following time systems and output formats:

    1. Ephemeris Time (ET) in seconds past J2000

    2. Calendar Ephemeris Time

    3. Spacecraft Clock Time

and displays the results. Use the program to convert "2013-02-10 20:40:00" UTC into these alternate systems.



Top

Learning Goals




Familiarity with the various time conversion and parsing functions available in the Toolkit. Exposure to source code headers and their usage in learning to call functions.



Top

Approach




The solution to the problem can be broken down into a series of simple steps:

    -- Decide which SPICE kernels are necessary. Prepare a meta-kernel listing the kernels and load it into the program.

    -- Prompt the user for an input UTC time string.

    -- Convert the input time string into ephemeris time expressed as seconds past J2000 TDB. Display the result.

    -- Convert ephemeris time into a calendar format. Display the result.

    -- Convert ephemeris time into a spacecraft clock string. Display the result.

You may find it useful to consult the permuted index, the headers of various source modules, and the ``Time Required Reading'' (time.req) and ``SCLK Required Reading'' (sclk.req) documents.

When completing the ``calendar format'' step above, consider using one of two possible methods: cspice_etcal or cspice_timout.



Top

Solution






Top

Solution Meta-Kernel



The meta-kernel we created for the solution to this exercise is named 'convtm.tm'. Its contents follow:

   KPL/MK
 
   This is the meta-kernel used in the solution of the ``Time
   Conversion'' task in the Remote Sensing Hands On Lesson.
 
      \begindata
      KERNELS_TO_LOAD = (
                'kernels/lsk/naif0009.tls',
                'kernels/sclk/phsrm_201008031645.tsc'
                        )
      \begintext
 
 


Top

Solution Source Code



A sample solution to the problem follows:

   %
   % Remote sensing lesson:  Time conversion
   %
   function convtm()
 
   %
   % Local parameters
   %
   METAKR = 'convtm.tm';
   SCLKID = -555;
 
   %
   % Load the kernels his program requires.
   % Both the spacecraft clock kernel and a
   % leapseconds kernel should be listed in
   % the meta-kernel.
   %
   cspice_furnsh ( METAKR );
 
   %
   % Prompt the user for the input time string.
   %
   utctim = input ( 'Input UTC Time: ', 's' );
 
   fprintf ( 'Converting UTC Time: %s\n', utctim )
 
   %
   % Convert utctim to et.
   %
   et = cspice_str2et ( utctim );
 
   fprintf ( '   ET Seconds Past J2000: %16.3f\n', et )
 
   %
   % Now convert ET to a formal calendar time
   % string.  This can be accomplished in two
   % ways.
   %
   calet = cspice_etcal ( et );
 
   fprintf ( '   Calendar ET (cspice_etcal):  %s\n', calet )
 
   %
   % Or use cspice_timout for finer control over the
   % output format.  The picture below was built
   % by examining the header of cspice_timout.
   %
   calet = cspice_timout ( et, 'YYYY-MON-DDTHR:MN:SC ::TDB' );
 
   fprintf ( '   Calendar ET (cspice_timout): %s\n', calet )
 
   %
   % Convert ET to spacecraft clock time.
   %
   sclkst = cspice_sce2s ( SCLKID, et );
 
   fprintf ( '   Spacecraft Clock Time: %s\n', sclkst )
 
   %
   % Unload kernels we loaded at the start of the function.
   %
   cspice_unload ( METAKR );
 
   %
   % End of function convtm
   %


Top

Solution Sample Output



Execute the program:

                   < M A T L A B (R) >
         Copyright 1984-2010 The MathWorks, Inc.
      Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                    February 5, 2010
 
 
     To get started, type one of these: helpwin, helpdesk, or demo.
     For product information, visit www.mathworks.com.
 
   >> Converting UTC Time: 2013-02-10 20:40:00
      ET Seconds Past J2000:    413800866.185
      Calendar ET (cspice_etcal):  2013 FEB 10 20:41:06.185
      Calendar ET (cspice_timout): 2013-FEB-10T20:41:06
      Spacecraft Clock Time: 1/0461:09600000


Top

Obtaining Target States and Positions (getsta)







Top

Task Statement




Write a program that prompts the user for an input UTC time string, computes the following quantities at that epoch:

    1. The apparent state of Phobos as seen from PHSRM in the J2000 frame, in kilometers and kilometers/second. This vector itself is not of any particular interest, but it is a useful intermediate quantity in some geometry calculations.

    2. The apparent position of the Earth as seen from PHSRM in the J2000 frame, in kilometers.

    3. The one-way light time between PHSRM and the apparent position of Earth, in seconds.

    4. The apparent position of the Sun as seen from Phobos in the J2000 frame (J2000), in kilometers.

    5. The actual (geometric) distance between the Sun and Phobos, in astronomical units.

and displays the results. Use the program to compute these quantities at "2013-02-10 20:40:00" UTC.



Top

Learning Goals




Understand the anatomy of an cspice_spkezr call. Discover the difference between cspice_spkezr and cspice_spkpos. Familiarity with the Toolkit utility ``brief''. Exposure to unit conversion with Mice.



Top

Approach




The solution to the problem can be broken down into a series of simple steps:

    -- Decide which SPICE kernels are necessary. Prepare a meta-kernel listing the kernels and load it into the program.

    -- Prompt the user for an input time string.

    -- Convert the input time string into ephemeris time expressed as seconds past J2000 TDB.

    -- Compute the state of Phobos relative to PHSRM in the J2000 reference frame, corrected for aberrations.

    -- Compute the position of Earth relative to PHSRM in the J2000 reference frame, corrected for aberrations. (The function in the library that computes this also returns the one-way light time between PHSRM and Earth.)

    -- Compute the position of the Sun relative to Phobos in the J2000 reference frame, corrected for aberrations.

    -- Compute the position of the Sun relative to Phobos without correcting for aberration.

    -- Compute the length of this vector. This provides the desired distance in kilometers.

    -- Convert the distance in kilometers into AU.

You may find it useful to consult the permuted index, the headers of various source modules, and the ``SPK Required Reading'' (spk.req) document.

When deciding which SPK files to load, the Toolkit utility ``brief'' may be of some use.

``brief'' is located in the ``mice/exe'' directory for MATLAB toolkits. Consult its user's guide available in ``mice/doc/brief.ug'' for details.



Top

Solution






Top

Solution Meta-Kernel



The meta-kernel we created for the solution to this exercise is named 'getsta.tm'. Its contents follow:

   KPL/MK
 
   This is the meta-kernel used in the solution of the
   ``Obtaining Target States and Positions'' task in the
   Remote Sensing Hands On Lesson.
 
      \begindata
      KERNELS_TO_LOAD = (
                'kernels/lsk/naif0009.tls',
                'kernels/spk/de421xs.bsp',
                'kernels/spk/phobos_kiam_101231_v00.bsp',
                'kernels/spk/phsrm_130114_130114_130214_nom2.bsp'
                'kernels/fk/phsrm_v00.tf'
                        )
      \begintext


Top

Solution Source Code



A sample solution to the problem follows:

   %
   % Remote sensing lesson:  State vector lookup
   %
   function getsta()
 
   %
   % Local parameters
   %
   METAKR = 'getsta.tm';
 
   %
   % Load the kernels that this program requires.  We
   % will need a leapseconds kernel to convert input
   % UTC time strings into ET.  We also will need
   % SPK files with coverage for the bodies
   % in which we are interested.
   %
   cspice_furnsh ( METAKR );
 
   %
   % Prompt the user for the input time string.
   %
   utctim = input ( 'Input UTC Time: ', 's' );
 
   fprintf ( 'Converting UTC Time: %s\n', utctim )
 
   %
   % Convert utctim to ET.
   %
   et = cspice_str2et ( utctim );
 
   fprintf ( '   ET seconds past J2000: %16.3f\n', et )
 
   %
   % Compute the apparent state of Phobos as seen from
   % PHSRM in the J2000 frame.  All of the ephemeris
   % readers return states in units of kilometers and
   % kilometers per second.
   %
   [state, ltime] = cspice_spkezr ( 'PHOBOS', et,    ...
                                    'J2000', 'LT+S', 'PHSRM' );
 
   fprintf ( [ '   Apparent state of Phobos as seen ', ...
               'from PHSRM in the J2000\n',          ...
               '      frame (km, km/s):\n']                )
 
   fprintf ( '      X = %16.3f\n', state(1) )
   fprintf ( '      Y = %16.3f\n', state(2) )
   fprintf ( '      Z = %16.3f\n', state(3) )
   fprintf ( '     VX = %16.3f\n', state(4) )
   fprintf ( '     VY = %16.3f\n', state(5) )
   fprintf ( '     VZ = %16.3f\n', state(6) )
 
 
   %
   % Compute the apparent position of Earth as seen from
   % PHSRM in the J2000 frame.  Note: We could have
   % continued using cspice_spkezr and simply ignored the
   % velocity components.
   %
   [pos, ltime] = cspice_spkpos ( 'EARTH', et,     ...
                                  'J2000', 'LT+S', 'PHSRM' );
 
   fprintf ( [ '   Apparent position of Earth as seen ', ...
               'from PHSRM in the J2000\n',            ...
               '      frame (km):\n' ]               )
 
   fprintf ( '      X = %16.3f\n', pos(1) )
   fprintf ( '      Y = %16.3f\n', pos(2) )
   fprintf ( '      Z = %16.3f\n', pos(3) )
 
   %
   % Display the light time from target to observer.
   %
   fprintf ( [ '   One way light time between PHSRM ', ...
               'and the apparent position\n',            ...
               '      of Earth (seconds): %16.3f\n' ],   ...
               ltime                                          )
 
   %
   % Compute the apparent position of the Sun as seen
   % from Phobos in the J2000 frame.
   %
   [pos, ltime] = cspice_spkpos ( 'SUN',   et,     ...
                                  'J2000', 'LT+S', 'PHOBOS' );
 
   fprintf ( [ '   Apparent position of Sun as seen ', ...
               'from Phobos in the \n',               ...
               '      J2000 frame (km):\n' ]                 )
 
   fprintf ( '      X = %16.3f\n', pos(1) )
   fprintf ( '      Y = %16.3f\n', pos(2) )
   fprintf ( '      Z = %16.3f\n', pos(3) )
 
   %
   % Now we need to compute the actual distance between
   % the Sun and Phobos.  The above SPKPOS call gives us
   % the apparent distance, so we need to adjust our
   % aberration correction appropriately.
   %
   [pos, ltime] = cspice_spkpos ( 'SUN',   et,     ...
                                  'J2000', 'NONE', 'PHOBOS' );
 
   %
   % Compute the distance between the body centers in
   % kilometers.
   %
   dist = norm ( pos );
 
   %
   % Convert this value to AU using cspice_convrt.
   %
   dist_au = cspice_convrt ( dist, 'KM', 'AU' );
 
   fprintf ( [ '   Actual distance between Sun and Phobos ' ...
               'body centers:\n' ]                         )
   fprintf ( '      (AU): %16.3f\n', dist_au               )
 
   %
   % Unload all kernels.
   %
   cspice_kclear;
 
   %
   % End of function getsta
   %


Top

Solution Sample Output



Execute the program:

                   < M A T L A B (R) >
         Copyright 1984-2010 The MathWorks, Inc.
      Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                    February 5, 2010
 
 
     To get started, type one of these: helpwin, helpdesk, or demo.
     For product information, visit www.mathworks.com.
 
   >> Converting UTC Time: 2013-02-10 20:40:00
      ET seconds past J2000:    413800866.185
      Apparent state of Phobos as seen from PHSRM in the J2000
         frame (km, km/s):
         X =           43.646
         Y =            5.698
         Z =          -20.731
        VX =            0.008
        VY =           -0.002
        VZ =           -0.005
      Apparent position of Earth as seen from PHSRM in the J2000
         frame (km):
         X =   -318212438.123
         Y =    123091882.078
         Z =     59808626.721
      One way light time between PHSRM and the apparent position
         of Earth (seconds):         1155.441
      Apparent position of Sun as seen from Phobos in the
         J2000 frame (km):
         X =   -201733820.746
         Y =     39838264.775
         Z =     23717367.433
      Actual distance between Sun and Phobos body centers:
         (AU):            1.384


Top

Spacecraft Orientation and Reference Frames (xform)







Top

Task Statement




Write a program that prompts the user for an input time string, computes and displays the following at the epoch of interest:

    1. The apparent state of Phobos as seen from PHSRM in the IAU_PHOBOS body-fixed frame. This vector itself is not of any particular interest, but it is a useful intermediate quantity in some geometry calculations.

    2. The angular separation between the apparent position of Sun as seen from PHSRM and the normal vector of the PHSRM solar arrays (SA).

    Nominally the SA normal direction is the +X axis of the PHSRM_SPACECRAFT reference frame. This information can be found by examining description of the PHSRM_SPACECRAFT frame provided in the FK file.

Use the program to compute these quantities at the epoch "2013-02-10 20:40:00" UTC.



Top

Learning Goals




Familiarity with the different types of kernels involved in chaining reference frames together, both inertial and non-inertial. Discover some of the vector math functions. Understand the difference between cspice_pxform and cspice_sxform.



Top

Approach




The solution to the problem can be broken down into a series of simple steps:

    -- Decide which SPICE kernels are necessary. Prepare a meta-kernel listing the kernels and load it into the program.

    -- Prompt the user for an input time string.

    -- Convert the input time string into ephemeris time expressed as seconds past J2000 TDB.

    -- Compute the state of Phobos relative to PHSRM in the J2000 reference frame, corrected for aberrations.

    -- Compute the state transformation matrix from J2000 to IAU_PHOBOS at the epoch, adjusted for light time.

    -- Multiply the state of Phobos relative to PHSRM in the J2000 reference frame by the state transformation matrix computed in the previous step.

    -- Compute the position of Sun relative to PHSRM in the J2000 reference frame, corrected for aberrations.

    -- Determine what the normal vector of the PHSRM solar arrays is by examining the frame kernel's content.

    -- Compute the rotation matrix from the PHSRM spacecraft frame to J2000.

    -- Multiply the normal vector expressed in the PHSRM spacecraft frame by the rotation matrix from the previous step.

    -- Compute the separation between the result of the previous step and the apparent position of the Sun relative to PHSRM in the J2000 frame.

HINT: Several of the steps above may be compressed into a single using Mice functions with which you are already familiar. The ``long-way'' presented above is intended to facilitate the introduction of the functions cspice_pxform and cspice_sxform.

You may find it useful to consult the permuted index, the headers of various source modules, and the following toolkit documentation:

    2. PCK Required Reading (pck.req)

    3. SPK Required Reading (spk.req)

    4. CK Required Reading (ck.req)

This particular example makes use of many of the different types of SPICE kernels. You should spend a few moments thinking about which kernels you will need and what data they provide.



Top

Solution






Top

Solution Meta-Kernel



The meta-kernel we created for the solution to this exercise is named 'xform.tm'. Its contents follow:

   KPL/MK
 
   This is the meta-kernel used in the solution of the ``Spacecraft
   Orientation and Reference Frames'' task in the Remote Sensing
   Hands On Lesson.
 
      \begindata
      KERNELS_TO_LOAD = (
                'kernels/lsk/naif0009.tls',
                'kernels/sclk/phsrm_201008031645.tsc',
                'kernels/spk/de421xs.bsp',
                'kernels/spk/phobos_kiam_101231_v00.bsp',
                'kernels/spk/phsrm_130114_130114_130214_nom2.bsp',
                'kernels/fk/phsrm_v00.tf',
                'kernels/ck/phsrm_sc_test2_111108_130214_v00.bc',
                'kernels/pck/pck00009.tpc'
                        )
      \begintext


Top

Solution Source Code



A sample solution to the problem follows:

   %
   % Remote sensing lesson:  Spacecraft Orientation and Reference Frames
   %
   function xform()
 
   %
   % Local Parameters
   %
   METAKR = 'xform.tm';
 
   %
   % Load the kernels that this program requires.  We
   % will need:
   %
   %      A leapseconds kernel
   %      A spacecraft clock kernel for PHSRM
   %      The necessary ephemerides
   %      A planetary constants file (PCK)
   %      A spacecraft orientation kernel for PHSRM (CK)
   %      A frame kernel (TF)
   %
   cspice_furnsh ( METAKR );
 
   %
   % Prompt the user for the input time string.
   %
   utctim = input ( 'Input UTC Time: ', 's' );
 
   fprintf ( 'Converting UTC Time: %s\n', utctim )
 
   %
   % Convert utctim to ET.
   %
   et = cspice_str2et ( utctim );
 
   fprintf ( '   ET seconds past J2000: %16.3f\n', et )
 
   %
   % Compute the apparent state of Phobos as seen from
   % PHSRM in the J2000 frame.  All of the ephemeris
   % readers return states in units of kilometers and
   % kilometers per second.
   %
   [state, ltime] = cspice_spkezr ( 'PHOBOS', et,    ...
                                    'J2000', 'LT+S', 'PHSRM' );
 
   %
   % Now obtain the transformation from the inertial
   % J2000 frame to the non-inertial body-fixed IAU_PHOBOS
   % frame. Since we want the apparent state in the
   % (body-fixed) IAU_PHOBOS reference frame, we
   % need to correct the orientation of this frame for
   % one-way light time; hence we subtract ltime from et
   % in the call below.
   %
   sxfmat = cspice_sxform ( 'J2000', 'IAU_PHOBOS', et-ltime );
 
   %
   % Now rotate the apparent J2000 state into IAU_PHOBOS
   % with the following matrix multiplication:
   %
   bfixst = sxfmat * state;
 
   %
   % Display the results.
   %
   fprintf ( [ '   Apparent state of Phobos as seen ', ...
               'from PHSRM in the IAU_PHOBOS\n',     ...
               '      body-fixed frame (km, km/s):\n' ] )
 
   fprintf ( '      X = %19.6f\n', bfixst(1) )
   fprintf ( '      Y = %19.6f\n', bfixst(2) )
   fprintf ( '      Z = %19.6f\n', bfixst(3) )
   fprintf ( '     VX = %19.6f\n', bfixst(4) )
   fprintf ( '     VY = %19.6f\n', bfixst(5) )
   fprintf ( '     VZ = %19.6f\n', bfixst(6) )
 
   %
   % It is worth pointing out, all of the above could
   % have been done with a single use of cspice_spkezr:
   %
   %
   [state, ltime] = cspice_spkezr ( 'PHOBOS', et,         ...
                                    'IAU_PHOBOS', 'LT+S', ...
                                    'PHSRM'                 );
   %
   % Display the results.
   %
   fprintf ( [ '   Apparent state of Phobos as seen ',  ...
               'from PHSRM in the IAU_PHOBOS\n',      ...
               '      body-fixed frame (km, km/s) ',    ...
               'obtained using cspice_spkezr\n',        ...
               '      directly:\n'                 ]   )
 
   fprintf ( '      X = %19.6f\n', state(1) )
   fprintf ( '      Y = %19.6f\n', state(2) )
   fprintf ( '      Z = %19.6f\n', state(3) )
   fprintf ( '     VX = %19.6f\n', state(4) )
   fprintf ( '     VY = %19.6f\n', state(5) )
   fprintf ( '     VZ = %19.6f\n', state(6) )
 
   %
   % Note that the velocity found by using cspice_spkezr
   % to compute the state in the IAU_PHOBE frame differs
   % at the few mm/second level from that found previously
   % by calling cspice_spkezr and then cspice_sxform.
   % Computing velocity via a single call to cspice_spkezr
   % as we've done immediately above is slightly more
   % accurate than the previous method because the latter
   % accounts for the effect of the rate of change of light
   % time on the apparent angular velocity of the target's
   % body-fixed reference frame.
   %
   % Now we are to compute the angular separation between
   % the apparent position of the Sun as seen from the
   % spacecraft and the normal vector of the
   % solar array.  First, compute the apparent position of
   % the Sun as seen from PHSRM in the J2000 frame.
   %
   [pos, ltime] = cspice_spkpos ( 'SUN', et,     ...
                                  'J2000', 'LT+S', 'PHSRM' );
 
   %
   % Now set the direction of the solar array normal
   % at this same epoch.  From reading the frame kernel
   % we know that the solar array normal is nominally the
   % +X axis of the PHSRM_SPACECRAFT frame defined there.
   %
   bsight = [ 1.D0; 0.D0; 0.D0 ];
 
   %
   % Now compute the rotation matrix from PHSRM_SPACECRAFT into
   % J2000.
   %
   pform = cspice_pxform ( 'PHSRM_SPACECRAFT', 'J2000', et );
 
   %
   % And multiply the result to obtain the nominal
   % solar array normal in the J2000 reference frame.
   %
   bsight = pform * bsight;
 
   %
   % Lastly compute the angular separation.
   %
   sep = cspice_convrt ( cspice_vsep(bsight, pos), ...
                         'RADIANS', 'DEGREES'         );
 
   fprintf ( [ '   Angular separation between the ',    ...
               'apparent position of \n',               ...
               '      Sun and the ',                  ...
               'PHSRM solar array normal ',  ...
               '(degrees):\n      %16.3f\n' ],          ...
               sep                                            );
 
   %
   % Or alternatively we can work in the spacecraft
   % frame directly.
   %
   [pos, ltime] = cspice_spkpos ( 'SUN', et, 'PHSRM_SPACECRAFT', ...
                                  'LT+S', 'PHSRM'               );
 
   %
   % the solar array normal is the X-axis in the
   % PHSRM_SPACECRAFT frame.
   %
   bsight = [ 1.D0; 0.D0; 0.D0 ];
 
   %
   % Lastly compute the angular separation.
   %
   sep = cspice_convrt ( cspice_vsep(bsight, pos), ...
                         'RADIANS', 'DEGREES'         );
 
   fprintf ( [ '   Angular separation between the ',    ...
               'apparent position of \n'                ...
               '      Sun and the ',                  ...
               'PHSRM solar array normal ',  ...
               'computed \n',                           ...
               '      using vectors in the ',           ...
               'PHSRM_SPACECRAFT frame (degrees):\n',        ...
               '      %16.3f\n' ],                      ...
             sep                                            );
 
   %
   % Unload all kernels.
   %
   cspice_kclear;
 
   %
   % End of function xform
   %


Top

Solution Sample Output



Execute the program:

                  < M A T L A B (R) >
        Copyright 1984-2010 The MathWorks, Inc.
     Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                   February 5, 2010
 
 
     To get started, type one of these: helpwin, helpdesk, or demo.
     For product information, visit www.mathworks.com.
 
   >> Converting UTC Time: 2013-02-10 20:40:00
      ET seconds past J2000:    413800866.185
      Apparent state of Phobos as seen from PHSRM in the IAU_PHOBOS
         body-fixed frame (km, km/s):
         X =           32.950479
         Y =          -35.796727
         Z =           -0.250178
        VX =           -0.004507
        VY =           -0.016033
        VZ =           -0.000054
      Apparent state of Phobos as seen from PHSRM in the IAU_PHOBOS
         body-fixed frame (km, km/s) obtained using cspice_spkezr
         directly:
         X =           32.950479
         Y =          -35.796727
         Z =           -0.250178
        VX =           -0.004507
        VY =           -0.016033
        VZ =           -0.000054
      Angular separation between the apparent position of
         Sun and the PHSRM solar array normal (degrees):
                   25.807
      Angular separation between the apparent position of
         Sun and the PHSRM solar array normal computed
         using vectors in the PHSRM_SPACECRAFT frame (degrees):
                   25.807


Top

Computing Sub-spacecraft and Sub-solar Points (subpts)







Top

Task Statement




Write a program that prompts the user for an input UTC time string, computes the following quantities at that epoch:

    1. The apparent sub-observer point of PHSRM on Phobos in the body fixed frame IAU_PHOBOS in kilometers.

    2. The apparent sub-solar point on Phobos as seen from PHSRM in the body fixed frame IAU_PHOBOS in kilometers.

and displays the results. Use the program to compute these quantities at "2013-02-10 20:40:00" UTC.



Top

Learning Goals




Discover higher level geometry calculation functions in Mice and their usage as it relates to PHSRM.



Top

Approach




This particular problem is more of an exercise in searching the permuted index to find the appropriate functions and then reading their headers to understand how to call them.

One point worth considering: Which method do you want to use to compute the sub-solar (or sub-observer) point?



Top

Solution






Top

Solution Meta-Kernel



The meta-kernel we created for the solution to this exercise is named 'subpts.tm'. Its contents follow:

   KPL/MK
 
   This is the meta-kernel used in the solution of the
   ``Computing Sub-spacecraft and Sub-solar Points'' task
   in the Remote Sensing Hands On Lesson.
 
      \begindata
      KERNELS_TO_LOAD = (
                'kernels/lsk/naif0009.tls',
                'kernels/spk/de421xs.bsp',
                'kernels/spk/phobos_kiam_101231_v00.bsp',
                'kernels/spk/phsrm_130114_130114_130214_nom2.bsp',
                'kernels/pck/pck00009.tpc'
                'kernels/fk/phsrm_v00.tf'
                        )
      \begintext


Top

Solution Source Code



A sample solution to the problem follows:

   %
   % Remote sensing lesson:  Computing Sub-spacecraft
   % and Sub-solar Points
   %
   function subpts()
 
   %
   % Local parameters
   %
   METAKR = 'subpts.tm';
 
   %
   % Load the kernels that this program requires.  We
   % will need:
   %
   %      A leapseconds kernel
   %      The necessary ephemerides
   %      A planetary constants file (PCK)
   %
   cspice_furnsh ( METAKR );
 
   %
   % Prompt the user for the input time string.
   %
   utctim = input ( 'Input UTC Time: ', 's' );
 
   fprintf ( 'Converting UTC Time: %s\n', utctim )
 
   %
   % Convert utctim to ET.
   %
   et = cspice_str2et ( utctim );
 
   fprintf ( '   ET seconds past J2000: %16.3f\n', et )
 
   %
   % Compute the apparent sub-observer point of PHSRM
   % on Phobos.
   %
   [spoint, trgepc, srfvec ] = ...
         cspice_subpnt ( 'NEAR POINT: ELLIPSOID',  'PHOBOS', ...
                         et, 'IAU_PHOBOS', 'LT+S', 'PHSRM'     );
 
   fprintf ( [ '   Apparent sub-observer point of PHSRM ', ...
               'on Phobos in the\n',                         ...
               '   IAU_PHOBOS frame (km):\n' ]                   )
 
   fprintf ( '      X = %16.3f\n', spoint(1) )
   fprintf ( '      Y = %16.3f\n', spoint(2) )
   fprintf ( '      Z = %16.3f\n', spoint(3) )
   fprintf ( '    ALT = %16.3f\n', norm(srfvec) )
 
   %
   % Compute the apparent sub-solar point on Phobos
   % as seen from PHSRM.
   %
   [spoint, trgepc, srfvec ] = ...
         cspice_subslr ( 'NEAR POINT: ELLIPSOID',  'PHOBOS', ...
                         et, 'IAU_PHOBOS', 'LT+S', 'PHSRM'     );
 
   fprintf ( [ '   Apparent sub-solar point ',        ...
               'on Phobos as seen from PHSRM in\n', ...
               '   the IAU_PHOBOS frame (km):\n' ]        )
 
   fprintf ( '      X = %16.3f\n', spoint(1) )
   fprintf ( '      Y = %16.3f\n', spoint(2) )
   fprintf ( '      Z = %16.3f\n', spoint(3) )
 
   %
   % Unload all kernels.
   %
   cspice_kclear;
 
   %
   % End of function subpts
   %


Top

Solution Sample Output



Execute the program:

                   < M A T L A B (R) >
         Copyright 1984-2010 The MathWorks, Inc.
      Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                    February 5, 2010
 
 
     To get started, type one of these: helpwin, helpdesk, or demo.
     For product information, visit www.mathworks.com.
 
   >> Converting UTC Time: 2013-02-10 20:40:00
      ET seconds past J2000:    413800866.185
      Apparent sub-observer point of PHSRM on Phobos in the
      IAU_PHOBOS frame (km):
         X =           -9.501
         Y =            7.897
         Z =            0.040
       ALT =           36.446
      Apparent sub-solar point on Phobos as seen from PHSRM in
      the IAU_PHOBOS frame (km):
         X =           -7.904
         Y =            8.282
         Z =           -2.986


Top

Intersecting Vectors with a Triaxial Ellipsoid (fovint)







Top

Task Statement




Write a program that prompts the user for an input UTC time string and, for that time, computes the intersection of the PHSRM TSNS NAC 1 camera boresight and field of view (FOV) boundary vectors with the surface of Phobos. The program presents each point of intersection as

    1. A cartesian vector in the IAU_PHOBOS frame

    2. Planetocentric (latitudinal) coordinates in the IAU_PHOBOS frame.

For each vector, if an intersection is found, the program displays the results of the above computations, otherwise it indicates no intersection has occurred.

At each point of intersection compute the following:

    3. Phase angle

    4. Solar incidence angle

    5. Emission angle

Additionally compute the local solar time at the intercept of the camera boresight with the surface of Phobos.

Use this program to compute values at the epoch:

    2013-02-10 20:40:00 UTC



Top

Learning Goals




Understand how field of view parameters are retrieved from instrument kernels. Learn how various standard planetary constants are retrieved from text PCKs. Discover how to compute the intersection of field of view vectors with triaxial ellipsoidal target bodies. Discover another high level geometry function and another time conversion function in Mice.



Top

Approach




This problem can be broken down into several simple, small steps:

    -- Decide which SPICE kernels are necessary. Prepare a meta-kernel listing the kernels and load it into the program. Remember, you will need to find a kernel with information about the PHSRM TSNS NAC 1 camera.

    -- Prompt the user for an input time string.

    -- Convert the input time string into ephemeris time expressed as seconds past J2000 TDB.

    -- Retrieve the FOV (field of view) configuration for the PHSRM TSNS NAC 1 camera.

For each vector in the set of boundary corner vectors, and for the boresight vector, perform the following operations:

    -- Compute the intercept of the vector with Phobos.

    -- If this intercept is found, convert the position vector of the intercept into planetocentric coordinates.

    Then compute the phase, solar incidence, and emission angles at the intercept. Otherwise indicate to the user no intercept was found for this vector.

    -- Compute the planetocentric longitude of the boresight intercept.

Finally

    -- Compute the local solar time at the boresight intercept longitude on a 24-hour clock. The input time for this computation should be the TDB observation epoch minus one-way light time from the boresight intercept to the spacecraft.

It may be useful to consult the name-ID definitions section at the end of the PHSRM frames kernel to determine the name of the TSNS NAC 1 camera. This exercise may make use of some of the concepts and (loosely) code from the ``Spacecraft Orientation and Reference Frames'' task.



Top

Solution






Top

Solution Meta-Kernel



The meta-kernel we created for the solution to this exercise is named 'fovint.tm'. Its contents follow:

   KPL/MK
 
   This is the meta-kernel used in the solution of the
   ``Intersecting Vectors with a Triaxial Ellipsoid'' task
   in the Remote Sensing Hands On Lesson.
 
      \begindata
      KERNELS_TO_LOAD = (
                'kernels/lsk/naif0009.tls',
                'kernels/sclk/phsrm_201008031645.tsc',
                'kernels/spk/de421xs.bsp',
                'kernels/spk/phobos_kiam_101231_v00.bsp',
                'kernels/spk/phsrm_130114_130114_130214_nom2.bsp',
                'kernels/fk/phsrm_v00.tf',
                'kernels/ck/phsrm_sc_test2_111108_130214_v00.bc',
                'kernels/pck/pck00009.tpc',
                'kernels/ik/phsrm_tsns_v00.ti'
                        )
      \begintext


Top

Solution Source Code



A sample solution to the problem follows:

   %
   % Remote sensing lesson:  Intersecting Vectors
   % with a Triaxial Ellipsoid
   %
 
   function fovint()
 
   %
   % Local Parameters
   %
   METAKR    = 'fovint.tm';
   BCVLEN    = 5;
 
   %
   % We use a cell array to store our vector names, which
   % have unequal lengths.
   %
   vecnam = { 'Boundary Corner 1',
              'Boundary Corner 2',
              'Boundary Corner 3',
              'Boundary Corner 4',
              'PHSRM TSNS NAC 1 Boresight' };
 
   %
   % Load the kernels that this program requires.  We will need:
   %
   %    A leapseconds kernel.
   %    A SCLK kernel for PHSRM.
   %    Any necessary ephemerides.
   %    The PHSRM frame kernel.
   %    A PHSRM C-kernel.
   %    A PCK file with Phobos constants.
   %    The PHSRM TSNS I-kernel.
   %
   cspice_furnsh ( METAKR );
 
   %
   % Prompt the user for the input time string.
   %
   utctim = input ( 'Input UTC Time: ', 's' );
 
   fprintf ( 'Converting UTC Time: %s\n', utctim )
 
   %
   % Convert utctim to ET.
   %
   et = cspice_str2et ( utctim );
 
   fprintf ( '  ET seconds past J2000: %16.3f\n', et )
 
   %
   % Now we need to obtain the FOV configuration of
   % the TSNS NAC 1 camera. To do this we will need the
   % ID code for PHSRM_TSNS_NAC_1.
   %
   [ nacid, found ] = cspice_bodn2c ( 'PHSRM_TSNS_NAC_1' );
 
   %
   % Stop the program if the code was not found.
   %
   if  ~found
 
      fprintf ( [ 'Unable to locate the ID code for ', ...
                  'PHSRM_TSNS_NAC_1\n' ]                    );
      return;
 
   end
 
   %
   % Now retrieve the field of view parameters.
   %
   [shape, insfrm, bsight, bounds] =  ...
      cspice_getfov ( nacid, BCVLEN );
 
 
   %
   % Rather than treat 'bsight' as a separate vector,
   % copy it and 'bounds' to 'scan_vecs'.
   %
   scan_vecs = [ bounds, bsight ];
 
   %
   % Now perform the same set of calculations for each
   % vector listed in the 'bounds' array.
   %
   for vi = 1:5
 
      %
      % Call sincpt to determine coordinates of the
      % intersection of this vector with the surface
      % of Phobos.
      %
      [ point, trgepc, srfvec, found ] =                    ...
         cspice_sincpt ( 'Ellipsoid',  'PHOBOS', et,        ...
                         'IAU_PHOBOS', 'LT+S',   'PHSRM', ...
                         insfrm,       scan_vecs(:,vi)          );
 
      %
      % Check the found flag.  Display a message if
      % the point of intersection was not found,
      % otherwise continue with the calculations.
      %
      fprintf ( 'Vector: %s\n', vecnam{vi} )
 
      if  ~found
 
          fprintf ( 'No intersection point found at this epoch.' );
 
      else
 
         %
         % Now, we have discovered a point of intersection.
         % Start by displaying the position vector in the
         % IAU_PHOBOS frame of the intersection.
         %
         fprintf ( [ '  Position vector of surface intercept ', ...
                     'in the IAU_PHOBOS frame (km):\n' ] );
 
         fprintf ( '     X   = %16.3f\n', point(1) )
         fprintf ( '     Y   = %16.3f\n', point(2) )
         fprintf ( '     Z   = %16.3f\n', point(3) )
 
         %
         % Display the planetocentric latitude and longitude
         % of the intercept.
         %
         [ radius, lon, lat ] = cspice_reclat ( point );
 
         fprintf ( [ '  Planetocentric coordinates of the ', ...
                     'intercept (degrees):\n' ]                   );
 
         fprintf ( '     LAT = %16.3f\n', lat * cspice_dpr );
         fprintf ( '     LON = %16.3f\n', lon * cspice_dpr );
 
         %
         % Compute the illumination angles at this point.
         %
         [ trgepc, srfvec, phase, solar, emissn ] =            ...
            cspice_ilumin ( 'Ellipsoid',  'PHOBOS', et,        ...
                            'IAU_PHOBOS', 'LT+S',   'PHSRM', ...
                            point                                  );
 
         fprintf ( [ '  Phase angle (degrees):',           ...
                     '             %14.3f\n'   ],          ...
                   phase  * cspice_dpr                         );
 
         fprintf ( [ '  Solar incidence angle (degrees):', ...
                     '   %14.3f\n'   ],                    ...
                   solar  * cspice_dpr                         );
 
         fprintf ( [ '  Emission angle (degrees):',        ...
                     '          %14.3f\n'   ],             ...
                     emissn * cspice_dpr                       );
 
      end
 
      fprintf ( '\n' );
 
   end
 
   %
   % Lastly compute the local solar time at the boresight
   % intersection.
   %
   if  found
 
      %
      % Get Phobos ID.
      %
      [ phoeid, found ] = cspice_bodn2c ( 'PHOBOS' );
 
      %
      % Return if the code was not found.
      %
      if  ~found
 
         fprintf ( 'Unable to locate the ID code for Phobos.' )
         return
 
      end
 
      %
      % Compute local solar time corresponding to the TDB light
      % time corrected epoch at the intercept.
      %
      [ hr, min, sc, time, ampm ] = ...
         cspice_et2lst ( trgepc, phoeid, lon, 'PLANETOCENTRIC' );
 
      fprintf ( [ '  Local Solar Time at boresight ', ...
                  'intercept (24 Hour Clock):\n',     ...
                   '     %s\n' ],                     ...
                time                                       )
 
   else
 
      fprintf ( [ '  No boresight intercept to compute ', ...
                  'local solar time.' ]                        )
   end
 
 
   %
   % Unload kernels we loaded at the start of the function.
   %
   cspice_unload ( METAKR );
 
   %
   % End of function fovint
   %


Top

Solution Sample Output



Execute the program:

                   < M A T L A B (R) >
         Copyright 1984-2010 The MathWorks, Inc.
      Version 7.10.0.499 (R2010a) 64-bit (glnxa64)
                    February 5, 2010
 
 
     To get started, type one of these: helpwin, helpdesk, or demo.
     For product information, visit www.mathworks.com.
 
   >> Converting UTC Time: 2013-02-10 20:40:00
     ET seconds past J2000:    413800866.185
   Vector: Boundary Corner 1
     Position vector of surface intercept in the IAU_PHOBOS frame (km):
        X   =           -7.873
        Y   =            9.060
        Z   =           -0.203
     Planetocentric coordinates of the intercept (degrees):
        LAT =           -0.971
        LON =          130.989
     Phase angle (degrees):                     26.338
     Solar incidence angle (degrees):           22.465
     Emission angle (degrees):                  12.132
 
   Vector: Boundary Corner 2
     Position vector of surface intercept in the IAU_PHOBOS frame (km):
        X   =           -7.889
        Y   =            9.044
        Z   =            0.340
     Planetocentric coordinates of the intercept (degrees):
        LAT =            1.622
        LON =          131.101
     Phase angle (degrees):                     25.527
     Solar incidence angle (degrees):           26.790
     Emission angle (degrees):                  12.108
 
   Vector: Boundary Corner 3
     Position vector of surface intercept in the IAU_PHOBOS frame (km):
        X   =           -8.355
        Y   =            8.748
        Z   =            0.316
     Planetocentric coordinates of the intercept (degrees):
        LAT =            1.498
        LON =          133.684
     Phase angle (degrees):                     25.279
     Solar incidence angle (degrees):           26.523
     Emission angle (degrees):                   8.968
 
   Vector: Boundary Corner 4
     Position vector of surface intercept in the IAU_PHOBOS frame (km):
        X   =           -8.338
        Y   =            8.764
        Z   =           -0.226
     Planetocentric coordinates of the intercept (degrees):
        LAT =           -1.068
        LON =          133.574
     Phase angle (degrees):                     26.096
     Solar incidence angle (degrees):           22.151
     Emission angle (degrees):                   9.076
 
   Vector: PHSRM TSNS NAC 1 Boresight
     Position vector of surface intercept in the IAU_PHOBOS frame (km):
        X   =           -8.120
        Y   =            8.909
        Z   =            0.057
     Planetocentric coordinates of the intercept (degrees):
        LAT =            0.270
        LON =          132.344
     Phase angle (degrees):                     25.807
     Solar incidence angle (degrees):           24.456
     Emission angle (degrees):                  10.241
 
     Local Solar Time at boresight intercept (24 Hour Clock):
        12:34:36