8000 Add simple and advanced tomato examples with a report and grower batch sheets by rafatahmed · Pull Request #73 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

Add simple and advanced tomato examples with a report and grower batch sheets - #73

Merged
rafatahmed merged 1 commit into
mainfrom
feat/tomato-examples
Oct 21, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
feat/tomato-examples

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Adds tomato examples that show what FlahaX can do, from a one-screen simple case to a full analysis-to-batch plan, plus an offline HTML report and printable grower batch sheets.

Run

$env:PYTHONPATH = 'src'
python -m examples.tomato_simple
python -m examples.tomato_advanced
python -m examples.tomato_report --output build/tomato-report

Simple: Tomato (Howard Resh) in RO water

The example covers products and doses, a 1000 L batch, nutrient fit (every target within 0.04%), the formula's ion balance (0.0%), chemical identity per product, and an experimental EC estimate (2.31 mS/cm). It also reports that the unacidified mix sits at pH 6.90, outside the 5.3–5.8 feed range.

Advanced: a published brackish well

Real, cited data: the Shomar et al. (2024) station 104 well, with De Kreij, Voogt & Baas tomato open-system targets.

  1. Water analysis. The analysis is −3.52% out of charge balance. It is kept at its measured pH 7.8 and closed on chloride (−9.5%).
  2. Blend. At the published 25% blend, Na (170 mg/L) and Cl (290 mg/L) exceed the 3 mmol/L open-system limits. The largest acceptable share is 9% well water.
  3. Formulation. With the whole catalogue, the fit takes P from 75% phosphoric acid and the feed mixes to pH 3.77. Phosphoric acid is withdrawn as a P source and MKP supplies P instead, giving a feed pH of 5.89.
  4. Chemistry. Saturation indices are reported: hydroxylapatite and MnHPO₄ are supersaturated.
  5. Acid.
    • FlahaX evaluates both acids. Nitric is refused (supersaturated phases) and phosphoric is refused (P target), each with the reason given.
    • The nitric dose is still computed: 12 mL of 60% HNO₃ per 1000 L to reach pH 5.5. That acid also lifts nitrate-N from 220.9 to 223.0 mg/L, within 1% of the target.
  6. EC. About 3.07 mS/cm after acid (experimental estimate).
  7. Concentrate tanks. Grouped from the cited Yara compatibility table (04_Fertilizer.pdf p. 65, read with p. 63).
  8. Injection. Sizing for an illustrative 1000 m² event.
  9. Stages. Howard Resh stages 1–3, each run as its own batch. Stage 3 misses targets because its formula is 29% out of ion balance.

Tank grouping from a cited source

  • Encoding. examples/tomato_tanks.py encodes the page 65 table, which I verified visually against the PDF (the hash matches the one already cited in the pepper review).
  • Grouping. It places products in the fewest tanks with no incompatible pair. Products the table doesn't list are marked "Not in table", never guessed.
  • Finding. The simple recipe uses magnesium sulfate. Page 65 says magnesium sulfate is incompatible with calcium nitrate and with phosphates (MKP, MAP, phosphoric acid). So concentrates for that recipe need three tanks. The advanced recipe uses Mg nitrate and fits two.

Reports

  • tomato-report.html. Both examples, with charts (target vs delivered, Na/Cl by blend), tables and the sources.
  • batch-sheet-simple.html and batch-sheet-advanced.html. Printable one-page sheets: the water line; what to weigh per tank, with tick boxes; concentrate g/L at 1:100; the acid step with its warning; and measure-after-mixing lines for EC, pH, operator, date and signature.

All three are offline HTML with no scripts and no external resources, printable to PDF. I checked them visually in the browser.

Example acid grades, the site figures and the 1:100 ratio are labelled illustrative. Every computed value comes from run().

Also

  • Both examples join run_all.
  • The examples README gains a tomato section, and two stale lines are fixed ("unreleased checkout / PyPI 0.3.0", "28 catalogue").

Tests

  • 382 tests pass.
  • tests/test_tomato_examples.py (9 tests) checks the claims the report makes:
    • the blend is the largest share within the limits;
    • phosphoric acid over-acidifies;
    • both acids are evaluated and the nitrate gap closes;
    • every tank is pairwise compatible;
    • magnesium sulfate needs a third tank;
    • the HTML is complete and offline.

…h sheets

tomato_simple: the shipped Howard Resh tomato formula in RO water; recipe,
1000 L batch, nutrient fit, ion balance, identities and an EC estimate, and
the note that the unacidified mix (pH 6.9) needs acid.

tomato_advanced: a published brackish well (Shomar et al. 2024, station
104) with Dutch open-system tomato targets. Balances the analysis at its
measured pH, picks the largest blend within 3 mmol/L Na and Cl (9% well),
shows why phosphoric acid is withdrawn as a P source (feed pH 3.8),
speciates the mix, evaluates nitric and phosphoric acid (both refused,
with reasons) and computes the nitric dose, which also closes the nitrate
gap; estimates EC, groups concentrate tanks, sizes injection, and runs
three stage formulas as separate batches.

tomato_tanks groups concentrates with the Yara compatibility table
(04_Fertilizer.pdf p. 65, read with p. 63); products it does not list are
marked, never guessed. tomato_report writes an offline HTML report with
charts and two printable one-page batch sheets. Both examples join run_all;
tests check the claims the report and sheets make.
@rafatahmed
Copy link
Copy Markdown
Owner Author

On hold (owner decision 2026-10-21): the grower-path audit found package-level bugs (#74-#80). This PR will be rebuilt on the fixed package so the examples need no workarounds.

@rafatahmed rafatahmed self-assigned this Oct 23, 2026
rafatahmed added a commit that referenced this pull request Nov 7, 2026
Add simple and advanced tomato examples with a report and grower batch sheets
rafatahmed added a commit that referenced this pull request Nov 7, 2026
…79)

An installed FlahaX gave growers JSON: the report, the batch sheet and the
concentrate-tank grouping existed only as example code (#73).

- flahax batch: one formula (packaged, or your targets) and one water (ro, or a
  measured analysis closed at its pH) to report.html, batch-sheet.html and
  summary.json, with the coupled pH plan (acids from certificate values, plus
  the packaged bases). Exit 0 ready/review, 3 blocked, 1 input error.
- summarize_batch, render_report, render_batch_sheet: the same from any
  plan_fertilizer_workflow result. With a selected reagent the sheet weighs the
  refitted recipe that counts its nutrients; a blocked plan shows the acid-free
  recipe and the phases that block it. Offline HTML, no script.
- group_tanks: the Yara p. 65 compatibility table (read with p. 63) as three
  composition rules (Ca-phosphate, Ca-sulfate, Mg-phosphate), which reproduce
  its twelve incompatible pairs exactly. Owner rule: micronutrients and
  chelates go to tank A with calcium and stay out of phosphate concentrates;
  tank A is never acidified; pH reagents get their own channel. User
  compatibilityRule records apply on top. default_compatibility_rules gives
  plan_stocks the same rules.
- Tomato examples use the packaged grouping (micronutrients no longer 'Not in
  table') and their acid text reflects #78. Stock solubility is still not
  checked, and the outputs say so.
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.

1 participant

0