# shr-aditya/gwsa-stage-0b architecture

> Architecture diagram of the GitHub repository shr-aditya/gwsa-stage-0b, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shr-aditya/gwsa-stage-0b
- Repository: https://github.com/shr-aditya/gwsa-stage-0b

## Overview

This single-file scientific workflow derives Stage 0B groundwater-storage anomalies from GLDAS-2.2 GRACE-DA data. Its principal flow inventories input files, processes them in either gridded or study-area-mean mode, aggregates valid daily GWS to monthly values, computes a fixed 2004–2009 reference and anomaly, and writes mode-specific outputs. The script also documents water-balance checks and an optional seasonal diagnostic. The graph reflects only relationships visible in the excerpts; some internal processing details and output calls are not shown.

Main entry points: [`gwsa_stage0b.py`](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py) (Grid processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Input and spatial setup"]
  node_inventory["File inventory<br/>[gwsa_stage0b.py]"]
  node_metadata_qc["Metadata and units<br/>[gwsa_stage0b.py]"]
  node_spatial_prep["Spatial preparation<br/>[gwsa_stage0b.py]"]
end

subgraph group_processing["GWS processing"]
  node_grid_mode["Grid processing<br/>[gwsa_stage0b.py]"]
  node_area_mode["Study-area processing<br/>[gwsa_stage0b.py]"]
  node_clean_mask["Cleaning and masks<br/>[gwsa_stage0b.py]"]
  node_daily_gws["Daily GWS states<br/>[gwsa_stage0b.py]"]
  node_monthly_gws["Monthly GWS states<br/>[gwsa_stage0b.py]"]
end

subgraph group_analysis["Analysis and diagnostics"]
  node_water_balance["Water-balance checks<br/>[gwsa_stage0b.py]"]
  node_reference["Fixed-mean reference<br/>[gwsa_stage0b.py]"]
  node_gwsa["Fixed-mean GWSA<br/>[gwsa_stage0b.py]"]
  node_seasonal["Seasonal diagnostic<br/>[gwsa_stage0b.py]"]
  node_gap_flag["GRACE-gap flag<br/>[gwsa_stage0b.py]"]
end

subgraph group_outputs["Products"]
  node_netcdf_output["Grid NetCDF<br/>[gwsa_stage0b.py]"]
  node_csv_output["Area-mean CSV<br/>[gwsa_stage0b.py]"]
end

node_source_files["GLDAS input files"]
node_boundary_data["Study boundary"]

node_source_files -->|"scans pattern"| node_inventory
node_inventory -->|"dispatches files"| node_grid_mode
node_inventory -->|"dispatches files"| node_area_mode
node_boundary_data -->|"provides geometry"| node_spatial_prep
node_grid_mode -->|"logs and validates"| node_metadata_qc
node_grid_mode -->|"clips spatially"| node_spatial_prep
node_grid_mode -->|"cleans variables"| node_clean_mask
node_clean_mask -->|"produces valid states"| node_daily_gws
node_daily_gws -->|"aggregates daily"| node_monthly_gws
node_grid_mode -->|"checks variables"| node_water_balance
node_monthly_gws -->|"computes baseline"| node_reference
node_monthly_gws -->|"subtracts reference"| node_gwsa
node_reference -->|"supplies baseline"| node_gwsa
node_monthly_gws -->|"computes diagnostic"| node_seasonal
node_grid_mode -->|"flags missing period"| node_gap_flag
node_grid_mode -->|"saves results"| node_netcdf_output
node_area_mode -->|"builds area weights"| node_spatial_prep
node_area_mode -->|"saves results"| node_csv_output

click node_inventory "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_metadata_qc "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_spatial_prep "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_grid_mode "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_area_mode "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_clean_mask "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_daily_gws "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_monthly_gws "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_water_balance "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_reference "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_gwsa "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_seasonal "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_gap_flag "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_netcdf_output "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"
click node_csv_output "https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_inventory,node_metadata_qc,node_spatial_prep toneBlue
class node_grid_mode,node_area_mode,node_clean_mask,node_daily_gws,node_monthly_gws toneAmber
class node_water_balance,node_reference,node_gwsa,node_seasonal,node_gap_flag toneMint
class node_netcdf_output,node_csv_output toneRose
class node_source_files,node_boundary_data toneIndigo
```

## Components

### Input and spatial setup

- [File inventory](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Metadata and units](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Spatial preparation](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`

### GWS processing

- [Grid processing](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Study-area processing](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Cleaning and masks](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Daily GWS states](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Monthly GWS states](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`

### Analysis and diagnostics

- [Water-balance checks](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Fixed-mean reference](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Fixed-mean GWSA](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Seasonal diagnostic](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [GRACE-gap flag](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`

### Products

- [Grid NetCDF](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`
- [Area-mean CSV](https://github.com/shr-aditya/gwsa-stage-0b/blob/main/gwsa_stage0b.py): `gwsa_stage0b.py`

### Other components

- **GLDAS input files**
- **Study boundary**

## Connections

- GLDAS input files → File inventory: scans pattern (evidence: `gwsa_stage0b.py`)
- File inventory → Grid processing: dispatches files (evidence: `gwsa_stage0b.py`)
- File inventory → Study-area processing: dispatches files (evidence: `gwsa_stage0b.py`)
- Study boundary → Spatial preparation: provides geometry (evidence: `gwsa_stage0b.py`)
- Grid processing → Metadata and units: logs and validates (evidence: `gwsa_stage0b.py`)
- Grid processing → Spatial preparation: clips spatially (evidence: `gwsa_stage0b.py`)
- Grid processing → Cleaning and masks: cleans variables (evidence: `gwsa_stage0b.py`)
- Cleaning and masks → Daily GWS states: produces valid states (evidence: `gwsa_stage0b.py`)
- Daily GWS states → Monthly GWS states: aggregates daily (evidence: `gwsa_stage0b.py`)
- Grid processing → Water-balance checks: checks variables (evidence: `gwsa_stage0b.py`)
- Monthly GWS states → Fixed-mean reference: computes baseline (evidence: `gwsa_stage0b.py`)
- Monthly GWS states → Fixed-mean GWSA: subtracts reference (evidence: `gwsa_stage0b.py`)
- Fixed-mean reference → Fixed-mean GWSA: supplies baseline (evidence: `gwsa_stage0b.py`)
- Monthly GWS states → Seasonal diagnostic: computes diagnostic (evidence: `gwsa_stage0b.py`)
- Grid processing → GRACE-gap flag: flags missing period (evidence: `gwsa_stage0b.py`)
- Grid processing → Grid NetCDF: saves results (evidence: `gwsa_stage0b.py`)
- Study-area processing → Spatial preparation: builds area weights (evidence: `gwsa_stage0b.py`)
- Study-area processing → Area-mean CSV: saves results (evidence: `gwsa_stage0b.py`)
