s2_res / preprocessing /README.md
riccardode's picture
Add minimal raw-data preprocessing for MODIS-to-S2 inputs (#2)
33dd50b
|
Raw History Blame Contribute Delete
3.72 kB

Raw observations to inputs.npz

This folder contains the preprocessing for the released MODIS-to-Sentinel-2 model. It produces normalized input arrays; use the repository's existing normalization.json unchanged. Tensor definitions are in INPUTS.md.

Usage

From the repository root, with Python 3.11:

python -m pip install -r preprocessing/requirements.txt
cp preprocessing/manifest.example.json scene.json
# Edit scene.json for your grid, acquisition IDs/times and local source paths.
python -m preprocessing.raw --manifest scene.json \
  --aligned-output work/scene --output work/scene/inputs.npz

The output directory contains inputs.npz and its georeferencing metadata.json. It must be a new directory. The example manifest documents a complete input configuration; the referenced data files are not included. recipe.json documents the fixed preprocessing conventions used by the model.

Sources in the manifest

  • S1: georeferenced RTC VV/VH rasters in linear power, with observation timestamps and processing metadata. The code converts positive power to dB once and applies the released training normalization.
  • S2: native L2A DN rasters for B01, B02, B03, B04, B05, B06, B07, B08, B8A, B09, B11, B12 and SCL. Supply the original product metadata XML using product_metadata_xml, or its authoritative BOA quantification/offsets in radiometry. Keep cloudy observations: SCL and measurement masks are separate.
  • MODIS: exact target-day MOD09GQ and matching MOD09GA Collection 061 HDF4 products, with the same tile/date/production. Their common numeric/QA support preserves the released model's paired 250m/500m input recipe.
  • MTG: archived native FCI vis_06/vis_08 patches, one NPZ per candidate, with keys vis_06, vis_08, origin. origin is the native full-disk [row0, col0] shared by both bands. Preserve the archive's units and row orientation. For each observation provide the three nearest available source grids in their original rank order. The code performs geostationary mapping, bilinear sampling, support checks, scaling and five-slot padding.
  • Land cover: georeferenced MCD12Q1 LC_Type1 categorical raster, preserving its native grid and nodata. The original archive's year was not verified.

All paths are relative to the manifest. Its geometry specifies the actual 256 x 256, north-up, 20m output grid; do not infer a footprint from array size. The reader accepts explicitly selected source assets. Catalogue search, downloads, and the upstream FCI L1C-to-archive conversion are outside this entry point. No source imagery is overwritten.

Select prior S2 products from the same MGRS tile, one per date, in chronological order. Exclude the target and target-day S2. Prior S1 must have a common known orbit direction/relative orbit and cover the footprint. The newer original cohort requested eight S2 dates and up to six S1 dates, with at least two S1; preserve the actual committed history when reproducing an existing scene.

Already aligned observations

If the native products have already been assembled into the original aligned sentinel.npz (or legacy conditioning.npz), context.npz and paired_modis.npz, together with their metadata.json:

python -m preprocessing.assemble --scene-dir aligned_scene \
  --output aligned_scene/inputs.npz

The released input assembly reads no target image. It uses original product timestamps, a cutoff at midnight ending the target UTC day, and train-only normalization. Do not normalize the output again. This preserves retrospective input conventions; it does not certify historical real-time product availability.