Python and spreadsheet calcs from the reviewer's side of the desk
What a checker needs from a coded pressure-vessel calculation before signing it: code-order output, validation against published worked examples, version and units, and honest refusals.
- VIII-1 UG-27
- PTB-3
- WRC 297 §3.2
On this page
The question of how to document Python hand calcs for review keeps coming up, and the answers it gets are nearly all about tooling: which library renders LaTeX, how to export a notebook to PDF, whether to use Jupyter or a script. Those are fair questions. They are also the questions of the person writing the calc.
I review vessel calcs as well as write them, so this is the other side of the desk. What follows is what I need before I can sign a coded calculation, whether it was built in Python, Excel or anything else. Most of it is my practice rather than a code requirement, and where a code or bulletin does say something, I quote it.
What the reviewer actually checks
A reviewer checks three things: the inputs, the code paragraph, and the number. Everything in the output should make those three fast to find.
That means the output uses the code’s own symbols, cites the clause, and runs in the order the code runs. If the paragraph calls it S, the output calls it S, not allow_stress_mpa. If I have to read your source to follow the calc, the documentation has failed, however nice the rendering is.
Here is the shape I want, using the cylinder formula from ASME VIII Division 1, UG-27(c)(1):
UG-27(c)(1) Circumferential stress (longitudinal joints)
Inputs (corroded condition, UG-16(e))
P = 1.50 MPa internal design pressure, UG-21
R = 753.0 mm inside radius, 750.0 + c, c = 3.0 mm
S = 138 MPa SA-516-70, UG-23, II-D Subpart 1 Table 1A at design temperature
E = 0.85 Table UW-12, Type (1), spot examination
Applicability
P <= 0.385·S·E 1.50 <= 0.385 × 138 × 0.85 = 45.2 MPa satisfied
Equation (1)
t = P·R / (S·E − 0.6·P)
= 1.50 × 753.0 / (138 × 0.85 − 0.6 × 1.50)
= 9.70 mm
t + c = 12.70 mm
Every input carries a unit and a source. The applicability condition is printed, not assumed. The equation appears once in symbols and once with the numbers substituted, so I can check the algebra and the arithmetic separately. The inputs are in the corroded condition because UG-16(e) says the symbols in the design formulas “represent dimensions in the corroded condition”, and the output says so instead of leaving me to guess.
This is the format ASME uses in its own example manual. PTB-3 states that in its example problems, the tubesheet rules of 4.18 excepted, “the code equations are shown with symbols and with substituted numerical values to fully illustrate the use of the code rules” (PTB-3-2022, §2.2). It also says rounding “should only be done on the final results” (§2.3). A coded calc can do both for free. A hand calc rarely does the second.
Validation is the bigger half
Presentation gets a calc through review faster. It doesn’t make the calc right. What makes a coded calc trustworthy is evidence that the method is implemented correctly, and the cheapest evidence available is a published worked example.
ASME publishes example problem manuals for exactly this. PTB-3 is the Section VIII, Division 2 Example Problem Manual; the 2022 third edition was updated to the 2021 edition of VIII-2 and covers the Part 4 design-by-rule and Part 5 design-by-analysis procedures, among others. Its examples are “primarily in US Customary units”, with select problems in SI, and all are worked for a Class 2 vessel. PTB-4 is the Division 1 counterpart. The WRC bulletins carry their own worked examples too: WRC 297 has three in Appendix A, two stress calculations and a nozzle-flexibility example.
The practice I’d ask for:
- Reproduce the published examples that exercise your code.
- Freeze each one as an automated test with the published inputs and expected outputs.
- Run every test on every change, before any output leaves the building.
Two cautions. The examples are tied to a code edition, so when you move editions, check whether the example moved with it. And PTB-3 says its precision is for demonstration only, so set a tolerance you can defend rather than demanding a match to the last printed digit. What that tolerance should be is a judgement call; I come back to it at the end.
Once the method is demonstrated this way, a review collapses to a review of inputs, which is exactly where a reviewer’s time should go. “Calculated with version 2.4.1, which reproduces the PTB examples for these paragraphs” is a sentence a checker can sign off on. A live notebook that may have changed since anyone last ran the tests is not.
Version stamping and units
Every output should say which version of the calculation produced it, and which code edition that version implements. A commit hash or a release number both work. A filename with “final_v3” in it does not. If the calc is ever questioned, someone has to be able to rerun exactly the code that produced the signed PDF.
Units should be explicit at every boundary. Python has no idea whether 12 is kN·m or N·m, and neither does a spreadsheet cell. Either carry units through the calculation with a units library, or convert once at input into one consistent system and print the unit beside every number in the output. I covered how a thousandfold unit slip prints as a clean pass in the Excel post, so I won’t repeat it here.
Refuse outside the validity range
Every method has a box, and the codes say so in plain words. UG-27(c)(1) applies “When the thickness does not exceed one-half of the inside radius, or P does not exceed 0.385SE”; past that, Mandatory Appendix 1, 1-2(a) applies instead. UG-28(c)(1) allows interpolation between Do/t lines when reading the external pressure chart, but “extrapolation is not permitted”. WRC 297 §3.2 is just as direct about its curves:
“It is not recommended that curves be extrapolated beyond the λ values for which stress resultants are plotted.”
So a coded calc that meets a geometry outside its method should refuse. Not warn in a log nobody reads, not return a number with a footnote. Refuse, and say why in the output.
I can tell you what happens when this goes wrong, because it happened to me. PV Cloud, the nozzle tool I build, used to read a WRC 297 curve that the geometry had fallen off and get zero back instead of a refusal. That zero went through the stress equations, and the summary rows treated a non-finite stress as a pass. The report printed “0.00 MPa PASS”.
The trigger was ordinary: a 168.3 mm OD nozzle with a 6.35 mm wall on a 1500 mm × 20 mm vessel falls off one of the figures. The landing page’s own sample report was publishing a fabricated −45.34 MPa until it was fixed on 2026-07-28.
Now a refused read prints a dash instead of a number, with the reason stamped against each point: which λ, which figure, and its plotted range. Acceptance checks that needed those components read INCOMPLETE. The refusal is surgical: only the checks that depended on the missing curve go incomplete. Tests pin it: a refused read can only produce an incomplete row, never a pass or a fail, and a calculation refused outright prints no verdict at all.
One caveat, since this section is about honesty. The tool does not refuse at the exact end of the plotted curve. A short way past it, the fitted value is still used, and the report marks that read as extrapolated and cites §3.2 beside it. Beyond that margin it refuses. By the rule I set out above, a flagged number is the weaker of the two behaviours, so check for that flag when you review one of its reports.
The general trap is worth knowing even if you never touch WRC. In Python, every ordering comparison with NaN (<, >, <=, >=) returns False. A check written as “fail if stress > allowable” passes a NaN stress without complaint. A zero is worse, because it looks like a real result. The fix is the same for both: validity checks run before the arithmetic, and a value that didn’t come from the method can never reach a pass/fail comparison.
When a notebook or spreadsheet is fine
For scoping, one-off checks and your own sanity checks, a notebook or a small spreadsheet is fine, and often the right tool. Nobody needs a release process to find out whether a concept is in the right ballpark.
It stops being fine when the calc is reviewed outside the author’s team, or when it gets reused. At that point the reviewer is relying on code they can’t see, and reuse means the geometry will eventually land somewhere the author never tested. A notebook adds its own problem: cells can run in any order, so the output on the page need not match a top-to-bottom run. The earlier post was about what spreadsheets cost the author. This one is about what the checker needs, and those requirements don’t change with the tool.
A reviewer’s checklist
- Every input has a unit and a source: drawing, datasheet, code table or stated assumption.
- Inputs are in the condition the code requires, for VIII-1 the corroded condition per UG-16(e).
- Symbols match the code paragraph, and each step cites its clause.
- Steps run in the code’s order, with each equation shown in symbols and then substituted.
- Rounding happens only on the final result.
- Applicability limits for each method are printed and checked, with the governing value shown.
- Anything outside a method’s range is refused in the output, with a reason, not returned as a number.
- The output states the calc version and the code edition it implements.
- Published worked examples covering these paragraphs pass as automated tests on that version.
- No result in the output came from a cell or variable that a person typed over.
If you check coded calcs for a living, I’d like to know where you set the tolerance against a published example. Do you want the printed digits reproduced exactly, or do you accept a percentage, and how big?