Step to specified sun depression script

This Stellarium script lets you specify the desired sun depression, morning or evening, to step to. It is useful for seeing how the stars appeared at civil, nautical, and astronomic dusk/dawn conditions, among other things.

// ******************************************************************************************
// Stellarium script to go to specified sun depression, either morning or evening,
// depending upon variable setting.
//
// Created by David O'Neil, Aug, 2019. Released to the public domain, for anyone interested.
// Just leave this 'created by' (or 'originally created by') verbage in the derived work.
//
// To use:
//   * Set the date via Stellarium's user interface
//   * Set 'gotoMorning' = true for morning viewing, false for evening
//   * You might want to change the 'core.wait(0.03);' line to another number, so
//     Stellarium has enough time to process and update before checking new positions.
//     This is dependent upon your computer's capabilities, since Stellarium does not
//     do things asynchronously for scripting.
//   * Run the script.
//   * You can change the year/month/day and Stellarium will automatically update
//     the time to the selected sun depression. Once it is finished getting to the time,
//     the selected object will be re-selected (the cross-hairs will reappear).
// ******************************************************************************************



objectToSelect = "Mars";   //SET THIS ONE (to "" if you want nothing selected)
gotoMorning = true;        //SET THIS ONE!
//gotoMorning = false;
desiredDepression = 18.0;  //AND SET THIS ONE! The next chart is useful:

GridLinesMgr.setFlagHorizonLine(true);
LandscapeMgr.setFlagCardinalsPoints(true);

//These are the arcus visionis values for the planets, and an estimation for Sirius:
//The planetary values were taken from the Planetary, Lunar, and Stellar Visibility computer
//program, version 3.1.0, 2006, by Rainer Lange and Noel M. Swerdlow. The newest version
//should be at http://www.alcyone.de/planetary_lunar_and_stellar_visibility.html.
//
// Inner Planets   Morning First       Morning Last       Evening First       Evening Last
//  Mercury            13.0°               9.5°               10.5°              11.0°
//  Venus               5.7°               6.0°                6.0°               5.2°
//
//                Heliacal Rising    Heliacal Setting   Acronychal Rising   Cosmical Setting
// Object            (Morning)          (Evening)           (Evening)          (Morning)
//  Mars               14.5°              13.2°                6.0°               6.0°
//
//  Jupiter             9.3°               7.4°                6.0°               6.0°
//
//  Saturn             13.0°              10.0°                8.0°               8.0°
//
//  Sirius              7.8°               6.5°                4.0°               4.0°
//
// In addition, Civil Dusk = 0 - 6°, Nautical = 6 - 12°, Astronomic = 12 - 18°

desiredDepression = -desiredDepression;   //Enter it positively, and switch to negative here.
sunAzimuth = core.getObjectInfo("Sun").azimuth;
sunAlt = core.getObjectInfo("Sun").altitude;
//A 'catch up' time for Stellarium to do its work before re-querying attributes
waitTime = 0.03;

if (sunAzimuth >= 180 && sunAzimuth <= 360 && gotoMorning) {   //180 - 360 = western sun
   //We need to shift by half day.
   core.setDate("-12 hours");
   }
else if (sunAzimuth >= 0 && sunAzimuth <= 180 && !gotoMorning) {  //eastern sun
   core.setDate("+12 hours");
   }

core.wait(waitTime);  //Let computer catch up.
sunAzimuth = core.getObjectInfo("Sun").azimuth;
sunAlt = core.getObjectInfo("Sun").altitude;

// We now have 4 conditions:
// 1 - looking for morning, sun above desired condition
// 2 - looking for morning, sun below desired condition
// 3 - looking for evening, sun above desired condition
// 4 - looking for evening, sun below desired condition.

// For 1 and 4, the sun needs to go backward with respect to its normal forward movement.
// But each case stands on its own, because one coming from below, the other from above.

//So we can loop the entire chain, so the user can change the date and Stellarium
//will automatically update when change is made

lastDate = "dummy start date";
core.wait(waitTime);
justFinishedProcessing = false;

while (true) {
   specifiedDate = core.getDate();
   if (justFinishedProcessing) {
      lastDate = specifiedDate;
      justFinishedProcessing = false;
      }
   if (specifiedDate != lastDate) {
      //Clear the crosshairs, so you can tell it is processing:
      core.selectObjectByName("", true);
      sunAlt = core.getObjectInfo("Sun").altitude;
      // Case 1:
      if (gotoMorning && sunAlt>desiredDepression) {
         //Go backward first:
         while (sunAlt>desiredDepression) {
            gotoTime("-10 minutes");
            }
         //Then forward:
         while (sunAlt<desiredDepression) {
            gotoTime("+1 minutes");
            }
         //You get the picture...
         while (sunAlt>desiredDepression) {
            gotoTime("-10 seconds");
            }
         while (sunAlt<desiredDepression) {
            gotoTime("+1 seconds");
            }
         while (sunAlt>desiredDepression) {
            gotoTime("-1 seconds");
            }
         sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
        }

      //Case 2, start at morning below
      else if (gotoMorning && sunAlt<desiredDepression) {
         //Go forward first:
         while (sunAlt<desiredDepression) {
            gotoTime("+10 minutes");
            }
         //Then backward:
         while (sunAlt>desiredDepression) {
            gotoTime("-1 minutes");
            }
         //You get the picture...
         while (sunAlt<desiredDepression) {
            gotoTime("+10 seconds");
            }
         while (sunAlt>desiredDepression) {
            gotoTime("-1 seconds");
            }
         sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
         }
         
      //Case 3, start at evening above
      else if (!gotoMorning && sunAlt>desiredDepression) {
         //Go forward first:
         while (sunAlt>desiredDepression) {
            gotoTime("+10 minutes");
            }
         //Then backward:
         while (sunAlt<desiredDepression) {
            gotoTime("-1 minutes");
            }
         //You get the picture...
         while (sunAlt>desiredDepression) {
            gotoTime("+10 seconds");
            }
         while (sunAlt<desiredDepression) {
            gotoTime("-1 seconds");
            }
          sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
        }

      //Case 4, start at evening below
      else if (!gotoMorning && sunAlt<desiredDepression) {
         //Go backward first:
         while (sunAlt<desiredDepression) {
            gotoTime("-10 minutes");
            }
         //Then forward:
         while (sunAlt>desiredDepression) {
            gotoTime("+1 minutes");
            }
         //You get the picture...
         while (sunAlt<desiredDepression) {
            gotoTime("-10 seconds");
            }
         while (sunAlt>desiredDepression) {
            gotoTime("+1 seconds");
            }
         sunAlt = desiredDepression;   //It has been done, so quit jimmying with it.
         }
      justFinishedProcessing = true;
      lastDate = specifiedDate;
      core.debug(sunAlt);
      
      //If you want to add a marker, for showing trajectory day-by-day:
      //alt = core.getObjectInfo(objectToSelect).altitude;
      //azi = core.getObjectInfo(objectToSelect).azimuth;
      //HighlightMgr.addPointAltAzi(alt, azi);
      //HighlightMgr.update(1440);
      //And later, to unhighlight it:
      //HighlightMgr.cleanHighlightList();
      // Unfortunately, highlights move with background, not stay at alt/azi!
      // To overcome this, you will need to store a list of alt/azi values, then
      // plot them at the end of a sequence.
      
      //Set the crosshairs again, to tell it is done processing:
      core.selectObjectByName(objectToSelect, true);
      core.wait(0.3);
      core.setTimeRate(0); //Lock the sky in place, so we can see it unmoving!
      }
   core.wait(0.1); //Allow the processor some rest.
   }
   

function gotoTime(time) {
   core.setDate(time);
   core.wait(waitTime);
   sunAlt = core.getObjectInfo("Sun").altitude;
   }

Leave a Reply

Your email address will not be published. Required fields are marked *

Search Site / View Categories / View Tags

All content © 2005-present by David O'Neil