Skip to content

Ambiguous descriptions of axis_azimuth and axis_tilt in pvlib.tracking.singleaxis() docs #1976

Closed

Description

@williamhobbs

Is your feature request related to a problem? Please describe.
Some details around axis_azimuth and axis_tilt in the docs (https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.tracking.singleaxis.html) seem ambiguous to me.

Examples:

  1. For a north-south aligned tracker axis, sloping 5 degrees down to the south, what are the inputs for axis_azimuth and axis_tilt? I assume axis_azimuth = 180, axis_tilt = 5.
  2. For the same north-south aligned tracker axis, but sloping 5 degrees down to the north, what are the inputs? I assume axis_azimuth = 0, axis_tilt = 5, since axis_tilt must be >= 0.

Additionally, the description in the docs includes:

For example, if tracker axis_azimuth is 180 (oriented south) and axis_tilt is zero...

But the default for axis_azimuth is 0, which could lead to confusion around inputs and output sign convention.

Describe the solution you'd like
More clear docs.

Additional context
Changing definitions slightly and allowing for negative axis_tilt would make more sense to me, but maybe that causes other problems. [edit: now I don't think this is a good idea - see the full discussion below] [2nd edit: looks like code allows for this even though docs do not. Also, my opinion is easily swayed...]

For example # 2 above (sloping down to the North), allowing for axis_azimuth = 180, axis_tilt = -5 makes more since to me. You could unambigously define axis_azimuth as "the South-most direction of the axis of rotation" and axis_tilt as "the tilt of the axis of rotation, with positive values indicating downward slope towards the South-most direction, and negative values indicating downward slope towards the North-most direction...".

I'm not sure how to handle the odd case of a tracker axis aligned perfectly East-West.

And for systems in the Southern Hemisphere, I don't think anything would need to change.

Activity

  1. mikofski commented on Feb 20, 2024

    @mikofski
    Member

    Another argument for allowing negative axis tilt is to keep the common convention that rotation increases during the day, from negative in the morning when facing east to positive in the afternoon & trackers facing west. I think this only works if the axis points south?

  2. williamhobbs commented on Feb 20, 2024

    @williamhobbs
    ContributorAuthor

    @mikofski, I agree. Good point.

    Keeping a consistent rotation convention makes more sense to me than (the way I interpret) the existing docs for pvlib.tracking.singleaxis(): tracker_theta sign reverses depending on whether you pick 0 or 180 for axis_azimuth.

  3. williamhobbs commented on Feb 20, 2024

    @williamhobbs
    ContributorAuthor

    I just ran some tests in NREL SAM using both the detailed PV model and the PVWatts model - in both cases, it does not allow tilt for 1-axis trackers to be less than zero.

    The documentation there is also not clear, but it appears that azimuth = 0 and tilt = 5 models a system sloping down to the north, while azimuth = 180 and tilt = 5 models a system sloping down to the south.

    So, I can now see a benefit to keeping the conventions in pvlib.tracking.singleaxis() as they are and simply updating the docs a bit. But @mikofski's point about rotation angle convention is still a good one...

  4. janinefreeman commented on Feb 20, 2024

    @janinefreeman

    I left a comment on the SAM issue as well, but allowing negative input tilts would require some additional mathematical gymnastics inside the functions to make angle calculations and shading calculations work out (I'm assuming this is true for pvlib as well) - at the very least, transposition to the expected case before doing the math (i.e. if a user enters azimuth = 180, tilt = -5, the code would need to translate that to azimuth = 0, tilt = 5, then correctly re-translate the outputs). I have wondered about this issue of "how to explain which end of the tracker is the rotation around" before, since right now it follows mathematical rotational axis definitions, rather than cardinal direction conventions, that certainly aren't intuitive for most. Open to ideas here on the best way to communicate what tracker rotation angles mean...

    Thanks @williamhobbs for linking the issues so we can brainstorm collectively! :)

  5. williamhobbs commented on Feb 20, 2024

    @williamhobbs
    ContributorAuthor

    Keeping conventions the same between pvlib and SAM seems like it would be very beneficial to users.

    The rotation "convention" of negative in the morning, positive in the afternoon, would stay reversed in the case of sloping down to the North, but 1) this can be clarified in docs, and 2) is likely a pretty rare case. I think anyone that is modeling an atypical system like this and needs to carefully interpret tracker_theta is already pretty far into the "weeds" and can probable make sense of it all with decent docs.

  6. mikofski commented on Feb 20, 2024

    @mikofski
    Member

    @williamhobbs please just try it with negative axis_tilt and see if it works already as expected. I looked through the code here: https://github.com/pvlib/pvlib-python/blob/main/pvlib/tracking.py and I don’t see anything other than the docstring that limits it between zero and 90°. @janinefreeman I believe pvlib should just work even if axis tilt is negative without any changes at all because singleaxis() used arctan2 instead of cosine so should work in any quadrant.

  7. AdamRJensen commented on Feb 20, 2024

    @AdamRJensen
    Member

    I would vote in favor of allowing negative tilts, and thus allowing the standard convention of negative morning and positive evening tilts.

    I could easily imagine simulations of larger systems (where the field is broken down into several sub-systems of uniform tilt) where one part of the field is sloping north and another is sloping south. In such a case it would be inconvenient having different axis azimuth conventions for different parts of the field.

  8. williamhobbs commented on Feb 20, 2024

    @williamhobbs
    ContributorAuthor

    @mikofski you are correct, it works with negative axis_tilt.

    image

    (edit: code below)

    import pvlib
    import matplotlib.pyplot as plt
    import pandas as pd
    
    lat, lon = 33.52, -86.81
    tz = 'US/Central'
    
    times = pd.date_range('2023-12-21 5:00',
                          '2023-12-21 18:00',
                          freq='5min',
                          tz=tz)
    
    solpos = pvlib.solarposition.get_solarposition(times, lat, lon)
    
    angles_1 = pvlib.tracking.singleaxis(
        apparent_zenith=solpos['apparent_zenith'],
        apparent_azimuth=solpos['azimuth'],
        axis_tilt=0,
        axis_azimuth=180,
        max_angle=50,
        backtrack=True,
        gcr=0.45
    )['tracker_theta'].fillna(0)
    
    angles_2 = pvlib.tracking.singleaxis(
        apparent_zenith=solpos['apparent_zenith'],
        apparent_azimuth=solpos['azimuth'],
        axis_tilt=10,
        axis_azimuth=180,
        max_angle=50,
        backtrack=True,
        gcr=0.45
    )['tracker_theta'].fillna(0)
    
    angles_3 = pvlib.tracking.singleaxis(
        apparent_zenith=solpos['apparent_zenith'],
        apparent_azimuth=solpos['azimuth'],
        axis_tilt=-10,
        axis_azimuth=0,
        max_angle=50,
        backtrack=True,
        gcr=0.45
    )['tracker_theta'].fillna(0)
    
    angles_1.plot()
    angles_2.plot()
    angles_3.plot()
    plt.legend(['tilt=0, az=180', 'tilt=10, az=180', 'tilt=-10, az=0'])
    plt.ylabel('Tracker rotation angle, degrees')
    plt.xlabel('Local time')
    plt.show()
  9. williamhobbs commented on Feb 20, 2024

    @williamhobbs
    ContributorAuthor

    Since negative values of axis_tilt are allowed in the code, it seems like users can use either convention and the docs simply need to be updated accordingly. And part of that is noting that if users select axis_azimuth between 270 and 90 (North-facing), the rotation angle convention is reversed.

  10. cwhanse commented on Feb 20, 2024

    @cwhanse
    Member

    I'm OK with negative axis tilt, as long as the definition of axis_tilt and axis_azimuth are not dependent on hemisphere, and together unambiguously define the coordinate system that defines rotation. I'd be opposed to start with a desired rotation convention (e.g. negative is east) because I'm fairly sure that will make the coordinate system depend on hemisphere.

  11. matsuobasho commented on Mar 19, 2024

    @matsuobasho
    Contributor

    Taking the above discussion into account, if we specify an axis_azimuth of 0 and an axis_tilt of -5, what does that mean in terms of the positioning of the trackers?

    From the way the docstring is currently worded
    The tilt of the axis of rotation (i.e, the y-axis defined by axis_azimuth) with respect to horizontal.
    seems like it would be a confusing situation where we specify that the azimuth is 0 (point towards north), but also specify that there is a -5 degree tilt, meaning that the slope is actually towards the south?

  12. markcampanelli commented on Feb 12, 2026

    @markcampanelli
    Contributor

    I set up what I think is a typical computational workflow using the ground slope, slope azimuth, and axis azimuth to first compute the axis tilt and cross-axis tilt using pvlib.tracking.calc_axis_tilt and pvlib.tracking.calc_cross_axis_tilt, respectively. Then, these values were fed into pvlib.tracking.singleaxis. I tried to set up the same geometry (here, a northern hemisphere setup with the array axis sloping away from the equator), using the two 180-degree opposing choices for axis azimuth. I see the expected change in sign for the rotation angles, but the computations from pvlib.tracking.singleaxis appear to be different (esp. different AOIs). I think they should have been the same, but I may be missing something.

    First representation:

    slope_azimuth = 0
    print(f"Slope azimuth: {slope_azimuth:0.01f}°")
    slope_tilt = 10
    print(f"Slope tilt: {slope_tilt:0.01f}°")
    axis_azimuth = 180
    print(f"Axis azimuth: {axis_azimuth:0.01f}°")
    
    # calculate the tracker axis tilt, assuming that the axis follows the terrain:
    axis_tilt = pvlib.tracking.calc_axis_tilt(slope_azimuth, slope_tilt, axis_azimuth)
    print(f"Axis tilt: {axis_tilt:0.01f}°")
    
    # calculate the cross-axis tilt:
    cross_axis_tilt = pvlib.tracking.calc_cross_axis_tilt(
        slope_azimuth, slope_tilt, axis_azimuth, axis_tilt
    )
    print(f"Cross-Axis tilt: {cross_axis_tilt:0.01f}°")
    
    apparent_zenith = numpy.array((45, 30, 45))
    apparent_azimuth = numpy.array((135, 180, 225))
    
    pvlib.tracking.singleaxis(
        apparent_zenith,
        apparent_azimuth,
        axis_tilt=axis_tilt,
        axis_azimuth=axis_azimuth,
        max_angle=90,
        backtrack=False,
        gcr=2.0 / 7.0,
        cross_axis_tilt=cross_axis_tilt,
    )

    Outputs:
    pvlib.tracking.calc_axis_tilt: -10.0°

    pvlib.tracking.calc_cross_axis_tilt: -0.0°

    pvlib.tracking.singleaxis:

    {'tracker_theta': array([-39.36170387,   0.        ,  39.36170387]),
     'aoi': array([22.68560889, 20.        , 22.68560889]),
     'surface_azimuth': array([101.9525464, 180.       , 258.0474536]),
     'surface_tilt': array([40.41119575, 10.        , 40.41119575])}
    

    Second representation:

    slope_azimuth = 0
    print(f"Slope azimuth: {slope_azimuth:0.01f}°")
    slope_tilt = 10
    print(f"Slope tilt: {slope_tilt:0.01f}°")
    axis_azimuth = 0
    print(f"Axis azimuth: {axis_azimuth:0.01f}°")
    
    # calculate the tracker axis tilt, assuming that the axis follows the terrain:
    axis_tilt = pvlib.tracking.calc_axis_tilt(slope_azimuth, slope_tilt, axis_azimuth)
    print(f"Axis tilt: {axis_tilt:0.01f}°")
    
    # calculate the cross-axis tilt:
    cross_axis_tilt = pvlib.tracking.calc_cross_axis_tilt(
        slope_azimuth, slope_tilt, axis_azimuth, axis_tilt
    )
    print(f"Cross-Axis tilt: {cross_axis_tilt:0.01f}°")
    
    apparent_zenith = numpy.array((45, 30, 45))
    apparent_azimuth = numpy.array((135, 180, 225))
    
    pvlib.tracking.singleaxis(
        apparent_zenith,
        apparent_azimuth,
        axis_tilt=axis_tilt,
        axis_azimuth=axis_azimuth,
        max_angle=90,
        backtrack=False,
        gcr=2.0 / 7.0,
        cross_axis_tilt=cross_axis_tilt,
    )

    Outputs:
    pvlib.tracking.calc_axis_tilt : 10.0°

    pvlib.tracking.calc_cross_axis_tilt: 0.0°

    pvlib.tracking.singleaxis:
    {'tracker_theta': array([ 3.93617039e+01,  4.57983173e-15, -3.93617039e+01]),
     'aoi': array([37.96584945, 40.        , 37.96584945]),
     'surface_azimuth': array([7.80474536e+01, 2.63741998e-14, 2.81952546e+02]),
     'surface_tilt': array([40.41119575, 10.        , 40.41119575])}
    
  13. williamhobbs commented on Feb 12, 2026

    @williamhobbs
    ContributorAuthor

    @markcampanelli, I'm seeing similar behavior. When I previously tried "flipping around" the azimuth and tilt, I only looked at tracker theta, not AOI and surface orientation. That doesn't seem expected.

    Image Image Image
    latitude, longitude = 36.397, -114.962
    times = pd.date_range('2025-12-21 13:00', '2025-12-22 2:00', freq='1min', tz='UTC')
    sp = pvlib.solarposition.get_solarposition(times, latitude, longitude)
    
    tr1 = pvlib.tracking.singleaxis(
        apparent_zenith=sp.apparent_zenith,
        solar_azimuth=sp.azimuth,
        axis_tilt=0,
        axis_azimuth=180,
        max_angle=52,
    )
    
    tr2 = pvlib.tracking.singleaxis(
        apparent_zenith=sp.apparent_zenith,
        solar_azimuth=sp.azimuth,
        axis_tilt=10,
        axis_azimuth=180,
        max_angle=52,
    )
    
    tr3 = pvlib.tracking.singleaxis(
        apparent_zenith=sp.apparent_zenith,
        solar_azimuth=sp.azimuth,
        axis_tilt=0,
        axis_azimuth=0,
        max_angle=52,
    )
    
    tr4 = pvlib.tracking.singleaxis(
        apparent_zenith=sp.apparent_zenith,
        solar_azimuth=sp.azimuth,
        axis_tilt=-10,
        axis_azimuth=0,
        max_angle=52,
    )
    
    tr1.tracker_theta.plot(label='tilt=0, az=180')
    tr2.tracker_theta.plot(label='tilt=10, az=180')
    tr3.tracker_theta.plot(label='tilt=0, az=0')
    tr4.tracker_theta.plot(label='tilt=-10, az=0')
    plt.ylabel('tracker_theta')
    plt.legend()
    plt.show()
    
    tr1.aoi.plot(label='tilt=0, az=180')
    tr2.aoi.plot(label='tilt=10, az=180')
    tr3.aoi.plot(label='tilt=0, az=0', linestyle='--')
    tr4.aoi.plot(label='tilt=-10, az=0')
    plt.ylabel('aoi')
    plt.legend()
    plt.show()
    
    tr1.surface_azimuth.plot(label='tilt=0, az=180')
    tr2.surface_azimuth.plot(label='tilt=10, az=180')
    tr3.surface_azimuth.plot(label='tilt=0, az=0', linestyle='--')
    tr4.surface_azimuth.plot(label='tilt=-10, az=0')
    plt.ylabel('surface_azimuth')
    plt.legend()
    plt.show()
  14. cwhanse commented on Feb 13, 2026

    @cwhanse
    Member

    AOI looks wrong for tilt=-10 because the calculation of AOI relies on tracking.calc_surface_orientation which converts axis_tilt to the usual pvlib interpretation of tilt, i.e., a positive angle from horizontal that is ignorant of azimuth. If negative axis_tilt is not to be forbidden, this line needs to be corrected:

    surface_tilt = acosd(cosd(tracker_theta) * cosd(axis_tilt))

  15. markcampanelli commented on Feb 14, 2026

    @markcampanelli
    Contributor

    @cwhanse Would you agree that that the addition here of the axis_azimuth ALSO defining a rotation axis is what makes this geometric situation more complex so that "the usual pvlib interpretation of tilt, i.e., a positive angle from horizontal that is ignorant of azimuth" is insufficient?

  16. 11 remaining items

  17. markcampanelli commented on Mar 9, 2026

    @markcampanelli
    Contributor

    One piece of info on existing implementation, which may be redundant at this point: Using calc_surface_orientation in singleaxis appears to make an arbitrary choice for surface_azimuth when a "typical" tracker configuration is pointing straight up. Wouldn't the mathematically correct thing to do here be to define such azimuths as NaN? (I haven't thought of a more elegant way to "define" our way out of this "discontinuity".)

    axis_azimuth=0 gives surface_azimuth=90 when surface_tilt=0:

    pvlib.tracking.singleaxis(
        apparent_zenith=numpy.array((44, 45, 44)),
        solar_azimuth=numpy.array((179, 180, 181)),
        axis_tilt=0,
        axis_azimuth=0,
        max_angle=90,
        backtrack=False,
        gcr=2.0 / 7.0,
        cross_axis_tilt=0,
    )
    
    {'tracker_theta': array([ 9.65548336e-01,  7.01670930e-15, -9.65548336e-01]),
     'aoi': array([43.99157359, 45.        , 43.99157359]),
     'surface_azimuth': array([ 90.,  90., 270.]),
     'surface_tilt': array([0.96554834, 0.        , 0.96554834])}

    axis_azimuth=180 gives surface_azimuth=270 when surface_tilt=0:

    pvlib.tracking.singleaxis(
        apparent_zenith=numpy.array((44, 45, 44)),
        solar_azimuth=numpy.array((179, 180, 181)),
        axis_tilt=0,
        axis_azimuth=180,
        max_angle=90,
        backtrack=False,
        gcr=2.0 / 7.0,
        cross_axis_tilt=0,
    )
    
    {'tracker_theta': array([-0.96554834,  0.        ,  0.96554834]),
     'aoi': array([43.99157359, 45.        , 43.99157359]),
     'surface_azimuth': array([ 90., 270., 270.]),
     'surface_tilt': array([0.96554834, 0.        , 0.96554834])}
  18. cwhanse commented on Mar 9, 2026

    @cwhanse
    Member

    @markcampanelli I wonder if returning nan would be annoying in workflows that process surface_azimuth although I don't have an example where that would be the case. I'm slightly in favor of returning axis_azimuth.

  19. markcampanelli commented on Mar 9, 2026

    @markcampanelli
    Contributor

    @markcampanelli I wonder if returning nan would be annoying in workflows that process surface_azimuth although I don't have an example where that would be the case. I'm slightly in favor of returning axis_azimuth.

    @cwhanse To avoid the honest, yet pesky, NaN for surface_azimuth, that seems like a good idea to use the axis_azimuth, which I think can be viewed as the well-defined limiting case of surface_tilt -> 0^+. (I think the limit needs to be one-sided to be generally well defined.) 🙂

    I have to admit to just now fully reading the paper referenced in calc_surface_orientation, but just looking through the existing code suggests a way to avoid the division by zero altogether, which is where the arbitrary choice is made and which is essentially being checked for twice in the existing code:

    def calc_surface_orientation(tracker_theta, axis_tilt=0, axis_azimuth=0):
        """Avoid any division by zero."
    
        tracker_theta = np.asanyarray(tracker_theta)
        surface_tilt = acosd(cosd(tracker_theta) * cosd(axis_tilt))
        # axis_azimuth is the arbitrary surface_azimuth when surface_tilt is zero.
        surface_azimuth = np.full_like(surface_tilt, axis_azimuth)
    
        nonzero_surface_tilt_idx = surface_tilt != 0
    
        if np.any(nonzero_surface_tilt_idx):
            # clip(..., -1, +1) to prevent arcsin(1 + epsilon) issues:
            azimuth_delta = asind(
                np.clip(
                    sind(tracker_theta[nonzero_surface_tilt_idx]) / 
                        sind(surface_tilt[nonzero_surface_tilt_idx]),
                    a_min=-1,
                    a_max=1,
                )
            )
            # Combine Eqs 2, 3, and 4:
            azimuth_delta = np.where(
                abs(tracker_theta[nonzero_surface_tilt_idx]) < 90,
                azimuth_delta,
                -azimuth_delta + np.sign(tracker_theta[nonzero_surface_tilt_idx]) * 180)
            
            surface_azimuth[nonzero_surface_tilt_idx] = (axis_azimuth[nonzero_surface_tilt_idx] + azimuth_delta) % 360
    
        out = {
            'surface_tilt': surface_tilt,
            'surface_azimuth': surface_azimuth,
        }
    
        if hasattr(tracker_theta, 'index'):
            out = pd.DataFrame(out)
    
        return out

    UPDATE: I think the tracker_theta = np.asanyarray(tracker_theta) breaks the pandas integration, but could be worked around. Always the pandas integration... ☹️

  20. cwhanse commented on Mar 11, 2026

    @cwhanse
    Member

    @markcampanelli thanks for the suggestion. There are two issues to address: accepting axis_tilt<0, and choosing surface_azimuth when surface_tilt=0. That method still yields incorrect surface_azimuth for negative axis_tilt. I think the reference's use of triangles is the underlying cause. The authors state that axis_azimuth is the direction when viewing the tracker axis from when the inclined end. That's 180 out from axis_azimuth when axis_tilt is negative. In my view, creating some if/then's to handle this case, and revisiting the trigonometry to respect all four quadrants, deviates enough from the reference that I don't think pvlib should claim to implement that computation approach. Also in my view, an approach based on 3d rotations is easier to follow and to maintain. See #2702

  21. echedey-ls commented on Apr 2, 2026

    @echedey-ls
    Member

    My two cents is that for surface_tilt=0 I prefer to choose surface_azimuth = axis_azimuth +/- 90 over axis_azimuth. Let's say I have this rectangle that I can draw in 3D as a function of surface_tilt and surface_azimuth. There would be a discontinuity at surface_tilt=0 in which this rectangle would switch longest and shortest sides. The logic I propose is surface_azimuth = np.mod(axis_azimuth + 90, 360)

  22. cwhanse commented on Apr 2, 2026

    @cwhanse
    Member

    @echedey-ls I'm afraid I don't follow. If you are rotating a rectangle with fixed surface_azimuth and decreasing surface_tilt, how does axis_aximuth enter?

  23. echedey-ls commented on Apr 2, 2026

    @echedey-ls
    Member

    The hypothetical situation I propose is probably just that, hypothetical. That was the first thing that came to my mind to illustrate that the fact that surface_azimut=axis_azimuth is probably unexpected in some cases as it is completely different from the neighboring values axis_azimuth +/- 90 in the typical HSAT case.

    The workflow is the following: theta (variable), axis_azimuth (fixed) and axis_tilt (fixed) are inputs to pvlib.tracking.calc_surface_orientation. Surface's azimuth and tilt are obtained, and they are then used to draw this rectangle.

    For non-zero thetas:

    1. -20
    Image
    1. -10
    Image
    1. 10
    Image
    1. 20
    Image

    But for theta=0:

    Image
    Code

    Search for theta = and change it:

    import matplotlib.pyplot as plt
    import numpy as np
    from scipy.spatial.transform import Rotation
    
    # from pvlib.tracking import calc_surface_orientation
    from pvlib.tools import acosd, cosd, sind
    
    
    def _unit_normal(axis_azimuth, axis_tilt, theta):
        theta = np.asarray(theta)
    
        cA, sA = cosd(-axis_azimuth), sind(-axis_azimuth)
        cT, sT = cosd(-axis_tilt), sind(-axis_tilt)
    
        cTh = cosd(theta)
        sTh = sind(theta)
    
        x = sA * sT * cTh + cA * sTh
        y = sA * sTh - cA * sT * cTh
        z = cT * cTh
    
        result = np.column_stack((x, y, z))
    
        return result
    
    
    def calc_surface_orientation(tracker_theta, axis_tilt=0, axis_azimuth=0):
        with np.errstate(invalid="ignore", divide="ignore"):
            surface_tilt = acosd(cosd(tracker_theta) * cosd(axis_tilt))
    
        # unit normal to rotated tracker surface
        unit_normal = _unit_normal(axis_azimuth, axis_tilt, tracker_theta)
    
        # deviate from [1] to allow for negative tilt.
        # project unit_normal to x-y plane to calculate azimuth
        surface_azimuth = np.degrees(np.arctan2(unit_normal[:, 0], unit_normal[:, 1]))
        # constrain angles to [0, 360)
        surface_azimuth = np.mod(surface_azimuth, 360.0)
    
        surface_azimuth = np.where(surface_tilt == 0.0, axis_azimuth, surface_azimuth)
    
        out = {
            "surface_tilt": surface_tilt,
            "surface_azimuth": surface_azimuth,
        }
        if hasattr(tracker_theta, "index"):
            out = pd.DataFrame(out)
        return out
    
    
    plt.interactive(True)
    
    # Create rectangle vertices (10 in x, 20 in y)
    x = np.array([-5, 5, 5, -5, -5])  # Close the loop by repeating first point
    y = np.array([-10, -10, 10, 10, -10])
    z = np.zeros_like(x)
    
    # Stack coordinates
    points = np.vstack([x, y, z])
    
    theta = 0
    axis_azimuth = 180
    axis_tilt = 0
    surface_orientation = calc_surface_orientation(
        theta, axis_tilt=axis_tilt, axis_azimuth=axis_azimuth
    )
    surface_azimuth = surface_orientation["surface_azimuth"][0]
    surface_tilt = surface_orientation["surface_tilt"]
    # Apply rotations
    # surface_azimuth = 90
    # surface_tilt = 30
    rot = Rotation.from_euler(
        "ZX", [-surface_azimuth, -surface_tilt], degrees=True
    )
    
    points_rot1 = rot.apply(points.T).T
    
    # Extract rotated coordinates
    x_rot, y_rot, z_rot = points_rot1
    
    # Create the figure and 3D axis
    fig = plt.figure(figsize=(10, 8))
    ax = fig.add_subplot(111, projection="3d")
    
    # Plot wireframe (connect the vertices in order)
    ax.plot(x_rot, y_rot, z_rot, "b-", linewidth=2, label="Rectangle wireframe")
    
    # The rectangle is defined by 4 vertices, we've already closed the loop
    # Additional lines for the rectangle structure
    for i in range(4):
        ax.plot(
            [x_rot[i], x_rot[(i + 1) % 4]],
            [y_rot[i], y_rot[(i + 1) % 4]],
            [z_rot[i], z_rot[(i + 1) % 4]],
            "b-",
            linewidth=2,
        )
    
    # Set labels
    ax.set_xlabel("> to East")
    ax.set_ylabel("< to North")
    
    # Set equal aspect ratio
    ax.set_box_aspect([1, 1, 1])
    
    # Position camera to look towards Y+ direction (North)
    # Matplotlib convention differs from pvlib's
    ax.view_init(elev=30, azim=-90)
    
    # Set limits to show the rectangle properly
    max_range = 20
    
    ax.set_xlim(-max_range / 2 - 5, max_range / 2 + 5)
    ax.set_ylim(-max_range / 2 - 5, max_range / 2 + 5)
    ax.set_zlim(-max_range / 2 - 5, max_range / 2 + 5)
    
    ax.set_title(
        f"Rectangle 10x20\nRotated: {surface_azimuth=:.0f}°, {surface_tilt=:.0f}°\n"
        "Camera facing North"
    )
    
    plt.show(block=True)

    Disclaimer: I don't think anybody should ever take this approach for drawing 3D PV scenes, but I can't guarantee nobody will. Note the code above is only valid for axis_tilt=0. I haven't had the energy to fix it for non-zero values.

    This example is just for the purpose of illustrating that picking this value may introduce unwanted discontinuities into the dataflow.

  24. cwhanse commented on Apr 2, 2026

    @cwhanse
    Member

    Thanks, I understand your point now. Thinking...

  25. cwhanse commented on Apr 5, 2026

    @cwhanse
    Member

    TL:DR there's no unique way to define surface_azimuth when surface_tilt=0. But the common use case suggests either surface_azimuth = axis_azimuth - 90 or surface_azimuth = axis_azimuth + 90. I propose pvlib returns surface_azimuth = axis_azimuth - 90 instead of axis_azimuth.

    Long story:

    surface_tilt = acosd(cosd(tracker_theta) * cosd(axis_tilt)) so the only way that surface_tilt = 0 is if both cos(tracker_theta)=1 and cos(axis_tilt)=1, i.e, both surface_tilt=0 and tracker_theta=0.

    If axis_tilt is not 0, then surface_tilt is never zero - a tilted axis tracker can never position the array horizontal.

    If either axis_tilt or tracker_theta are fixed at 0, then we can consider limits as the other angle approaches zero to decide what to return when both are zero. I posit that fixing axis_tilt==0 is far more common than tracker_theta==0 (why have a tracker that fixes the torque tube in rotation, and elevates the tube)?

    If axis_tilt=0 then the equation for surface azimuth simplifies to

    surface_azimuth = atan2(cos(-axis_azimuth) * sin(theta), sin(-axis_azimuth) * sin(theta))

    Reminder: axis_azimuth is negated in the conversion from azimuth to a rotation angle about the z-azis.

    Considering the limit as theta -> 0+ (from the positive side) yields surface_azimuth = axis_azimuth - 90.

    As theta -> 0-, the script flips to axis_azimuth + 90.

    Arbitrarily, I suggest we choose surface_azimuth = axis_azimuth - 90.

  26. echedey-ls commented on Apr 7, 2026

    @echedey-ls
    Member

    @cwhanse thanks for bringing clarity to my comment, that's exactly what I meant.

  27. kandersolar commented on Apr 7, 2026

    @kandersolar
    Member

    I am +1 to surface_azimuth = axis_azimuth ± 90 and have no preference between them.

  28. modified the milestones: v0.16.0, v0.15.1 on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions