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,97 @@
1
+ {
2
+ "name": "sar-basics",
3
+ "layer": "domain",
4
+ "domains": [
5
+ "geospatial"
6
+ ],
7
+ "capabilities": [
8
+ "sar-radiometric-calibration",
9
+ "sar-speckle-filtering",
10
+ "sar-terrain-correction"
11
+ ],
12
+ "triggers": [
13
+ "sentinel-1",
14
+ "sentinel 1",
15
+ "backscatter",
16
+ "sigma0",
17
+ "gamma0",
18
+ "beta0",
19
+ "decibel",
20
+ "grd",
21
+ "single look complex",
22
+ "slc",
23
+ "speckle",
24
+ "terrain correction",
25
+ "vv polarization",
26
+ "vh polarization",
27
+ "incidence angle"
28
+ ],
29
+ "recommended": [
30
+ "raster-processing",
31
+ "accuracy-assessment"
32
+ ],
33
+ "requires": [],
34
+ "conflicts": [],
35
+ "explanation": "Works correctly with Sentinel-1 C-band SAR: identifying GRD versus SLC, calibrating DN to sigma0/gamma0/beta0 with the product LUTs, keeping linear power for arithmetic and dB for display, speckle filtering trade-offs, and terrain correction and geocoding before spatial analysis.",
36
+ "sections": [
37
+ {
38
+ "id": "identify-the-product-before-using-pixel-values",
39
+ "title": "Identify the product before using pixel values",
40
+ "source": "SKILL.md#identify-the-product-before-using-pixel-values"
41
+ },
42
+ {
43
+ "id": "calibrate-to-β⁰-σ⁰-or-γ⁰-with-the-product-luts",
44
+ "title": "Calibrate to β⁰, σ⁰ or γ⁰ with the product LUTs",
45
+ "source": "SKILL.md#calibrate-to-β⁰-σ⁰-or-γ⁰-with-the-product-luts"
46
+ },
47
+ {
48
+ "id": "keep-linear-power-for-arithmetic-db-for-display-and-thresholds",
49
+ "title": "Keep linear power for arithmetic, dB for display and thresholds",
50
+ "source": "SKILL.md#keep-linear-power-for-arithmetic-db-for-display-and-thresholds"
51
+ },
52
+ {
53
+ "id": "speckle-filtering-is-a-trade-off",
54
+ "title": "Speckle: filtering is a trade-off",
55
+ "source": "SKILL.md#speckle-filtering-is-a-trade-off"
56
+ },
57
+ {
58
+ "id": "terrain-correction-and-geocoding",
59
+ "title": "Terrain correction and geocoding",
60
+ "source": "SKILL.md#terrain-correction-and-geocoding"
61
+ },
62
+ {
63
+ "id": "polarisation-water-flood-and-change",
64
+ "title": "Polarisation, water, flood and change",
65
+ "source": "SKILL.md#polarisation-water-flood-and-change"
66
+ },
67
+ {
68
+ "id": "incidence-angle-and-acquisition-geometry",
69
+ "title": "Incidence angle and acquisition geometry",
70
+ "source": "SKILL.md#incidence-angle-and-acquisition-geometry"
71
+ },
72
+ {
73
+ "id": "verify-with-terraproof",
74
+ "title": "Verify with Terraproof",
75
+ "source": "SKILL.md#verify-with-terraproof"
76
+ },
77
+ {
78
+ "id": "sources",
79
+ "title": "Sources",
80
+ "source": "SKILL.md#sources"
81
+ },
82
+ {
83
+ "id": "calibration-lut",
84
+ "title": "Calibration LUT",
85
+ "source": "references/calibration-lut.md"
86
+ }
87
+ ],
88
+ "checks": [
89
+ "sar.value_domain",
90
+ "sar.geocoded",
91
+ "raster.grid_alignment",
92
+ "raster.nodata_declared",
93
+ "raster.resampling",
94
+ "crs.defined",
95
+ "stac.provenance"
96
+ ]
97
+ }
@@ -0,0 +1,241 @@
1
+ ---
2
+ name: satellite-preprocessing
3
+ description: Prepare Sentinel-2 Level-2A and Landsat Collection 2 Level-2 surface reflectance with sensor-specific QA masks, exactly-once scale and offset decoding, grid harmonization, and temporal compositing; use before quantitative indices, cross-sensor comparison, or optical satellite time-series analysis.
4
+ ---
5
+
6
+ # Satellite preprocessing
7
+
8
+ ## Establish the product and encoding
9
+
10
+ Use product metadata to identify sensor, processing level, collection/baseline,
11
+ acquisition time, band identity, nodata, scale/offset and previous processing.
12
+ Sentinel-2 L2A provides surface (formerly BOA) reflectance; L1C provides TOA
13
+ reflectance. Landsat Collection 2 Level-2 SR is not Level-1 imagery, temperature,
14
+ or a display composite. QA arrays are categorical/bit-packed, not reflectance.
15
+
16
+ A provider may already decode or harmonize the original DN encoding. Inspect
17
+ both raster scale metadata and product XML/MTL/STAC metadata, plus the reader's
18
+ behavior. Rasterio `read()` returns stored values; rioxarray
19
+ `mask_and_scale=True` decodes scale/offset exposed by its raster reader.
20
+ Do not infer encoding from a plausible-looking histogram alone.
21
+
22
+ Use [raster processing](../raster-processing/SKILL.md) for masks, grids and output
23
+ I/O; [spectral indices](../spectral-indices/SKILL.md) for index computation; and
24
+ [geomaster](../geomaster/SKILL.md) for broader remote-sensing workflows.
25
+ Shared rules: [engineering](../../instructions/engineering.md),
26
+ [simplicity](../../instructions/simplicity.md), [security](../../instructions/security.md).
27
+
28
+ ## Decode Sentinel-2 L2A reflectance
29
+
30
+ For original L2A DN, ESA defines [S1]:
31
+
32
+ ```text
33
+ surface_reflectance_i = (DN_i + BOA_ADD_OFFSET_i) / BOA_QUANTIFICATION_VALUE
34
+ ```
35
+
36
+ Starting with processing baseline **04.00**, radiometric offsets were introduced.
37
+ The operational `BOA_ADD_OFFSET` is **-1000 DN** for all spectral bands [S2]; the
38
+ reflectance quantification value is **10000** [S3]. Read the actual band-specific
39
+ offset and quantification value from the product metadata rather than hardcoding
40
+ based on acquisition date. Reprocessed older acquisitions can use newer baselines.
41
+ For pre-offset original products, follow their documented metadata/encoding;
42
+ do not subtract the newer offset from every historical product.
43
+
44
+ **DN 0 is nodata**, not a dark valid pixel [S1]. Mask it before decoding. Cast to
45
+ float before adding a negative offset, or unsigned arithmetic can wrap. A negative
46
+ retrieved reflectance is not automatically fill; ESA introduced the offset to
47
+ retain such values. Keep quality flags and investigate unexpected values instead
48
+ of clipping all outputs to a cosmetic range.
49
+
50
+ This function expects original, undecoded DN and an SCL already aligned by
51
+ nearest-neighbor to the band grid. Pass metadata values, not provider-adjusted DN:
52
+
53
+ ```python
54
+ import numpy as np
55
+
56
+ def decode_s2_l2a(dn, scl, boa_add_offset, quantification_value):
57
+ if dn.shape != scl.shape or quantification_value <= 0:
58
+ raise ValueError("Aligned arrays and positive quantification required")
59
+ invalid = np.ma.getmaskarray(dn) | np.ma.getmaskarray(scl)
60
+ raw = np.ma.getdata(dn)
61
+ classes = np.ma.getdata(scl)
62
+ # Conservative example: also exclude unclassified, cast shadow and snow.
63
+ invalid |= (raw == 0) | np.isin(classes, [0, 1, 2, 3, 7, 8, 9, 10, 11])
64
+ sr = (raw.astype("float32") + boa_add_offset) / quantification_value
65
+ return np.where(invalid | ~np.isfinite(sr), np.nan, sr).astype("float32")
66
+ ```
67
+
68
+ ## Mask Sentinel-2 SCL cloud and shadow classes
69
+
70
+ SCL is a classification, not a probability band. ESA's class values are [S4]:
71
+
72
+ | SCL | Meaning | Example policy |
73
+ |---|---|---|
74
+ | 0 | No data | Exclude |
75
+ | 1 | Saturated or defective | Exclude |
76
+ | 2 | Cast shadows; historically dark features/shadows | Review baseline; exclude in the conservative example |
77
+ | 3 | Cloud shadows | Exclude |
78
+ | 4 | Vegetation | Retain if task-relevant |
79
+ | 5 | Not vegetated | Retain if task-relevant |
80
+ | 6 | Water | Retain for water tasks; not automatically bad |
81
+ | 7 | Unclassified | Exclude or review explicitly |
82
+ | 8 | Cloud medium probability | Exclude |
83
+ | 9 | Cloud high probability | Exclude |
84
+ | 10 | Thin cirrus | Exclude |
85
+ | 11 | Snow or ice | Exclude for snow-free analysis; retain for snow studies |
86
+
87
+ The cloud/shadow rejection core is 3, 8, 9, 10 plus nodata/defective pixels; other
88
+ exclusions depend on the scientific question. Native SCL is supplied on coarser
89
+ grids than some reflectance bands [S1]. Reproject/resample it with nearest, never
90
+ bilinear. Retain the intersection of QA and validity for **all required bands**.
91
+
92
+ SCL can miss cloud edges, fog, or classify bright terrain incorrectly. Inspect
93
+ residual cloud/shadow contamination and document any additional spatial mask
94
+ expansion; no universal dilation distance is prescribed here.
95
+
96
+ ## Decode Landsat Collection 2 Level-2 SR
97
+
98
+ For Landsat 8/9 Collection 2 Level-2 surface reflectance [S5, table 6-1]:
99
+
100
+ ```text
101
+ surface_reflectance = DN * 0.0000275 - 0.2
102
+ ```
103
+
104
+ Fill is **0**. Mask fill and quality flags before decoding; do not apply this
105
+ formula to QA bands or thermal bands. Read the MTL band multipliers/addends and
106
+ confirm that they describe the input encoding. Do not reuse Collection 1 scaling.
107
+ USGS notes that atmospheric correction can yield negative or above-unity values;
108
+ range checks alone cannot establish calibration correctness.
109
+
110
+ For Landsat **8/9** `QA_PIXEL`, bit positions are zero-based [S5, table 6-2; S6]:
111
+
112
+ | Bit | Flag when set |
113
+ |---|---|
114
+ | 0 | Fill |
115
+ | 1 | Dilated cloud |
116
+ | 2 | High-confidence cirrus |
117
+ | 3 | High-confidence cloud |
118
+ | 4 | High-confidence cloud shadow |
119
+ | 5 | High-confidence snow |
120
+ | 6 | Clear: cloud and dilated-cloud bits are not set |
121
+ | 7 | Water |
122
+
123
+ Bit 6 alone does not establish absence of cirrus, shadow, snow or saturation.
124
+ The confidence fields require separate decoding if used; they are not single
125
+ Boolean flags. Do not copy this sensor-specific table to older Landsat sensors.
126
+
127
+ ```python
128
+ import numpy as np
129
+
130
+ def decode_landsat89_c2_sr(dn, qa_pixel, qa_radsat):
131
+ if not (dn.shape == qa_pixel.shape == qa_radsat.shape):
132
+ raise ValueError("QA and SR arrays must share a grid")
133
+ invalid = (np.ma.getmaskarray(dn) | np.ma.getmaskarray(qa_pixel)
134
+ | np.ma.getmaskarray(qa_radsat))
135
+ raw = np.ma.getdata(dn)
136
+ qa = np.ma.getdata(qa_pixel).astype("uint16")
137
+ # Snow-free policy: reject fill, dilation, cirrus, cloud, shadow and snow.
138
+ reject_bits = sum(1 << bit for bit in (0, 1, 2, 3, 4, 5))
139
+ invalid |= (raw == 0) | ((qa & reject_bits) != 0)
140
+ # Conservative: reject any QA_RADSAT flag; a band-specific policy is possible.
141
+ invalid |= np.ma.getdata(qa_radsat) != 0
142
+ sr = raw.astype("float32") * 0.0000275 - 0.2
143
+ return np.where(invalid | ~np.isfinite(sr), np.nan, sr).astype("float32")
144
+ ```
145
+
146
+ This does not filter every aerosol problem. Review `SR_QA_AEROSOL` and the guide's
147
+ caveats for the task; do not treat a clear QA_PIXEL flag as scientific certification.
148
+
149
+ ## Apply scale and offset exactly once
150
+
151
+ Declare one of two states at every boundary: encoded DN with calibration metadata,
152
+ or decoded physical reflectance. Apply the source calibration only when crossing
153
+ from the first to the second. If a loader already decoded the values, skip manual
154
+ decoding. If a provider shifted the original DN, use that provider's encoding.
155
+
156
+ For a decoded single-band array, save physical values with identity metadata:
157
+
158
+ ```python
159
+ import numpy as np
160
+ import rasterio
161
+
162
+ def write_reflectance(path, sr, crs, transform):
163
+ with rasterio.open(
164
+ path, "w", driver="GTiff", width=sr.shape[1], height=sr.shape[0],
165
+ count=1, dtype="float32", crs=crs, transform=transform, nodata=np.nan,
166
+ ) as dst:
167
+ dst.write(sr.astype("float32"), 1)
168
+ dst.scales = (1.0,)
169
+ dst.offsets = (0.0,)
170
+ ```
171
+
172
+ Keep original calibration and mask policy in provenance, not active decoding
173
+ metadata on already decoded pixels. Reopen a known valid pixel and independently
174
+ compute its physical value from original DN; test nodata and dark pixels too.
175
+ A plausible range can still result from a missing offset or double scaling.
176
+
177
+ ## Harmonize sensors before comparing them
178
+
179
+ Common CRS and resolution are necessary but not sufficient. Match band meaning,
180
+ spatial grid and effective resolution, atmospheric processing, QA policy, angular
181
+ conditions, acquisition season and temporal sampling. Sentinel-2 broad NIR and
182
+ narrow NIR are not interchangeable without analysis. Resampling a coarse band to
183
+ a finer grid does not create finer information.
184
+
185
+ Do not invent a universal regression to turn Sentinel-2 into Landsat. For work
186
+ requiring consistent multi-sensor time series, consider NASA Harmonized Landsat
187
+ Sentinel-2 (HLS), and follow its own band, QA, scaling and processing documentation
188
+ [S7]. HLS is a derived product, not original ESA/USGS DN with the same decoding
189
+ contract. Validate remaining bias over stable targets for the AOI.
190
+
191
+ ## Build temporal composites from masked observations
192
+
193
+ Select acquisition dates and season first. Decode and mask each observation,
194
+ align required bands to a common grid, and retain acquisition IDs. De-duplicate
195
+ overlapping tiles from the same acquisition before counting temporal observations.
196
+ Choose a
197
+ composite statistic suited to the question: a masked median suppresses some
198
+ outliers but is not cloud detection and may combine different acquisition dates
199
+ across bands. A medoid/selected-observation composite can retain a real spectral
200
+ observation. Document tie-breaking and quality ranking.
201
+
202
+ Store valid-observation count and acquisition/date support alongside the
203
+ composite. All-invalid pixels remain nodata, not zero. Report coverage gaps,
204
+ seasonal bias and scenes rejected by QA. An index of a reflectance composite is
205
+ not generally the same as a composite of per-date indices.
206
+
207
+ ## Verify with Terraproof
208
+
209
+ Use an installed Python core and real local outputs/STAC Items:
210
+
211
+ ```bash
212
+ python -m terraproof check sr_red.tif sr_nir.tif --expect reflectance --format md --lang en --out sr-report.md
213
+ python -m terraproof check scl_aligned.tif --categorical --resampling nearest
214
+ python -m terraproof check source-item.json
215
+ ```
216
+
217
+ `rs.reflectance_range` checks sampled statistics after raster scale/offset
218
+ metadata is applied. It is only a coarse plausibility test, not proof of the
219
+ correct processing level or calibration. `raster.nodata_declared` checks nodata
220
+ metadata. `raster.grid_alignment` compares CRS/pixel sizes/grid origin for
221
+ multiple rasters, not equal extents or actual image co-registration.
222
+ `raster.resampling` checks a declared categorical method, not historical usage.
223
+ `stac.provenance` checks Item time and a projection code, not full processing
224
+ lineage, licenses or calibration metadata. `crs.defined`/`crs.consistent` apply
225
+ to raster CRS metadata; `raster.cog_layout` may also run on GeoTIFFs.
226
+
227
+ Cloud/shadow-mask application, correct SCL/QA decoding, scale/offset applied
228
+ exactly once, sensor harmonization, valid-observation support and compositing
229
+ correctness are **not checked automatically yet**. Preserve independent pixel
230
+ arithmetic and QA tests; see [verification](../verification/SKILL.md).
231
+
232
+ ## Sources
233
+
234
+ - [S1 — ESA Sentinel-2 products](https://sentiwiki.copernicus.eu/web/s2-products): L2A formula, baseline 04.00, DN 0 nodata, band grids and metadata authority.
235
+ - [S2 — ESA L2A Data Quality Report, October 2026](https://sentiwiki.copernicus.eu/__attachments/a_05551f216ff3e0ff859cd12fcc162978f08d70b32eaace391ba2ee5423bdc86b/S2-OMPC.CS.DQR.002.09-2026-i102r0-MSI-L2A-DQR-October-2026.pdf): radiometric offset section specifies -1000 DN for all spectral bands.
236
+ - [S3 — ESA Sen2Cor Input Output Data Definition](https://step.esa.int/thirdparties/sen2cor/2.13.0/docs/OMPC.TPZG.IOD.004%20-%20i1r0%20-%20Sen2Cor%202.13.02%20Input%20Output%20Data%20Definition.pdf): PDF page 12 specifies reflectance quantification 10000 and Reflectance = (DN - 1000) / 10000.
237
+ - [S4 — ESA Sentinel-2 processing](https://sentiwiki.copernicus.eu/web/s2-processing): scene-classification table 3 (classes 0–11), class-label evolution and algorithm limitations.
238
+ - [S5 — USGS Landsat 8–9 Collection 2 Level-2 Science Product Guide](https://www.usgs.gov/media/files/landsat-8-9-collection-2-level-2-science-product-guide): table 6-1 scale 0.0000275, offset -0.2, fill 0; table 6-2 QA_PIXEL bits; QA_RADSAT and aerosol caveats.
239
+ - [S6 — USGS Collection 2 QA bands](https://www.usgs.gov/landsat-missions/landsat-collection-2-quality-assessment-bands): zero-based QA_PIXEL positions 0–7 and clear-bit meaning for Landsat 8/9.
240
+ - [S7 — NASA HLS algorithms](https://hls.gsfc.nasa.gov/algorithms/): atmospheric, geometric, angular and spectral harmonization components.
241
+ - [Rasterio masks](https://rasterio.readthedocs.io/en/stable/topics/masks.html) and [rioxarray API](https://vylor.github.io/rioxarray/stable/rioxarray.html): masked reads, scale decoding and writing interfaces.
@@ -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,84 @@
1
+ {
2
+ "name": "satellite-preprocessing",
3
+ "layer": "domain",
4
+ "domains": [
5
+ "geospatial"
6
+ ],
7
+ "capabilities": [
8
+ "surface-reflectance-decoding",
9
+ "cloud-masking",
10
+ "sensor-harmonization",
11
+ "temporal-compositing"
12
+ ],
13
+ "triggers": [
14
+ "surface reflectance",
15
+ "scene classification",
16
+ "scl band",
17
+ "qa_pixel",
18
+ "boa_add_offset",
19
+ "landsat collection 2"
20
+ ],
21
+ "recommended": [
22
+ "raster-processing"
23
+ ],
24
+ "requires": [],
25
+ "conflicts": [],
26
+ "explanation": "Decodes Sentinel-2 L2A and Landsat Collection 2 Level-2 surface reflectance once, applies sensor-specific QA masks, and prepares harmonized composites.",
27
+ "sections": [
28
+ {
29
+ "id": "establish-the-product-and-encoding",
30
+ "title": "Establish the product and encoding",
31
+ "source": "SKILL.md#establish-the-product-and-encoding"
32
+ },
33
+ {
34
+ "id": "decode-sentinel-2-l2a-reflectance",
35
+ "title": "Decode Sentinel-2 L2A reflectance",
36
+ "source": "SKILL.md#decode-sentinel-2-l2a-reflectance"
37
+ },
38
+ {
39
+ "id": "mask-sentinel-2-scl-cloud-and-shadow-classes",
40
+ "title": "Mask Sentinel-2 SCL cloud and shadow classes",
41
+ "source": "SKILL.md#mask-sentinel-2-scl-cloud-and-shadow-classes"
42
+ },
43
+ {
44
+ "id": "decode-landsat-collection-2-level-2-sr",
45
+ "title": "Decode Landsat Collection 2 Level-2 SR",
46
+ "source": "SKILL.md#decode-landsat-collection-2-level-2-sr"
47
+ },
48
+ {
49
+ "id": "apply-scale-and-offset-exactly-once",
50
+ "title": "Apply scale and offset exactly once",
51
+ "source": "SKILL.md#apply-scale-and-offset-exactly-once"
52
+ },
53
+ {
54
+ "id": "harmonize-sensors-before-comparing-them",
55
+ "title": "Harmonize sensors before comparing them",
56
+ "source": "SKILL.md#harmonize-sensors-before-comparing-them"
57
+ },
58
+ {
59
+ "id": "build-temporal-composites-from-masked-observations",
60
+ "title": "Build temporal composites from masked observations",
61
+ "source": "SKILL.md#build-temporal-composites-from-masked-observations"
62
+ },
63
+ {
64
+ "id": "verify-with-terraproof",
65
+ "title": "Verify with Terraproof",
66
+ "source": "SKILL.md#verify-with-terraproof"
67
+ },
68
+ {
69
+ "id": "sources",
70
+ "title": "Sources",
71
+ "source": "SKILL.md#sources"
72
+ }
73
+ ],
74
+ "checks": [
75
+ "rs.reflectance_range",
76
+ "raster.nodata_declared",
77
+ "raster.grid_alignment",
78
+ "raster.resampling",
79
+ "stac.provenance",
80
+ "crs.defined",
81
+ "crs.consistent",
82
+ "raster.cog_layout"
83
+ ]
84
+ }