topobathykit 0.1.0__tar.gz

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 (138) hide show
  1. topobathykit-0.1.0/.agent/rules/context.md +7 -0
  2. topobathykit-0.1.0/.github/copilot-instructions.md +68 -0
  3. topobathykit-0.1.0/.github/workflows/docs.yml +49 -0
  4. topobathykit-0.1.0/.github/workflows/publish.yml +51 -0
  5. topobathykit-0.1.0/.github/workflows/tests.yml +47 -0
  6. topobathykit-0.1.0/.gitignore +154 -0
  7. topobathykit-0.1.0/.markdownlint.yaml +5 -0
  8. topobathykit-0.1.0/.pre-commit-config.yaml +37 -0
  9. topobathykit-0.1.0/CONTRIBUTING.md +179 -0
  10. topobathykit-0.1.0/Dockerfile +68 -0
  11. topobathykit-0.1.0/LICENSE +21 -0
  12. topobathykit-0.1.0/PKG-INFO +304 -0
  13. topobathykit-0.1.0/README.md +231 -0
  14. topobathykit-0.1.0/docs/Makefile +20 -0
  15. topobathykit-0.1.0/docs/VISION.md +68 -0
  16. topobathykit-0.1.0/docs/requirements-docs.txt +4 -0
  17. topobathykit-0.1.0/docs/source/_extra/CNAME +1 -0
  18. topobathykit-0.1.0/docs/source/_static/dem-viewer-provenance.png +0 -0
  19. topobathykit-0.1.0/docs/source/_static/dem-viewer.png +0 -0
  20. topobathykit-0.1.0/docs/source/_static/hydrate.png +0 -0
  21. topobathykit-0.1.0/docs/source/_static/repo-logo.png +0 -0
  22. topobathykit-0.1.0/docs/source/_static/topobathy-blues-with-countours.png +0 -0
  23. topobathykit-0.1.0/docs/source/_static/topobathy-sources.png +0 -0
  24. topobathykit-0.1.0/docs/source/_static/topobathyscreenshot.png +0 -0
  25. topobathykit-0.1.0/docs/source/api.rst +33 -0
  26. topobathykit-0.1.0/docs/source/cache_viewer.rst +69 -0
  27. topobathykit-0.1.0/docs/source/cli_tools.rst +249 -0
  28. topobathykit-0.1.0/docs/source/conf.py +60 -0
  29. topobathykit-0.1.0/docs/source/data_sources.rst +156 -0
  30. topobathykit-0.1.0/docs/source/diagrams/runtime_loop.mmd +29 -0
  31. topobathykit-0.1.0/docs/source/fuse_endpoint.md +205 -0
  32. topobathykit-0.1.0/docs/source/gallery.rst +75 -0
  33. topobathykit-0.1.0/docs/source/hydration.md +231 -0
  34. topobathykit-0.1.0/docs/source/index.rst +36 -0
  35. topobathykit-0.1.0/docs/source/performance.rst +21 -0
  36. topobathykit-0.1.0/docs/source/policy_dsl.rst +118 -0
  37. topobathykit-0.1.0/docs/source/policy_walkthrough.rst +91 -0
  38. topobathykit-0.1.0/docs/source/runtime_architecture.rst +138 -0
  39. topobathykit-0.1.0/docs/source/vision.md +4 -0
  40. topobathykit-0.1.0/environment.yml +67 -0
  41. topobathykit-0.1.0/policies/examples/gbr_overlay.yaml +16 -0
  42. topobathykit-0.1.0/policies/examples/wlis.yaml +57 -0
  43. topobathykit-0.1.0/pyproject.toml +144 -0
  44. topobathykit-0.1.0/scripts/run_hydrate.py +7 -0
  45. topobathykit-0.1.0/service/Dockerfile +27 -0
  46. topobathykit-0.1.0/service/__init__.py +0 -0
  47. topobathykit-0.1.0/service/pyproject.toml +29 -0
  48. topobathykit-0.1.0/service/run_server.py +63 -0
  49. topobathykit-0.1.0/service/static/cache-viewer.css +612 -0
  50. topobathykit-0.1.0/service/static/cache-viewer.html +152 -0
  51. topobathykit-0.1.0/service/static/cache-viewer.js +585 -0
  52. topobathykit-0.1.0/service/static/dem-viewer.html +818 -0
  53. topobathykit-0.1.0/service/static/favicon.ico +0 -0
  54. topobathykit-0.1.0/service/static/favicon.svg +12 -0
  55. topobathykit-0.1.0/service/static/hydrate.html +924 -0
  56. topobathykit-0.1.0/service/static/index.html +574 -0
  57. topobathykit-0.1.0/service/static/provenance-utils.js +175 -0
  58. topobathykit-0.1.0/service/tests/test_api_integration.py +94 -0
  59. topobathykit-0.1.0/service/tests/test_dem_viewer_cache.py +104 -0
  60. topobathykit-0.1.0/service/tests/test_fuse_endpoint.py +307 -0
  61. topobathykit-0.1.0/service/tests/test_job_state.py +119 -0
  62. topobathykit-0.1.0/service/tests/test_policy_dynamic_post.py +118 -0
  63. topobathykit-0.1.0/service/tests/test_policy_hash.py +69 -0
  64. topobathykit-0.1.0/service/topobathyserve/__init__.py +0 -0
  65. topobathykit-0.1.0/service/topobathyserve/job_state.py +178 -0
  66. topobathykit-0.1.0/service/topobathyserve/main.py +2227 -0
  67. topobathykit-0.1.0/service/topobathyserve/models.py +98 -0
  68. topobathykit-0.1.0/service/topobathyserve/routers/cache_viewer.py +125 -0
  69. topobathykit-0.1.0/service/topobathyserve/routers/dem_viewer.py +967 -0
  70. topobathykit-0.1.0/service/verify_bathy.py +44 -0
  71. topobathykit-0.1.0/src/topobathykit/__init__.py +33 -0
  72. topobathykit-0.1.0/src/topobathykit/api/cache_api.py +530 -0
  73. topobathykit-0.1.0/src/topobathykit/api/models.py +157 -0
  74. topobathykit-0.1.0/src/topobathykit/config.py +65 -0
  75. topobathykit-0.1.0/src/topobathykit/fusion.py +263 -0
  76. topobathykit-0.1.0/src/topobathykit/manifest.py +193 -0
  77. topobathykit-0.1.0/src/topobathykit/operators/__init__.py +9 -0
  78. topobathykit-0.1.0/src/topobathykit/operators/blend.py +114 -0
  79. topobathykit-0.1.0/src/topobathykit/policy/__init__.py +1 -0
  80. topobathykit-0.1.0/src/topobathykit/policy/loader.py +75 -0
  81. topobathykit-0.1.0/src/topobathykit/policy/schema.py +121 -0
  82. topobathykit-0.1.0/src/topobathykit/providers/__init__.py +22 -0
  83. topobathykit-0.1.0/src/topobathykit/providers/base.py +272 -0
  84. topobathykit-0.1.0/src/topobathykit/providers/copernicus_dsm.py +507 -0
  85. topobathykit-0.1.0/src/topobathykit/providers/gebco_2025.py +520 -0
  86. topobathykit-0.1.0/src/topobathykit/providers/jcu_gbr100.py +170 -0
  87. topobathykit-0.1.0/src/topobathykit/providers/nasadem.py +506 -0
  88. topobathykit-0.1.0/src/topobathykit/providers/ncei_bag.py +1482 -0
  89. topobathykit-0.1.0/src/topobathykit/providers/ncei_cudem.py +467 -0
  90. topobathykit-0.1.0/src/topobathykit/providers/noaa_bluetopo.py +1922 -0
  91. topobathykit-0.1.0/src/topobathykit/providers/noaa_topobathy.py +1609 -0
  92. topobathykit-0.1.0/src/topobathykit/providers/registry.py +105 -0
  93. topobathykit-0.1.0/src/topobathykit/providers/source_classifier.py +46 -0
  94. topobathykit-0.1.0/src/topobathykit/providers/usgs_3dep.py +526 -0
  95. topobathykit-0.1.0/src/topobathykit/providers/usgs_lidar.py +997 -0
  96. topobathykit-0.1.0/src/topobathykit/quality.py +245 -0
  97. topobathykit-0.1.0/src/topobathykit/runtime.py +1216 -0
  98. topobathykit-0.1.0/src/topobathykit/scripts/__init__.py +1 -0
  99. topobathykit-0.1.0/src/topobathykit/scripts/build_noaa_index.py +241 -0
  100. topobathykit-0.1.0/src/topobathykit/scripts/cache_manager.py +1561 -0
  101. topobathykit-0.1.0/src/topobathykit/scripts/hydrate_cache.py +265 -0
  102. topobathykit-0.1.0/src/topobathykit/utils/cache.py +93 -0
  103. topobathykit-0.1.0/src/topobathykit/vdatum.py +434 -0
  104. topobathykit-0.1.0/src/topobathysim/__init__.py +53 -0
  105. topobathykit-0.1.0/tests/integration/conftest.py +18 -0
  106. topobathykit-0.1.0/tests/integration/test_api_caching.py +116 -0
  107. topobathykit-0.1.0/tests/integration/test_fusion_quality.py +166 -0
  108. topobathykit-0.1.0/tests/integration/test_gbr_fusion.py +79 -0
  109. topobathykit-0.1.0/tests/integration/test_integration.py +99 -0
  110. topobathykit-0.1.0/tests/integration/test_lidar_ept.py +42 -0
  111. topobathykit-0.1.0/tests/integration/test_noaa_coastal_lidar_streaming.py +85 -0
  112. topobathykit-0.1.0/tests/integration/test_noaa_multi_survey.py +96 -0
  113. topobathykit-0.1.0/tests/integration/test_provider_caching.py +124 -0
  114. topobathykit-0.1.0/tests/integration/test_runtime_pairwise.py +210 -0
  115. topobathykit-0.1.0/tests/integration/test_scenarios.py +131 -0
  116. topobathykit-0.1.0/tests/integration/test_topobathy_leak.py +224 -0
  117. topobathykit-0.1.0/tests/integration/test_wlis_fusion.py +60 -0
  118. topobathykit-0.1.0/tests/unit/test_bag_hole_fill.py +173 -0
  119. topobathykit-0.1.0/tests/unit/test_cache_lru.py +49 -0
  120. topobathykit-0.1.0/tests/unit/test_contours.py +65 -0
  121. topobathykit-0.1.0/tests/unit/test_cudem_fusion.py +143 -0
  122. topobathykit-0.1.0/tests/unit/test_despike.py +170 -0
  123. topobathykit-0.1.0/tests/unit/test_elevation_filter.py +151 -0
  124. topobathykit-0.1.0/tests/unit/test_fusion_seamline.py +99 -0
  125. topobathykit-0.1.0/tests/unit/test_gebco.py +243 -0
  126. topobathykit-0.1.0/tests/unit/test_hydration_integrity.py +333 -0
  127. topobathykit-0.1.0/tests/unit/test_multicell_mosaic.py +220 -0
  128. topobathykit-0.1.0/tests/unit/test_noaa_bluetopo_provider.py +287 -0
  129. topobathykit-0.1.0/tests/unit/test_noaa_topobathy.py +117 -0
  130. topobathykit-0.1.0/tests/unit/test_policy.py +133 -0
  131. topobathykit-0.1.0/tests/unit/test_provider_base.py +77 -0
  132. topobathykit-0.1.0/tests/unit/test_provider_concurrency.py +454 -0
  133. topobathykit-0.1.0/tests/unit/test_quality.py +49 -0
  134. topobathykit-0.1.0/tests/unit/test_raster_ops.py +62 -0
  135. topobathykit-0.1.0/tests/unit/test_rename_compat.py +77 -0
  136. topobathykit-0.1.0/tests/unit/test_runtime.py +172 -0
  137. topobathykit-0.1.0/tests/unit/test_runtime_shapes.py +172 -0
  138. topobathykit-0.1.0/tests/unit/test_vdatum.py +149 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ trigger: always_on
3
+ ---
4
+
5
+ # Agent Instructions
6
+
7
+ > **Redirect**: Please refer to [copilot-instructions.md](../../.github/copilot-instructions.md) for the primary source of truth regarding project context, architecture constraints, and development workflows.
@@ -0,0 +1,68 @@
1
+ # topobathykit Copilot Instructions
2
+
3
+ ## 🧠 Project Architecture & Core Concepts
4
+
5
+ - **Mission**: High-fidelity topobathymetric fusion for digital twins/robotics, merging disparate sources into unified tiles.
6
+ - **Fusion Hierarchy (Strict Priority)**:
7
+ 1. **Tier 0 (Absolute)**: NOAA BAG (Raw Survey, high precision).
8
+ 2. **Tier 1 (Fusion)**: Airborne Lidar (>0m) + Greenwave Topobathy (Intertidal).
9
+ 3. **Tier 2 (Coastal)**: NOAA CUDEM (Gap-fill).
10
+ 4. **Tier 3 (Regional)**: NOAA BlueTopo.
11
+ 5. **Tier 4 (Global Fallback)**: GEBCO 2025.
12
+ - **Microservice**: `service/topobathyserve` is a FastAPI app serving tiles (`/tiles/{z}/{x}/{y}`) and raw NumPy buffers.
13
+ - **Data Flow**: `Runtime` (in `src/topobathykit/runtime.py`) orchestrates data fetching and fusion based on YAML policies. It uses `Policy` objects to define fusion steps.
14
+
15
+ ## 🛠️ Tech Stack & Conventions
16
+
17
+ - **Language**: Python 3.12+ (Strict type hinting required).
18
+ - **Core Libs**: `xarray`/`rioxarray` (raster manip), `numpy` (math), `pdal` (point clouds), `bmi-topography` (standard fetching).
19
+ - **Environment**: **Micromamba** is preferred due to complex binary deps (`gdal`, `pdal`).
20
+ - *Warning*: `bmi-topography` version is pinned (~0.9.0); handle upgrades with caution.
21
+ - **CRITICAL**: Always use `micromamba run -n topobathykit <command>` or `micromamba activate topobathykit` before running any Python code (including pytest/pip).
22
+ - **Linting/Formatting**: `ruff` for linting/formatting, `mypy` for static analysis (configured in `pyproject.toml`).
23
+ - **CRITICAL**: Avoid `E501` line-length violations. Keep lines under 110 characters (or as configured in `pyproject.toml`). Break long strings, complex imports, and nested calls into multiple lines.
24
+ - **Path Handling**: Use `pathlib.Path` over `os.path`.
25
+
26
+ ### 1. Code Generation & Refactoring
27
+
28
+ - **Type Safety**: ALWAYS add type hints. Run `mypy` after significant changes.
29
+ - **Path Handling**: Use `pathlib.Path` over `os.path`.
30
+ - **Fusion Logic**: When modifying fusion logic (`fusion.py`), respect the **Source ID** constants defined in `manager.py`.
31
+ - **Refactoring**: If moving files, use `git mv`. Note recent refactor of `service` module -> `topobathyserve`.
32
+
33
+ ### 2. Service & API
34
+
35
+ - **FastAPI**: The service is located in `service/topobathyserve/main.py`.
36
+ - **Endpoints**:
37
+ - `GET /tiles/{z}/{x}/{y}.png` (Visual debug)
38
+ - `GET /tiles/{z}/{x}/{y}?format=npy` (Simulation data)
39
+ - `GET /source_map/{z}/{x}/{y}.png` (Provenance debugging)
40
+
41
+ ### 3. Testing & Verification
42
+
43
+ - **Framework**: `pytest`.
44
+ - **Markers**: Use `@pytest.mark.integration` for tests hitting external APIs (USGS/NOAA).
45
+ - **Running Tests**: `pytest` or `hatch run test`.
46
+ - **Debugging**:
47
+ - Use the built-in viewer: `python service/run_server.py`, then open `http://localhost:9595/viewer`.
48
+ - Check `~/.cache/topobathykit` for cached COGs/LAZ files if data looks weird.
49
+
50
+ ### 4. Common Tasks & Commands
51
+
52
+ - **Start Server**: `python service/run_server.py`
53
+ - **Lint/Format**: `pre-commit run --all-files` or `ruff check .`
54
+ - **Tests**: `python -m pytest tests/unit` (offline, about 70 s) and `python -m pytest tests/integration` (live NOAA/USGS endpoints, 10 to 12 minutes; `test_wlis_fusion` also needs a built NOAA spatial index). `tests/conftest.py` puts `service/` on `sys.path`, so no `PYTHONPATH` export is needed. Use the `topobathykit` micromamba env.
55
+ - **Clean Cache**: `rm -rf ~/.cache/topobathykit` (Useful when debugging bad downloads).
56
+
57
+ ### 5. Git Operations
58
+
59
+ - **Commit Messages**: Conventional commits (`feat:`, `fix:`, `docs:`, `chore:`). No emoji.
60
+ - **Staging**: Stage files explicitly (`git add <file>`). Never `git add .`.
61
+ - **Approval**: Present the change set and commit message and wait for explicit user approval before any `git commit`. Never `git push` without the user's direct go-ahead.
62
+ - **Attribution**: Author and committer are always the human contributor (`dfry-lhzn <dfry@lhzn.io>`, from `git config`), so the log shows who was behind each change. No `Co-Authored-By:` trailers or non-human identities: GitHub parses those into the Contributors list, which is reserved for people. Noting the agent harness or model that collaborated is welcome as plain text in the commit body. Verify with `git var GIT_AUTHOR_IDENT` before the first commit in a shell.
63
+
64
+ ## ⚠️ Gotchas & Edge Cases
65
+
66
+ - **Vertical Datums**: Data comes in varying datums. We strive for **LMSL** or **NAVD88**. Transformations happen via VDatum logic (`vdatum.py`).
67
+ - **Offline Mode**: logic handles `offline_mode=True`. Ensure new providers respect this flag (fail gracefully or use cache).
68
+ - **Geometry**: Bathymetry is negative down? No, usually typical DEMs are **positive up** (Elevation). standard is `z > 0` = Land, `z < 0` = Water (in most contexts, but check `fusion.py` for specific normalization).
@@ -0,0 +1,49 @@
1
+ name: Deploy Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - "docs/**"
8
+ - "src/topobathykit/**"
9
+ - ".github/workflows/docs.yml"
10
+ workflow_dispatch:
11
+
12
+ permissions:
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ concurrency:
18
+ group: pages
19
+ cancel-in-progress: false
20
+
21
+ jobs:
22
+ build:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+
27
+ - uses: actions/setup-python@v5
28
+ with:
29
+ python-version: "3.12"
30
+
31
+ - name: Install Sphinx dependencies
32
+ run: pip install -r docs/requirements-docs.txt
33
+
34
+ - name: Build HTML docs
35
+ run: sphinx-build -b html docs/source docs/build/html
36
+
37
+ - uses: actions/upload-pages-artifact@v3
38
+ with:
39
+ path: docs/build/html
40
+
41
+ deploy:
42
+ needs: build
43
+ runs-on: ubuntu-latest
44
+ environment:
45
+ name: github-pages
46
+ url: ${{ steps.deployment.outputs.page_url }}
47
+ steps:
48
+ - id: deployment
49
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,51 @@
1
+ name: Publish to PyPI
2
+
3
+ # Pushing a tag vX.Y.Z builds the sdist and wheel and publishes them to PyPI through trusted
4
+ # publishing (OIDC): no API token is stored anywhere. PyPI must list this repository, this
5
+ # workflow file and the `pypi` environment as a trusted publisher for topobathykit.
6
+ on:
7
+ push:
8
+ tags: ["v*"]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - uses: astral-sh/setup-uv@v6
17
+
18
+ - name: Check the tag matches the package version
19
+ run: |
20
+ version=$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')
21
+ if [ "v$version" != "$GITHUB_REF_NAME" ]; then
22
+ echo "Tag $GITHUB_REF_NAME does not match pyproject.toml version $version" >&2
23
+ exit 1
24
+ fi
25
+
26
+ - name: Build
27
+ run: uv build
28
+
29
+ - name: Check the distributions
30
+ run: uvx twine check --strict dist/*
31
+
32
+ - uses: actions/upload-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+
37
+ publish:
38
+ needs: build
39
+ runs-on: ubuntu-latest
40
+ environment:
41
+ name: pypi
42
+ url: https://pypi.org/p/topobathykit
43
+ permissions:
44
+ id-token: write
45
+ steps:
46
+ - uses: actions/download-artifact@v4
47
+ with:
48
+ name: dist
49
+ path: dist/
50
+
51
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,47 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ unit:
11
+ name: Unit tests
12
+ runs-on: ubuntu-latest
13
+ # The geospatial stack (pdal, gdal via rasterio/pyogrio) needs conda-forge
14
+ # binaries, so the environment comes from environment.yml rather than pip.
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: mamba-org/setup-micromamba@v2
19
+ with:
20
+ environment-file: environment.yml
21
+ cache-environment: true
22
+
23
+ - name: Install the package itself
24
+ shell: bash -el {0}
25
+ run: pip install -e . --no-deps
26
+
27
+ # Gating. Runs the pinned hooks from .pre-commit-config.yaml rather than
28
+ # whatever ruff happens to be on PATH, so CI and a local commit apply the
29
+ # same version and the same rule selection. Grading against ambient-latest
30
+ # is what made the first run of this workflow fail on untouched code.
31
+ - name: Lint
32
+ shell: bash -el {0}
33
+ run: pre-commit run --all-files --show-diff-on-failure
34
+
35
+ # Integration tests are excluded: they hit live NOAA, USGS and Planetary
36
+ # Computer endpoints, take 10 to 12 minutes, and depend on a prebuilt
37
+ # NOAA spatial index. Run them locally or via workflow_dispatch.
38
+ - name: Unit tests
39
+ shell: bash -el {0}
40
+ run: python -m pytest tests/unit -m "not integration" --durations=10
41
+
42
+ # The FastAPI service suite mocks run(), so it needs no network or cache and
43
+ # finishes in a few seconds. It covers the /fuse zarr export and the DEM
44
+ # viewer cache, which the library unit tests do not reach.
45
+ - name: Service tests
46
+ shell: bash -el {0}
47
+ run: python -m pytest service/tests -m "not integration" --durations=10
@@ -0,0 +1,154 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+
131
+ # pytype static type analyzer
132
+ .pytype/
133
+
134
+ # Cython debug symbols
135
+ cython_debug/
136
+
137
+ # Editors
138
+ .vscode/
139
+ .idea/
140
+ *.swp
141
+ *.swo
142
+
143
+ # AI Agents
144
+ .claude/
145
+ .gemini/
146
+ memory
147
+
148
+ # Project Specific
149
+ data/
150
+ logs/
151
+ *.nc
152
+ *.tif
153
+ *.laz
154
+ *.copc.laz
@@ -0,0 +1,5 @@
1
+ default: true
2
+ MD013: false # line-length: Disable (too strict for documentation/URLs)
3
+ MD033: false # no-inline-html: Disable (needed for centering/resizing images)
4
+ MD003: # heading-style
5
+ style: atx # Enforce hash-style headers
@@ -0,0 +1,37 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: check-added-large-files
9
+ args: ["--maxkb=500000"]
10
+ - id: check-toml
11
+
12
+ # Pinned deliberately. This rev is the authoritative linter version for the
13
+ # repo; CI runs these same hooks so there is one standard everywhere. Bump it
14
+ # as its own reviewed change, never implicitly.
15
+ - repo: https://github.com/astral-sh/ruff-pre-commit
16
+ rev: v0.16.9
17
+ hooks:
18
+ - id: ruff-check
19
+ args: [--fix]
20
+ - id: ruff-format
21
+
22
+ - repo: local
23
+ hooks:
24
+ - id: mypy
25
+ name: mypy
26
+ entry: mypy
27
+ language: system
28
+ types: [python]
29
+ require_serial: true
30
+ args: ["--ignore-missing-imports", "--explicit-package-bases"]
31
+
32
+ - repo: https://github.com/igorshubovych/markdownlint-cli
33
+ rev: v0.39.0
34
+ hooks:
35
+ - id: markdownlint
36
+ language_version: 20.10.0
37
+ args: ["--fix"]
@@ -0,0 +1,179 @@
1
+ # Contributing to topobathykit
2
+
3
+ topobathykit is a policy-driven **topobathymetric fusion runtime** (library + optional service). The core idea is to fuse heterogeneous geospatial layers into data-first products (`xarray.Dataset`) with **per-pixel provenance**.
4
+
5
+ We welcome contributions, especially **new dataset providers** and **policy presets** for regions outside our initial Northeast US focus.
6
+
7
+ ## Project principles
8
+
9
+ 1. **Data-first outputs**
10
+ - The canonical output is an `xarray.Dataset` (not PNGs).
11
+ - Visual tiles and the viewer exist primarily for QA/provenance debugging.
12
+
13
+ 2. **Overwrite in trusted zones; blend in transition zones**
14
+ - Survey “truth” should win where present.
15
+ - Use operators (seamline feathering, logistic blend, etc.) to avoid hard seams at coverage boundaries.
16
+
17
+ 3. **Provenance is first-class**
18
+ - Every fused variable must have a corresponding source mask (e.g., `source_elevation`).
19
+ - Assumptions must be explicit: CRS, vertical reference/datum, transforms, and caveats belong in metadata.
20
+
21
+ 4. **Policy-driven behavior**
22
+ - Fusion strategies are defined in YAML policy presets (selected by filename).
23
+ - New fusion logic should generally be expressed as:
24
+ - a new **operator**, and/or
25
+ - a new **policy preset**, rather than hardcoding rules into the runtime.
26
+
27
+ 5. **International-friendly by default**
28
+ - Avoid US-specific assumptions in core logic.
29
+ - Region-specific logic belongs in providers and policy presets.
30
+
31
+ ## Ways to contribute
32
+
33
+ ### 1) Add a dataset provider (high value)
34
+
35
+ Providers are the main extension mechanism. A provider is responsible for:
36
+
37
+ - fetching/streaming remote data
38
+ - caching for offline replay
39
+ - normalizing CRS/metadata
40
+ - returning an `xarray.DataArray` + provider metadata
41
+
42
+ When adding a provider:
43
+
44
+ - Include dataset citation + license/terms (and any attribution requirements).
45
+ - Prefer stable endpoints (STAC, COG, COPC, OPeNDAP).
46
+ - Handle “data missing” gracefully: return `None` (or an empty/NaN layer) rather than synthesizing data.
47
+
48
+ ### 2) Add a policy preset (high value)
49
+
50
+ Policy presets are YAML files under `policies/` and act as shareable “domain knowledge”:
51
+
52
+ - provider ordering per zone
53
+ - transition blending operators
54
+ - variable-specific strategies (elevation vs covariates)
55
+
56
+ Good presets include:
57
+
58
+ - a short description and intended region/use case
59
+ - recommended bounding boxes for demos
60
+ - expectations about coverage and vertical reference
61
+
62
+ ### 3) Add an operator or QA test
63
+
64
+ Operators are small, testable functions used by policies (e.g., seamline feathering in meters).
65
+ Operators should:
66
+
67
+ - be deterministic
68
+ - work globally (CRS-aware; distances in meters)
69
+ - come with unit tests using synthetic rasters (no network access)
70
+
71
+ ### 4) Improve docs and onboarding
72
+
73
+ Especially valuable:
74
+
75
+ - provider authoring docs
76
+ - policy authoring docs
77
+ - “iconic presets” walkthroughs (e.g., Great Barrier Reef)
78
+
79
+ ## Development setup
80
+
81
+ We recommend **Micromamba** (or Mamba/Conda) for development because topobathykit depends on compiled geospatial libraries such as GDAL/PDAL.
82
+
83
+ ### Option A: Micromamba (recommended)
84
+
85
+ ```bash
86
+ micromamba create -f environment.yml
87
+ micromamba activate topobathykit
88
+ pip install -e .
89
+ ```
90
+
91
+ ### Option B: Python venv (pip)
92
+
93
+ If you prefer standard Python tooling, you must install system-level dependencies for GDAL/PDAL yourself.
94
+
95
+ ```bash
96
+ python -m venv .venv
97
+ source .venv/bin/activate
98
+ pip install -e ".[test]"
99
+ ```
100
+
101
+ ## Troubleshooting & Known Issues
102
+
103
+ ### "Too many open files" (Errno 24) on macOS
104
+
105
+ If you encounter `[Errno 24] Too many open files` when running large fusions or processing many tiles, you may be hitting the operating system's file descriptor limit. This is common when working with Zarr-backed datasets (like `ncei_bag`) which can open many small files simultaneously.
106
+
107
+ On macOS, the default limit is often low (256). To fix this, increase the limit in your shell:
108
+
109
+ ```bash
110
+ ulimit -n 10240
111
+ ```
112
+
113
+ For a persistent fix, you may need to configure `limit maxfiles` via `launchctl`.
114
+
115
+ ## Code quality tooling
116
+
117
+ ### Pre-commit hooks
118
+
119
+ We use [pre-commit](https://pre-commit.com/) for formatting, linting, and type checks.
120
+
121
+ ```bash
122
+ pip install pre-commit
123
+ pre-commit install
124
+ pre-commit run --all-files
125
+ ```
126
+
127
+ ### Type checking
128
+
129
+ - All new code must be type-hinted.
130
+ - Run:
131
+
132
+ ```bash
133
+ mypy
134
+ ```
135
+
136
+ ### Tests
137
+
138
+ - Run unit tests:
139
+
140
+ ```bash
141
+ pytest
142
+ ```
143
+
144
+ #### Network and dataset tests
145
+
146
+ If you add tests that require network access or large external downloads, mark them clearly (e.g., `@pytest.mark.network`) and keep them **opt-in** so CI remains stable.
147
+
148
+ ## Contribution workflow
149
+
150
+ 1. Fork the repository.
151
+ 2. Create a feature branch.
152
+ 3. Make changes with small, reviewable commits.
153
+ 4. Add/extend tests.
154
+ 5. Update docs (README, policies/README, provider docs) as needed.
155
+ 6. Open a Pull Request describing:
156
+ - what changed
157
+ - how to test
158
+ - dataset citations/licenses (if you added a provider or preset)
159
+ - any known limitations (CRS, datum, coverage)
160
+
161
+ ## Guidance for provider PRs (checklist)
162
+
163
+ - [ ] Provider returns a valid `xarray.DataArray` for the requested bbox (or `None` if unavailable)
164
+ - [ ] Provider caches downloads locally for offline replay
165
+ - [ ] Provider metadata includes citation and license/terms
166
+ - [ ] Vertical reference/datum is declared (or explicitly `"Unknown"`)
167
+ - [ ] Policy preset added/updated to demonstrate usage
168
+ - [ ] Provenance/source mask reflects the provider where it contributes
169
+ - [ ] Unit tests added (synthetic where possible); network tests opt-in
170
+
171
+ ## Community norms
172
+
173
+ We aim for:
174
+
175
+ - clear, technical discussions
176
+ - explicit assumptions and reproducibility
177
+ - regionally inclusive contributions (providers and presets from outside the US are especially welcome)
178
+
179
+ Thank you for helping build a long-lived open-source fusion framework.
@@ -0,0 +1,68 @@
1
+ # syntax=docker/dockerfile:1
2
+ # Tested on: NVIDIA Jetson AGX Orin (JetPack 6.x / l4t r36), x86_64 (Ubuntu 24.04 + CUDA 12.x),
3
+ # and macOS (Apple Silicon / OrbStack)
4
+ # Override BASE_IMAGE at build time for your target platform:
5
+ # Jetson Orin: --build-arg BASE_IMAGE=nvcr.io/nvidia/l4t-jetpack:r36.2.0
6
+ # x86_64/WSL2 GPU: --build-arg BASE_IMAGE=nvidia/cuda:12.6.3-devel-ubuntu24.04 (default)
7
+ # macOS / no GPU: --build-arg BASE_IMAGE=ubuntu:24.04 (multi-arch; pulls arm64 on Apple Silicon)
8
+ ARG BASE_IMAGE=nvidia/cuda:12.6.3-devel-ubuntu24.04
9
+ FROM ${BASE_IMAGE}
10
+
11
+ WORKDIR /app
12
+
13
+ # Minimal apt: only curl + bzip2 to bootstrap micromamba.
14
+ # All geo libs (GDAL/NetCDF4 via rasterio manylinux wheel, PDAL via conda-forge),
15
+ # Python, cmake, and ninja come from conda-forge or pip — no universe repo needed.
16
+ RUN apt-get update && apt-get install -y --no-install-recommends \
17
+ curl \
18
+ bzip2 \
19
+ ca-certificates \
20
+ && rm -rf /var/lib/apt/lists/*
21
+
22
+ # Alias python to python3
23
+ RUN ln -sf /usr/bin/python3 /usr/bin/python
24
+
25
+ # Install micromamba
26
+ RUN curl -Ls "https://micro.mamba.pm/api/micromamba/$(uname -m | sed 's/x86_64/linux-64/;s/aarch64/linux-aarch64/;s/arm64/linux-aarch64/')/latest" | \
27
+ tar -xvj -C /usr/local/bin/ --strip-components=1 bin/micromamba
28
+
29
+ # Create the Python environment via micromamba. Includes:
30
+ # - python 3.12 with headers (for building C extensions)
31
+ # - pdal + python-pdal (only available pre-built via conda-forge, not PyPI)
32
+ # - cmake + ninja (build tools, avoids needing apt universe)
33
+ RUN micromamba create -y -p /app/.venv -c conda-forge \
34
+ "python=3.12" \
35
+ "pdal>=2.7" \
36
+ "python-pdal" \
37
+ "cmake" \
38
+ "ninja" && \
39
+ micromamba clean -q --all
40
+
41
+ ENV PATH="/app/.venv/bin:$PATH"
42
+
43
+ # Pre-install build requirements to avoid build-isolation issues (like NumPy 2.0)
44
+ RUN pip install --upgrade pip setuptools wheel
45
+ RUN pip install Cython hatchling scikit-build py-cpuinfo setuptools_scm
46
+
47
+ # Copy Library and install it
48
+ # We assume the build context is the root of topobathykit/
49
+ COPY pyproject.toml README.md LICENSE ./
50
+ COPY src ./src
51
+ RUN pip install --no-build-isolation .
52
+
53
+ # Copy Service dependencies and install service
54
+ COPY service ./service
55
+ RUN pip install ./service --no-deps && pip install fastapi uvicorn[standard] pydantic-settings fastapi-cache2[redis] click
56
+
57
+ # Default port 9595
58
+ EXPOSE 9595
59
+
60
+ # Set pythonpath so it finds topobathyserve
61
+ ENV PYTHONPATH="/app:/app/src:/app/service"
62
+
63
+ # Fix ownership so non-root users can write to logs
64
+ ARG UID=1000
65
+ ARG GID=1000
66
+ RUN chown -R ${UID}:${GID} /app
67
+
68
+ CMD ["uvicorn", "topobathyserve.main:app", "--host", "0.0.0.0", "--port", "9595", "--workers", "2"]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.