The solar module contains just one class definition, with many associated methods to perform a plethora of calculations based around the sun-earth relationship. It replicates the functionality of the common NOAA excel calculator, including adjustments due to atmospheric refraction. Each method may be run independently as the user wishes, as each method will automatically invoke any other calculations that must be performed first, and it will not unnecessarily redo calculations that have already been completed.

A solar class object allows scalar or numpy array inputs for latitude and longitude values for per-pixel computation and improved accuracy when scene-center calculations are insufficient. The solar class is not yet capable of ingesting digital elevation models to calculate slope and aspect dependent parameters, but it is a planned addition.


Compute all available solar parameters

For a simple example, lets just assume we want to go ahead and calculate everything. The inputs for all solar calculations come down to space and time. More specifically, latitude and longitude coordinates and a precise time in standard GMT. For the example below, we are going to use 2015-May-15th at exactly noon local time, in Hampton Virginia USA. Note that while observing daylight savings time, the east coast observes EDT, which is GMT-4, watch out for mistakes with time zones!

from dnppy import solar

lat         = 37                    # lat (N positive)
lon         = -76.4                 # lon (E positive)
datestamp   = "20150515-120000"     # date stamp
fmt         = "%Y%m%d-%H%M%S"       # datestamp format
tz          = -4                    # timezone (GMT/UTC) offset

sc  = solar(lat, lon, datestamp, tz, fmt)

The code above successfully updates solar instance sc to have all the attributes supported by the class, and prints a summary with descriptive variable names, values, and units. If the datestamp and fmt variables are unfamiliar to you, you can read more about python datetime objects and how to create them from strings with fmt syntax.

Once you mastered datetime objects, you will probably want to use them all the time (they are pretty great). Fortunately, you can simply input a datetime object in place of the datestamp variable in the code above, and omit the fmt variable entirely, such as:

from dnppy import solar
from datetime import datetime

lat     = 37
lon     = -76.4
dt_obj  = datetime(2015,5,15,12,0,0)
tz      = -4

sc  = solar(lat, lon, dt_obj, tz)

Lets say you aren’t interested in anything except the solar elevation angle. After consulting help(solar) or the function list below, we see there is a method called get_elevation, and decide to invoke that instead of compute_all() and save it in a new variable called solar_elevation.

solar_elevation = sc.get_elevation()  # invoke method of solar instance "sc"

That’s it! you can get any available attribute of a solar instance in exactly the same way!

Code Help

Auto-documentation for functions and classes within this module is generated below!

class solar(lat, lon, date_time_obj, time_zone=0, fmt=False, slope=None, aspect=None)[source]

Object class for handling solar calculations. Many equations are taken from the excel sheet at this url : []

It requires a physical location on the earth and a datetime object

  • lat – decimal degrees latitude (float OR numpy array)
  • lon – decimal degrees longitude (float OR numpy array)
  • time_zone – float of time shift from GMT (such as “-5” for EST)
  • date_time_obj – either a timestamp string following fmt or a datetime obj
  • fmt – if date_time_obj is a string, fmt is required to interpret it
  • slope – slope of land at lat,lon for solar energy calculations
  • aspect – aspect of land at lat,lon for solar energy calculations

An instance of this class may have the following attributes:

attribute description type
lat latitude (array)
lon longitude (array)
tz time zone (scalar)
rdt reference datetime object (date_time_obj) (scalar)
slope slope, derivative of DEM (array)
aspect aspect (north is 0, south is 180) (array)
ajd absolute julian day (scalar)
ajc absolute julian century (scalar)
geomean_long geometric mean longitude of the sun (scalar)
geomean_anom geometric mean longitude anomaly of the sun (scalar)
earth_eccent eccentricity of earths orbit (scalar)
sun_eq_of_center the suns equation of center (scalar)
true_long true longitude of the sun (scalar)
true_anom true longitude anomaly of the sun (scalar)
app_long the suns apparent longitude (scalar)
oblique_mean_elip earth oblique mean ellipse (scalar)
oblique_corr correction to earths oblique elipse (scalar)
right_ascension suns right ascension angle (scalar)
declination solar declination angle (scalar)
equation_of_time equation of time (minutes) (scalar)
hour_angle_sunrise the hour angle at sunrise (array)
solar_noon LST of solar noon (array)
sunrise LST of sunrise time (array)
sunset LST of sunset time (array)
sunlight LST fractional days of sunlight (array)
true_solar LST for true solar time (array)
hour_angle total hour angle (array)
zenith zenith angle (array)
elevation elevation angle (array)
azimuth azimuthal angle (array)
rad_vector radiation vector (distance in AU) (scalar)
earth_distance earths distance to sun in meters (scalar)
norm_irradiance incident solar energy at earth distance (scalar)

Units used by this class unless otherwise labeled

  • angle = degrees
  • distance = meters
  • energy = watts or joules
  • time = mostly in datetime objects. labeled in most cases.

Planned improvements

  1. DONE. Inputs of numpy arrays for lat and lon needs to be allowed.
  2. inputs of a numpy array DEM for slope/aspect effects on incident solar energy

Present performance

To process about one landsat tile (7300^2 matrix) requires 9GB of memory and takes 45 seconds to process on a single 3.3GHz thread. It would be nice to get the same output to run on ~5GB of memory so a 8GB system could handle it.

Computes and prints all the attributes of this solar object. Spatial averages are printed for numpy array type attributes.

Return app_long:
 calculates apparent longitude of the sun
Return azimuth:returns solar azimuth angle at ref_datetime
Return declination:
 solar declination angle at ref_datetime
Return earth_distance:
 distance between the earth and the sun at ref_datetime
Return earth_eccent:
 precise eccentricity of earths orbit at referece datetime
Return elevation:
 returns solar elevation angle at ref_datetime
Return equation_of_time:
 the equation of time in minutes

calculates the geometric mean anomoly of the sun

Return geomean_long:
 geometric mean longitude of the sun
Return hour_angle:
 returns hour angle at ref_datetime
Return hour_angle_sunrise:
 the hour angle of sunrise

calculates the actual incident solar irradiance at a given lat,lon coordinate with adjustments for slope and aspect if they have been given. Not finished.


Calculates incoming solar energy in W/m^2 to a surface normal to the sun.

inst_irradiance is calculated as = sun_surf_radiance*(sun_radius / earth_distance)^2 and is then corrected as a function of solar incidence angle

Return norm_irradiance:
 the normal irradiance in W/m^2
Return oblique_corr:
 the oblique correction
Return oblique_mean_elip:
 oblique mean elliptic of earth orbit
Return rad_vector:
 incident radiation vector to surface at ref_datetime (AUs)
Return right_ascension:
 the suns right ascension angle
Return solar_noon:
 solar noon in (local sidereal time LST)
Return sun_eq_of_center:
 the suns equation of center
Return sunlight:
 amount of daily sunlight in fractional days
Return sunrise:returns the time of sunrise
Return sunset:returns the time of sunset
Return true_anom:
 calculates the true anomaly of the sun
Return true_long:
 the tru longitude of the sun
Return true_solar:
 true solar time at ref_datetime
Return zenith:returns solar zenith angle at ref_datetime

prints attribute list and corresponding values