process.sh 1.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash

set -u
set -e

SCENE=$1
URL=$2
TMP=$PWD/temp
FILE="scene.zip"

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

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

function download() {
  URL=$1
  FILE=$2
  time lors_download -t 10 -b 10m $URL -o $FILE
# for testing...
#  cp $URL $FILE
}

function process() {
  FILE=$1
  mkdir -p $TMP
  echo "Unpacking ${SCENE}..."
  unzip $FILE -d $TMP
  cd $TMP
  
  sed -i s:\&quot\;:\":g *.aux.xml # swap " for actual quotes
  
  for REF in "" _QB _TIR; do
    case $REF in
      _QB )
        IMG=${STRIP}${REF}.png
        TAG=QB
        ;;
      _TIR )
        IMG=${STRIP}${REF}.jpg
        TAG=TIR
        ;;
      "" )
        IMG=${STRIP}${REF}.jpg
        TAG=FC
        ;;
    esac
  
    if [ ! -f $IMG ]; then  # some zips don't have all the image types - skip any that don't exist
      continue
    fi
  
    grep SRS ${IMG}.aux.xml > WKT # extract the WKT line from XML
    sed -i s:\ \ \<SRS\>::g WKT # remove XML tags from WKT
    sed -i s:\<\/SRS\>::g WKT
  
    TIF=EODN-${TAG}_${YMD}_120000.part${PART}.tif
  
    gdal_translate -of GTiff -a_srs WKT $IMG $TIF
    wmsupload $TIF
  done
  
  rm -r $TMP
}


download $URL $FILE 

if [ ! -f $FILE ]; then
    echo "Could not download $URL"
    exit
fi

( process $FILE )
rm $FILE