Skip to content

Modified the calc tilt angle function for pysam solar#646

Merged
johnjasa merged 1 commit intoNatLabRockies:developfrom
johnjasa:neg_tilt_angle
Apr 6, 2026
Merged

Modified the calc tilt angle function for pysam solar#646
johnjasa merged 1 commit intoNatLabRockies:developfrom
johnjasa:neg_tilt_angle

Conversation

@johnjasa
Copy link
Copy Markdown
Collaborator

@johnjasa johnjasa commented Apr 3, 2026

Fix calc_tilt_angle for southern hemisphere (negative) latitudes

PYSAMSolarPlantPerformanceModel.calc_tilt_angle previously passed latitude directly to the "lat" and "lat-func" tilt calculations. For southern hemisphere sites (negative latitudes), this produced negative or incorrect tilt angles.

The fix applies abs(latitude) before computing tilt in those branches, so positive and negative latitudes of the same magnitude yield identical tilt angles. The "none" branch is unaffected.

# Before (broken for negative latitudes)
if self.design_config.tilt_angle_func == "lat":
    return latitude

# After
abs_latitude = abs(latitude)
if self.design_config.tilt_angle_func == "lat":
    return abs_latitude

Section 1: Type of Contribution

  • Feature Enhancement
    • Framework
    • New Model
    • Updated Model
    • Tools/Utilities
    • Other (please describe):
  • Bug Fix
  • Documentation Update
  • CI Changes
  • Other (please describe):

Section 2: General PR Checklist

  • PR description thoroughly describes the new feature, bug fix, etc.
  • Added tests for new functionality or bug fixes
  • Tests pass (If not, and this is expected, please elaborate in the Section 6: Test Results)
  • Documentation
    • Docstrings are up-to-date
    • Related docs/ files are up-to-date, or added when necessary
    • Documentation has been rebuilt successfully
    • Examples have been updated (if applicable)
  • CHANGELOG.md
    • At least one complete sentence has been provided to describe the changes made in this PR
    • After the above, a hyperlink has been provided to the PR using the following format:
      "A complete thought. [PR XYZ]((https://github.com/NatLabRockies/H2Integrate/pull/XYZ)", where
      XYZ should be replaced with the actual number.

Section 3: Related Issues

Resolves #645

N/A

Section 4: Impacted Areas of the Software

Section 4.1: New Files

N/A

Section 4.2: Modified Files

  • h2integrate/converters/solar/solar_pysam.py
    • calc_tilt_angle: Use abs(latitude) in the "lat" and "lat-func" branches to support southern hemisphere sites.
  • h2integrate/converters/solar/test/test_pysam_solar.py
    • Added TestCalcTiltAngle class (26 tests) covering all tilt_angle_func modes with positive, negative, zero, and boundary latitudes.

Section 5: Additional Supporting Information

N/A

Section 6: Test Results, if applicable

All 26 new TestCalcTiltAngle tests pass. Existing PySAM solar tests are unaffected.

h2integrate/converters/solar/test/test_pysam_solar.py::TestCalcTiltAngle  26 passed

@johnjasa johnjasa requested a review from elenya-grant April 3, 2026 18:38
Copy link
Copy Markdown
Collaborator

@elenya-grant elenya-grant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this update and all the awesome tests for this function! Looks great to me!

@johnjasa johnjasa merged commit 910e872 into NatLabRockies:develop Apr 6, 2026
5 checks passed
@johnjasa johnjasa deleted the neg_tilt_angle branch April 6, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants