Skip to content

Document rack corner order and warn when a rack faces below the horizon - #59

Merged
javlor merged 5 commits into
dnv-opensource:mainfrom
wholmgren:bugfix/rack-corner-order
Nov 23, 2026
Merged

javlor merged 5 commits into
dnv-opensource:mainfrom
wholmgren:bugfix/rack-corner-order

Conversation

@wholmgren

@wholmgren wholmgren commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #58

What this changes

  • Corner order: QuadDouble and Rack now document the corner order (P1 at the low corner, P1→P2 up the slope, P1→P4 along the row: SW-low, NW-high, NE-high, SE-low for a south-facing rack) and the axes (x east, y north, z up). This matches the example rack in the ModelChainAsync documentation's Racks and Trackers section. That page calls the order "anti-clockwise around the rack", which holds only when seen from below; from above or from the front of the modules it is clockwise. Review confirmed the convention against SF-Core; the documentation's wording should be corrected separately.
  • Module positions: QuadDouble and ModuleIndexRange document where modules sit on a rack, with a 3 × 2 diagram. Index x counts along the row from the P1 end, and y counts rows up the slope from the P1–P4 edge. Module (0, 0) is inset from P1 by frame_end_width and frame_bottom_width, and the module spacing sets the rest. Either endpoint order covers the same inclusive module positions. The docs also say the SDK doesn't check the quad's size against the mounting type, so correct winding alone doesn't mean the modules fit.
  • Geometry properties: QuadDouble.width, depth, front_normal, tilt and azimuth show how a quad's corners will be read.
  • Warning: PVPlant and Racks issue one RackOrientationWarning (exported from solarfarmer) when any racks' front faces point below the horizon or their quads have no area. A single warning covers both cases, with the count and the first ten rack IDs for each. It warns rather than reordering corners, because reordering would also change module indexing.
  • Fixtures: the four rack quads in tests/test_models/test_composition.py used the reverse order and are corrected.
  • Live 2D/3D tests: tests/test_rack_3d_parity.py, marked integration and skipped without SF_API_KEY. They build small plants from the Bern sample's weather, PAN and OND files, with identical equipment, electrical layout and losses in 2D and 3D.
  • CHANGELOG entries under Unreleased.

Why the orientation check runs on the collection, not on Rack

A validator on every Rack added about 7 µs per rack and printed one warning per reversed rack. A 500 MW layout of 7-module racks (about 130,000 racks) generated in the wrong order would print 130,000 warnings. The collection-level check validates 130,000 racks in the same time as without it (0.74 s locally) and issues one warning. A standalone Rack isn't checked until it goes into a PVPlant or Racks.

Live test results (API 7.0.15)

Test 3D 2D Difference
Two south-facing racks in one row, 20 m apart, 2 rows of 30 each, one string per row: effective irradiation 1328.3676483 kWh/m² 1328.3676455 kWh/m² 0.0000002%
Same: annual AC energy 37.7131278 MWh 37.7131278 MWh 0
East (90°/20°) and west-southwest (250°/35°) racks, nearest corners 40 m apart: effective irradiation 1140.0796555 kWh/m² 1140.1092016 kWh/m² −0.0026%
Same: annual AC energy 9.3956628 MWh 9.3959844 MWh −0.0034%

Near shading was 0 and −0.00003. The tests allow 0.1% and 0.001; a reversed rack is off by about 85%. At those spacings a neighbour can shade a rack only with the sun within about 6° of the horizon. With the racks 200 m apart, the mixed-orientation differences were −0.0002% and −0.00076%, and near shading was −0.000003.

Energy parity can't catch an indexing error, because every module on an unshaded rack sees the same irradiance. So test_module_index_x_starts_at_p1 puts a wall in front of the P1 (west) end of a 48-module rack. It wires 30 modules as a live string and the other 18 to an inverter they can't reach the MPPT window of, so the plant's energy is the live string's. The live string produced 0.605 MWh starting at index 0 and 5.523 MWh starting at index 18 (unchanged by moving the spare rack from 200 m to 20 m away), so index 0 is at P1.

The y direction, frame insets and spacing follow the definitions in the web API reference. The tests use zero frames and one-row strings, so they don't exercise those beyond y = 0 and 1.

Notes for the service team

  • Single-rack plants fail silently. Every 3D plant we tried with only one rack ended with runtimeStatus "Failed" and null customStatus and output, after 6–12 s. That covered four wirings, with and without a shading object, and the full status payload gave no reason. The same racks completed in two-rack plants, so each test plant has two.
  • The Matera sample's trackers are slightly shorter than their mounting type implies. It specifies 19 modules × 1.96 m = 37.24 m, but the axes are 37.0–37.2 m long, so the engine evidently accepts some size difference. We haven't tested what it does with one.

Testing

  • TestQuadDoubleGeometry (6 tests, including the documentation's example rack: tilt 34.0°, azimuth 177.4°) and TestRackOrientation (8 tests) in tests/test_models/test_validation.py.
  • Offline suite: 835 passed, 19 skipped (the 3 new live tests skip without a key), with RackOrientationWarning treated as an error. ruff check and ruff format --check pass (ruff 0.14.14, as pinned in pre-commit).
  • Live: all 3 tests in tests/test_rack_3d_parity.py pass with SF_API_KEY set. All three were rerun on f63ff5a, which moved the racks closer together. The shared helper rejects non-finite or non-positive effective irradiation and net energy, so two zero-production results can't pass a relative comparison.

🤖 Generated with Claude Code

wholmgren and others added 2 commits November 19, 2026 14:54
The order of a rack's quad corners decides which face the calculation
treats as the front of the modules, but QuadDouble and Rack did not
document it, and every rack fixture in test_composition.py used the
reverse order. That order passes validation and completes, but in an
unshaded 3D control it returned about 15% of the equivalent 2D energy.

- Document the order on QuadDouble and Rack: P1 at the low corner,
  P1->P2 up the slope, P1->P4 along the row (SW-low, NW-high, NE-high,
  SE-low for a south-facing rack), with x east, y north and z up,
  matching the ModelChainAsync documentation example
- Add QuadDouble.width, depth, front_normal, tilt and azimuth
- Issue RackOrientationWarning when a rack's front face points below
  the horizon, or its quad has no area
- Correct the four rack fixtures in test_composition.py

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A validator on every Rack added about 7 us per rack and printed one
warning per reversed rack: 130,000 warnings for a 500 MW layout of
7-module racks generated in the wrong order. PVPlant and Racks now check
all of their racks in one pass and issue a single RackOrientationWarning
with the count and the first ten rack IDs. Validating 130,000 racks
takes the same time as without the check (0.74 s here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wholmgren-dnv

Copy link
Copy Markdown
Collaborator

focused 2D/3D parity tests belong in this PR. They directly address the silent energy failure, and they’re already part of #58’s acceptance check.

Use Bern as the resource, not the whole plant
Reuse the weather, PAN and OND files from Inputs_Bern_2D_racks. Build small, controlled payloads rather than converting its existing multi-row, shaded plant.

I’d include:

A single-orientation, unshaded case.
A mixed-azimuth/tilt case, represented equivalently in 2D and 3D.
Keep equipment, electrical configuration and losses identical. Assert effective irradiation, annual AC energy and negligible near-shading loss, with an explicit tolerance justified by the observed results—not exact equality. Mark them as integration tests and reuse the existing credential-skipping api_key fixture

The multi-module documentation gap also belongs here
The PR explains winding but stops before explaining how modules occupy the rack. Document:

Rack-local X increases P1→P4; Y increases P1→P2.
(0, 0) identifies the module nearest P1, inset by frame offsets.
Module orientation, dimensions and spacing determine physical placement.
Index endpoints are inclusive; descending endpoints select the same module positions.
Winding alone does not establish that the quad fits the mounting specification.
Add a small 3-column × 2-row diagram, plus an offline test placing identifiable modules at different indices. Energy parity alone could miss an indexing error on uniformly illuminated modules.

Review on dnv-opensource#59 asked for the 2D/3D parity check from dnv-opensource#58's acceptance
criteria and for the multi-module documentation the PR left out.

- QuadDouble and ModuleIndexRange document where modules sit on a rack:
  index x counts along the row from the P1 end, y counts rows up the
  slope from the P1-P4 edge, and frame widths and spacing set each
  module's position. A descending range covers the same modules. The
  docs note that the SDK does not check the quad's size against the
  mounting type.
- tests/test_rack_3d_parity.py (integration, skipped without SF_API_KEY)
  builds small plants from the Bern sample's weather, PAN and OND files:
  two-row south-facing racks and mixed-orientation racks must match the
  equivalent 2D layout within 0.1% with no near shading, and a wall in
  front of one end must show that index 0 is the module at P1.

Results on API 7.0.15: the largest 2D/3D difference was 0.00076%, and
the string at the P1 end behind the wall produced 1/9 of the same
string at the other end. Every single-rack 3D plant we tried ended with
status Failed and no reason, so each test plant has two racks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wholmgren

Copy link
Copy Markdown
Contributor Author

Thanks. Both are in ea3a6ce, with two changes to the plan.

Parity tests: tests/test_rack_3d_parity.py uses Bern's weather, PAN and OND files with small new plants, the same equipment, electrical layout and losses in 2D and 3D, the integration marker and the existing api_key fixture. There are two cases: two-row south-facing racks with one string per row, and east (90°/20°) plus west-southwest (250°/35°) racks. They assert effective irradiation, annual AC energy and near shading. The largest 2D/3D difference was 0.00076%, so the tolerance is 0.1%; a reversed rack is off by about 85%. The numbers are in the description.

Module positions: QuadDouble and ModuleIndexRange now have the 3 × 2 diagram and the points you listed. I checked one of them first, because the web API reference doesn't say which end of the rack is x = 0. Row direction (0 at the bottom edge), frame insets and spacing are defined there, but the x origin isn't. A live test confirms it: a wall shades the P1 end of a 48-module rack, and a 30-module string starting at index 0 produced 0.605 MWh, against 5.523 MWh starting at index 18. So index 0 is at P1.

I left out the offline indexing test. The SDK passes ModuleIndexRange through as data and never places modules, so an offline test could only check serialization. It couldn't catch the indexing error you describe. The wall test does.

Single-rack plants fail silently. Every 3D plant I tried with only one rack ended with runtimeStatus "Failed" and null customStatus and output. That covered four wirings, with and without a shading object, while the same racks in two-rack plants completed. Each test plant therefore has two racks. This looks like something for the service team, and it's another example of the missing failure diagnostics.

🤖 Generated with Claude Code

@wholmgren-dnv wholmgren-dnv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed ea3a6ce. The Bern-based parity cases and multi-module diagram address the earlier feedback well. The live wall test is better evidence than the proposed serialization-only indexing test; I agree with leaving that offline test out.

Two remaining findings are attached inline. Before declaring live validation complete, please rerun the mixed-orientation case on the exact committed version: the description says it was not rerun after corner rounding.

Two smaller documentation points:

  • The collection check can issue two warnings when both reversed and degenerate racks are present, rather than the advertised single warning. Either qualify the wording or combine the messages.
  • Please link the ModelChainAsync documentation, Racks and Trackers section in the PR description and beside the example-based geometry test. Its example matches this PR, but its unqualified anti-clockwise wording is misleading. The convention is confirmed by inspection of SF-Core; the public documentation wording should be corrected separately.

Validation: 78 focused tests passed, 3 live tests skipped; targeted Ruff lint and formatting passed. All six payload-construction paths were exercised offline. No live API calculations were submitted during this review.

a row on the mount. On a rack, index 0 is the module at the ``P1``
end; see :class:`~solarfarmer.models.QuadDouble`. May be larger than
``end_x``: the range then covers the same modules, wired in the
opposite direction along the row

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Please remove the guarantee that descending endpoints mean modules are wired in the opposite direction. The reliable guarantee here is that they select the same inclusive module positions; reversed electrical traversal is not established by the new tests. This qualification is confirmed by inspection of SF-Core. Suggested wording: 'May be larger than end_x; either endpoint order covers the same inclusive module positions.'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 1b74cb8, with your wording.

assert result_3d["effective_irradiation"] == pytest.approx(
result_2d["effective_irradiation"], rel=ENERGY_TOLERANCE
)
assert result_3d["net_energy"] == pytest.approx(result_2d["net_energy"], rel=ENERGY_TOLERANCE)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] These parity assertions accept two zero-production summaries. I reproduced _assert_parity({'effective_irradiation': 0.0, 'net_energy': 0.0, 'near_shading': 0.0}, same_summary) passing. The wall test can also accept certain negative-energy comparisons. Please assert finite, positive effective irradiation and net energy in the shared _annual helper before returning its summary, so all three tests reject invalid/non-producing results before their relative comparisons.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 1b74cb8. _annual now asserts finite, positive effective irradiation and net energy (and finite near shading) before returning, so all three tests reject non-producing results. I checked it offline with zero, negative and NaN summaries.

- Reversed and zero-area racks now share a single RackOrientationWarning
  instead of one each, matching the documented "one warning".
- ModuleIndexRange no longer claims that a descending range is wired in
  the opposite direction; either endpoint order covers the same
  inclusive module positions.
- The live tests' _annual helper rejects non-finite or non-positive
  effective irradiation and net energy, so two zero-production results
  can no longer pass the relative comparisons.
- The documentation-example geometry test links the ModelChainAsync
  "Racks and Trackers" section and notes that its "anti-clockwise"
  wording holds only when seen from below.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wholmgren

Copy link
Copy Markdown
Contributor Author

The mixed-orientation case passes on 1b74cb8 with the same results as before. Reversed and zero-area racks now share one warning, with a test for both together. The Racks and Trackers link is in the description and in the example test's docstring.

The racks were 200 m apart, which made the scenes mostly empty ground.
Two-row racks and the indexing test's spare rack now stand in one row
20 m apart (RACK_GAP), and the mixed-orientation racks' nearest corners
are 40 m apart. A neighbour can then shade a rack only with the sun
within about 6 degrees of the horizon in the east or west.

Rerun on API 7.0.15: the two-row and indexing results are unchanged to
the printed precision; the mixed-orientation 3D/2D energy difference
went from 0.00076% to 0.0034%, and its near shading from 0.000003 to
0.00003, well inside the 0.1% and 0.001 tolerances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@javlor javlor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the contribution Will.

@javlor
javlor merged commit 7b029a9 into dnv-opensource:main Nov 23, 2026
12 checks passed
@wholmgren
wholmgren deleted the bugfix/rack-corner-order branch November 23, 2026 14:53
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.

3D racks: quad corner order is undocumented, and the test fixtures use an order that gives wrong energy

3 participants