process-LCtgz.sh 1.45 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

set -u
set -e

13
14
#BANDS=(1 2 3 4 5 6 7 8 9 10 11)
BANDS=(1 2 3 4) # nadir seems to be struggling, try just a few bands?
15
16
17
18
19

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

20
WMSUPLOAD=${DIR}/re_upload
21
22

SCENE=$1
23
OPFLAG=${2:-""}
24

25
log "PROCESSING: $1"
26
27
28
29
30
31
32
33
34

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
35
for band in ${BANDS[@]}; do
36
37
  MTL="${STRIP}_MTL.txt"
  BN="${STRIP}_B${band}.TIF"
38
  log "extracting band ${band}"
39
40
  tar xzf $SCENE $BN $MTL
  
41
  log "calculating TOA radiance"
42
43
44
45
46
47
48
49
  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}"

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