Sun position
Sun position algorithm
|
sky.h - structures and routines for astronomical observing & tracking More...
Go to the source code of this file.
Data Structures | |
struct | Sky_TrueEquatorial |
Struct used for holding an object's coordinates in equatorial apparent or Intermediate coordinates. More... | |
struct | Sky_SiteHorizon |
Coordinates of a celestial object in the horizon frame, in both rectangular and polar forms. More... | |
struct | Sky_DeltaTs |
This structure contains relatively constant data, and is set up by one of the three functions sky_initTime(), sky_initTimeSimple() or sky_initTimeDetailed(). More... | |
struct | Sky_Times |
This structure contains the continuously varying time (and earth rotation) data, in various forms that we will find useful. More... | |
struct | Sky_PolarMot |
This structure contains polar motion parameters and a rotation matrix. More... | |
struct | Sky_SiteProp |
Site properties. More... | |
Functions | |
void | sky_initTime (int deltaAT_s, double deltaUT_s, Sky_DeltaTs *d) |
This is one of three alternative routines for setting up the various delta time values for use in ongoing calculations. More... | |
void | sky_initTimeSimple (Sky_DeltaTs *d) |
This is one of three alternative routines for setting up the various delta time values for use in ongoing calculations. More... | |
void | sky_initTimeDetailed (double mjdUtc, double usnoMjdBase, double usnoCoeffC11, double usnoCoeffC12, int deltaAT_s, Sky_DeltaTs *d) |
This is one of three alternative routines for setting up the various delta time values for use in ongoing calculations. More... | |
double | sky_calTimeToJ2kd (int year, int month, int day, int hour, int minute, double second, double tz_h) |
Return the number of days (and fraction of a day) since noon 2000 Jan 1 (UTC) of the given calendar date and time. More... | |
double | sky_unixTimeToJ2kd (time_t unixTime) |
Convert a time in Unix system time format to days since 2000 Jan 1, noon UTC. More... | |
double | sky_unixTimespecToJ2kd (struct timespec uTs) |
double | sky_calTimeToMjd (int year, int month, int day, int hour, int minute, double second, double tz_h) |
double | sky_unixTimeToMjd (time_t unixTime) |
double | sky_unixTimespecToMjd (struct timespec uTs) |
void | sky_updateTimes (double j2kUtc_d, const Sky_DeltaTs *d, Sky_Times *t) |
Convert the given "J2KD" in the UTC timescale to the other timescales, and pre-calculate some other quantities. More... | |
void | sky_updateTimesFromMjd (double mjdUtc, const Sky_DeltaTs *d, Sky_Times *t) |
void | sky_setPolarMotion (double xPolar_as, double yPolar_as, double t_cy, Sky_PolarMot *polar) |
Update polar motion correction. More... | |
void | sky_j2kdToCalTime (double j2k_d, int *year, int *month, int *day, int *hour, int *minute, double *second) |
This procedure converts the integral part of the date in "J2KD" form to a calendar date and the fractional part to hours, minutes and seconds. More... | |
void | sky_mjdToCalTime (double mjd, int *year, int *month, int *day, int *hour, int *minute, double *second) |
void | sky_setSiteLocation (double latitude_deg, double longitude_deg, double height_m, Sky_SiteProp *site) |
Initialise the site structure by calculating those site-related values that do not change with time. More... | |
void | sky_setSiteLoc2 (double astLat_deg, double astLong_deg, double geodLat_deg, double geodLong_deg, double height_m, Sky_SiteProp *site) |
Alternative initialisation function to sky_setSiteLocation(). More... | |
void | sky_setSiteTempPress (double temperature_degC, double pressure_hPa, Sky_SiteProp *site) |
Set refraction coefficients based on atmospheric temperature and pressure at the site. More... | |
void | sky_setSiteTimeZone (double timeZone_h, Sky_SiteProp *site) |
Set the time zone offset for this site. More... | |
void | sky_setupSiteSurface (double azimuth_deg, double slope_deg, Sky_SiteHorizon *surface) |
Set the orientation and slope of a surface (such as a solar panel) for which you want to calculate the incidence angle of incoming radiation. More... | |
void | sky_adjustSiteForPolarMotion (const Sky_PolarMot *polar, Sky_SiteProp *site) |
Modify our azEl rotation matrix to incorporate a polar motion rotation matrix. More... | |
void | sky_siteTirsToTopo (const V3D_Vector *terInterV, double dist_au, const Sky_SiteProp *site, Sky_SiteHorizon *topo) |
Transform a coordinate vector from the Terrestrial Intermediate Reference System to topocentric Az/El coordinates for the observing site whose properties are described in parameter "site". More... | |
void | sky_siteAzElToHaDec (const V3D_Vector *topoV, const Sky_SiteProp *site, double *hourAngle_rad, double *declination_rad) |
Take a topocentric position vector in Azimuth/Elevation frame and use it to calculate the observed Hour Angle and Declination. More... | |
double | sky_siteIncidence_rad (const V3D_Vector *topoV, const V3D_Vector *surfaceV) |
Calculate the incidence angle of rays from the celestial object described by topoV (such as the sun) falling onto a surface described by surfaceV (such as a solar panel). More... | |
sky.h - structures and routines for astronomical observing & tracking
This collection is in two parts:
The routines are designed to provide an efficient implementation of the necessary calculations. When combined with the routines in the skyfast.h and skyfast.c module, they enable accurate tracking with even a small processor.
Other modules required:
You will need to separately include one of the following modules:
Definition in file sky.h.
void sky_initTime | ( | int | deltaAT_s, |
double | deltaUT_s, | ||
Sky_DeltaTs * | d | ||
) |
This is one of three alternative routines for setting up the various delta time values for use in ongoing calculations.
(The other two are sky_initTimeDetailed() and sky_initTimeSimple()). For an explanation of these delta times, see Timescales, and converting between them.
[in] | deltaAT_s | (= TAI - UTC). Cumulative number of leap seconds (seconds) |
[in] | deltaUT_s | (= UT1 - UTC) (seconds). Valid range [-0.9,+0.9] |
[out] | d | Fields initialised as follows:
|
Definition at line 96 of file sky-time.c.
void sky_initTimeSimple | ( | Sky_DeltaTs * | d | ) |
This is one of three alternative routines for setting up the various delta time values for use in ongoing calculations.
(The other two are sky_initTime() and sky_initTimeDetailed()). This function initialises the delta times with simnple default values. For an explanation of these delta times, see Timescales, and converting between them.
[out] | d | Fields initialised as follows:
|
Definition at line 181 of file sky-time.c.
void sky_initTimeDetailed | ( | double | mjdUtc, |
double | usnoMjdBase, | ||
double | usnoCoeffC11, | ||
double | usnoCoeffC12, | ||
int | deltaAT_s, | ||
Sky_DeltaTs * | d | ||
) |
This is one of three alternative routines for setting up the various delta time values for use in ongoing calculations.
(The other two are sky_initTime() and sky_initTimeSimple()). This routine uses a prediction formula to calculate the value of delta_UT, rather than having it specified directly. For an explanation of these delta times, see Timescales, and converting between them.
[in] | mjdUtc | Modified Julian Date (= JD - 2 400 000.5), UTC timescale |
[in] | usnoMjdBase,usnoCoeffC11,usnoCoeffC12 | US Naval Observatory prediction formula values. These three values are obtained from "Bulletin A" of the International Earth Rotation Service (IERS), updated at the IERS (& USNO) website from time to time (see Timescales, and converting between them) |
[in] | deltaAT_s | (= TAI - UTC). Cumulative number of leap seconds (seconds) |
[out] | d | Fields initialised as follows:
|
Definition at line 134 of file sky-time.c.
double sky_calTimeToJ2kd | ( | int | year, |
int | month, | ||
int | day, | ||
int | hour, | ||
int | minute, | ||
double | second, | ||
double | tz_h | ||
) |
Return the number of days (and fraction of a day) since noon 2000 Jan 1 (UTC) of the given calendar date and time.
This is one of three alternative routines that return a J2KD - the other two are sky_unixTimeToJ2kd() and sky_unixTimespecToJ2kd().
[in] | year,month,day | calendar date |
[in] | hour | valid range [0, 23] |
[in] | minute | valid range [0, 59] |
[in] | second | valid range [0.0, 60.0) |
[in] | tz_h | time zone offset (hours), positive for zones east of Greenwich (e.g. Australian time zones AEST = +10.0, ACST = +9.5, AEDT = +11.0; UTC = 0.0; USA time zones are negative) |
Definition at line 241 of file sky-time.c.
double sky_unixTimeToJ2kd | ( | time_t | unixTime | ) |
Convert a time in Unix system time format to days since 2000 Jan 1, noon UTC.
This is one of three alternative routines that return a J2KD - the other two are sky_calTimeToJ2kd() and sky_unixTimespecToJ2kd().
[in] | unixTime | - time in C standard time_t (or unix) format ((sort of) seconds since 1-Jan-1970 UTC) |
Definition at line 275 of file sky-time.c.
void sky_updateTimes | ( | double | j2kUtc_d, |
const Sky_DeltaTs * | d, | ||
Sky_Times * | t | ||
) |
Convert the given "J2KD" in the UTC timescale to the other timescales, and pre-calculate some other quantities.
[in] | j2kUtc_d | Date in "J2KD" form - i.e. the number of days elapsed since 2000 Jan 1.5 (= JD - 2 451 545.0), UTC timescale, as returned by sky_calTimeToJ2kd(), sky_unixTimeToJ2kd() or sky_unixTimespecToJ2kd(). |
[in] | d | The various delta T values as set by one of sky_initTime(), sky_initTimeDetailed() or sky_initTimeSimple() |
[out] | t | All fields are updated |
Definition at line 206 of file sky-time.c.
void sky_setPolarMotion | ( | double | xPolar_as, |
double | yPolar_as, | ||
double | t_cy, | ||
Sky_PolarMot * | polar | ||
) |
Update polar motion correction.
[in] | xPolar_as | Polar motion in x (arcseconds) |
[in] | yPolar_as | Polar motion in y (arcseconds) |
[in] | t_cy | Julian centuries since J2000.0, TT timescale |
[out] | polar | Polar motion params and rotation matrix, calculated from R1(-y) * R2(-x) * R3(s') |
Definition at line 570 of file sky-time.c.
void sky_j2kdToCalTime | ( | double | j2k_d, |
int * | year, | ||
int * | month, | ||
int * | day, | ||
int * | hour, | ||
int * | minute, | ||
double * | second | ||
) |
This procedure converts the integral part of the date in "J2KD" form to a calendar date and the fractional part to hours, minutes and seconds.
If the returned date is from 1582-10-15 or later, it is a Gregorian calendar date. If the returned date is 1582-10-04 or earlier, it is a Julian calendar date.
[in] | j2k_d | Days since J2000.0 (= Julian Date - 2 451 545.0) Valid range: j2k_d >= -2447065, otherwise incorrect results |
[out] | year,month,day | calendar date |
[out] | hour,minute,second | time of day |
Definition at line 321 of file sky-time.c.
void sky_setSiteLocation | ( | double | latitude_deg, |
double | longitude_deg, | ||
double | height_m, | ||
Sky_SiteProp * | site | ||
) |
Initialise the site structure by calculating those site-related values that do not change with time.
[in] | latitude_deg | Latitude of site (ϕ) (degrees) |
[in] | longitude_deg | Longitude of site (degrees) |
[in] | height_m | Height above ellipsoid (e.g. GPS height) (metres) |
[out] | site | All fields initialised |
This is a simplified version of sky_setSiteLoc2(), which is good enough for most purposes.
This function calculates the quantities that will be used to convert geocentric coordinates to topocentric ones. This involves calculating the position of the site relative to the centre of the earth, and calculating constants that will be used for diurnal parallax and aberration corrections.
This is complicated by the fact that the earth is elliptical rather than perfectly spherical. See section K of The Astronomical Almanac (pages K11 & K12 in the 2007 edition) for details of the geometry. This function effectively calculates the Geocentric latitude (ϕ′) from the Geodetic latitude (ϕ), and then sin(ϕ - ϕ′) and cos(ϕ - ϕ′). But in practice, the sin and cos terms can be obtained without explicitly calculating ϕ′ itself, and that is done here.
The site->refracPT field is initialised assuming that the site pressure is 1010 hPa and the temperature is 10 °C. If other values are required, follow this call by a call to sky_setSiteTempPress().
The site->timezone_d field is initialised to 0, assuming that the site time zone is UTC. If another value is required, follow this call by a call to sky_setSiteTimeZone().
Definition at line 105 of file sky-site.c.
void sky_setSiteLoc2 | ( | double | astLat_deg, |
double | astLong_deg, | ||
double | geodLat_deg, | ||
double | geodLong_deg, | ||
double | height_m, | ||
Sky_SiteProp * | site | ||
) |
Alternative initialisation function to sky_setSiteLocation().
It initialises the site structure, but it supports a distinction between Astronomical latitude & longitude and Geodetic latitude & longitude.
[in] | astLat_deg | Astronomical Latitude of site (ϕA) (degrees) |
[in] | astLong_deg | Astronomical Longitude of site (degrees) |
[in] | geodLat_deg | Geodetic Latitude of site (GPS latitude) (ϕ) (degrees) |
[in] | geodLong_deg | Geodetic Longitude of site (GPS longitude) (degrees) |
[in] | height_m | Height above ellipsoid (e.g. GPS height) (metres) |
[out] | site | All fields initialised |
This function calculates the same quantities as described for sky_setSiteLocation(). The only difference is that the site.azElBaseM rotation matrix is based on Astronomical latitude and latitude (instead of Geodetic).
Astronomical latitude and longitude are coordinates as determined by the local gravity vector and astronomical observation. Geodetic latitude and longitude are coordinates as measured by some geodetic system - e.g. a map reference, or GPS coordinates.
The site->refracPT field is initialised assuming that the site pressure is 1010 hPa and the temperature is 10 °C. If other values are required, follow this call by a call to sky_setSiteTempPress().
The site->timezone_d field is initialised to 0, assuming that the site time zone is UTC. If another value is required, follow this call by a call to sky_setSiteTimeZone().
Definition at line 156 of file sky-site.c.
void sky_setSiteTempPress | ( | double | temperature_degC, |
double | pressure_hPa, | ||
Sky_SiteProp * | site | ||
) |
Set refraction coefficients based on atmospheric temperature and pressure at the site.
[in] | temperature_degC | - average annual air temperature at the site (°C) |
[in] | pressure_hPa | - average annual air pressure at the site (hPa = mbar) |
[out] | site | - field refracPT, a combined refraction coefficient for pressure & temperature |
This coefficient will be used in the simple refraction algorithm that is called from routine sky_siteTirsToTopo().
Definition at line 261 of file sky-site.c.
void sky_setSiteTimeZone | ( | double | timeZone_h, |
Sky_SiteProp * | site | ||
) |
Set the time zone offset for this site.
[in] | timeZone_h | Zonal correction (hours). Time zones east of Greenwich are positive (e.g. Australian Eastern Standard Time is +10.0) and those west of Greenwich are negative (e.g. US Pacific Daylight Time is -7.0) |
[out] | site | field timeZone_d, time zone scaled to fractions of a day |
Definition at line 293 of file sky-site.c.
void sky_setupSiteSurface | ( | double | azimuth_deg, |
double | slope_deg, | ||
Sky_SiteHorizon * | surface | ||
) |
Set the orientation and slope of a surface (such as a solar panel) for which you want to calculate the incidence angle of incoming radiation.
[in] | azimuth_deg | The azimuth angle of the normal to the surface (degrees). This is measured clockwise from North, as for all other azimuth angles. |
[in] | slope_deg | The slope of the surface measured from the horizontal (degrees). Alternatively, this is the zenith distance of the normal to the surface. |
[out] | surface | The coordinates of the normal to the surface, in both polar and rectangular forms. The rectangular form will be passed later to sky_siteIncidence_rad(). |
Definition at line 317 of file sky-site.c.
void sky_adjustSiteForPolarMotion | ( | const Sky_PolarMot * | polar, |
Sky_SiteProp * | site | ||
) |
Modify our azEl rotation matrix to incorporate a polar motion rotation matrix.
[in] | polar | Polar motion parameters, as set by function sky_setPolarMotion() |
[in,out] | site | Fields azElM and possibly azElPolM are updated |
Definition at line 347 of file sky-site.c.
void sky_siteTirsToTopo | ( | const V3D_Vector * | terInterV, |
double | dist_au, | ||
const Sky_SiteProp * | site, | ||
Sky_SiteHorizon * | topo | ||
) |
Transform a coordinate vector from the Terrestrial Intermediate Reference System to topocentric Az/El coordinates for the observing site whose properties are described in parameter "site".
Note: there is a mixture of vectors in right-handed and left-handed coordinate systems here
[in] | terInterV | Position vector in Terrestrial Intermediate Reference System. (This will have been obtained by calling either routine astsite_appToTirs() or routine astsite_intermedToTopo().) |
[in] | dist_au | Geocentric Distance to object (astronomical units). Note: for far distant objects outside of the solar system, you can supply 0.0 for this value. It will be treated as infinity. |
[in] | site | Block of data describing the observing site, as initialised by one of the functions sky_setSiteLocation() or sky_setSiteLoc2(). |
[out] | topo | Topocentric position, both as a vector in horizon coordinates, and as azimuth (radian) and elevation (radian). |
Definition at line 378 of file sky-site.c.
void sky_siteAzElToHaDec | ( | const V3D_Vector * | topoV, |
const Sky_SiteProp * | site, | ||
double * | hourAngle_rad, | ||
double * | declination_rad | ||
) |
Take a topocentric position vector in Azimuth/Elevation frame and use it to calculate the observed Hour Angle and Declination.
[in] | topoV | Topocentric position vector in Azimuth/Elevation frame (as returned by the sky_siteTirsToTopo() function) |
[in] | site | Field haDecM - rotation matrix to HA/Dec coordinates |
[out] | hourAngle_rad | Hour angle (radian - note: not in hours) |
[out] | declination_rad | Declination (radian) |
The hour angle and declination returned by this function will be those of the refracted position of the object.
Definition at line 511 of file sky-site.c.
double sky_siteIncidence_rad | ( | const V3D_Vector * | topoV, |
const V3D_Vector * | surfaceV | ||
) |
Calculate the incidence angle of rays from the celestial object described by topoV (such as the sun) falling onto a surface described by surfaceV (such as a solar panel).
[in] | topoV | Unit vector pointing to the celestial object, as returned by the sky_siteTirsToTopo() routine (in the topo->rectV field). Must be of unity magnitude, otherwise an assertion failure occurs. |
[in] | surfaceV | Unit vector of normal to the surface, as returned by routine sky_setupSiteSurface() (in the surface->rectV field). Must be of unity magnitude, otherwise an assertion failure occurs. |
Definition at line 547 of file sky-site.c.