"""Assemble exact released inputs from committed, spatially aligned observations.""" from pathlib import Path import argparse,json import numpy as np from .legacy_sentinel import predictors,sha,parse,cutoff def assemble(scene_dir,normalization,modis_pair=None,no_modis=False): scene_dir=Path(scene_dir);meta_path=scene_dir/'metadata.json';meta=json.loads(meta_path.read_text()) if meta['geometry']['shape'] != [256,256]:raise ValueError('This checkpoint requires 256x256 at 20m') transform=meta['geometry']['transform'] if not np.allclose([transform[0],transform[1],transform[3],transform[4]],[20,0,0,-20],atol=1e-9,rtol=0):raise ValueError('Use the original north-up 20m scene grid') stats=json.loads(Path(normalization).read_text()) # Keep the production functions' floating-point order, S1 float64 logarithm, # radiometry, masks, SCL one-hot encoding, calendar and last-clear anchor. p,_,_=predictors({'folder':str(scene_dir),'metadata_sha256':sha(meta_path)},stats) p.pop('modis') for key in ['s2_quality','s2_quality_valid']:p[key]=p[key].astype(bool).astype(np.float32) with np.load(scene_dir/'context.npz',allow_pickle=False) as z: geo=z['geo'][-5:].copy();ages=z['geo_age'][-5:].copy();times=z['geo_times'][-5:].copy();land=z['landcover'].copy() if land.ndim==2: valid=z['landcover_valid'].astype(bool) land=np.concatenate([(land==np.arange(1,18)[:,None,None])&valid,valid[None]],axis=0) assert geo.shape==(5,3,256,256) and land.shape==(18,256,256) and ages.shape==(5,) for index,stamp in enumerate(times): if stamp: observed=parse(str(stamp));assert str(stamp)[:10]==meta['date'] and observed