#!/bin/bash -x #input is daily GWP file input=$1 indir=$2 outdir=$3 export GDAL_CACHEMAX=6000 date=$(basename $input .tif | cut -d'_' -f2) dir_to_search=${indir}/ocean_mask/ cp ${dir_to_search}/ocean_mask_global_GWP_res.tif . ls . if [ ! -f ${outfolder}/GWP.OSWF.DAILY.${date}.v1.tif ]; then mkdir -p output/ #reproject to WGS84 gdalwarp -t_srs EPSG:4326 $input swat_${date}_global.tif -te -180 -90 180 90 -ts 172800 86400 -co compress=deflate -r near #change nodata value gdal_translate swat_${date}_global.tif swat_${date}_global_1.tif -a_nodata 254 -ot Byte -co compress=deflate #change pixel value 255 to 0 gdal_calc.py --outfile=swat_${date}_global_2.tif -A swat_${date}_global_1.tif --calc="0*(A==255)+A*logical_and(A>0, A<255)" --co=COMPRESS=LZW --type=Byte #add ocean mask to GWP file gdal_calc.py --outfile=swat_masked_${date}.tif -A swat_${date}_global_2.tif -B ocean_mask_global_GWP_res.tif --calc="A*B+1*(B==0)" --co=COMPRESS=LZW --type=Byte #change tif to cog file gdal_translate -of COG -co COMPRESS=ZSTD -co PREDICTOR=2 -co RESAMPLING=NEAREST swat_masked_${date}.tif GWP.OSWF.DAILY.${date}.v1.tif mv GWP.OSWF.DAILY.${date}.v1.tif output/ else echo "${outfolder}/GWP.OSWF.DAILY.${date}.v1.tif already exists" fi exit 0