How apasto/decorrelate-grids works
1. Repository role
- This is a small Python package, not an application server or service.
- Its purpose is to compute windowed linear decorrelation between two same-shaped 2-D grids, producing fitted coefficient grids and residuals.
2. Top-level package boundary
- The actual runtime code lives in the decorrelategrids/ package.
- readme_figures/ is documentation-only.
- pyproject.toml and environment.yml define packaging and dependencies; they matter because the project is intended to run in a Python scientific stack, likely with xarray and netCDF support.
3. Main subsystems
- decorrelategrids/rollinglinreg.py: the numerical core for rolling ordinary-least-squares regression.
- decorrelategrids/cliwrapper.py: the command-line entry point and I/O orchestration.
- decorrelategrids/__init__.py: package marker and likely exports/version surface.
4. Primary data flow
- Input: two aligned 2-D arrays/grids, referred to in the README as A and B.
- The core algorithm slides a local window over each valid interior pixel.
- For each window, it fits A = c0 + c1 * B.
- Output: coefficient grids for c0 and c1, plus a residual grid epsilon = A - fitted(A).
5. Computation boundary
- The math layer is intended to be format-agnostic in principle.
- In practice, the current implementation is tied to xarray/netCDF at the edges, because the README says the script reads and writes netCDF files.
- That means the architecture is split between a reusable algorithm core and a file-format wrapper.
6. Rolling regression behavior
- The window is boxcar-shaped and centered on each pixel, with a configurable half-width in rows and columns.
- No fit is performed on edge pixels where the full window would exceed array bounds.
- No fit is performed when the target pixel or any required input is NaN.
- The only implemented model is ordinary least squares; there is no generic model-plug-in system yet.
7. Output semantics
- The package does not just return a single decorrelated grid.
- It also returns the spatially varying fitted coefficients, which are first-class results.
- This matters for architecture diagrams because the output is a small product family: intercept grid, slope grid, and residual grid.
8. CLI subsystem
- cliwrapper.py is the user-facing entry point exposed as the decorrelategrids command.
- Its job is to parse user options, load grid data, call the regression core, and persist results.
- So the CLI is an orchestration layer rather than a computational layer.
9. Runtime and tooling
- The project targets standard Python packaging and local installation.
- The docs explicitly mention pip, editable installs, uv, and Conda, so it is meant to run in common scientific Python environments.
- Lint/config files (.flake8, .isort.cfg, .markdownlint.yaml) indicate a lightweight repository focused on code quality, not on a larger build pipeline.
10. Domain-specific design constraint
- The code was motivated by InSAR tropospheric-delay mitigation, but the implementation is intentionally domain-neutral.
- That means the architecture should be drawn as a general grid-regression tool with an optional geoscience use case, not as an InSAR application.
11. Current maturity boundary
- The README labels the project as a concept / early-stage prototype.
- Architecturally, that means the core shape is present, but extensibility points are limited and the format dependence is still part of the design.
12. What an architecture diagram should show
- Two input grids enter a CLI/IO layer.
- The CLI hands them to a rolling regression engine.
- The engine performs local-window OLS over valid pixels only.
- The outputs are coefficient grids and a residual grid, which are written back out through the same I/O layer.
Main entry points: README.md README docs · rollinglinreg.py Rolling OLS · __init__.py Package API · cliwrapper.py CLI entry
Components 16
Runtime package
Installable Python package containing the CLI and numerical core.
- CLI entry · User-facing `decorrelategrids` command exposed by the package.
decorrelategrids/cliwrapper.py - Grid I/O · Reads aligned grid inputs and writes coefficient/residual outputs, likely through netCDF/xarray.
decorrelategrids/cliwrapper.py - Rolling OLS · Sliding-window ordinary least squares over two same-shaped 2-D grids.
decorrelategrids/rollinglinreg.py - Window scan · Centers a boxcar window on each interior pixel and skips edge pixels without a full window.
decorrelategrids/rollinglinreg.py - OLS fit · Fits `A = c0 + c1 * B` within each valid window.
decorrelategrids/rollinglinreg.py - Valid pixels · Excludes pixels or windows containing required missing values from fitting.
decorrelategrids/rollinglinreg.py - Coeff grids · Spatial grids for intercept `c0` and slope `c1`.
decorrelategrids/rollinglinreg.py - Residual grid · Residual field `epsilon = A - fitted(A)` returned as a first-class result.
decorrelategrids/rollinglinreg.py - Package API · Package marker and export surface for the installable module.
decorrelategrids/__init__.py
Docs and examples
Repository content for README visuals and issue templates.
- README docs · Project narrative, usage, and conceptual figures.
README.md - Figures · Static assets used by the README and documentation.
readme_figures - Issue template · GitHub issue template for bug reports.
.github/ISSUE_TEMPLATE/bug_report.md
Packaging and config
Project metadata, dependency definitions, and lightweight repo tooling.
- Python stack · Scientific Python runtime used by the package.
pyproject.toml - Dependencies · Declares project dependencies and installation metadata.
pyproject.toml - Conda env · Alternative scientific environment definition.
environment.yml - Lint config · Lightweight code-quality settings for formatting and linting.
.flake8
Connections 20
- CLI entry → Grid I/O: orchestrates · CLI coordinates file loading and result writing.
- Grid I/O → Rolling OLS: calls · I/O layer hands arrays to the numerical engine.
- Rolling OLS → Window scan: slides · Core iterates a centered boxcar window over the grid.
- Window scan → OLS fit: feeds · Each valid window is passed to the regression step.
- Valid pixels → OLS fit: filters · Missing data and invalid pixels suppress a fit.
- OLS fit → Coeff grids: produces · Regression emits intercept and slope grids.
- OLS fit → Residual grid: produces · Regression emits a residual grid alongside coefficients.
- Rolling OLS → Coeff grids: returns · Core returns fitted coefficient products.
- Rolling OLS → Residual grid: returns · Core returns residuals as part of the output family.
- Package API → Rolling OLS: exposes · Package surface can expose the main algorithm entry points.
- Package API → CLI entry: exposes · Package surface can expose CLI-facing symbols.
- README docs → CLI entry: describes · README explains the command-line workflow.
- README docs → Rolling OLS: describes · README documents the rolling decorrelation algorithm.
- README docs → Coeff grids: documents · Docs treat coefficient grids as primary outputs.
- README docs → Residual grid: documents · Docs describe the residual decorrelation product.
- Figures → README docs: supports · Figures are used as documentation assets.
- Dependencies → Python stack: targets · Packaging metadata defines the Python runtime stack.
- Conda env → Python stack: mirrors · Conda environment mirrors the scientific Python setup.
- Lint config → Package API: governs · Repo tooling enforces lightweight code quality on the package.
- Issue template → README docs: extends · Issue template supports the repository documentation workflow.