Vizzuality/landgriffon

View on GitHub
data/preprocessing/earthstat/resample.sh

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash

set -e

data_dir="data"
resampling_resolution="0.083333"

for file in $data_dir/*.tif; do
  filename=$(basename "$file")
  crop_type="${filename%%_*}"
  if [[ $file == *"HarvestedAreaHectares"* ]]; then
   harv_or_prod="harvest"
   unit="ha"
  elif [[ $file == *"Production"* ]]; then
   harv_or_prod="production"
   unit="t"
  fi
  outfile="earthstat_global_${harv_or_prod}_${crop_type}_${unit}.tif"
  echo "Resampling $file to $outfile"
  rio warp \
   $file \
   $data_dir/$harv_or_prod/"$outfile" \
   --resampling sum \
   --res $resampling_resolution \
   --src-nodata nan \
   --dst-nodata -1 \
   --co compress=deflate \
   --co predictor=3 \
   --overwrite
  rm "$file"
done