<?php /** * An example for looking up the current solar position in the sky from a given * location (elevation/azimuth) */ require_once 'Predict/Solar.php'; require_once 'Predict/QTH.php'; // Use current time in the form of a daynum $time = time(); $daynum = Predict_Time::unix2daynum($time); // Set up the observer position on the ground $qth = new Predict_QTH(); $qth->lat = 37.786759; $qth->lon = -122.405162; $qth->alt = 10; // Altitude above sea level in meters $sunInfo = Predict_Solar::FindSun($qth, $daynum); $output = array('elevation' => $sunInfo->el, 'azimuth' => $sunInfo->az, 'timestamp' => $time); // output results echo json_encode($output);
/** * Calculate satellite visibility. * * @param Predict_Sat $sat The satellite structure. * @param Predict_QTH $qth The QTH * @param float $jul_utc The time at which the visibility should be calculated. * * @return int The visiblity constant, 0, 1, 2, or 3 (see above) */ public function get_sat_vis(Predict_Sat $sat, Predict_QTH $qth, $jul_utc) { /* gboolean sat_sun_status; gdouble sun_el; gdouble threshold; gdouble eclipse_depth; sat_vis_t vis = SAT_VIS_NONE; */ $eclipse_depth = 0.0; $zero_vector = new Predict_Vector(); $obs_geodetic = new Predict_Geodetic(); /* Solar ECI position vector */ $solar_vector = new Predict_Vector(); /* Solar observed az and el vector */ $solar_set = new Predict_ObsSet(); /* FIXME: could be passed as parameter */ $obs_geodetic->lon = $qth->lon * self::de2ra; $obs_geodetic->lat = $qth->lat * self::de2ra; $obs_geodetic->alt = $qth->alt / 1000.0; $obs_geodetic->theta = 0; Predict_Solar::Calculate_Solar_Position($jul_utc, $solar_vector); Predict_SGPObs::Calculate_Obs($jul_utc, $solar_vector, $zero_vector, $obs_geodetic, $solar_set); if (Predict_Solar::Sat_Eclipsed($sat->pos, $solar_vector, $eclipse_depth)) { /* satellite is eclipsed */ $sat_sun_status = false; } else { /* satellite in sunlight => may be visible */ $sat_sun_status = true; } if ($sat_sun_status) { $sun_el = Predict_Math::Degrees($solar_set->el); if ($sun_el <= $this->threshold && $sat->el >= 0.0) { $vis = self::SAT_VIS_VISIBLE; } else { $vis = self::SAT_VIS_DAYLIGHT; } } else { $vis = self::SAT_VIS_ECLIPSED; } return $vis; }
<?php /** * An example of looking up the lat/lon of the sun for putting on a map. * "dark" lat/lon is the anti-solar point, useful for drawing a * "solar terminator" */ // No autoloading here, require needed files require_once 'Predict/Solar.php'; require_once 'Predict/SGPObs.php'; require_once 'Predict/Math.php'; require_once 'Predict/Time.php'; // Set up data constructs $solar_vector = new Predict_Vector(); $solar_geodetic = new Predict_Geodetic(); // Use current time in the form of a daynum $time = time(); $daynum = Predict_Time::unix2daynum($time); // Do calculations Predict_Solar::Calculate_Solar_Position($daynum, $solar_vector); Predict_SGPObs::Calculate_LatLonAlt($daynum, $solar_vector, $solar_geodetic); // Format to degrees $solar_lat = Predict_Math::Degrees($solar_geodetic->lat); $solar_lon = Predict_Math::Degrees($solar_geodetic->lon); // Reverse values for night circle center $dark_lat = -$solar_lat; $dark_lon = -$solar_lon; $output = array('solar_lat' => $solar_lat, 'solar_lon' => $solar_lon, 'dark_lat' => $dark_lat, 'dark_lon' => $dark_lon, 'timestamp' => $time); // output results var_dump(json_encode($output));
/** * Experimental attempt at calculating apparent magnitude. Known intrinsic * magnitudes are listed inside the function for now. * * @param float $time The daynum the satellite is calculated for * @param Predict_QTH $qth The observer location * * @return null on failure, float otherwise */ public function calculateApparentMagnitude($time, Predict_QTH $qth) { // Recorded intrinsic magnitudes and their respective // illumination and distance from heavens-above.com static $intrinsicMagnitudes = array('25544' => array('mag' => -1.3, 'illum' => 0.5, 'distance' => 1000)); // Return null if we don't have a record of the intrinsic mag if (!isset($intrinsicMagnitudes[$this->tle->catnr])) { return null; } $imag = $intrinsicMagnitudes[$this->tle->catnr]; // Convert the observer's geodetic info to radians and km so // we can compare vectors $observerGeo = new Predict_Geodetic(); $observerGeo->lat = Predict_Math::Radians($qth->lat); $observerGeo->lon = Predict_Math::Radians($qth->lon); $observerGeo->alt = $qth->alt * 1000; // Now determine the sun and observer positions $observerPos = new Predict_Vector(); $observerVel = new Predict_Vector(); $solarVector = new Predict_Vector(); Predict_Solar::Calculate_Solar_Position($time, $solarVector); Predict_SGPObs::Calculate_User_PosVel($time, $observerGeo, $observerPos, $observerVel); // Determine the solar phase and and thus the percent illumination $observerSatPos = new Predict_Vector(); Predict_Math::Vec_Sub($this->pos, $observerPos, $observerSatPos); $phaseAngle = Predict_Math::Degrees(Predict_Math::Angle($solarVector, $observerSatPos)); $illum = $phaseAngle / 180; $illuminationChange = $illum / $imag['illum']; $inverseSquareOfDistanceChange = pow($imag['distance'] / $this->range, 2); $changeInMagnitude = log($illuminationChange * $inverseSquareOfDistanceChange, self::POGSONS_RATIO); return $imag['mag'] - $changeInMagnitude; }