API reference
Core geometry and designs
Planting-site geometry.
The canonical geometry is an arbitrary set of two-dimensional plant coordinates. Rectangles, masks, polygons, GPS-like point sets and other shapes are convenience constructors around that representation.
Source code in src/cropmix/geometry.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
from_polygon(boundary, *, spacing=1.0, origin=None)
classmethod
Generate a regular planting lattice clipped to an arbitrary polygon.
For already surveyed planting positions, prefer :meth:from_coordinates.
Source code in src/cropmix/geometry.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
Assign exactly one named variety to every planting site.
Source code in src/cropmix/design.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
plot(ax=None, *, marker_size=80, legend=True)
Plot the planting assignment. Requires the optional viz extra.
Source code in src/cropmix/design.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
Biology
Host-dependent virus transmission rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acquisition_rate
|
float
|
Rate at which a virus-free vector acquires virus while feeding on an infectious plant of this variety, in day^-1. |
required |
inoculation_rate
|
float
|
Per-virus-bearing-vector inoculation rate for a susceptible plant of this variety, in vector^-1 day^-1. |
required |
Source code in src/cropmix/biology.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
Plant-side epidemic rates, in day^-1.
Source code in src/cropmix/biology.py
45 46 47 48 49 50 51 52 53 54 | |
Healthy and infectious yields in a common user-chosen unit.
Source code in src/cropmix/biology.py
57 58 59 60 61 62 63 64 65 66 67 68 69 | |
One crop variety used in a mixture.
Source code in src/cropmix/biology.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
with_transmission(transmission)
Return a copy with updated transmission rates.
Source code in src/cropmix/biology.py
85 86 87 | |
Vector demographic and movement rates, in day^-1.
Source code in src/cropmix/biology.py
90 91 92 93 94 95 96 97 98 99 | |
Virus-vector parameters shared across host varieties.
vector_latent_progression_rate is required only for PT transmission.
Cropmix 0.1 can infer PT parameters through the EpiPvr bridge, but the
spatial simulation engine currently implements SPT dynamics only.
Source code in src/cropmix/biology.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
Biological parameters plus the vector movement kernel.
Source code in src/cropmix/system.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
Simulation
Simulate a supplied planting design under the spatial SPT model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
design
|
MixtureDesign
|
Arbitrary assignment of system varieties to field coordinates. |
required |
system
|
CropMixSystem
|
Varieties, vector/pathogen parameters and movement kernel. |
required |
scenario
|
Scenario
|
Season duration, vector burden and initial inoculum. |
required |
n_runs
|
int
|
Number of stochastic epidemic replicates. |
100
|
seed
|
int
|
Master seed. Reusing it across candidate designs supplies common random numbers for paired comparisons and optimization. |
12345
|
observation_times
|
ndarray | None
|
Times at which trajectories are recorded. Defaults to 101 equally spaced points including 0 and harvest. |
None
|
transmission_draw
|
TransmissionDraw | None
|
Optional coherent parameter draw. If omitted, point values in |
None
|
store_final_states
|
bool
|
If false, final state arrays are discarded after computing summaries. |
True
|
Notes
The event loop is Numba compiled. The first call in a Python process pays a compilation cost; subsequent calls reuse cached compiled functions when possible and are substantially faster than the reference pure-Python loop.
Source code in src/cropmix/simulation.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
Monte Carlo output for one supplied planting design.
Source code in src/cropmix/results.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
incidence_by_variety_sd
property
Pointwise standard deviations for each cultivar-specific incidence trajectory.
incidence_sd
property
Pointwise standard deviation of stochastic incidence trajectories.
vector_prevalence_sd
property
Pointwise standard deviation of stochastic vector-prevalence trajectories.
Mean field and calibration
Solve the n-variety PLOS-style SPT mean-field model.
The deterministic model preserves the PLOS convention in which plant
latent/infectious states are fractions of the entire field and vector
provenance states are counts. It requires a common vector-clearance rate,
which is represented at pathogen level in CropMixSystem.
Source code in src/cropmix/meanfield.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
Deprecated compatibility alias for :func:assess_mean_field_consistency.
The historical name calibrate_kernel suggested biological parameter
estimation. Cropmix 0.2 retains it only so older scripts keep working.
Source code in src/cropmix/calibration.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
Optimization
Search for a high-performing planting design with fixed variety counts.
Cropmix 0.1 uses swap-based simulated annealing. A swap proposal preserves the requested counts exactly. Candidate designs are evaluated with the same Monte Carlo seed block (common random numbers), reducing simulation noise in pairwise design comparisons.
The optimizer is heuristic: combinatorial design spaces become enormous even for modest fields, so global optimality is not claimed.
Source code in src/cropmix/optimization.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
Source code in src/cropmix/optimization.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
Source code in src/cropmix/optimization.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
EpiPvr
One varying-access-period sub-assay.
Source code in src/cropmix/epipvr/models.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
A complete EpiPvr SPT or PT access-period experiment.
Source code in src/cropmix/epipvr/models.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
Call EpiPvr through Rscript while keeping the public API Python-only.
Source code in src/cropmix/epipvr/backend.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
epidemic_probability(*, vectors_per_plant, virus_parameters_per_day, local_parameters, initial_interval=0.1)
Call EpiPvr's branching-process epidemic-probability calculator.
Source code in src/cropmix/epipvr/backend.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
fit(experiment, *, options=None)
Fit EpiPvr without exposing an R object to the Python caller.
Source code in src/cropmix/epipvr/backend.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
Python-side EpiPvr posterior and diagnostics.
Source code in src/cropmix/epipvr/models.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |