CLIMED Runs 1-3 — Multi-GCM Step 2 climate-NaN hotfix
Date: 2026-10-24

Reported error:
  MULTI-GCM: reused validated median input ... combined_median_climate.nc
  ValueError: INVALID CLIMATE: temperature contains missing source values or dates

CAUSE ADDRESSED
The v1 median-input preprocessor merged all GLOBAL GCM grids and did not check
for invalid values before marking the combined file as reusable. Differences in
global grid endpoints/coverage can create NaNs during spatial interpolation,
including at poles or edges far outside India. The existing Step 2 safeguard then
stops, as it should.

WHAT CHANGED
ONLY app/core/climate_median.py is replaced.
- Reads the same CLIMED study shapefile boundary used by the existing solver.
- Crops each source to the India region plus a generous spatial interpolation halo
  BEFORE checking for missing source values.
- Creates the median on the finest available native climate grid over the region,
  with a small padding halo for CLIMED's existing common-grid interpolation.
- Preserves original daily conversion, full-member median (skipna=False), no
  spatial/temporal gap filling and the existing biological/SEI solver unchanged.
- Validates all three combined fields are finite before accepting an output or
  reusing a cache. Errors include missing-data diagnostics.
- Changes module version/fingerprint, automatically replacing the OLD cached
  combined_median_climate.nc when Steps 1/2/3 next run.

INSTALL ON THE WINDOWS FOLDER FROM THE ERROR
1. Close the CLIMED GUI.
2. Locate:
     D:\CliMed_Methods_Audit_Candidate_CodeOnly_2026-10-21\app\core\climate_median.py
3. Make a backup copy of that one file.
4. Copy app\core\climate_median.py from this ZIP over the old file, maintaining
   the same relative directory. DO NOT replace run_cli_step2.py or any solver.
5. Start CLIMED, keep your existing config and selected historical model folders.
6. Run Step 1 (preflight), then Step 2. The first run SHOULD print
     MULTI-GCM: saved one combined input ...
   rather than reusing the old v1 global median file.
7. If the inputs contain missing values IN INDIA or missing dates, the strict
   source validation will still stop. Please share the NEW error and the
   combined_median_manifest.json if available. Do NOT turn off the safety check.

VALIDATION
Synthetic three-GCM test with differing global grid endpoints, invalid polar
cells, and 17 daily samples passed the combined-input roundtrip through CLIMED's
existing load_climate_dataset() and standardize_daily() with zero gap flags.
An intentionally missing temperature source value inside India was correctly
rejected. Actual user's Windows data and the complete 10-year run not tested.
