SOLAR_ZEN_AN

This function computes solar zenith from latitude, hour angle, and declination using an analytical spherical-geometry expression.

Zenith is the angle between the sun vector and local vertical and is a primary quantity for irradiance decomposition and transposition.

The analytical relation is:

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

where \phi is latitude, \delta is declination, and h is hour angle, all in radians.

Excel Usage

=SOLAR_ZEN_AN(latitude, hourangle, declination)
  • latitude (float, required): Site latitude (radians).
  • hourangle (list[list], required): Solar hour angle (radians).
  • declination (list[list], required): Solar declination angle (radians).

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

Example 1: Solar zenith at solar noon in radians

Inputs:

latitude hourangle declination
0.6936 0 0.4091

Excel formula:

=SOLAR_ZEN_AN(0.6936, {0}, {0.4091})

Expected output:

0.2845

Example 2: Zenith angle for morning hour angle

Inputs:

latitude hourangle declination
0.6936 -0.5 0.2

Excel formula:

=SOLAR_ZEN_AN(0.6936, {-0.5}, {0.2})

Expected output:

0.662631

Example 3: Zenith angle for afternoon hour angle

Inputs:

latitude hourangle declination
0.6936 0.5 0.2

Excel formula:

=SOLAR_ZEN_AN(0.6936, {0.5}, {0.2})

Expected output:

0.662631

Example 4: Multiple hour angles in one call

Inputs:

latitude hourangle declination
0.6936 -0.3 0.1
0.3 0.1

Excel formula:

=SOLAR_ZEN_AN(0.6936, {-0.3;0.3}, {0.1;0.1})

Expected output:

Result
0.652184
0.652184

Python Code

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

def solar_zen_an(latitude, hourangle, declination):
    """
    Calculate the solar zenith angle using an analytical expression.

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

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

    Args:
        latitude (float): Site latitude (radians).
        hourangle (list[list]): Solar hour angle (radians).
        declination (list[list]): Solar declination angle (radians).

    Returns:
        list[list]: 2D list of solar zenith 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

        ha_list = flatten_num(hourangle)
        dec_list = flatten_num(declination)

        n = len(ha_list)
        if n == 0 or len(dec_list) != n:
            return "Error: hourangle and declination arrays must have the same non-zero length"

        lat = float(latitude)

        res = result_func(
            latitude=lat,
            hourangle=np.array(ha_list),
            declination=np.array(dec_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

Site latitude (radians).
Solar hour angle (radians).
Solar declination angle (radians).