terraproof 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -2
  3. package/bin/terraproof.js +4 -0
  4. package/dist/router/apply.js +147 -0
  5. package/dist/router/classify.js +111 -0
  6. package/dist/router/explain.js +9 -0
  7. package/dist/router/index.js +272 -0
  8. package/dist/router/resolve.js +239 -0
  9. package/dist/router/score.js +60 -0
  10. package/dist/router/types.js +1 -0
  11. package/dist/router/validate.js +81 -0
  12. package/instructions/engineering.md +14 -0
  13. package/instructions/security.md +14 -0
  14. package/instructions/simplicity.md +13 -0
  15. package/package.json +65 -4
  16. package/routing/DOMAIN_ROUTING.md +161 -0
  17. package/routing/ROUTER_DESIGN.md +173 -0
  18. package/routing/SKILL_MANIFEST.md +86 -0
  19. package/routing/checks.json +121 -0
  20. package/routing/collections.json +47 -0
  21. package/routing/registry.json +2211 -0
  22. package/routing/rules.json +64 -0
  23. package/skills/accuracy-assessment/SKILL.md +213 -0
  24. package/skills/accuracy-assessment/UPSTREAM.md +7 -0
  25. package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
  26. package/skills/accuracy-assessment/skill.json +103 -0
  27. package/skills/brainstorming/SKILL.md +250 -0
  28. package/skills/brainstorming/UPSTREAM.md +29 -0
  29. package/skills/brainstorming/scripts/frame-template.html +213 -0
  30. package/skills/brainstorming/scripts/helper.js +167 -0
  31. package/skills/brainstorming/scripts/server.cjs +723 -0
  32. package/skills/brainstorming/scripts/start-server.sh +209 -0
  33. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  34. package/skills/brainstorming/skill.json +73 -0
  35. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  36. package/skills/brainstorming/visual-companion.md +299 -0
  37. package/skills/crs-and-units/SKILL.md +200 -0
  38. package/skills/crs-and-units/UPSTREAM.md +7 -0
  39. package/skills/crs-and-units/skill.json +74 -0
  40. package/skills/design-postgis-tables/SKILL.md +494 -0
  41. package/skills/design-postgis-tables/UPSTREAM.md +21 -0
  42. package/skills/design-postgis-tables/skill.json +90 -0
  43. package/skills/gdal/SKILL.md +125 -0
  44. package/skills/gdal/UPSTREAM.md +22 -0
  45. package/skills/gdal/references/gdal-recipes.md +103 -0
  46. package/skills/gdal/skill.json +66 -0
  47. package/skills/geomaster/README.md +105 -0
  48. package/skills/geomaster/SKILL.md +366 -0
  49. package/skills/geomaster/UPSTREAM.md +21 -0
  50. package/skills/geomaster/references/advanced-gis.md +376 -0
  51. package/skills/geomaster/references/big-data.md +363 -0
  52. package/skills/geomaster/references/code-examples.md +531 -0
  53. package/skills/geomaster/references/coordinate-systems.md +364 -0
  54. package/skills/geomaster/references/core-libraries.md +273 -0
  55. package/skills/geomaster/references/data-sources.md +330 -0
  56. package/skills/geomaster/references/gis-software.md +369 -0
  57. package/skills/geomaster/references/industry-applications.md +420 -0
  58. package/skills/geomaster/references/machine-learning.md +462 -0
  59. package/skills/geomaster/references/programming-languages.md +456 -0
  60. package/skills/geomaster/references/remote-sensing.md +370 -0
  61. package/skills/geomaster/references/scientific-domains.md +416 -0
  62. package/skills/geomaster/references/specialized-topics.md +428 -0
  63. package/skills/geomaster/references/troubleshooting.md +439 -0
  64. package/skills/geomaster/skill.json +157 -0
  65. package/skills/geopandas/SKILL.md +250 -0
  66. package/skills/geopandas/UPSTREAM.md +22 -0
  67. package/skills/geopandas/references/crs-management.md +231 -0
  68. package/skills/geopandas/references/data-io.md +323 -0
  69. package/skills/geopandas/references/data-structures.md +207 -0
  70. package/skills/geopandas/references/geometric-operations.md +262 -0
  71. package/skills/geopandas/references/spatial-analysis.md +294 -0
  72. package/skills/geopandas/references/visualization.md +230 -0
  73. package/skills/geopandas/scripts/_common.py +605 -0
  74. package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
  75. package/skills/geopandas/scripts/export_plan.py +305 -0
  76. package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
  77. package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
  78. package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
  79. package/skills/geopandas/scripts/vector_inventory.py +140 -0
  80. package/skills/geopandas/skill.json +116 -0
  81. package/skills/geoparquet-validation/SKILL.md +125 -0
  82. package/skills/geoparquet-validation/UPSTREAM.md +24 -0
  83. package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
  84. package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
  85. package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
  86. package/skills/geoparquet-validation/skill.json +71 -0
  87. package/skills/geospatial-data-discovery/SKILL.md +49 -0
  88. package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
  89. package/skills/geospatial-data-discovery/skill.json +51 -0
  90. package/skills/geospatial-frontend/SKILL.md +86 -0
  91. package/skills/geospatial-frontend/UPSTREAM.md +23 -0
  92. package/skills/geospatial-frontend/references/design-system.md +283 -0
  93. package/skills/geospatial-frontend/references/user-preferences.md +96 -0
  94. package/skills/geospatial-frontend/skill.json +87 -0
  95. package/skills/geozarr/SKILL.md +244 -0
  96. package/skills/geozarr/UPSTREAM.md +21 -0
  97. package/skills/geozarr/skill.json +97 -0
  98. package/skills/networkx/SKILL.md +440 -0
  99. package/skills/networkx/UPSTREAM.md +22 -0
  100. package/skills/networkx/references/algorithms.md +384 -0
  101. package/skills/networkx/references/generators.md +385 -0
  102. package/skills/networkx/references/graph-basics.md +284 -0
  103. package/skills/networkx/references/io.md +457 -0
  104. package/skills/networkx/references/visualization.md +531 -0
  105. package/skills/networkx/skill.json +93 -0
  106. package/skills/raster-processing/SKILL.md +222 -0
  107. package/skills/raster-processing/UPSTREAM.md +7 -0
  108. package/skills/raster-processing/skill.json +81 -0
  109. package/skills/sar-basics/SKILL.md +202 -0
  110. package/skills/sar-basics/UPSTREAM.md +7 -0
  111. package/skills/sar-basics/references/calibration-lut.md +98 -0
  112. package/skills/sar-basics/skill.json +97 -0
  113. package/skills/satellite-preprocessing/SKILL.md +241 -0
  114. package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
  115. package/skills/satellite-preprocessing/skill.json +84 -0
  116. package/skills/scientific-visualization/SKILL.md +285 -0
  117. package/skills/scientific-visualization/UPSTREAM.md +25 -0
  118. package/skills/scientific-visualization/assets/color_palettes.py +263 -0
  119. package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
  120. package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
  121. package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
  122. package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
  123. package/skills/scientific-visualization/references/color_palettes.md +227 -0
  124. package/skills/scientific-visualization/references/journal_requirements.md +169 -0
  125. package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
  126. package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
  127. package/skills/scientific-visualization/references/sources.md +76 -0
  128. package/skills/scientific-visualization/scripts/_common.py +136 -0
  129. package/skills/scientific-visualization/scripts/export_plan.py +493 -0
  130. package/skills/scientific-visualization/scripts/figure_export.py +642 -0
  131. package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
  132. package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
  133. package/skills/scientific-visualization/scripts/style_presets.py +501 -0
  134. package/skills/scientific-visualization/scripts/style_preview.py +232 -0
  135. package/skills/scientific-visualization/skill.json +95 -0
  136. package/skills/spectral-indices/SKILL.md +235 -0
  137. package/skills/spectral-indices/UPSTREAM.md +7 -0
  138. package/skills/spectral-indices/skill.json +88 -0
  139. package/skills/stac-and-cloud-access/SKILL.md +209 -0
  140. package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
  141. package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
  142. package/skills/stac-and-cloud-access/skill.json +98 -0
  143. package/skills/statistical-analysis/SKILL.md +446 -0
  144. package/skills/statistical-analysis/UPSTREAM.md +24 -0
  145. package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
  146. package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
  147. package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
  148. package/skills/statistical-analysis/references/reporting_standards.md +482 -0
  149. package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
  150. package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
  151. package/skills/statistical-analysis/skill.json +127 -0
  152. package/skills/systematic-debugging/SKILL.md +283 -0
  153. package/skills/systematic-debugging/UPSTREAM.md +28 -0
  154. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  155. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  156. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  157. package/skills/systematic-debugging/find-polluter.sh +72 -0
  158. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  159. package/skills/systematic-debugging/skill.json +88 -0
  160. package/skills/time-series-and-change/SKILL.md +217 -0
  161. package/skills/time-series-and-change/UPSTREAM.md +7 -0
  162. package/skills/time-series-and-change/references/change-methods.md +42 -0
  163. package/skills/time-series-and-change/skill.json +116 -0
  164. package/skills/vector-quality/SKILL.md +204 -0
  165. package/skills/vector-quality/UPSTREAM.md +7 -0
  166. package/skills/vector-quality/skill.json +82 -0
  167. package/skills/verification/SKILL.md +120 -0
  168. package/skills/verification/UPSTREAM.md +31 -0
  169. package/skills/verification/skill.json +67 -0
  170. package/skills/writing-plans/SKILL.md +171 -0
  171. package/skills/writing-plans/UPSTREAM.md +23 -0
  172. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  173. package/skills/writing-plans/skill.json +80 -0
  174. package/sources/SOURCES.md +374 -0
  175. package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
  176. package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
  177. package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
  178. package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
  179. package/third_party/superpowers/LICENSE +21 -0
  180. package/third_party/superpowers/NOTICE.md +17 -0
  181. package/third_party/timescale-pg-aiguide/LICENSE +176 -0
  182. package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
@@ -0,0 +1,64 @@
1
+ {
2
+ "$schema": "./rules.schema.json",
3
+ "version": "1.0.0",
4
+ "weights": {
5
+ "technologyExactMatch": 5,
6
+ "capabilityMatch": 4,
7
+ "domainMatch": 3,
8
+ "strongTriggerMatch": 3,
9
+ "weakTriggerMatch": 1,
10
+ "recommendedBonus": 2,
11
+ "requiredDependency": 10,
12
+ "explicitInclusion": 20,
13
+ "explicitExclusion": -50,
14
+ "conflictPenalty": -50
15
+ },
16
+ "layerOrder": [
17
+ "process",
18
+ "domain",
19
+ "implementation",
20
+ "risk",
21
+ "verification"
22
+ ],
23
+ "thresholds": {
24
+ "selectionMinimumScore": 4,
25
+ "highConfidenceThreshold": 8
26
+ },
27
+ "intentRules": {
28
+ "buildNewFeature": {
29
+ "triggers": ["build", "create", "implement", "scaffold", "new feature", "from scratch", "develop"],
30
+ "injectProcess": ["brainstorming", "writing-plans"]
31
+ },
32
+ "debugging": {
33
+ "triggers": ["fix", "bug", "error", "broken", "debug", "crash", "intermittent", "failure", "fails", "failing", "exception", "401", "500", "timeout"],
34
+ "injectProcess": ["systematic-debugging"],
35
+ "suppressProcess": ["brainstorming"]
36
+ },
37
+ "architectureRefactoring": {
38
+ "triggers": ["architecture", "refactor architecture", "modularize", "system design", "domain boundaries"],
39
+ "injectSkills": ["writing-plans"]
40
+ },
41
+ "trivialEdit": {
42
+ "triggers": ["button label", "typo", "color change", "text change", "rename variable", "minor fix"],
43
+ "suppressProcess": ["brainstorming", "writing-plans", "systematic-debugging"]
44
+ }
45
+ },
46
+ "riskBoundaries": {},
47
+ "verificationRules": {
48
+ "frontend": {
49
+ "triggers": ["frontend", "ui", "ux", "browser", "react", "maplibre", "component", "page", "dashboard"],
50
+ "injectVerification": ["verification"]
51
+ },
52
+ "backendApiDb": {
53
+ "triggers": ["api", "database", "postgres", "supabase", "postgis", "backend", "endpoint", "webhook", "rest"],
54
+ "injectVerification": ["verification"]
55
+ },
56
+ "algorithmMath": {
57
+ "triggers": ["algorithm", "function", "utility", "calculation", "statistic", "graph", "formula", "parser"],
58
+ "injectVerification": ["verification"]
59
+ },
60
+ "generalDefault": {
61
+ "injectVerification": ["verification"]
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,213 @@
1
+ ---
2
+ name: accuracy-assessment
3
+ description: Design and analyze a statistically defensible accuracy assessment for a classified or change map, covering probability sampling stratified by map class, the response design, area-weighted confusion matrices, overall/user's/producer's accuracy with confidence intervals, and stratified area-adjusted class areas; use whenever a land-cover or change map's accuracy or class areas will be reported.
4
+ license: MIT
5
+ ---
6
+
7
+ # Accuracy assessment and area estimation
8
+
9
+ ## Report estimates, not pixel counts
10
+
11
+ A map's class pixel counts are not an unbiased estimate of class area: every
12
+ omission and commission error shifts area between classes, and rare classes (such
13
+ as change) are often affected most. Good practice is to estimate area from the
14
+ **reference classification of a probability sample**, using the map to stratify,
15
+ and to report confidence intervals for accuracy and area [S1, S2].
16
+
17
+ Worked example (counts from Olofsson et al. 2014, Table 8, recomputed with the
18
+ estimator in [the reference](references/stratified-estimator.md)): the map shows
19
+ 18,000 ha of deforestation; the stratified estimate is **21,158 ha ± 6,158 ha**
20
+ (95 % CI). Reporting 18,000 ha as "the area" hides both the bias and the
21
+ uncertainty.
22
+
23
+ The workflow has three parts, each documented in the report: sampling design,
24
+ response design and analysis [S1, S3, S4]. Use
25
+ [statistical analysis](../statistical-analysis/SKILL.md) for general statistics and
26
+ [time series and change](../time-series-and-change/SKILL.md) for producing change
27
+ maps. Shared rules: [engineering](../../instructions/engineering.md),
28
+ [simplicity](../../instructions/simplicity.md), [security](../../instructions/security.md).
29
+
30
+ ## Sampling design: stratified random by map class
31
+
32
+ Use a **probability sampling design**: every unit in the population has a known,
33
+ non-zero inclusion probability [S1, S4]. Stratified random sampling with the
34
+ final map classes as strata is the common choice for change and rare classes,
35
+ because it guarantees samples in small strata [S1, S2].
36
+
37
+ - Draw the sample from the **final** map that will be reported, within the
38
+ exact reporting region. Record every stratum's mapped area `A_m,i` (in an
39
+ equal-area CRS or with true per-pixel areas; see
40
+ [CRS and units](../crs-and-units/SKILL.md)).
41
+ - Do **not** reuse training, calibration or hand-picked "clear" points; they are
42
+ not a probability sample and give unknown bias.
43
+ - Allocation: equal allocation favours user's accuracy of rare classes;
44
+ proportional allocation usually gives smaller standard errors for overall and
45
+ producer's accuracy. A compromise with a minimum per stratum is suggested [S2].
46
+ FAO cites a minimum of 20 to 100 samples per stratum (Congalton and Green) [S2].
47
+ - Size the sample from a target standard error and anticipated user's
48
+ accuracies, following the sample-size section of Olofsson et al. (after Cochran
49
+ 1977) [S1, S2]. No sample size makes a biased (non-probability) sample valid.
50
+ - Keep the sampling seed, frame, strata raster and unit list, so the sample can
51
+ be regenerated.
52
+
53
+ If the strata are **not** the map classes being assessed (e.g. a stratification
54
+ from an older map), the estimators below do not apply directly; use the estimator
55
+ for strata that differ from map classes [S5].
56
+
57
+ ## Response design: how reference labels are decided
58
+
59
+ The response design specifies the spatial assessment unit (pixel, block or
60
+ polygon), the reference data sources, the labeling protocol and the definition of
61
+ agreement [S1, S2, S4].
62
+
63
+ - The reference classification must be more accurate than the map: a better
64
+ source (finer resolution, field data) or a more careful process (expert visual
65
+ interpretation of the same imagery) [S2].
66
+ - Reference data should be temporally coincident with the map (for change: cover
67
+ both dates); otherwise area estimates refer to the reference date [S2].
68
+ - Define the minimum mapping unit, rules for mixed units and the agreement rule
69
+ before labeling [S2]. Interpret blind to the map label where feasible.
70
+ - Record interpreter, source image/date and confidence per unit; evaluate
71
+ reference-label variability rather than assuming the reference is perfect [S1].
72
+
73
+ ## Confusion matrix in proportion of area
74
+
75
+ Rows are map classes (strata) `i`, columns reference classes `j`, `n_ij` sample
76
+ counts, `n_i·` the row total, `W_i = A_m,i / A_tot` the mapped area proportion.
77
+ When strata are the map classes (simple random, systematic or stratified random
78
+ sampling), estimate each cell as a proportion of area [S1, S2]:
79
+
80
+ ```text
81
+ p_ij = W_i * n_ij / n_i·
82
+ ```
83
+
84
+ Report this estimated matrix (in area proportions), not only raw counts [S1].
85
+ Raw-count matrices from a stratified sample over-represent rare strata and give
86
+ biased overall and producer's accuracies if used directly.
87
+
88
+ ## Overall, user's and producer's accuracy
89
+
90
+ From the area-proportion matrix [S1, S2]:
91
+
92
+ ```text
93
+ overall accuracy O = Σ_j p_jj
94
+ user's accuracy U_i = p_ii / p_i· (= n_ii / n_i· under this design)
95
+ producer's accuracy P_j = p_jj / p_·j
96
+ commission error = 1 - U_i
97
+ omission error = 1 - P_j
98
+ ```
99
+
100
+ User's accuracy answers "if the map says class i, how often is it i?"; producer's
101
+ accuracy answers "of the true class j area, how much is mapped as j?" [S2].
102
+ Report all three with confidence intervals (variances in
103
+ [the reference](references/stratified-estimator.md)) [S1].
104
+
105
+ Kappa is not recommended as an accuracy measure [S2, S6]; do not report it as a
106
+ substitute for these estimates.
107
+
108
+ ## Area-adjusted estimates with confidence intervals
109
+
110
+ Estimate the area of reference class `k` from the column of the area-proportion
111
+ matrix, with the stratified-estimator standard error [S1, S2]:
112
+
113
+ ```text
114
+ p_·k = Σ_i W_i * n_ik / n_i·
115
+ A_k = A_tot * p_·k
116
+ SE(p_·k) = sqrt( Σ_i W_i² * (n_ik / n_i·) * (1 - n_ik / n_i·) / (n_i· - 1) )
117
+ SE(A_k) = A_tot * SE(p_·k)
118
+ 95 % CI = A_k ± 1.96 * SE(A_k)
119
+ ```
120
+
121
+ `A_tot` and `A_m,i` must be true areas (or pixel counts in an equal-area grid
122
+ multiplied by pixel area). The 1.96 factor is the large-sample normal
123
+ approximation used in the guidance [S2]; with very small strata or proportions
124
+ near 0 or 1, state that the interval is approximate.
125
+ For a random-start systematic sample, these variance formulas are approximate
126
+ and typically overestimate uncertainty [S1]. They assume pixel units with hard
127
+ map/reference labels; polygon units or mixed labels require other estimators.
128
+
129
+ A stratum needs at least 2 sample units (division by `n_i· - 1`); a class with
130
+ no reference sample has an estimated area of zero with an uninformative SE, which
131
+ is a design gap to report, not evidence of absence.
132
+
133
+ ## Compute the estimates
134
+
135
+ Full, tested Python for accuracy, variances and areas, with the worked example
136
+ above, is in [references/stratified-estimator.md](references/stratified-estimator.md).
137
+ Minimal area estimate:
138
+
139
+ ```python
140
+ import numpy as np
141
+
142
+ def stratified_area(counts, mapped_area, z=1.96):
143
+ n = np.asarray(counts, dtype=float) # rows: map strata, cols: reference
144
+ a_map = np.asarray(mapped_area, dtype=float)
145
+ n_i = n.sum(axis=1)
146
+ if np.any(n_i < 2):
147
+ raise ValueError("every stratum needs at least 2 sample units")
148
+ w = a_map / a_map.sum()
149
+ frac = n / n_i[:, None]
150
+ area = a_map.sum() * (w[:, None] * frac).sum(axis=0)
151
+ se = a_map.sum() * np.sqrt((w[:, None] ** 2 * frac * (1 - frac)
152
+ / (n_i[:, None] - 1)).sum(axis=0))
153
+ return area, z * se
154
+ ```
155
+
156
+ Keep the counts matrix, `A_m,i` per stratum, CRS/area method and the code
157
+ version with the results so that the numbers can be recomputed.
158
+
159
+ ## Report checklist
160
+
161
+ - Sampling design (strata, allocation, sample size rationale, seed) and the map
162
+ version sampled.
163
+ - Response design (unit, sources and dates, labeling protocol, agreement rule,
164
+ interpreter procedure) and any deviations from good practice [S1].
165
+ - Estimated error matrix in area proportions; overall, user's and producer's
166
+ accuracy with 95 % CIs.
167
+ - Mapped area and stratified area estimate with 95 % CI per class; say which one
168
+ any downstream number uses.
169
+ - Limitations: reference-label uncertainty, strata/class mismatch, missing
170
+ strata.
171
+
172
+ ## Verify with Terraproof
173
+
174
+ Existing checks help with the inputs, not with the statistics:
175
+
176
+ ```bash
177
+ python -m terraproof check classified_map.tif --operation area
178
+ python -m terraproof check sample_points.gpkg
179
+ ```
180
+
181
+ `crs.defined`, `crs.consistent` and `raster.nodata_declared` check map/sample
182
+ metadata; `geometry.valid`, `geometry.non_empty`, `geometry.type_consistent`
183
+ and `scope.record_count` check the sample file. With `--operation area`,
184
+ `crs.metric_operation` fails geographic/geocentric CRSs and passes projected
185
+ metre/foot CRSs; it does not confirm an equal-area projection.
186
+
187
+ ```bash
188
+ python -m terraproof check classified_map.tif --accuracy-samples samples.json --class-areas areas.json --min-per-class 50 --estimates-requested
189
+ ```
190
+
191
+ `samples.json` contains reference records with `map_class`, `ref_class` and
192
+ optional `stratum_weight`; `areas.json` maps each map class to its mapped area
193
+ in consistent units. `accuracy.sample_design` checks class coverage, counts and
194
+ declared weights. The default minimum of 50 per class is a configurable design
195
+ convention, not a precision guarantee. `accuracy.estimates` computes the
196
+ area-weighted matrix, accuracy estimates and approximate intervals, plus
197
+ area-adjusted class areas. It does not compare an external published report's
198
+ claims with those estimates.
199
+
200
+ **Not checked automatically:** whether the sample was truly probability-based,
201
+ whether reference labels are correct or temporally coincident, response-design
202
+ rules, and whether reported numbers are used correctly downstream. See
203
+ [verification](../verification/SKILL.md).
204
+
205
+ ## Sources
206
+
207
+ - [S1 — Olofsson, P., Foody, G.M., Herold, M., Stehman, S.V., Woodcock, C.E., Wulder, M.A. (2014). Good practices for estimating area and assessing accuracy of land change. Remote Sensing of Environment 148:42–57](https://doi.org/10.1016/j.rse.2014.02.015): good-practice recommendations, stratified estimators for accuracy, area and their variances; Table 8 example counts.
208
+ - [S2 — FAO (2016). Map accuracy assessment and area estimation: a practical guide. NFMA Working Paper 46](https://www.fao.org/3/i5601e/i5601e.pdf): sampling/response/analysis steps, allocation trade-offs, 20–100 per stratum minimum, `p_ij = W_i n_ij / n_i·` when strata are map classes, accuracy definitions, CI as 1.96 × SE, area from reference column totals, kappa not recommended; references Olofsson et al. (2014) eqs. 5–7 and 10–11 for the variances.
209
+ - [S3 — Olofsson, P., Foody, G.M., Stehman, S.V., Woodcock, C.E. (2013). Making better use of accuracy data in land change studies. Remote Sensing of Environment 129:122–131](https://doi.org/10.1016/j.rse.2012.10.031): stratified estimation of accuracy and area.
210
+ - [S4 — Stehman, S.V., Czaplewski, R.L. (1998). Design and analysis for thematic map accuracy assessment: fundamental principles. Remote Sensing of Environment 64(3):331–344](https://doi.org/10.1016/S0034-4257(98)00010-8); [Stehman, S.V., Foody, G.M. (2019). Key issues in rigorous accuracy assessment of land cover products. Remote Sensing of Environment 231:111199](https://doi.org/10.1016/j.rse.2019.05.018): sampling, response and analysis components.
211
+ - [S5 — Stehman, S.V. (2014). Estimating area and map accuracy for stratified random sampling when the strata are different from the map classes. International Journal of Remote Sensing 35(13):4923–4939](https://doi.org/10.1080/01431161.2014.930207).
212
+ - [S6 — Pontius, R.G., Millones, M. (2011). Death to Kappa. International Journal of Remote Sensing 32(15):4407–4429](https://doi.org/10.1080/01431161.2011.552923).
213
+ - [mapaccuracy R package, `olofsson()` (H. Costa)](https://github.com/cran/mapaccuracy/blob/master/R/olofsson.R): independent implementation used to cross-check the formulas and the Table 8 counts.
@@ -0,0 +1,7 @@
1
+ # Attribution
2
+
3
+ Terraproof native — no upstream source.
4
+
5
+ Authored for Terraproof by Geova. License: MIT; see the [project license](../../LICENSE).
6
+ Primary technical references are listed in [SKILL.md](SKILL.md#sources).
7
+ No upstream skill text or code was copied or adapted.
@@ -0,0 +1,127 @@
1
+ # Stratified estimator: formulas and tested code
2
+
3
+ Reference for [accuracy assessment](../SKILL.md). Applies when the sampling strata
4
+ are the map classes and units were selected by stratified random sampling [S1,
5
+ S2]. Equal-probability simple random or random-start systematic samples can use
6
+ the point estimates as poststratified estimators. For systematic sampling the
7
+ variance formulas are approximations, typically overestimating uncertainty;
8
+ document that limitation [S1, sections 2.1.3 and 4.3–4.4]. The formulas assume
9
+ pixel units with hard map/reference labels, not polygon units or mixed labels.
10
+ For strata that differ from the map classes use Stehman (2014) instead [S3].
11
+
12
+ ## Notation
13
+
14
+ | Symbol | Meaning |
15
+ |---|---|
16
+ | `i` | map class = stratum (row) |
17
+ | `j`, `k` | reference class (column) |
18
+ | `n_ij` | sample units in stratum `i` with reference class `j` |
19
+ | `n_i·` | sample size in stratum `i` |
20
+ | `A_m,i` (`N_i·`) | mapped area (or pixel count in an equal-area grid) of stratum `i` |
21
+ | `A_tot` | total mapped area, `Σ_i A_m,i` |
22
+ | `W_i` | `A_m,i / A_tot` |
23
+
24
+ ## Estimators
25
+
26
+ Point estimates [S1, S2]:
27
+
28
+ ```text
29
+ p_ij = W_i * n_ij / n_i·
30
+ O = Σ_j p_jj
31
+ U_i = p_ii / p_i·
32
+ P_j = p_jj / p_·j
33
+ p_·k = Σ_i W_i * n_ik / n_i·
34
+ A_k = A_tot * p_·k
35
+ ```
36
+
37
+ Variances (Olofsson et al. 2014, eqs. 5–7 for accuracy and 10–11 for area, as
38
+ referenced by FAO 2016; cross-checked against the `mapaccuracy` implementation)
39
+ [S1, S2, S4]:
40
+
41
+ ```text
42
+ V(O) = Σ_i W_i² * U_i * (1 - U_i) / (n_i· - 1)
43
+ V(U_i) = U_i * (1 - U_i) / (n_i· - 1)
44
+ V(P_j) = (1 / N_·j²) * [ N_j·² * (1 - P_j)² * U_j * (1 - U_j) / (n_j· - 1)
45
+ + P_j² * Σ_{i≠j} N_i·² * (n_ij / n_i·) * (1 - n_ij / n_i·) / (n_i· - 1) ]
46
+ with N_·j = Σ_i (N_i· / n_i·) * n_ij
47
+ SE(p_·k) = sqrt( Σ_i W_i² * (n_ik / n_i·) * (1 - n_ik / n_i·) / (n_i· - 1) )
48
+ SE(A_k) = A_tot * SE(p_·k)
49
+ 95 % CI = estimate ± 1.96 * SE
50
+ ```
51
+
52
+ ## Python implementation
53
+
54
+ ```python
55
+ import numpy as np
56
+
57
+ def stratified_estimates(counts, mapped_area, z=1.96):
58
+ """counts[i, j]: sample units in map stratum i with reference class j.
59
+ mapped_area[i]: mapped area of stratum i (strata == map classes)."""
60
+ n = np.asarray(counts, dtype=float)
61
+ a_map = np.asarray(mapped_area, dtype=float)
62
+ n_i = n.sum(axis=1)
63
+ if n.shape[0] != n.shape[1] or n.shape[0] != a_map.size:
64
+ raise ValueError("square matrix with one mapped area per stratum required")
65
+ if np.any(n_i < 2):
66
+ raise ValueError("each stratum needs at least 2 sample units for a variance")
67
+ a_tot = a_map.sum()
68
+ w = a_map / a_tot # W_i
69
+ p = w[:, None] * n / n_i[:, None] # p_ij
70
+ oa = np.trace(p)
71
+ ua = np.diag(p) / p.sum(axis=1)
72
+ pa = np.diag(p) / p.sum(axis=0)
73
+ area_prop = p.sum(axis=0) # p_.k
74
+ frac = n / n_i[:, None] # n_ij / n_i.
75
+ se_prop = np.sqrt((w[:, None] ** 2 * frac * (1 - frac) / (n_i[:, None] - 1)).sum(axis=0))
76
+ var_oa = np.sum(w ** 2 * ua * (1 - ua) / (n_i - 1))
77
+ var_ua = ua * (1 - ua) / (n_i - 1)
78
+ n_hat_j = (a_map[:, None] * n / n_i[:, None]).sum(axis=0) # N_.j
79
+ var_pa = np.empty(n.shape[0])
80
+ for j in range(n.shape[0]):
81
+ own = a_map[j] ** 2 * (1 - pa[j]) ** 2 * ua[j] * (1 - ua[j]) / (n_i[j] - 1)
82
+ others = sum(a_map[i] ** 2 * frac[i, j] * (1 - frac[i, j]) / (n_i[i] - 1)
83
+ for i in range(n.shape[0]) if i != j)
84
+ var_pa[j] = (own + pa[j] ** 2 * others) / n_hat_j[j] ** 2
85
+ return {
86
+ "overall": (oa, z * np.sqrt(var_oa)),
87
+ "users": (ua, z * np.sqrt(var_ua)),
88
+ "producers": (pa, z * np.sqrt(var_pa)),
89
+ "area": (area_prop * a_tot, z * se_prop * a_tot),
90
+ "mapped_area": a_map,
91
+ }
92
+ ```
93
+
94
+ A class with a zero column (no reference units) yields `P_j` = NaN (0/0); report
95
+ it as not estimable rather than replacing it with 0 or 1.
96
+
97
+ ## Worked example (regression test)
98
+
99
+ Counts from Olofsson et al. (2014) Table 8 (as encoded in the `mapaccuracy`
100
+ documentation), classes deforestation, forest gain, stable forest, stable
101
+ non-forest; mapped pixel counts 200,000 / 150,000 / 3,200,000 / 6,450,000 of 30 m
102
+ (0.09 ha) [S1, S4]:
103
+
104
+ ```python
105
+ counts = [[66, 0, 5, 4], [0, 55, 8, 12], [1, 0, 153, 11], [2, 1, 9, 313]]
106
+ pixels = np.array([200_000, 150_000, 3_200_000, 6_450_000])
107
+ r = stratified_estimates(counts, pixels * 0.09)
108
+ ```
109
+
110
+ Output computed with the code above (rounded):
111
+
112
+ | Class | Mapped (ha) | Estimated (ha) ± 95 % CI | User's ± CI | Producer's ± CI |
113
+ |---|---|---|---|---|
114
+ | Deforestation | 18,000 | 21,158 ± 6,158 | 0.88 ± 0.07 | 0.75 ± 0.21 |
115
+ | Forest gain | 13,500 | 11,686 ± 3,756 | 0.73 ± 0.10 | 0.85 ± 0.25 |
116
+ | Stable forest | 288,000 | 285,770 ± 15,510 | 0.93 ± 0.04 | 0.93 ± 0.03 |
117
+ | Stable non-forest | 580,500 | 581,386 ± 16,282 | 0.96 ± 0.02 | 0.96 ± 0.02 |
118
+
119
+ Overall accuracy 0.947 ± 0.018. Use this table to test any reimplementation;
120
+ treat it as a computed value, not as a quotation of the paper.
121
+
122
+ ## Sources
123
+
124
+ - [S1 — Olofsson et al. (2014), Remote Sensing of Environment 148:42–57](https://doi.org/10.1016/j.rse.2014.02.015).
125
+ - [S2 — FAO (2016), Map accuracy assessment and area estimation: a practical guide](https://www.fao.org/3/i5601e/i5601e.pdf).
126
+ - [S3 — Stehman (2014), International Journal of Remote Sensing 35(13):4923–4939](https://doi.org/10.1080/01431161.2014.930207).
127
+ - [S4 — mapaccuracy `olofsson()` source](https://github.com/cran/mapaccuracy/blob/master/R/olofsson.R).
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "accuracy-assessment",
3
+ "layer": "domain",
4
+ "domains": [
5
+ "geospatial"
6
+ ],
7
+ "capabilities": [
8
+ "map-accuracy-assessment",
9
+ "stratified-area-estimation",
10
+ "reference-sample-design"
11
+ ],
12
+ "triggers": [
13
+ "accuracy assessment",
14
+ "confusion matrix",
15
+ "user's accuracy",
16
+ "producer's accuracy",
17
+ "overall accuracy",
18
+ "area-adjusted",
19
+ "stratified sampling",
20
+ "stratified random sampling",
21
+ "probability sample",
22
+ "error matrix",
23
+ "map accuracy",
24
+ "map class area",
25
+ "reference sample"
26
+ ],
27
+ "recommended": [
28
+ "statistical-analysis",
29
+ "crs-and-units"
30
+ ],
31
+ "requires": [],
32
+ "conflicts": [],
33
+ "explanation": "Designs and analyzes a defensible accuracy assessment for a classified or change map: probability sampling stratified by map class, response design, area-proportion confusion matrices, overall/user's/producer's accuracy with confidence intervals, and stratified area-adjusted class areas.",
34
+ "sections": [
35
+ {
36
+ "id": "report-estimates-not-pixel-counts",
37
+ "title": "Report estimates, not pixel counts",
38
+ "source": "SKILL.md#report-estimates-not-pixel-counts"
39
+ },
40
+ {
41
+ "id": "sampling-design-stratified-random-by-map-class",
42
+ "title": "Sampling design: stratified random by map class",
43
+ "source": "SKILL.md#sampling-design-stratified-random-by-map-class"
44
+ },
45
+ {
46
+ "id": "response-design-how-reference-labels-are-decided",
47
+ "title": "Response design: how reference labels are decided",
48
+ "source": "SKILL.md#response-design-how-reference-labels-are-decided"
49
+ },
50
+ {
51
+ "id": "confusion-matrix-in-proportion-of-area",
52
+ "title": "Confusion matrix in proportion of area",
53
+ "source": "SKILL.md#confusion-matrix-in-proportion-of-area"
54
+ },
55
+ {
56
+ "id": "overall-users-and-producers-accuracy",
57
+ "title": "Overall, user's and producer's accuracy",
58
+ "source": "SKILL.md#overall-users-and-producers-accuracy"
59
+ },
60
+ {
61
+ "id": "area-adjusted-estimates-with-confidence-intervals",
62
+ "title": "Area-adjusted estimates with confidence intervals",
63
+ "source": "SKILL.md#area-adjusted-estimates-with-confidence-intervals"
64
+ },
65
+ {
66
+ "id": "compute-the-estimates",
67
+ "title": "Compute the estimates",
68
+ "source": "SKILL.md#compute-the-estimates"
69
+ },
70
+ {
71
+ "id": "report-checklist",
72
+ "title": "Report checklist",
73
+ "source": "SKILL.md#report-checklist"
74
+ },
75
+ {
76
+ "id": "verify-with-terraproof",
77
+ "title": "Verify with Terraproof",
78
+ "source": "SKILL.md#verify-with-terraproof"
79
+ },
80
+ {
81
+ "id": "sources",
82
+ "title": "Sources",
83
+ "source": "SKILL.md#sources"
84
+ },
85
+ {
86
+ "id": "stratified-estimator",
87
+ "title": "Stratified estimator",
88
+ "source": "references/stratified-estimator.md"
89
+ }
90
+ ],
91
+ "checks": [
92
+ "accuracy.sample_design",
93
+ "accuracy.estimates",
94
+ "crs.metric_operation",
95
+ "crs.defined",
96
+ "crs.consistent",
97
+ "raster.nodata_declared",
98
+ "geometry.valid",
99
+ "geometry.non_empty",
100
+ "geometry.type_consistent",
101
+ "scope.record_count"
102
+ ]
103
+ }