DECLINATION_SPENCER

This function computes solar declination, the angle between the Earth-sun line and the equatorial plane, from day-of-year values using the Spencer (1971) Fourier approximation.

Declination is a core geometric input for solar zenith, azimuth, sunrise/sunset timing, and plane-of-array irradiance models.

In solar-geometry notation, declination enters relationships such as:

\cos(\theta_z) = \sin(\phi)\sin(\delta) + \cos(\phi)\cos(\delta)\cos(h)

where \theta_z is solar zenith, \phi is latitude, \delta is declination, and h is hour angle.

Excel Usage

=DECLINATION_SPENCER(dayofyear)
  • dayofyear (list[list], required): Day of the year (1 to 366).

Returns (list[list]): 2D list of declination angles (radians), or an error string.

Example 1: Declination at summer solstice

Inputs:

dayofyear
172

Excel formula:

=DECLINATION_SPENCER({172})

Expected output:

0.409315

Example 2: Declination near March equinox

Inputs:

dayofyear
80

Excel formula:

=DECLINATION_SPENCER({80})

Expected output:

-0.00115059

Example 3: Declination near December solstice

Inputs:

dayofyear
355

Excel formula:

=DECLINATION_SPENCER({355})

Expected output:

-0.408754

Example 4: Scalar day-of-year input

Inputs:

dayofyear
1

Excel formula:

=DECLINATION_SPENCER(1)

Expected output:

-0.402449

Python Code

Show Code
import pandas as pd
import numpy as np
from pvlib.solarposition import declination_spencer71 as result_func

def declination_spencer(dayofyear):
    """
    Compute the solar declination angle using Spencer's (1971) formula.

    See: https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.solarposition.declination_spencer71.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        dayofyear (list[list]): Day of the year (1 to 366).

    Returns:
        list[list]: 2D list of declination angles (radians), or an error string.
    """
    try:
        def flatten_num(data):
            if not isinstance(data, list): return [float(data)]
            flat = []
            for row in data:
                row = row if isinstance(row, list) else [row]
                for val in row:
                    if val == "": flat.append(float('nan'))
                    else: flat.append(float(val))
            return flat

        doy_list = flatten_num(dayofyear)
        if len(doy_list) == 0:
            return "Error: input array cannot be empty"

        res = result_func(np.array(doy_list))

        return [[float(v) if not pd.isna(v) else ""] for v in res]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Day of the year (1 to 366).