Position of the Sun¶
- PyAstronomy.pyasl.sunpos(jd, end_jd=None, jd_steps=None, outfile=None, radian=False, plot=False, full_output=False)¶
Compute right ascension and declination of the Sun at a given time.
- Parameters
- jdfloat
The Julian date
- end_jdfloat, optional
The end of the time period as Julian date. If given, sunpos computes RA and DEC at jd_steps time points between jd and ending at end_jd.
- jd_stepsinteger, optional
The number of steps between jd and end_jd for which RA and DEC are to be calculated.
- outfilestring, optional
If given, the output will be written to a file named according to outfile.
- radianboolean, optional
Results are returned in radian instead of in degrees. Default is False.
- plotboolean, optional
If True, the result is plotted.
- full_output: boolean, optional
If True, sunpos, additionally, returns the elongation and obliquity of the Sun.
- Returns
- Timearray
The JDs for which calculations where carried out.
- Raarray
Right ascension of the Sun.
- Decarray
Declination of the Sun.
- Elongationarray, optional
Elongation of the Sun (only of full_output is set to True).
- Obliquityarray, optional
Obliquity of the Sun (only of full_output is set to True).
Notes
Note
This function was ported from the IDL Astronomy User’s Library.
- IDL - Documentation
- NAME:
SUNPOS
- PURPOSE:
To compute the RA and Dec of the Sun at a given date.
- CALLING SEQUENCE:
SUNPOS, jd, ra, dec, [elong, obliquity, /RADIAN ]
- INPUTS:
- jd - The Julian date of the day (and time), scalar or vector
usually double precision
- OUTPUTS:
- ra - The right ascension of the sun at that date in DEGREES
double precision, same number of elements as jd
dec - The declination of the sun at that date in DEGREES
- OPTIONAL OUTPUTS:
elong - Ecliptic longitude of the sun at that date in DEGREES. obliquity - the obliquity of the ecliptic, in DEGREES
- OPTIONAL INPUT KEYWORD:
- /RADIAN - If this keyword is set and non-zero, then all output variables
are given in Radians rather than Degrees
- NOTES:
Patrick Wallace (Rutherford Appleton Laboratory, UK) has tested the accuracy of a C adaptation of the sunpos.pro code and found the following results. From 1900-2100 SUNPOS gave 7.3 arcsec maximum error, 2.6 arcsec RMS. Over the shorter interval 1950-2050 the figures were 6.4 arcsec max, 2.2 arcsec RMS.
The returned RA and Dec are in the given date’s equinox.
Procedure was extensively revised in May 1996, and the new calling sequence is incompatible with the old one.
- METHOD:
Uses a truncated version of Newcomb’s Sun. Adapted from the IDL routine SUN_POS by CD Pike, which was adapted from a FORTRAN routine by B. Emerson (RGO).
- EXAMPLE:
Find the apparent RA and Dec of the Sun on May 1, 1982
IDL> jdcnv, 1982, 5, 1,0 ,jd ;Find Julian date jd = 2445090.5 IDL> sunpos, jd, ra, dec IDL> print,adstring(ra,dec,2)
02 31 32.61 +14 54 34.9
- The Astronomical Almanac gives 02 31 32.58 +14 54 34.9 so the error
in SUNPOS for this case is < 0.5”.
Find the apparent RA and Dec of the Sun for every day in 1997
IDL> jdcnv, 1997,1,1,0, jd ;Julian date on Jan 1, 1997 IDL> sunpos, jd+ dindgen(365), ra, dec ;RA and Dec for each day
- MODIFICATION HISTORY:
Written by Michael R. Greason, STX, 28 October 1988. Accept vector arguments, W. Landsman April,1989 Eliminated negative right ascensions. MRG, Hughes STX, 6 May 1992. Rewritten using the 1993 Almanac. Keywords added. MRG, HSTX,
10 February 1994.
Major rewrite, improved accuracy, always return values in degrees W. Landsman May, 1996 Added /RADIAN keyword, W. Landsman August, 1997 Converted to IDL V5.0 W. Landsman September 1997
Example¶
from __future__ import print_function, division
import numpy as np
from PyAstronomy import pyasl
import datetime
# Convert calendar date into JD
# use the datetime package
jd = datetime.datetime(2013, 4, 16)
jd = pyasl.jdcnv(jd)
print("JD = " + str(jd))
pos = pyasl.sunpos(jd, full_output=True)
print("Coordinates of the Sun (ra, dec): %g, %g" % (pos[1], pos[2]))
print("Solar elongation = %g and obliquity = %g" % (pos[3], pos[4]))
# Get the Sun's RA and DEC values for a period of time.
startjd = datetime.datetime(2013, 4, 16)
endjd = datetime.datetime(2013, 6, 16)
# Convert into Julian dates
startjd = pyasl.jdcnv(startjd)
endjd = pyasl.jdcnv(endjd)
print()
pos = pyasl.sunpos(startjd, end_jd=endjd, jd_steps=10, plot=False, full_output=True)
for i in range(len(pos[0])):
print("At JD = %g: ra = %g, dec = %g" % (pos[0][i], pos[1][i], pos[2][i]))