# Methods (paper-ready) Method descriptions for all three phases, written for direct reuse in a manuscript. Operational commands live in the per-phase READMEs and [REPRODUCTION.md](REPRODUCTION.md); this document is the prose. ## Study inputs and label schema **Inputs.** Georeferenced raster imagery (GeoTIFF) as orthomosaics or large mosaicked products: RGB orthomosaics, multispectral imagery (commonly 10-band stacks), and hyperspectral cubes (Specim FX10 / FX17, band wavelengths read from ENVI headers). **Label schema.** The default semantic segmentation classes are `BE=0`, `NPV=1`, and `PV=2`. Additional classes can be appended at runtime with `FVC_EXTRA_CLASS_LABELS`. **NoData handling.** Pixels outside valid annotation extents are represented as NoData/ignored labels and mapped to `-1` for training (ignore index). ## Phase 1 — Image preprocessing and tiling **Objective.** Convert large orthomosaics into fixed-size, spatially aligned tiles suitable for annotation and model training. 1. **(Optional) Reprojection / raster preparation** - Utilities in `phase_1_image_processing/step_1_rasterReprojection/` support harmonising spatial reference systems and preparing rasters for downstream processing. 2. **Tiling orthomosaics** - Large rasters are split into square tiles using GDAL window extraction. A representative implementation is in: - [phase_1_image_processing/step_2_orthomosaic_to_tiling/b_tiling_3072_rgb/2_1_imageProcessing_tiling_3072_rgb.py](../phase_1_image_processing/step_2_orthomosaic_to_tiling/b_tiling_3072_rgb/2_1_imageProcessing_tiling_3072_rgb.py) - Typical tile size is `3072×3072` pixels (script defaults), written as GeoTIFF. 3. **Grid-based clipping (QGIS-assisted)** - The workflow supports clipping by a vector grid (e.g., for selecting annotated regions) using OGR/GDAL, e.g.: - `phase_1_image_processing/step_2_orthomosaic_to_tiling/a_qgis/`. #### Row-major tile IDs (top-left → right → next row) If you want 256×256 tiles to be numbered in the same spatial order as they appear in the full orthomosaic (top-left to right across rows, then continuing on the next row), you should reindex the 256-grid shapefile so its `id` field follows **row-major order in CRS coordinates**. This is especially helpful when: - Your imagery was first tiled into 3072×3072 “big tiles”, and you then want consistent 256×256 sub-tiles. - You want filenames like `tiles_multispectral_.tif` to increase left→right across the map. **Step 1 — reindex the 256 grid shapefile** Create a new shapefile (recommended) with `id` rewritten in row-major order: ```bash python phase_1_image_processing/utils/reindex_grid_rowmajor.py \ --in-shp /data/calperumResearch/site1_1_DD0001/imagery/inputs/masks/tiles_3072/pv_class/annotations/gridding/grid_annotation_extraLabels_256.shp \ --out-shp /data/calperumResearch/site1_1_DD0001/imagery/inputs/masks/tiles_3072/pv_class/annotations/gridding/grid_annotation_extraLabels_256_rowmajor.shp \ --id-field id \ --start 1 ``` **Step 2 — use the row-major grid in your clipper** In your tiling/clipping script (example): - [phase_1_image_processing/step_2_orthomosaic_to_tiling/c_tiling_3072_multispec/2_2_clip_shp_gridAnnotation_MULTISPECTRALsampling_256m.py](../phase_1_image_processing/step_2_orthomosaic_to_tiling/c_tiling_3072_multispec/2_2_clip_shp_gridAnnotation_MULTISPECTRALsampling_256m.py) Set: - `clip_grid_shapefile_path = '.../grid_annotation_extraLabels_256_rowmajor.shp'` - keep `grid_id_field = 'id'` Now the output filenames will follow that global row-major ordering: - `tiles_multispectral_.tif` - `mask_tiles_multispectral_.tif` 4. **Random sampling of tile pairs (quality control / annotation efficiency)** - For paired products (e.g., RGB and multispectral/hyperspectral), tiles can be sampled such that corresponding tile IDs match across modalities. White-saturated RGB tiles can be rejected to reduce unusable samples. - Implementation example: - [phase_1_image_processing/step_3_randomSampling/3_1_random_sampling.py](../phase_1_image_processing/step_3_randomSampling/3_1_random_sampling.py) 5. **Global statistics and percentile stretch (visualisation support)** - The workflow includes scripts under `phase_1_image_processing/step_4_globalStats_percentileStretch/` to compute global statistics and apply percentile-based contrast stretching for visual composites used during manual annotation. 6. **Band stacking / band selection** - For multispectral stacks, band subsets can be extracted to create reduced predictor sets (e.g., selecting 5 informative bands from a 10-band stack). - For hyperspectral workflows, matching Specim FX10 and FX17 ENVI tiles can be resampled onto the FX10 grid and stacked into a single predictor cube with: ```bash python utils/stack_fx10_fx17_tiles_envi.py --overwrite ``` - Implementation example: - [phase_1_image_processing/step_5_stackBands_predictors/5_2_imageProcessing_stackedBandsRaster.py](../phase_1_image_processing/step_5_stackBands_predictors/5_2_imageProcessing_stackedBandsRaster.py) - For 3072-pixel hyperspectral ENVI tiles, the clip-then-subset workflow is: - Clip with [phase_1_image_processing/step_2_orthomosaic_to_tiling/c_tiling_3072_multispec/2_2_clip_shp_gridAnnotation_MULTISPECTRALsampling_envi.py](../phase_1_image_processing/step_2_orthomosaic_to_tiling/c_tiling_3072_multispec/2_2_clip_shp_gridAnnotation_MULTISPECTRALsampling_envi.py) - For the site1 low-offset regeneration workflow, run from the repo root: ```bash cd /home/laura/Documents/code/fvc_function env \ INPUT_RASTER_PATH=/media/laura/8402326D023263F8/calperumResearch/SASMDD0001/20220519/micasense_dual/level_1/20220519_SASMDD0001_dual_ortho_05.tif \ GRID_SHAPEFILE_PATH=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/masks/tiles_3072/pv_class/annotations/gridding/grid_annotation_614.shp \ OUTPUT_RASTER_FOLDER_ENVI=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/multispec/res_05/raw/tiles_multispectral_int16_envi_614grid \ OUTPUT_RASTER_FOLDER_TIF=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/multispec/res_05/raw/tiles_multispectral_int16_614grid \ GRID_ID_FIELD=id \ ANNOTATED_FIELD=annotated \ ANNOTATED_VALUE=1 \ python phase_1_image_processing/step_2_orthomosaic_to_tiling/c_tiling_3072_multispec/2_2_clip_shp_gridAnnotation_MULTISPECTRALsampling_envi.py ``` - This writes the regenerated predictor tiles to: - `/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/multispec/res_05/raw/tiles_multispectral_int16_envi_614grid` - `/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/multispec/res_05/raw/tiles_multispectral_int16_614grid` - Next step: point `REF_5CM_DIR` in [scripts/downsample_site1_labels_low_offset.sh](../scripts/downsample_site1_labels_low_offset.sh) to `tiles_multispectral_int16_envi_614grid` and rerun the `1 cm -> 5 cm` majority-vote label downsampling. After regenerating the `307` FX10 and FX17 predictor folders, rerun the full `1 cm -> 5 cm -> 10 cm` low-offset label workflow. - Regenerate and subset FX10 to bands `10..205` with: ```bash env CLIP_MODE=fixed256 python phase_1_image_processing/utils/run_hyspec_mosaic_to_256_then_subset.py \ --sensor fx10 \ --mosaic /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/hypspec/FX10__20240316_Calperum_SASMDD0001_Mosaic_refl.dat \ --grid /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/masks/tiles_3072/pv_class/annotations/gridding/grid_annotation_hyspecFX10_307.shp \ --out-raw /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX10_raw_envi_307px \ --out-subset /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX10_10_205_envi_307px \ --fixed-size 307 \ --fx10-band-min 10 \ --fx10-band-max 205 ``` - Regenerate and subset FX17 to bands `3..96` with: ```bash env CLIP_MODE=fixed256 python phase_1_image_processing/utils/run_hyspec_mosaic_to_256_then_subset.py \ --sensor fx17 \ --mosaic /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/hypspec/FX17__20240316_Calperum_SASMDD0001_Mosaic_refl.dat \ --grid /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/masks/tiles_3072/pv_class/annotations/gridding/grid_annotation_hyspecFX17_307.shp \ --out-raw /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX17_raw_envi_307px \ --out-subset /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX17_3_96_envi_307px \ --fixed-size 307 \ --fx17-band-min 3 \ --fx17-band-max 96 ``` - Regenerate the aligned `10 cm` label rasters against FX10, FX17, and FX10+FX17 with: ```bash RUN_5CM=0 RUN_10CM_FX10=1 RUN_10CM_FX17=1 RUN_10CM_STACK=1 bash scripts/downsample_site1_labels_low_offset.sh ``` - Stack the FX10 and FX17 subset tiles with: ```bash python utils/stack_fx10_fx17_tiles_envi.py \ --fx10-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX10_10_205_envi_307px \ --fx17-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX17_3_96_envi_307px \ --output-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX10_FX17_subset_envi_307px \ --overwrite ``` - To stack selected full FX10 and FX17 orthomosaic bands before tiling, use the windowed whole-ortho subset stacker. It aligns FX17 to the FX10 grid with a VRT if needed and writes a combined ENVI `.dat + .hdr` without loading the full raster into memory: ```bash docker exec fvc-function-container bash -lc ' cd /workspace && /opt/conda/bin/python phase_1_image_processing/step_5_stackBands_predictors/5_6_stack_fx10_fx17_subset_orthomosaic_envi.py \ --fx10 /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/hypspec/FX10__20240316_Calperum_SASMDD0001_Mosaic_refl.dat \ --fx17 /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/hypspec/FX17__20240316_Calperum_SASMDD0001_Mosaic_refl.dat \ --output /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/hypspec/FX10_FX17_subset_ortho_refl.dat \ --fx10-band-min 10 \ --fx10-band-max 205 \ --fx17-band-min 3 \ --fx17-band-max 96 \ --resample-alg bilinear \ --interleave BSQ \ --chunk-size 512 \ --overwrite ' ``` - To convert a large multispectral or hyperspectral orthomosaic from float reflectance to model-ready int16 ENVI, use the windowed converter. For float32 multispectral orthomosaics: ```bash docker exec fvc-function-container bash -lc ' cd /workspace && /opt/conda/bin/python phase_1_image_processing/utils/convert_float_ortho_to_int16_envi.py \ --input /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/orthomosaics/multispectral_float32.tif \ --output /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/orthomosaics/multispectral_int16.dat \ --expected-dtype float32 \ --scale-factor 10000 \ --nodata-out -1 \ --interleave pixel \ --overwrite ' ``` - Verified Site 1 dual multispectral orthomosaic conversion. The source is a 10-band `float32` COG with nodata `-32767.0`; the command writes scaled `int16` ENVI using project defaults (`scale-factor=10000`, nodata `-1`, BIP/pixel interleave): ```bash docker exec -w /workspace fvc-function-container /opt/conda/bin/python \ phase_1_image_processing/utils/convert_float_ortho_to_int16_envi.py \ --input /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/imagery/orthomosaic/20220519_SASMDD0001_dual_ortho_05_cog.tif \ --output /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/imagery/orthomosaic/20220519_SASMDD0001_dual_ortho_05_int16.dat \ --expected-dtype float32 \ --scale-factor 10000 \ --nodata-out -1 \ --interleave pixel \ --overwrite ``` - For float64 inputs, use the same converter with `--expected-dtype float64`: ```bash docker exec fvc-function-container bash -lc ' cd /workspace && /opt/conda/bin/python phase_1_image_processing/utils/convert_float_ortho_to_int16_envi.py \ --input /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/orthomosaics/source_float64.tif \ --output /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/orthomosaics/source_int16.dat \ --expected-dtype float64 \ --scale-factor 10000 \ --nodata-out -1 \ --interleave pixel \ --overwrite ' ``` - Local FX10 float64 ENVI conversion to int16 at `10 cm` resolution (with band batching): ```bash /home/laura/.local/share/mamba/envs/fvc_function/bin/python phase_1_image_processing/utils/convert_float_ortho_to_int16_envi.py \ --input /media/laura/8402326D023263F8/calperumResearch/SASMDD0013/20240310/imagery/hyspec/FX10/Calperum_FX10_flight5_mosaic_CC_Registered_refl \ --output /media/laura/8402326D023263F8/calperumResearch/SASMDD0013/20240310/imagery/hyspec/FX10/data_int16/Calperum_FX10_flight5_mosaic_CC_Registered_refl_int16_10cm.dat \ --expected-dtype float64 \ --scale-factor 10000 \ --nodata-out -1 \ --interleave pixel \ --target-resolution 0.10 \ --resampling bilinear \ --num-threads ALL_CPUS \ --warp-mem-limit 1024 \ --band-batch-size 16 \ --overwrite ``` ## Phase 2 — Reference data generation **Objective.** Create pixel-wise masks aligned with predictor tiles and harmonise class definitions. 1. **Annotation conversion (Labelme → GIS)** - Polygon annotations exported from Labelme (JSON) can be transformed into GIS-friendly vector layers (shapefile) using raster georeferencing for pixel→map conversion. - Implementation example: - [phase_2_reference_data/step_2_fvc_classes_combined/2_1_labelme_json_to_shpFormat.py](../phase_2_reference_data/step_2_fvc_classes_combined/2_1_labelme_json_to_shpFormat.py) 2. **Class harmonisation and masking** - Auxiliary scripts support merging label sources, computing class frequencies, and masking out unwanted classes (e.g., water/shadow) by setting them to NoData. - Examples: - `phase_2_reference_data/step_3_fvc_nowater/` - `phase_2_reference_data/step_4_fvc_noshadow/` 3. **Spatial downsampling of masks** - High-resolution classification rasters can be resampled to a coarser target resolution using nearest-neighbour interpolation to preserve categorical labels. - Implementation example: - [phase_2_reference_data/step_5_downsampling_labels/downsampling_labels.py](../phase_2_reference_data/step_5_downsampling_labels/downsampling_labels.py) ## Phase 3 — Model training and evaluation ### Phase 3: Model training and evaluation **Objective.** Train site-specific (block-based) UNet segmentation models and produce reproducible metrics and analyses. #### Model architecture The core model is a UNet with encoder/decoder blocks. The implementation includes optional spectral modules to better utilise multi/hyperspectral inputs: - **Spectral squeeze-and-excitation (SE) attention**: learns per-sample spectral channel weights using global average pooling and a bottleneck MLP. - **Spectral adapter**: applies SE attention followed by learnable channel mixing (e.g., `1×1` conv / MLP / multiscale paths) with optional residual connections. - **Hierarchical spectral attention and feature fusion**: optionally applies spectral processing at multiple encoder levels and fuses features. Reference implementation: - [phase_3_models/unet_site_models/model/unet_model_architecture.py](../phase_3_models/unet_site_models/model/unet_model_architecture.py) #### Data loading and NoData handling - Predictor tiles are loaded as tensors with shape `(C, H, W)` and converted to `(B, C, H, W)` during batching. - Mask NoData is represented as `-1` and is used as the ignore index in loss functions. Reference implementation: - [phase_3_models/unet_site_models/dataset/calperum_dataset.py](../phase_3_models/unet_site_models/dataset/calperum_dataset.py) #### Training configuration Training and data paths are configured in: - [phase_3_models/unet_site_models/config_param.py](../phase_3_models/unet_site_models/config_param.py) Key parameters include: - `IN_CHANNELS`: number of spectral bands; can be auto-detected from data - `OUT_CHANNELS`: number of classes - `UNET_FEATURES`: encoder channel widths - `CRITERION`: loss function (default uses focal loss with `ignore_index=-1`) - Optional senescence-aware loss toggled via `USE_SENESCENCE_AWARE_LOSS` The main training entry-point is: - [phase_3_models/unet_site_models/main_site_specific_models.py](../phase_3_models/unet_site_models/main_site_specific_models.py) This script performs block-based cross-validation training and writes checkpoint(s) and metric summaries to `CHECKPOINT_DIR`. ### Whole-orthomosaic inference and shadow screening Whole-orthomosaic inference is performed with a streaming window approach rather than by loading the complete raster into memory. The input orthomosaic is read in fixed-size windows matching the model patch size, each window is passed through the trained UNet model, and the predicted class window is written directly into a single georeferenced output mask. Edge windows are padded for model input and cropped back to their original raster extent before writing. This preserves the orthomosaic grid, coordinate reference system, and transform while avoiding intermediate tile files and high memory use. The semantic model remains a three-class FVC model with `BE=0`, `NPV=1`, and `PV=2`; shadow is not introduced as an additional label. To reduce false assignment of strong cast shadow to NPV, an optional post-inference dark-pixel screen can be applied. For each inference window, the median brightness across the 10 MICA bands is computed for valid pixels. Pixels below the selected darkness threshold are written to output NoData (`255`) only when the model has predicted one of the configured target classes. In the Site 1 MICA workflow, this screen is restricted to predicted NPV (`--dark-mask-target-classes 1`) and uses a conservative threshold of `600` in scaled `int16` reflectance units, corresponding approximately to `0.06` reflectance after the `10000` scale factor. This postprocess is a quality-control mask for uncertain shadowed NPV predictions; it does not modify model weights or relabel training data. ### Whole-Orthomosaic MICA Inference Use the streaming inference entrypoint for full orthomosaics. It follows the same window idea as tile inference: each `304 x 304` window is read from the raster, padded only at image edges when needed, predicted with the model, and written directly into the output mask. Unlike the tile-stitch workflow, it does not keep all tiles in memory and does not write intermediate tile files. The command below runs the best MICA shadow-augmentation spectral-transformer model over the Site 1 int16 orthomosaic on GPU 1. It writes the base prediction mask plus a compact DEFLATE COG without internal overviews. The compact COG is smaller for storage; if you need faster map browsing at many zoom levels, omit `--cog-overviews NONE` so the default COG includes overviews. The optional dark-pixel postprocess masks very dark predicted NPV pixels to nodata `255` instead of forcing them into one of the three FVC classes. This is an inference-time quality-control screen for strong cast shadow, not a fourth shadow class. For the Site 1 scaled `int16` MICA orthomosaic, `--dark-mask-threshold 600` means median band value `<= 600` across the 10 MICA bands, roughly `<= 0.06` reflectance after the `10000` scale factor. `--dark-mask-target-classes 1` restricts the masking to pixels that the model predicted as NPV; omit that flag to mask all classes below the dark threshold. Threshold selection should be checked against the scene histogram and output maps. A threshold of `1200` was too restrictive for this orthomosaic because it masked about `78%` of predicted NPV, while `600` masks about `31%`. ```bash docker exec fvc-function-container bash -lc ' cd /workspace && INPUT_RASTER=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/imagery/orthomosaic/20220519_SASMDD0001_dual_ortho_05_int16.dat && OUTPUT_DIR=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/outputs_ecosystems/medium/MICA_aug_spec_transformer_s304_crop608_shadow_aug/inference_outputs_streaming && OUTPUT_MASK=${OUTPUT_DIR}/20220519_SASMDD0001_dual_ortho_05_int16_mica_shadow_aug_darknpv600_masked.tif && OUTPUT_COG=${OUTPUT_DIR}/20220519_SASMDD0001_dual_ortho_05_int16_mica_shadow_aug_darknpv600_masked_cog_compact_deflate.tif && mkdir -p "$OUTPUT_DIR" && CUDA_VISIBLE_DEVICES=1 \ SENSOR_PROFILE=mica_aug_spec_transformer \ SPECTRAL_EXPERIMENT_MODE=enhanced \ USE_SPECTRAL_TRANSFORMER=1 \ USE_INT16_INPUT_STORAGE=1 \ FVC_DETECTED_CHANNELS=10 \ FVC_OUT_CHANNELS=3 \ IMAGE_FOLDER_OVERRIDE=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_304_crop608_ov152/multispec/res_05/raw/tiles_multispectral_int16_envi_304_crop608_ov152 \ MASK_FOLDER_OVERRIDE=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/masks/tiles_304_crop608_ov152/raw/fvc_class/downsample_5cm_mode_multispec_304_crop608_ov152 \ CHECKPOINT_DIR_OVERRIDE=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/outputs_ecosystems/medium/MICA_aug_spec_transformer_s304_crop608_shadow_aug \ INFERENCE_CHECKPOINT_DIR=/media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/outputs_ecosystems/medium/MICA_aug_spec_transformer_s304_crop608_shadow_aug \ INFERENCE_BLOCK_NUM=1 \ INFERENCE_IMAGE_PATH="$INPUT_RASTER" \ INFERENCE_TILE_SIZE=304 \ PATCH_SIZE=304 \ INFERENCE_BACKEND=pytorch \ /opt/conda/bin/python phase_3_models/unet_site_models/inference_FVCmapping_streaming.py \ --input-raster "$INPUT_RASTER" \ --output-mask "$OUTPUT_MASK" \ --output-cog "$OUTPUT_COG" \ --tile-size 304 \ --cog-compress DEFLATE \ --cog-level 9 \ --cog-predictor 1 \ --cog-overviews NONE \ --cog-block-size 512 \ --dark-mask-threshold 600 \ --dark-mask-target-classes 1 \ --log-every 50 \ --overwrite ' ``` The prediction mask uses `uint8` class values `0=BE`, `1=NPV`, and `2=PV`; nodata is `255`, including original raster nodata and any dark NPV pixels masked by the optional postprocess. The MICA run completed over `841` windows for the `8629 x 8685` Site 1 orthomosaic. - Export non-overlapping `128×128` image/mask pairs from the `307×307` FX10+FX17 tiles with: ```bash cd /home/laura/Documents/code/fvc_function python phase_3_models/unet_site_models/dataset/export_nonoverlap_pairs.py \ --image-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_3072/hyspec/FX10_FX17_subset_envi_307px \ --mask-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/masks/tiles_3072/mask_fvc_noshadow/manual_gt_infer/downsample_10cm_mode_fx10_clean \ --out-image-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/predictors/tiles_128/hyspec/FX10_FX17_subset_envi_128px \ --out-mask-dir /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/masks/tiles_128/mask_fvc_noshadow/manual_gt_infer/downsample_10cm_mode_fx10_clean \ --size 128 \ --metadata-csv /media/laura/8402326D023263F8/calperumResearch/site1_1_DD0001/inputs/data/medium/fx10_fx17_128_patch_metadata.csv ``` - By default this exports strict non-overlapping windows only, so a `307×307` tile produces `4` child patches (`2×2`) and drops the outer remainder. - If you want padded edge coverage instead, add `--cover-all`; that produces `9` child patches (`3×3`) for each `307×307` tile. ### Spectral attention analysis (band importance) If the model exposes `model.spectral_attention_weights` during forward passes, attention weights can be accumulated across batches and summarised as: - Per-level bar plots of mean attention weight per band - Heatmaps of attention across encoder levels and bands Reference utility: - [phase_3_models/unet_site_models/model/spectral_analysis_utils.py](../phase_3_models/unet_site_models/model/spectral_analysis_utils.py) ### Senescence analysis (PV↔NPV discrimination) To interpret ecologically meaningful PV↔NPV transitions within the existing FVC label schema, the workflow provides a sensor-aware senescence analysis that combines: - Model-derived attention differences between PV and NPV regions - Spectral trait maps derived from input imagery Two modes are supported: - **Multispectral (band mapping):** indices such as NDVI, NDRE, PSRI, SAVI - **Hyperspectral (wavelength-based):** indices/traits computed by selecting nearest wavelengths; optional SWIR water absorption feature metrics (continuum removal) when wavelength coverage permits Reference implementations: - [phase_3_models/unet_site_models/model/senescence_analysis.py](../phase_3_models/unet_site_models/model/senescence_analysis.py) - [phase_3_models/unet_site_models/example_senescence_analysis.py](../phase_3_models/unet_site_models/example_senescence_analysis.py) - [phase_3_models/unet_site_models/run_senescence_analysis.py](../phase_3_models/unet_site_models/run_senescence_analysis.py)