After a burn round, decides how many fires each FRI zone still needs and at what target sizes, for both reburn phases.

landmine_reburn_budget(tooSmallByPoly, friByPolygon, remainingSize = NULL)

Arguments

tooSmallByPoly

a data.table of the fires that did not reach their target, joined to their ignition zone: needs polygonNumeric, maxSize, and (optionally) pixel. May also carry the fire-identity columns fireID, attempt and targetSize, which are threaded through to the returned vectors so a re-ignited fire stays linked to the one it replaces.

friByPolygon

the per-zone FRI vector from landmine_ignition_budget() – ascending, with a trailing NA. Its order defines the output order.

remainingSize

optional numeric; phase 2 passes the remaining shortfall per fire, which replaces maxSize. Phase 1 leaves it NULL, keeping each fire's full original target.

Value

A list with polysNeedMoreFires (the joined table), numFiresThisPeriod (fires still needed per zone, in friByPolygon order), fireSizesInPixels (target sizes, positionally paired with the start cells to be drawn), and fireIDs/attempts/targetSizes – the identity of those same fires, paired the same way, or NULL when the input carried none.

Details

Three positional contracts live here, none of which errors when broken:

  • the right join is driven by friByPolygon, so the result – and hence numFiresThisPeriod – is in that order (zones ascending, NA row last). The caller indexes it with [.GRP] against a polygonNumeric-keyed table whose groups are also ascending, and the trailing NA row is never reached because that table has no NA zone.

  • na.omit() on the whole table is load-bearing: it drops both the zero-shortfall zones (maxSize is NA where the join found no match) and the NA-FRI row, leaving fireSizesInPixels paired positionally with the start cells the caller then draws by = polygonNumeric. It would also silently drop a row if any other column went NA. The identity vectors come from that same na.omit(), so they cannot drift out of step with the sizes – but an NA in any identity column would drop that fire entirely.

  • remainingSize is assigned by position onto the too-small rows; both descend from the same fa[tooSmall] subset, so they agree – but nothing enforces it.

remainingSize can be 0 for a fire that burned exactly its target; the caller's fireSizesInPixels > 0 filter is what removes those.

Unlike the inline code this replaces, the input table is not modified by reference.