terraproof 0.0.0-stage → 0.4.0
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.
- package/LICENSE +21 -0
- package/README.md +356 -2
- package/bin/terraproof.js +4 -0
- package/dist/router/apply.js +147 -0
- package/dist/router/classify.js +111 -0
- package/dist/router/explain.js +9 -0
- package/dist/router/index.js +272 -0
- package/dist/router/resolve.js +239 -0
- package/dist/router/score.js +60 -0
- package/dist/router/types.js +1 -0
- package/dist/router/validate.js +81 -0
- package/instructions/engineering.md +14 -0
- package/instructions/security.md +14 -0
- package/instructions/simplicity.md +13 -0
- package/package.json +65 -4
- package/routing/DOMAIN_ROUTING.md +161 -0
- package/routing/ROUTER_DESIGN.md +173 -0
- package/routing/SKILL_MANIFEST.md +86 -0
- package/routing/checks.json +121 -0
- package/routing/collections.json +47 -0
- package/routing/registry.json +2211 -0
- package/routing/rules.json +64 -0
- package/skills/accuracy-assessment/SKILL.md +213 -0
- package/skills/accuracy-assessment/UPSTREAM.md +7 -0
- package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
- package/skills/accuracy-assessment/skill.json +103 -0
- package/skills/brainstorming/SKILL.md +250 -0
- package/skills/brainstorming/UPSTREAM.md +29 -0
- package/skills/brainstorming/scripts/frame-template.html +213 -0
- package/skills/brainstorming/scripts/helper.js +167 -0
- package/skills/brainstorming/scripts/server.cjs +723 -0
- package/skills/brainstorming/scripts/start-server.sh +209 -0
- package/skills/brainstorming/scripts/stop-server.sh +120 -0
- package/skills/brainstorming/skill.json +73 -0
- package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/skills/brainstorming/visual-companion.md +299 -0
- package/skills/crs-and-units/SKILL.md +200 -0
- package/skills/crs-and-units/UPSTREAM.md +7 -0
- package/skills/crs-and-units/skill.json +74 -0
- package/skills/design-postgis-tables/SKILL.md +494 -0
- package/skills/design-postgis-tables/UPSTREAM.md +21 -0
- package/skills/design-postgis-tables/skill.json +90 -0
- package/skills/gdal/SKILL.md +125 -0
- package/skills/gdal/UPSTREAM.md +22 -0
- package/skills/gdal/references/gdal-recipes.md +103 -0
- package/skills/gdal/skill.json +66 -0
- package/skills/geomaster/README.md +105 -0
- package/skills/geomaster/SKILL.md +366 -0
- package/skills/geomaster/UPSTREAM.md +21 -0
- package/skills/geomaster/references/advanced-gis.md +376 -0
- package/skills/geomaster/references/big-data.md +363 -0
- package/skills/geomaster/references/code-examples.md +531 -0
- package/skills/geomaster/references/coordinate-systems.md +364 -0
- package/skills/geomaster/references/core-libraries.md +273 -0
- package/skills/geomaster/references/data-sources.md +330 -0
- package/skills/geomaster/references/gis-software.md +369 -0
- package/skills/geomaster/references/industry-applications.md +420 -0
- package/skills/geomaster/references/machine-learning.md +462 -0
- package/skills/geomaster/references/programming-languages.md +456 -0
- package/skills/geomaster/references/remote-sensing.md +370 -0
- package/skills/geomaster/references/scientific-domains.md +416 -0
- package/skills/geomaster/references/specialized-topics.md +428 -0
- package/skills/geomaster/references/troubleshooting.md +439 -0
- package/skills/geomaster/skill.json +157 -0
- package/skills/geopandas/SKILL.md +250 -0
- package/skills/geopandas/UPSTREAM.md +22 -0
- package/skills/geopandas/references/crs-management.md +231 -0
- package/skills/geopandas/references/data-io.md +323 -0
- package/skills/geopandas/references/data-structures.md +207 -0
- package/skills/geopandas/references/geometric-operations.md +262 -0
- package/skills/geopandas/references/spatial-analysis.md +294 -0
- package/skills/geopandas/references/visualization.md +230 -0
- package/skills/geopandas/scripts/_common.py +605 -0
- package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
- package/skills/geopandas/scripts/export_plan.py +305 -0
- package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
- package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
- package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
- package/skills/geopandas/scripts/vector_inventory.py +140 -0
- package/skills/geopandas/skill.json +116 -0
- package/skills/geoparquet-validation/SKILL.md +125 -0
- package/skills/geoparquet-validation/UPSTREAM.md +24 -0
- package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
- package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
- package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
- package/skills/geoparquet-validation/skill.json +71 -0
- package/skills/geospatial-data-discovery/SKILL.md +49 -0
- package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
- package/skills/geospatial-data-discovery/skill.json +51 -0
- package/skills/geospatial-frontend/SKILL.md +86 -0
- package/skills/geospatial-frontend/UPSTREAM.md +23 -0
- package/skills/geospatial-frontend/references/design-system.md +283 -0
- package/skills/geospatial-frontend/references/user-preferences.md +96 -0
- package/skills/geospatial-frontend/skill.json +87 -0
- package/skills/geozarr/SKILL.md +244 -0
- package/skills/geozarr/UPSTREAM.md +21 -0
- package/skills/geozarr/skill.json +97 -0
- package/skills/networkx/SKILL.md +440 -0
- package/skills/networkx/UPSTREAM.md +22 -0
- package/skills/networkx/references/algorithms.md +384 -0
- package/skills/networkx/references/generators.md +385 -0
- package/skills/networkx/references/graph-basics.md +284 -0
- package/skills/networkx/references/io.md +457 -0
- package/skills/networkx/references/visualization.md +531 -0
- package/skills/networkx/skill.json +93 -0
- package/skills/raster-processing/SKILL.md +222 -0
- package/skills/raster-processing/UPSTREAM.md +7 -0
- package/skills/raster-processing/skill.json +81 -0
- package/skills/sar-basics/SKILL.md +202 -0
- package/skills/sar-basics/UPSTREAM.md +7 -0
- package/skills/sar-basics/references/calibration-lut.md +98 -0
- package/skills/sar-basics/skill.json +97 -0
- package/skills/satellite-preprocessing/SKILL.md +241 -0
- package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
- package/skills/satellite-preprocessing/skill.json +84 -0
- package/skills/scientific-visualization/SKILL.md +285 -0
- package/skills/scientific-visualization/UPSTREAM.md +25 -0
- package/skills/scientific-visualization/assets/color_palettes.py +263 -0
- package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
- package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
- package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
- package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
- package/skills/scientific-visualization/references/color_palettes.md +227 -0
- package/skills/scientific-visualization/references/journal_requirements.md +169 -0
- package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
- package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
- package/skills/scientific-visualization/references/sources.md +76 -0
- package/skills/scientific-visualization/scripts/_common.py +136 -0
- package/skills/scientific-visualization/scripts/export_plan.py +493 -0
- package/skills/scientific-visualization/scripts/figure_export.py +642 -0
- package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
- package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
- package/skills/scientific-visualization/scripts/style_presets.py +501 -0
- package/skills/scientific-visualization/scripts/style_preview.py +232 -0
- package/skills/scientific-visualization/skill.json +95 -0
- package/skills/spectral-indices/SKILL.md +235 -0
- package/skills/spectral-indices/UPSTREAM.md +7 -0
- package/skills/spectral-indices/skill.json +88 -0
- package/skills/stac-and-cloud-access/SKILL.md +209 -0
- package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
- package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
- package/skills/stac-and-cloud-access/skill.json +98 -0
- package/skills/statistical-analysis/SKILL.md +446 -0
- package/skills/statistical-analysis/UPSTREAM.md +24 -0
- package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
- package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
- package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
- package/skills/statistical-analysis/references/reporting_standards.md +482 -0
- package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
- package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
- package/skills/statistical-analysis/skill.json +127 -0
- package/skills/systematic-debugging/SKILL.md +283 -0
- package/skills/systematic-debugging/UPSTREAM.md +28 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +72 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/skill.json +88 -0
- package/skills/time-series-and-change/SKILL.md +217 -0
- package/skills/time-series-and-change/UPSTREAM.md +7 -0
- package/skills/time-series-and-change/references/change-methods.md +42 -0
- package/skills/time-series-and-change/skill.json +116 -0
- package/skills/vector-quality/SKILL.md +204 -0
- package/skills/vector-quality/UPSTREAM.md +7 -0
- package/skills/vector-quality/skill.json +82 -0
- package/skills/verification/SKILL.md +120 -0
- package/skills/verification/UPSTREAM.md +31 -0
- package/skills/verification/skill.json +67 -0
- package/skills/writing-plans/SKILL.md +171 -0
- package/skills/writing-plans/UPSTREAM.md +23 -0
- package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/skills/writing-plans/skill.json +80 -0
- package/sources/SOURCES.md +374 -0
- package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
- package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
- package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
- package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
- package/third_party/superpowers/LICENSE +21 -0
- package/third_party/superpowers/NOTICE.md +17 -0
- package/third_party/timescale-pg-aiguide/LICENSE +176 -0
- package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: geomaster
|
|
3
|
+
description: Comprehensive geospatial science skill covering remote sensing, GIS, spatial analysis, machine learning for earth observation, and 30+ scientific domains. Supports satellite imagery processing (Sentinel, Landsat, MODIS, SAR, hyperspectral), vector and raster data operations, spatial statistics, point cloud processing, network analysis, cloud-native workflows (STAC, COG, Planetary Computer), and 8 programming languages (Python, R, Julia, JavaScript, C++, Java, Go, Rust) with 500+ code examples. Use for remote sensing workflows, GIS analysis, spatial ML, Earth observation data processing, terrain analysis, hydrological modeling, marine spatial analysis, atmospheric science, and any geospatial computation task.
|
|
4
|
+
license: MIT License
|
|
5
|
+
metadata:
|
|
6
|
+
version: "1.1"
|
|
7
|
+
skill-author: K-Dense Inc.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# GeoMaster
|
|
11
|
+
|
|
12
|
+
Comprehensive geospatial science skill covering GIS, remote sensing, spatial analysis, and ML for Earth observation across 70+ topics with 500+ code examples in 8 programming languages.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Core Python stack (conda recommended)
|
|
18
|
+
conda install -c conda-forge gdal rasterio fiona shapely pyproj geopandas
|
|
19
|
+
|
|
20
|
+
# Remote sensing & ML
|
|
21
|
+
uv pip install rsgislib torchgeo earthengine-api
|
|
22
|
+
uv pip install scikit-learn xgboost torch-geometric
|
|
23
|
+
|
|
24
|
+
# Network & visualization
|
|
25
|
+
uv pip install osmnx networkx folium keplergl
|
|
26
|
+
uv pip install cartopy contextily mapclassify
|
|
27
|
+
|
|
28
|
+
# Big data & cloud
|
|
29
|
+
uv pip install xarray rioxarray dask-geopandas
|
|
30
|
+
uv pip install pystac-client planetary-computer
|
|
31
|
+
|
|
32
|
+
# Point clouds
|
|
33
|
+
uv pip install laspy pylas open3d pdal
|
|
34
|
+
|
|
35
|
+
# Databases
|
|
36
|
+
conda install -c conda-forge postgis spatialite
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### NDVI from Sentinel-2
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import rasterio
|
|
45
|
+
import numpy as np
|
|
46
|
+
|
|
47
|
+
with rasterio.open('sentinel2.tif') as src:
|
|
48
|
+
red = src.read(4).astype(float) # B04
|
|
49
|
+
nir = src.read(8).astype(float) # B08
|
|
50
|
+
ndvi = (nir - red) / (nir + red + 1e-8)
|
|
51
|
+
ndvi = np.nan_to_num(ndvi, nan=0)
|
|
52
|
+
|
|
53
|
+
profile = src.profile
|
|
54
|
+
profile.update(count=1, dtype=rasterio.float32)
|
|
55
|
+
|
|
56
|
+
with rasterio.open('ndvi.tif', 'w', **profile) as dst:
|
|
57
|
+
dst.write(ndvi.astype(rasterio.float32), 1)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Spatial Analysis with GeoPandas
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import geopandas as gpd
|
|
64
|
+
|
|
65
|
+
# Load and ensure same CRS
|
|
66
|
+
zones = gpd.read_file('zones.geojson')
|
|
67
|
+
points = gpd.read_file('points.geojson')
|
|
68
|
+
|
|
69
|
+
if zones.crs != points.crs:
|
|
70
|
+
points = points.to_crs(zones.crs)
|
|
71
|
+
|
|
72
|
+
# Spatial join and statistics
|
|
73
|
+
joined = gpd.sjoin(points, zones, how='inner', predicate='within')
|
|
74
|
+
stats = joined.groupby('zone_id').agg({
|
|
75
|
+
'value': ['count', 'mean', 'std', 'min', 'max']
|
|
76
|
+
}).round(2)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Google Earth Engine Time Series
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import ee
|
|
83
|
+
import pandas as pd
|
|
84
|
+
|
|
85
|
+
ee.Initialize(project='your-project')
|
|
86
|
+
roi = ee.Geometry.Point([-122.4, 37.7]).buffer(10000)
|
|
87
|
+
|
|
88
|
+
s2 = (ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
|
|
89
|
+
.filterBounds(roi)
|
|
90
|
+
.filterDate('2020-01-01', '2023-12-31')
|
|
91
|
+
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)))
|
|
92
|
+
|
|
93
|
+
def add_ndvi(img):
|
|
94
|
+
return img.addBands(img.normalizedDifference(['B8', 'B4']).rename('NDVI'))
|
|
95
|
+
|
|
96
|
+
s2_ndvi = s2.map(add_ndvi)
|
|
97
|
+
|
|
98
|
+
def extract_series(image):
|
|
99
|
+
stats = image.reduceRegion(ee.Reducer.mean(), roi.centroid(), scale=10, maxPixels=1e9)
|
|
100
|
+
return ee.Feature(None, {'date': image.date().format('YYYY-MM-dd'), 'ndvi': stats.get('NDVI')})
|
|
101
|
+
|
|
102
|
+
series = s2_ndvi.map(extract_series).getInfo()
|
|
103
|
+
df = pd.DataFrame([f['properties'] for f in series['features']])
|
|
104
|
+
df['date'] = pd.to_datetime(df['date'])
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Core Concepts
|
|
108
|
+
|
|
109
|
+
### Data Types
|
|
110
|
+
|
|
111
|
+
| Type | Examples | Libraries |
|
|
112
|
+
|------|----------|-----------|
|
|
113
|
+
| Vector | Shapefile, GeoJSON, GeoPackage | GeoPandas, Fiona, GDAL |
|
|
114
|
+
| Raster | GeoTIFF, NetCDF, COG | Rasterio, Xarray, GDAL |
|
|
115
|
+
| Point Cloud | LAS, LAZ | Laspy, PDAL, Open3D |
|
|
116
|
+
|
|
117
|
+
### Coordinate Systems
|
|
118
|
+
|
|
119
|
+
- **EPSG:4326** (WGS 84) - Geographic, lat/lon, use for storage
|
|
120
|
+
- **EPSG:3857** (Web Mercator) - Web maps only (don't use for area/distance!)
|
|
121
|
+
- **EPSG:326xx/327xx** (UTM) - Metric calculations, <1% distortion per zone
|
|
122
|
+
- Use `gdf.estimate_utm_crs()` for automatic UTM detection
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
# Always check CRS before operations
|
|
126
|
+
assert gdf1.crs == gdf2.crs, "CRS mismatch!"
|
|
127
|
+
|
|
128
|
+
# For area/distance calculations, use projected CRS
|
|
129
|
+
gdf_metric = gdf.to_crs(gdf.estimate_utm_crs())
|
|
130
|
+
area_sqm = gdf_metric.geometry.area
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### OGC Standards
|
|
134
|
+
|
|
135
|
+
- **WMS**: Web Map Service - raster maps
|
|
136
|
+
- **WFS**: Web Feature Service - vector data
|
|
137
|
+
- **WCS**: Web Coverage Service - raster coverage
|
|
138
|
+
- **STAC**: Spatiotemporal Asset Catalog - modern metadata
|
|
139
|
+
|
|
140
|
+
## Common Operations
|
|
141
|
+
|
|
142
|
+
### Spectral Indices
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
def calculate_indices(image_path):
|
|
146
|
+
"""NDVI, EVI, SAVI, NDWI from Sentinel-2."""
|
|
147
|
+
with rasterio.open(image_path) as src:
|
|
148
|
+
B02, B03, B04, B08, B11 = [src.read(i).astype(float) for i in [1,2,3,4,5]]
|
|
149
|
+
|
|
150
|
+
ndvi = (B08 - B04) / (B08 + B04 + 1e-8)
|
|
151
|
+
evi = 2.5 * (B08 - B04) / (B08 + 6*B04 - 7.5*B02 + 1)
|
|
152
|
+
savi = ((B08 - B04) / (B08 + B04 + 0.5)) * 1.5
|
|
153
|
+
ndwi = (B03 - B08) / (B03 + B08 + 1e-8)
|
|
154
|
+
|
|
155
|
+
return {'NDVI': ndvi, 'EVI': evi, 'SAVI': savi, 'NDWI': ndwi}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Vector Operations
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
# Buffer (use projected CRS!)
|
|
162
|
+
gdf_proj = gdf.to_crs(gdf.estimate_utm_crs())
|
|
163
|
+
gdf['buffer_1km'] = gdf_proj.geometry.buffer(1000)
|
|
164
|
+
|
|
165
|
+
# Spatial relationships
|
|
166
|
+
intersects = gdf[gdf.geometry.intersects(other_geometry)]
|
|
167
|
+
contains = gdf[gdf.geometry.contains(point_geometry)]
|
|
168
|
+
|
|
169
|
+
# Geometric operations
|
|
170
|
+
gdf['centroid'] = gdf.geometry.centroid
|
|
171
|
+
gdf['simplified'] = gdf.geometry.simplify(tolerance=0.001)
|
|
172
|
+
|
|
173
|
+
# Overlay operations
|
|
174
|
+
intersection = gpd.overlay(gdf1, gdf2, how='intersection')
|
|
175
|
+
union = gpd.overlay(gdf1, gdf2, how='union')
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Terrain Analysis
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
def terrain_metrics(dem_path):
|
|
182
|
+
"""Calculate slope, aspect, hillshade from DEM."""
|
|
183
|
+
with rasterio.open(dem_path) as src:
|
|
184
|
+
dem = src.read(1)
|
|
185
|
+
|
|
186
|
+
dy, dx = np.gradient(dem)
|
|
187
|
+
slope = np.arctan(np.sqrt(dx**2 + dy**2)) * 180 / np.pi
|
|
188
|
+
aspect = (90 - np.arctan2(-dy, dx) * 180 / np.pi) % 360
|
|
189
|
+
|
|
190
|
+
# Hillshade
|
|
191
|
+
az_rad, alt_rad = np.radians(315), np.radians(45)
|
|
192
|
+
hillshade = (np.sin(alt_rad) * np.sin(np.radians(slope)) +
|
|
193
|
+
np.cos(alt_rad) * np.cos(np.radians(slope)) *
|
|
194
|
+
np.cos(np.radians(aspect) - az_rad))
|
|
195
|
+
|
|
196
|
+
return slope, aspect, hillshade
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Network Analysis
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
import osmnx as ox
|
|
203
|
+
import networkx as nx
|
|
204
|
+
|
|
205
|
+
# Download and analyze street network
|
|
206
|
+
G = ox.graph_from_place('San Francisco, CA', network_type='drive')
|
|
207
|
+
G = ox.add_edge_speeds(G).add_edge_travel_times(G)
|
|
208
|
+
|
|
209
|
+
# Shortest path
|
|
210
|
+
orig = ox.distance.nearest_nodes(G, -122.4, 37.7)
|
|
211
|
+
dest = ox.distance.nearest_nodes(G, -122.3, 37.8)
|
|
212
|
+
route = nx.shortest_path(G, orig, dest, weight='travel_time')
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Image Classification
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from sklearn.ensemble import RandomForestClassifier
|
|
219
|
+
import rasterio
|
|
220
|
+
from rasterio.features import rasterize
|
|
221
|
+
|
|
222
|
+
def classify_imagery(raster_path, training_gdf, output_path):
|
|
223
|
+
"""Train RF and classify imagery."""
|
|
224
|
+
with rasterio.open(raster_path) as src:
|
|
225
|
+
image = src.read()
|
|
226
|
+
profile = src.profile
|
|
227
|
+
transform = src.transform
|
|
228
|
+
|
|
229
|
+
# Extract training data
|
|
230
|
+
X_train, y_train = [], []
|
|
231
|
+
for _, row in training_gdf.iterrows():
|
|
232
|
+
mask = rasterize([(row.geometry, 1)],
|
|
233
|
+
out_shape=(profile['height'], profile['width']),
|
|
234
|
+
transform=transform, fill=0, dtype=np.uint8)
|
|
235
|
+
pixels = image[:, mask > 0].T
|
|
236
|
+
X_train.extend(pixels)
|
|
237
|
+
y_train.extend([row['class_id']] * len(pixels))
|
|
238
|
+
|
|
239
|
+
# Train and predict
|
|
240
|
+
rf = RandomForestClassifier(n_estimators=100, max_depth=20, n_jobs=-1)
|
|
241
|
+
rf.fit(X_train, y_train)
|
|
242
|
+
|
|
243
|
+
prediction = rf.predict(image.reshape(image.shape[0], -1).T)
|
|
244
|
+
prediction = prediction.reshape(profile['height'], profile['width'])
|
|
245
|
+
|
|
246
|
+
profile.update(dtype=rasterio.uint8, count=1)
|
|
247
|
+
with rasterio.open(output_path, 'w', **profile) as dst:
|
|
248
|
+
dst.write(prediction.astype(rasterio.uint8), 1)
|
|
249
|
+
|
|
250
|
+
return rf
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Modern Cloud-Native Workflows
|
|
254
|
+
|
|
255
|
+
### STAC + Planetary Computer
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
import pystac_client
|
|
259
|
+
import planetary_computer
|
|
260
|
+
import odc.stac
|
|
261
|
+
|
|
262
|
+
# Search Sentinel-2 via STAC
|
|
263
|
+
catalog = pystac_client.Client.open(
|
|
264
|
+
"https://planetarycomputer.microsoft.com/api/stac/v1",
|
|
265
|
+
modifier=planetary_computer.sign_inplace,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
search = catalog.search(
|
|
269
|
+
collections=["sentinel-2-l2a"],
|
|
270
|
+
bbox=[-122.5, 37.7, -122.3, 37.9],
|
|
271
|
+
datetime="2023-01-01/2023-12-31",
|
|
272
|
+
query={"eo:cloud_cover": {"lt": 20}},
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
# Load as xarray (cloud-native!)
|
|
276
|
+
data = odc.stac.load(
|
|
277
|
+
list(search.get_items())[:5],
|
|
278
|
+
bands=["B02", "B03", "B04", "B08"],
|
|
279
|
+
crs="EPSG:32610",
|
|
280
|
+
resolution=10,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
# Calculate NDVI on xarray
|
|
284
|
+
ndvi = (data.B08 - data.B04) / (data.B08 + data.B04)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Cloud-Optimized GeoTIFF (COG)
|
|
288
|
+
|
|
289
|
+
```python
|
|
290
|
+
import rasterio
|
|
291
|
+
from rasterio.session import AWSSession
|
|
292
|
+
|
|
293
|
+
# Read COG directly from cloud (partial reads)
|
|
294
|
+
session = AWSSession(aws_access_key_id=..., aws_secret_access_key=...)
|
|
295
|
+
with rasterio.open('s3://bucket/path.tif', session=session) as src:
|
|
296
|
+
# Read only window of interest
|
|
297
|
+
window = ((1000, 2000), (1000, 2000))
|
|
298
|
+
subset = src.read(1, window=window)
|
|
299
|
+
|
|
300
|
+
# Write COG
|
|
301
|
+
with rasterio.open('output.tif', 'w', **profile,
|
|
302
|
+
tiled=True, blockxsize=256, blockysize=256,
|
|
303
|
+
compress='DEFLATE', predictor=2) as dst:
|
|
304
|
+
dst.write(data)
|
|
305
|
+
|
|
306
|
+
# Validate COG
|
|
307
|
+
from rio_cogeo.cogeo import cog_validate
|
|
308
|
+
cog_validate('output.tif')
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Performance Tips
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
# 1. Spatial indexing (10-100x faster queries)
|
|
315
|
+
gdf.sindex # Auto-created by GeoPandas
|
|
316
|
+
|
|
317
|
+
# 2. Chunk large rasters
|
|
318
|
+
with rasterio.open('large.tif') as src:
|
|
319
|
+
for i, window in src.block_windows(1):
|
|
320
|
+
block = src.read(1, window=window)
|
|
321
|
+
|
|
322
|
+
# 3. Dask for big data
|
|
323
|
+
import dask.array as da
|
|
324
|
+
dask_array = da.from_rasterio('large.tif', chunks=(1, 1024, 1024))
|
|
325
|
+
|
|
326
|
+
# 4. Use Arrow for I/O
|
|
327
|
+
gdf.to_file('output.gpkg', use_arrow=True)
|
|
328
|
+
|
|
329
|
+
# 5. GDAL caching
|
|
330
|
+
from osgeo import gdal
|
|
331
|
+
gdal.SetCacheMax(2**30) # 1GB cache
|
|
332
|
+
|
|
333
|
+
# 6. Parallel processing
|
|
334
|
+
rf = RandomForestClassifier(n_jobs=-1) # All cores
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Best Practices
|
|
338
|
+
|
|
339
|
+
1. **Always check CRS** before spatial operations
|
|
340
|
+
2. **Use projected CRS** for area/distance calculations
|
|
341
|
+
3. **Validate geometries**: `gdf = gdf[gdf.is_valid]`
|
|
342
|
+
4. **Handle missing data**: `gdf['geometry'] = gdf['geometry'].fillna(None)`
|
|
343
|
+
5. **Use efficient formats**: GeoPackage > Shapefile, Parquet for large data
|
|
344
|
+
6. **Apply cloud masking** to optical imagery
|
|
345
|
+
7. **Preserve lineage** for reproducible research
|
|
346
|
+
8. **Use appropriate resolution** for your analysis scale
|
|
347
|
+
|
|
348
|
+
## Detailed Documentation
|
|
349
|
+
|
|
350
|
+
- **[Coordinate Systems](references/coordinate-systems.md)** - CRS fundamentals, UTM, transformations
|
|
351
|
+
- **[Core Libraries](references/core-libraries.md)** - GDAL, Rasterio, GeoPandas, Shapely
|
|
352
|
+
- **[Remote Sensing](references/remote-sensing.md)** - Satellite missions, spectral indices, SAR
|
|
353
|
+
- **[Machine Learning](references/machine-learning.md)** - Deep learning, CNNs, GNNs for RS
|
|
354
|
+
- **[GIS Software](references/gis-software.md)** - QGIS, ArcGIS, GRASS integration
|
|
355
|
+
- **[Scientific Domains](references/scientific-domains.md)** - Marine, hydrology, agriculture, forestry
|
|
356
|
+
- **[Advanced GIS](references/advanced-gis.md)** - 3D GIS, spatiotemporal, topology
|
|
357
|
+
- **[Big Data](references/big-data.md)** - Distributed processing, GPU acceleration
|
|
358
|
+
- **[Industry Applications](references/industry-applications.md)** - Urban planning, disaster management
|
|
359
|
+
- **[Programming Languages](references/programming-languages.md)** - Python, R, Julia, JS, C++, Java, Go, Rust
|
|
360
|
+
- **[Data Sources](references/data-sources.md)** - Satellite catalogs, APIs
|
|
361
|
+
- **[Troubleshooting](references/troubleshooting.md)** - Common issues, debugging, error reference
|
|
362
|
+
- **[Code Examples](references/code-examples.md)** - 500+ examples
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
**GeoMaster covers everything from basic GIS operations to advanced remote sensing and machine learning.**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Upstream Attribution
|
|
2
|
+
|
|
3
|
+
This skill is derived from the `geomaster` skill in `K-Dense-AI/scientific-agent-skills`.
|
|
4
|
+
|
|
5
|
+
- **Upstream repository:** https://github.com/K-Dense-AI/scientific-agent-skills
|
|
6
|
+
- **Upstream path:** `skills/geomaster/`
|
|
7
|
+
- **License:** MIT (see [third_party/kdense-scientific-agent-skills/LICENSE](../../third_party/kdense-scientific-agent-skills/LICENSE))
|
|
8
|
+
- **Imported commit:** `390f5146bf3c1877cf15636a3dd7b775e4f0f185`
|
|
9
|
+
- **Import date:** 2026-08-25
|
|
10
|
+
- **Local path:** `skills/geomaster/`
|
|
11
|
+
|
|
12
|
+
## Imported Files
|
|
13
|
+
|
|
14
|
+
- `SKILL.md`
|
|
15
|
+
|
|
16
|
+
## Local modifications
|
|
17
|
+
|
|
18
|
+
Initial import:
|
|
19
|
+
- Local behavioral modifications: none (faithful vendoring, byte-for-byte identical to upstream).
|
|
20
|
+
|
|
21
|
+
Any future AgentLayer modifications must be documented here.
|