<p>I'm no SPICE expert but here are some potential solutions (unless of course you want to try <a href="https://rhodesmill.org/skyfield/almanac.html" rel="nofollow noreferrer">Skyfield's Almanac methods</a>!)</p>
<h3>Firsrt possibility, but all these may not work</h3>
<p><a href="https://astronomy.stackexchange.com/a/18029/7982">this answer</a> links to <a href="https://astronomy.stackexchange.com/questions/17942/17946#comment27647_17946">this comment</a> links to <a href="https://naif.jpl.nasa.gov/naif/tutorials.html" rel="nofollow noreferrer">SPICE Tutorials, Updated December 11, 2019</a> links to the 69 slide presentation <a href="https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/Tutorials/pdf/individual_docs/29_geometry_finder.pdf" rel="nofollow noreferrer">SPICE Geometry Finder (GF) Subsystem; Searching for times when specified
geometric conditions occur</a> dated January 2020.</p>
<ul>
<li>Much SPICE software computes a geometry parameter at a given time, t, i.e. x = f(t). Example: on 2011 MAR 30 14:57:08, what is the spacecraft’s altitude
above Mars?</li>
<li>The <strong>Geometry Finder subsystem</strong> does the inverse: it finds times when specified geometric events occur</li>
</ul>
<p>GF provides two primary types of event-finding APIs</p>
<ul>
<li>Boolean: a geometric condition (an event) is true or false
– Numeric: a geometric quantity has a given value, is within a given range or has achieved a local or global maximum or minimum</li>
</ul>
<p>In your case you would specify a position on a body, then look for times when elevation was 0 or 0+/- small.</p>
<h3>Another possibility, this seems to address exactly what you are looking for</h3>
<ul>
<li><p><a href="https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcpo_c.html" rel="nofollow noreferrer">https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcpo_c.html</a></p>
<p>Examples</p>
<p>The numerical results shown for these examples may differ across
platforms. The results depend on the SPICE kernels used as
input, the compiler and supporting libraries, and the machine<br />
specific arithmetic implementation.</p>
<ol>
<li><p>Compute apparent solar azimuth and elevation as seen from a
specified surface point on the earth.</p>
<h1>Task Description</h1>
<p>In this example we'll use the location of the DSN station<br />
DSS-14 as our surface point.</p>
<p>We'll perform the solar azimuth and elevation computation two
ways:</p>
<ul>
<li><p>Using a station frame kernel to provide the<br />
specification of a topocentric reference frame
centered at DSS-14.</p>
</li>
<li><p>Computing inline the transformation from the earth-fixed,
earth-centered frame ITRF93 to a topocentric frame
centered at DSS-14.</p>
</li>
</ul>
<p>Note that results of the two computations will differ
slightly. There are three sources of the differences:</p>
<ol>
<li><p>The station position is time-dependent due to tectonic
plate motion, and epochs of the station positions used
to specify the axes of the topocentric frame are
different in the two cases. This gives rise to different
orientations of the frame's axes relative to the frame
ITRF93.</p>
</li>
<li><p>The two computations use different earth radii; this
results in computation of different geodetic latitudes
of the station. This difference also affects the
topocentric frame orientation relative to ITRF93.</p>
</li>
<li><p>The station movement between ET and the epoch at which
the DSS-14_TOPO frame is specified contributes a very
small offset---on the order of 10 cm---to the station-sun
position vector, expressed in the ITRF93 frame.</p>
</li>
</ol>
</li>
</ol>
</li>
</ul>
<p>and there's a lot more there.</p>
<h3>It seems you can do the same thing in Python using <a href="https://spiceypy.readthedocs.io/_/downloads/en/main/pdf/" rel="nofollow noreferrer">SpicyPy</a></h3>
<blockquote>
<p>Find the azimuth and elevation of the apparent position of the Moon as seen from the DSN station DSS-13 by the following steps:</p>
<ol start="11">
<li>Find the apparent position vector of the Moon relative to the DSN station DSS-13 in the topocentric reference frame DSS-13_TOPO at epoch ET. Use light time and stellar aberration corrections.</li>
</ol>
<p>For this step, you'll need to have loaded a station SPK file providing geocentric station position vectors, as well as a frame kernel specifying topocentric reference frames centered at the respective DSN stations. (Other kernels will be needed as well; you must choose these.)</p>
<ol start="12">
<li><p>Convert the position vector to latitudinal coordinates. Use the routine spiceypy.reclat for this computation.</p>
</li>
<li><p>Compute the Moon's azimuth and elevation as follows: azimuth is the negative of topocentric longitude and lies within the range 0-360 degrees; elevation is equal to the topocentric latitude. Display the results in degrees.</p>
</li>
</ol>
</blockquote>

CC BY-SA 4.0
2021-05-18T02:49:00.373Z
Thanks for the detailed answer
phil5
CC BY-SA 4.0
2021-05-15T04:13:42.597Z
2021-05-15T04:13:42.597Z
uhoh
<p>I've seen it mentioned <a href="https://stackoverflow.com/questions/704088/how-can-i-compute-sunrise-sunset-times#comment57112503_704088">here</a> that SPICE can be used to calculate sunrise and sunset. How?</p>
<p>According to the official <a href="https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/info/intrdctn.html" rel="nofollow noreferrer">documentation</a>, SPICE is used to calculate:</p>
<ul>
<li>Time system conversions</li>
<li>Positions of spacecraft and natural bodies</li>
<li>Orientation of spacecraft and instruments</li>
<li>Reference frame transformations</li>
<li>Illumination angles</li>
</ul>
<p>I know sunrise and sunset can be calculated from the Sun's coordinates and the <a href="https://en.wikipedia.org/wiki/Sunrise_equation" rel="nofollow noreferrer">sunrise equation</a>.</p>
<p>I was wondering if SPICE had a specific algorithm for this purpose?</p>

CC BY-SA 4.0
2021-05-15T03:14:49.740Z
This is an interesting and legitimate question; using SPICE you can specify a location on many solar system bodies using a latitude and longitude and calculate an altitude and azimuth of another body, and at least for Earth you can correct for atmospheric refraction, and I believe SPICE will help you to search for a time when altitude is zero (sunrise/sunset). [Here's an example](https://space.stackexchange.com/a/37155/12102) of doing it with JPL's Horizons website which I think itself uses SPICE. But I wonder if in addition to your question as asked, you would be interested in *also trying*
uhoh
CC BY-SA 4.0
2021-05-15T03:15:05.380Z
…something that mighrt be a lot easier? If you would like to dabble in Python, then check https://rhodesmill.org/skyfield/almanac.html Skyfield uses the same [JPL Development Ephemerides](https://en.wikipedia.org/wiki/Jet_Propulsion_Laboratory_Development_Ephemeris) that Horizons and SPICE do, but is a heck of a lot easier and more intuitive to use because it's a modern Python implementation rather than something originally designed for [career JPL mission planners using mainframes in the 1980's](https://space.stackexchange.com/q/49791/12102). What a difference 40 years makes!
uhoh
<algorithm><sunrise><sunset>
How does one use SPICE to calculate sunrise and sunset?
phil5
# How does one use SPICE to calculate sunrise and sunset?

(Asked by: username_0 on 2021-05-14)

I've seen it mentioned [here](https://stackoverflow.com/questions/704088/how-can-i-compute-sunrise-sunset-times#comment57112503_704088) that SPICE can be used to calculate sunrise and sunset. How?

According to the official [documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/info/intrdctn.html), SPICE is used to calculate:

* Time system conversions
* Positions of spacecraft and natural bodies
* Orientation of spacecraft and instruments
* Reference frame transformations
* Illumination angles

I know sunrise and sunset can be calculated from the Sun's coordinates and the [sunrise equation](https://en.wikipedia.org/wiki/Sunrise_equation).

I was wondering if SPICE had a specific algorithm for this purpose?

**Tags:** algorithm, sunrise, sunset

> **Comments:**
> **username_1**: This is an interesting and legitimate question; using SPICE you can specify a location on many solar system bodies using a latitude and longitude and calculate an altitude and azimuth of another body, and at least for Earth you can correct for atmospheric refraction, and I believe SPICE will help you to search for a time when altitude is zero (sunrise/sunset). [Here's an example](https://space.stackexchange.com/a/37155/12102) of doing it with JPL's Horizons website which I think itself uses SPICE. But I wonder if in addition to your question as asked, you would be interested in *also trying*  
> **username_1**: …something that mighrt be a lot easier? If you would like to dabble in Python, then check https://rhodesmill.org/skyfield/almanac.html Skyfield uses the same [JPL Development Ephemerides](https://en.wikipedia.org/wiki/Jet_Propulsion_Laboratory_Development_Ephemeris) that Horizons and SPICE do, but is a heck of a lot easier and more intuitive to use because it's a modern Python implementation rather than something originally designed for [career JPL mission planners using mainframes in the 1980's](https://space.stackexchange.com/q/49791/12102). What a difference 40 years makes!  

---

## 1 answers

### Answer by username_1 on 2021-05-15. Score: 1

I'm no SPICE expert but here are some potential solutions (unless of course you want to try [Skyfield's Almanac methods](https://rhodesmill.org/skyfield/almanac.html)!)

### Firsrt possibility, but all these may not work

[this answer](https://astronomy.stackexchange.com/a/18029/7982) links to [this comment](https://astronomy.stackexchange.com/questions/17942/17946#comment27647_17946) links to [SPICE Tutorials, Updated December 11, 2019](https://naif.jpl.nasa.gov/naif/tutorials.html) links to the 69 slide presentation [SPICE Geometry Finder (GF) Subsystem; Searching for times when specified
geometric conditions occur](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/Tutorials/pdf/individual_docs/29_geometry_finder.pdf) dated January 2020.

* Much SPICE software computes a geometry parameter at a given time, t, i.e. x = f(t). Example: on 2011 MAR 30 14:57:08, what is the spacecraft’s altitude
  above Mars?
* The **Geometry Finder subsystem** does the inverse: it finds times when specified geometric events occur

GF provides two primary types of event-finding APIs

* Boolean: a geometric condition (an event) is true or false
  – Numeric: a geometric quantity has a given value, is within a given range or has achieved a local or global maximum or minimum

In your case you would specify a position on a body, then look for times when elevation was 0 or 0+/- small.

### Another possibility, this seems to address exactly what you are looking for

* <https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcpo_c.html>

  Examples

  The numerical results shown for these examples may differ across
  platforms. The results depend on the SPICE kernels used as
  input, the compiler and supporting libraries, and the machine  
  specific arithmetic implementation.

  1. Compute apparent solar azimuth and elevation as seen from a
     specified surface point on the earth.

     # Task Description

     In this example we'll use the location of the DSN station  
     DSS-14 as our surface point.

     We'll perform the solar azimuth and elevation computation two
     ways:

     + Using a station frame kernel to provide the  
       specification of a topocentric reference frame
       centered at DSS-14.
     + Computing inline the transformation from the earth-fixed,
       earth-centered frame ITRF93 to a topocentric frame
       centered at DSS-14.

     Note that results of the two computations will differ
     slightly. There are three sources of the differences:

     1. The station position is time-dependent due to tectonic
        plate motion, and epochs of the station positions used
        to specify the axes of the topocentric frame are
        different in the two cases. This gives rise to different
        orientations of the frame's axes relative to the frame
        ITRF93.
     2. The two computations use different earth radii; this
        results in computation of different geodetic latitudes
        of the station. This difference also affects the
        topocentric frame orientation relative to ITRF93.
     3. The station movement between ET and the epoch at which
        the DSS-14\_TOPO frame is specified contributes a very
        small offset---on the order of 10 cm---to the station-sun
        position vector, expressed in the ITRF93 frame.

and there's a lot more there.

### It seems you can do the same thing in Python using [SpicyPy](https://spiceypy.readthedocs.io/_/downloads/en/main/pdf/)

> Find the azimuth and elevation of the apparent position of the Moon as seen from the DSN station DSS-13 by the following steps:
>
> 11. Find the apparent position vector of the Moon relative to the DSN station DSS-13 in the topocentric reference frame DSS-13\_TOPO at epoch ET. Use light time and stellar aberration corrections.
>
> For this step, you'll need to have loaded a station SPK file providing geocentric station position vectors, as well as a frame kernel specifying topocentric reference frames centered at the respective DSN stations. (Other kernels will be needed as well; you must choose these.)
>
> 12. Convert the position vector to latitudinal coordinates. Use the routine spiceypy.reclat for this computation.
> 13. Compute the Moon's azimuth and elevation as follows: azimuth is the negative of topocentric longitude and lies within the range 0-360 degrees; elevation is equal to the topocentric latitude. Display the results in degrees.

> **Comments:**
> **username_0**: Thanks for the detailed answer  

---

