process-LCtgz.sh 1.38 KB
Newer Older
1
2
3
4
#!/usr/bin/env bash
# https://www.mapbox.com/blog/processing-landsat-8/
# http://landsat.usgs.gov/Landsat8_Using_Product.php
#
Nick Bearson's avatar
cleanup    
Nick Bearson committed
5
6
7
8
# landsat-8 tifs are "digital numbers" (counts)
# those aren't very useful once the MTL is lost
# so create top-of-atmosphere radiance files for upload to realearth
# (could also do reflectance...) 
9
10
11
12
13
14
15
16
17
18
19
20
21

set -u
set -e

BANDS=(1 2 3 4 5 6 7 8 9 10 11)

DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/consts.sh"

WMSUPLOAD=${DIR}/wmsupload

SCENE=$1
22
23
OPFLAG=$2

24
25
26
27
28
29
30
31
32
33
echo "PROCESSING: $1"

BASE=${SCENE##*/} # filename w/ extension
STRIP=${BASE%%.tar.gz} # filename w/o extension

YEAR=${STRIP:9:4}
DOY=${STRIP:13:3}
YMD=`date -d "Jan 1 $YEAR + $DOY days - 1 day" "+%Y%m%d"`
PART=${STRIP:2:7}

Nick Bearson's avatar
cleanup    
Nick Bearson committed
34
for band in ${BANDS[@]}; do
35
36
  MTL="${STRIP}_MTL.txt"
  BN="${STRIP}_B${band}.TIF"
37
  echo "extracting band ${band}"
38
39
  tar xzf $SCENE $BN $MTL
  
40
  echo "calculating TOA radiance"
41
42
43
44
45
46
47
48
  vmul=$(grep "RADIANCE_MULT_BAND_${band} =" $MTL | cut -d " " -f 7)
  vadd=$(grep "RADIANCE_ADD_BAND_${band} ="  $MTL | cut -d " " -f 7)
  
  # calculate TOA radiance (Watts/( m2 * srad * μm))
  # https://landsat.usgs.gov/Landsat8_Using_Product.php
  product="nickb-lsat-TOArad-b${band}_${YMD}_120000.part${PART}.tif"
  gdal_calc.py -A $BN --outfile=${product} --calc="(A*${vmul})+${vadd}"

49
50
51
52
  if [ "${OPFLAG}" == "" ]; then
    echo "uploading ${product}"
    $WMSUPLOAD ${product}
  fi
53
done