8000 feat: pH interval, deviation ranges and the total-N urea rule (#303, #304, #305) by rafatahmed · Pull Request #306 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 8000 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ Development checkout: 0.7.1.dev0.

### Added

- Total nitrogen (`N`, mg/L as N) is a target alone or with nitrogen forms. Alone it imposes no form split; with all three forms it must agree with their sum; with some forms both are scored and `totalN.overlapForms` lists the overlap (#291).
- Total nitrogen (`N`, mg/L as N) is a target alone or with nitrogen forms. Alone it imposes no form split; with a nitrate and a positive ammonium target it must agree with their sum (an absent urea counts as zero); with other forms both are scored and `totalN.overlapForms` lists the overlap (#291).
- `flahax batch` takes `--available-tanks` and `--tank-capacity`; the report lists the tanks the recipe needs against yours, and a tank too small for its stock blocks without changing the recipe (#293).
- Acceptable deviation ranges, none by default: `deviation_ranges` on `recommend` and the workflow, and `--range-percent`, `--range` and `--require-ranges` on `flahax batch`. Assess classifies the result; Require constrains the fit and keeps an unmet candidate. A zero target or declared maximum is never relaxed (#305).
- `target_ph` accepts an acceptable interval `(low, high)` (`--ph-min` and `--ph-max` on `flahax batch`): a mix inside needs no reagent, otherwise the plan aims at the nearest bound, never a midpoint; single-purpose pH stages refuse an interval (#304).
- `--fit-equipment` and `available_product_search(on_equipment_miss=True)` search other products for a recipe that fits the declared tanks; tanks and separation rules never change, and the mode and equipment are saved in `remedies` (#294).
- A saved result keeps `supplied_inputs`, bound to its input fingerprint, and `saved_input_differences` names what a recalculation changed (#297).

### Changed

- The batch report and `plan_stocks` qualify a solubility value through one function (`qualify_single_product`): `verified` only where the recorded temperature range and the concentration basis support it, otherwise the gap is named. `StockPlan.qualification` is new and a solubility-limit record may state an optional `basis` (#307).
- The glossary no longer implies a fixed A/B: the stock assignment may use more than two tanks and the result lists every one (`tanks.tanks`) (#308).
- An absent or zero `N_NH4` target is no requirement and no maximum. The ammonium allowance is now an opt-in preset (`max_ammonium_fraction`), so default recipes may use ammonium nitrate and report NH4-N for review (#290).
- Products sharing an exact name are rejected as `ambiguous_product_name` before dose resolution (#288).
- `plan_stocks` no longer raises `missing_solubility_limit`: with no limit at the temperature it keeps the quantities, lists the product in `StockPlan.unverified` and approves nothing (#295).

### Fixed

- Total nitrogen counts an absent urea as a zero requirement: a declared nitrate and a positive ammonium now determine the total, a total that disagrees with them is rejected before fitting (for example `N` 150 with `N_NO3` 100 and `N_NH4` 30), and a consistent total is scored once (#303).
- Coupled recipes are assessed at the emitted reagent dose, and search provenance survives dose reassessment (#288).
- Each solubility row states that it is a single-product value and whether its temperature is verified; a value recorded at another temperature is flagged, not silently accepted (#295).
- The glossary defines stock assignment, required and available tanks, equipment fit and single-product solubility (#296).
Expand Down
21 changes: 17 additions & 4 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ _Avoid_: Acid, base, adjuster
The charge a product label's ions cannot balance, reported and not refused.
_Avoid_: Label check, identity check, charge gate

**Acceptable deviation range**:
A range a user declares around a positive target (a symmetric percentage, with per-nutrient shortage and excess in percent or
mg/L). None is a default. Assess classifies the result against it; Require constrains the search by it. It never relaxes a zero
target or a declared maximum, and a miss is reported, not widened.
_Avoid_: Tolerance, allowance, default range

**Acceptable pH interval**:
A pair `(low, high)` given as the target pH. It is judged against its bounds: a mix inside needs no reagent, a mix outside
is moved to the nearest bound. No midpoint is ever used.
_Avoid_: Target range midpoint, pH setpoint range

**Total nitrogen target**:
Elemental N (`N`, mg/L) summed over nitrate, ammonium and urea. Alone it imposes no form split; with all three forms it must
agree with their sum; with some forms both are scored and the overlap is reported. It is a target only, never water, a
maximum or an assay.
Elemental N (`N`, mg/L) summed over nitrate, ammonium and urea; urea that is not asked for is a zero requirement, not an
unknown. Alone it imposes no form split. With a nitrate target and a positive ammonium target the forms determine it and it
must agree with their sum; otherwise both are scored and the overlap is reported. It is a target only, never water, a maximum
or an assay.
_Avoid_: Total N conversion, N split

**Ammonium allowance**:
Expand All @@ -58,7 +70,8 @@ _Avoid_: Declaration, assumption to confirm

**Tank A / Tank B**:
The usual nutrient stock channels, with calcium and micronutrients in A and sulfates and
phosphates in B. Actual layouts depend on separation constraints, equipment and mixture evidence.
phosphates in B. This is a usual layout, not a limit: the assignment may use more than two tanks (named A, B, C and so on),
and the effective assignment is in the result (`tanks.tanks`). Layouts depend on separation constraints and mixture evidence.
_Avoid_: Part A / Part B, Stock 1 / Stock 2

**Stock assignment**:
Expand Down
9 changes: 9 additions & 0 deletions docs/site/agronomist/batch-command.md
8000
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ flahax batch --formula "Tomato (Howard Resh)" --water well.json --water-share 8
both product lists.
- `--volume` sets the batch size (default 1000 L), `--ph` the target pH
(default 5.8) and `--ratio` the injection ratio (default 1:100).
- `--ph-min` with `--ph-max` gives an acceptable pH interval instead of one `--ph`. A feed that mixes
inside the interval needs no reagent; otherwise the plan aims at the nearest bound, never a midpoint.
Give both or neither, and not together with `--ph`. The interactive `flahax mix` takes one pH.
- `--range-percent` gives an acceptable deviation in percent either side of every positive target, and
`--range SYMBOL=SHORTAGE:EXCESS` sets one nutrient's sides, each as `5%` or `3mg` (mg/L), for example
`K=2%:5%` or `Ca=:4mg`. There is no default: with neither option no range is used. Without
`--require-ranges` the result is only assessed against the ranges; with it the fit is constrained by
them (upper bounds as hard maximums, a nutrient below its lower bound weighted up). A zero target and a
declared maximum are never relaxed, and a range that cannot be met is reported, never widened.
- `--available-tanks` states how many concentrate tanks you have and `--tank-capacity`
(repeated once per tank, in litres) their sizes. The recipe does not change with the
equipment: the report shows the tanks the recipe needs, whether yours are enough, and
Expand Down
15 changes: 10 additions & 5 deletions docs/site/agronomist/formula-and-products.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ Total N can also be a target, written `N` (mg/L as N), alone or with forms (deci

- `N` alone is one requirement on the sum of the three forms. It imposes no form split, and
a urea-bearing product is still not used unless the formula declares urea.
- `N` with all three forms: the forms are scored once and the declared total is checked
against their sum. A disagreement is an error before any fitting.
- `N` with only some forms: both are scored and `totalN.overlapForms` lists the forms
scored besid 8BD0 e the total. No other form target is invented; the selected products decide
the unspecified forms. Forms that add up to more than `N` are an error.
- Total N is nitrate + ammonium + urea, and urea that is not asked for is a zero
requirement, not an unknown. `N` with a nitrate target and a positive ammonium target:
the forms determine the total, so they are scored once and the declared total is checked
against their sum (urea counted as declared or zero). A disagreement is an error before
any fitting. For example `N` 150 with `N_NO3` 100 and `N_NH4` 30 is rejected, because
100 + 30 + 0 = 130.
- `N` with other forms (for example nitrate only, or an explicit zero `N_NH4`, which asks
for nothing): both are scored and `totalN.overlapForms` lists the forms scored beside the
total. No other form target is invented; the selected products decide the unspecified
forms. Forms that add up to more than `N` are an error.
- `N` is accepted in targets only, not in water, maxima or product assays.

- `N_NO3` is fitted to its declared value.
Expand Down
3 changes: 3 additions & 0 deletions docs/site/agronomist/tanks-and-solubility.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ productId
maxGramsPerLitre
temperatureMinC
temperatureMaxC
basis (optional: what the g/L is a concentration of)
source, revision, recordedAt
```

The batch report and `plan_stocks` qualify each value through one function. A value is labelled `verified` only when the tank temperature lies in its recorded range and its basis is stated; anything else is listed under `unverified` (`temperature`, `concentration basis`, `solubility value`) and the mixture is always unverified. The quantities never change.

Every incompatibility must be an explicit `separate` compatibili 10000 ty-rule record. For a multi-product rule, no two listed products may share a concentrated tank. This is deliberately stricter than assuming a rule applies only to one named pair.

The planner rejects:
Expand Down
7 changes: 4 additions & 3 deletions docs/site/developer/python-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ the products that carry it; chloride products are never used without one.

**Nitrogen forms and the ammonium allowance.** `N_NO3`, `N_NH4` and `N_UREA` are
each their own fitted target; `result["totalN"]` reports their sum. Total `N` may be
a target too: alone it is one row over the three forms with no form split; with all
three forms they are scored once and the total is checked for consistency; with some
forms both are scored and `totalN["overlapForms"]` lists the overlap (`totalN["fitted"]`
a target too: alone it is one row over the three forms with no form split; total N is
nitrate + ammonium + urea, with an absent urea counted as zero, so a nitrate target and
a positive ammonium target determine it, are scored once and the total is checked for
consistency; with other forms both are scored and `totalN["overlapForms"]` lists the overlap (`totalN["fitted"]`
is true when the total is its own row). An absent `N_UREA` is a declared zero. An absent or zero `N_NH4` is no
ammonium requirement (no row, no ban) and, by default, no ammonium maximum:
the ammonium the products bring is reported. Passing `max_ammonium_fraction`
Expand Down
29 changes: 29 additions & 0 deletions docs/site/developer/water-to-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,35 @@ Potassium Carbonate); acids are supplied by the user with the assay and density
from the supplier's certificate. A supersaturated phase never rejects a plan; it is
reported (next section).

### Acceptable deviation ranges

`recommend(..., deviation_ranges=...)` and `plan_fertilizer_workflow(..., deviation_ranges=...)` take
`dict(percent=..., overrides={symbol: {shortage_percent | shortage_mg_per_l, excess_percent |
excess_mg_per_l}}, mode='assess' | 'require')`. None is a default: no setting means no range. A range
exists only for a positive target; an override for a nutrient with no positive target raises
`range_without_positive_target`, and a zero target is never relaxed. The result's `deviationRanges`
holds the `effective` ranges (`low`, `high`, None for an open side), the `assessment` (each nutrient
`inside`, `below` or `above`, and by how many mg/L) and, in `require` mode, a `requirement` with
status `met` or `search_incomplete`. `assess` leaves the recipe unchanged. `require` fits with each
upper bound as a hard maximum and doubles the weight of a nutrient below its lower bound, up to 24
times; a candidate that still misses is kept, `feasible` is false, the unmet nutrients are named and
nothing is widened (this is a candidate, not a proof that no recipe qualifies). In the workflow the
final recipe, with the pH reagent, is classified in `summary['deviation_ranges']`; a missed required
range asks for review. The settings are saved with the inputs.

### An acceptable pH interval

`target_ph` may be a pair `(low, high)` (a list in the JSON workflow) instead of one number. The
interval is judged against its bounds and no midpoint is used: a mix already inside it needs no
reagent (`direction` is `none`, `target_ph` is the mix's own pH), and a mix outside it is moved to
the nearest bound, the smallest change that qualifies. `PhAdjustmentPlan.interval` and
`FertilizerWorkflow.ph_interval` hold the pair, `workflow.target_ph` is the bound the plan aimed at
(None until `ph_adjustment` has run) and the summary carries `target_ph_interval` and
`ph.interval`. A zero-width interval is the point target. Only `ph_adjustment` accepts an interval:
`nitric`, `titration` and `acid_selection` plan a reagent to one pH, so they report
`unsupported_ph_interval` and choose no point. `low` above `high`, or a value outside 0 to 14, is
refused.

## Saturation indices and acceptance

A positive saturation index is a thermodynamic finding, not a precipitation rate, and
Expand Down
18 changes: 15 additions & 3 deletions docs/site/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ The same from files in one command, for scripts.
usage: flahax batch [-h] [--formula FORMULA | --crop CROP | --targets TARGETS |
--sonneveld-targets SONNEVELD_TARGETS] [--preview-targets] [--list-formulas]
[--water WATER] [--water-share PERCENT] [--volume VOLUME] [--ph PH]
[--ratio RATIO] [--available-tanks AVAILABLE_TANKS] [--fit-equipment]
[--tank-capacity LITRES] [--ec EC]
[--acid FORMULA:FRACTION:DENSITY[:NAME[:SOLVENT_FRACTION]]]
[--ph-min PH_MIN] [--ph-max PH_MAX] [--range-percent RANGE_PERCENT]
[--range SYMBOL=SHORTAGE:EXCESS] [--require-ranges] [--ratio RATIO]
[--available-tanks AVAILABLE_TANKS] [--fit-equipment] [--tank-capacity LITRES]
[--ec EC] [--acid FORMULA:FRACTION:DENSITY[:NAME[:SOLVENT_FRACTION]]]
[--limit SYMBOL=MG_PER_L] [--max-reagent-litres MAX_REAGENT_LITRES]
[--volumetric-stocks VOLUMETRIC_STOCKS]
[--alternative-products ALTERNATIVE_PRODUCTS]
Expand Down Expand Up @@ -149,6 +150,17 @@ options:
ion-free (desalinated or RO); default 100
--volume VOLUME final batch litres (default 1000)
--ph PH target feed pH (default 5.8)
--ph-min PH_MIN lowest acceptable feed pH; with --ph-max the target is this interval,
judged against its bounds, and no midpoint is used
--ph-max PH_MAX highest acceptable feed pH (see --ph-min)
--range-percent RANGE_PERCENT
acceptable deviation, in percent either side of every positive target; no
default, so no range is used unless you give one
--range SYMBOL=SHORTAGE:EXCESS
a nutrient's own range, each side as 5% or 3mg (mg/L), for example K=2%:5%
or Ca=:4mg; an empty side keeps --range-percent
--require-ranges constrain the fit by the ranges (default: only assess the result against
them); a zero target and a declared maximum are never relaxed
--ratio RATIO final litres per litre of concentrate (default 100)
--available-tanks AVAILABLE_TANKS
concentrate tanks you have (default: two assumed, and the report says so)
Expand Down
Loading
0