Created
July 9, 2015 09:06
-
-
Save maning/256e5f6a3b37f61b424f to your computer and use it in GitHub Desktop.
Import PALSAR 25m data to GRASS GIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -x | |
# | |
############################################################################ | |
# | |
# MODULE: import_palsar.sh | |
# AUTHOR(S): Maning Sambale - http://www.essc.org.ph | |
# PURPOSE: Import PALSAR 25m data to GRASS GIS | |
# | |
# | |
# COPYRIGHT: (C) 2013 Maning Sambale, ESSC | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
############################################################################ | |
#%Module | |
#% description: Import ALOS/PALSAR 25 m to a GRASS GIS mapset | |
#% keywords: imagery, import | |
#%End | |
#%Option | |
#% key: input | |
#% type: string | |
#% required: yes | |
#% multiple: no | |
#% key_desc: name | |
#% description: Name of tar.gz files. Omit the extension "tar.gz" | |
#%End | |
#%Option | |
#% key: temp | |
#% type: string | |
#% required: no | |
#% multiple: no | |
#% key_desc: name | |
#% description: Temporary directory to decompress files | |
#% answer: temp | |
#%End | |
if [ -z "$GISBASE" ] ; then | |
echo "You must be in GRASS GIS to run this program." 1>&2 | |
exit 1 | |
fi | |
if [ "$1" != "@ARGS_PARSED@" ] ; then | |
exec g.parser "$0" "$@" | |
fi | |
if [ $# -lt 1 -o "$1" = "help" -o "$1" = "-help" -o "$1" = "-h" ] ; then | |
echo "Usage: $0 sar_map" | |
exit 1 | |
fi | |
TEMPDIR=${GIS_OPT_TEMP} | |
HEADER=${GIS_OPT_INPUT}.hdr | |
FILE=${GIS_OPT_INPUT} | |
#=========== | |
# Decompress to a temporary directory. | |
mkdir $TEMPDIR | |
tar -zxvf ${FILE}.tar.gz -C ${TEMPDIR} | |
# Parse all the parameters from the filename and header file. | |
cd $TEMPDIR | |
# Read header file. | |
cat *.hdr | |
PREFIX1=$(sed -n 1p $HEADER) | |
PREFIX2=$(sed -n 4p $HEADER) | |
EPOCH=$(sed -n 3p $HEADER | sed 's .\{2\} ') | |
NORTH=$(sed -n 13p $HEADER) | |
WEST=$(sed -n 14p $HEADER) | |
SOUTH=$(sed -n 15p $HEADER) | |
EAST=$(sed -n 16p $HEADER) | |
COLS=$(sed -n 24p $HEADER) | |
DATE=$(sed -n 27p $HEADER) | |
PATHMODE=$(sed -n 5p $HEADER) | |
PATHTYPE=$(sed -n 6p $HEADER) | |
RESAMPLING=$(sed -n 10p $HEADER) | |
SATNAME=$(sed -n 7p $HEADER) | |
SLOPECORR=$(sed -n 11p $HEADER) | |
DIR=$(sed -n 9p $HEADER) | |
PIX=$(sed -n 8p $HEADER) | |
METASTRING=("Satellite"=${SATNAME},"ProductID"=${PREFIX1},"ObservationDate"=20${EPOCH},"PathMode"=${PATHMODE},"PathType"=${PATHTYPE},"Direction"=${DIR},"Resampling"=${RESAMPLING},"SlopeCorrection"=${SLOPECORR},"ProcessingDate"=${DATE}) | |
echo ${METASTRING} | |
echo "PREFIX1" $PREFIX1 | |
echo "PREFIX2" $PREFIX2 | |
echo "North Bound" $NORTH | |
echo "West Bound" $WEST | |
echo "South Bound" $SOUTH | |
echo "East Bound" $EAST | |
echo "Cols and Rows" $COLS | |
echo "Date Acquired" $DATE | |
# Assign region settings. | |
g.region n=${NORTH} s=${SOUTH} e=${EAST} w=${WEST} res=0:00:00.8 -pm | |
# Import HH and HV layer. | |
r.in.bin input=${PREFIX2}_${EPOCH}_sl_HV output=${PREFIX2}_${EPOCH}_sl_HV bytes=2 \ | |
order="native" north=${NORTH} south=${SOUTH} east=${EAST} west=${WEST} rows=${COLS} cols=${COLS} | |
r.in.bin input=${PREFIX2}_${EPOCH}_sl_HH output=${PREFIX2}_${EPOCH}_sl_HH bytes=2 \ | |
order="native" north=${NORTH} south=${SOUTH} east=${EAST} west=${WEST} rows=${COLS} cols=${COLS} | |
# Create a synthetic raster to HH-HV | |
r.mapcalc "${PREFIX2}_${EPOCH}_sl_HHdivHV = ( ${PREFIX2}_${EPOCH}_sl_HH / ${PREFIX2}_${EPOCH}_sl_HV )" | |
# Import supporting rasters (Acquisiton Date, Mask, Incidence Angle). | |
r.in.bin input=${PREFIX2}_${EPOCH}_linci output=${PREFIX2}_${EPOCH}_linci bytes=1 \ | |
order="native" north=${NORTH} south=${SOUTH} east=${EAST} west=${WEST} rows=${COLS} cols=${COLS} | |
r.in.bin input=${PREFIX2}_${EPOCH}_mask output=${PREFIX2}_${EPOCH}_mask bytes=1 \ | |
order="native" north=${NORTH} south=${SOUTH} east=${EAST} west=${WEST} rows=${COLS} cols=${COLS} | |
r.in.bin input=${PREFIX2}_${EPOCH}_date output=${PREFIX2}_${EPOCH}_date bytes=2 \ | |
order="native" north=${NORTH} south=${SOUTH} east=${EAST} west=${WEST} rows=${COLS} cols=${COLS} | |
# Update raster matadata. | |
r.support map=${PREFIX2}_${EPOCH}_sl_HH history=${METASTRING} source1="PALSAR-JAXA" \ | |
source2="ESSC, 2013" description="PALSAR, radar" title="${PREFIX2} HH polarization" | |
r.timestamp map=${PREFIX2}_${EPOCH}_sl_HH date="${DATE}" | |
r.support map=${PREFIX2}_${EPOCH}_sl_HV history="$METASTRING" source1="PALSAR-JAXA" \ | |
source2="ESSC, 2013" description="PALSAR, radar" title="${PREFIX2} HV polarization" | |
r.timestamp map=${PREFIX2}_${EPOCH}_sl_HV date="${DATE}" | |
r.support map=${PREFIX2}_${EPOCH}_sl_HHdivHV history="$METASTRING" source1="PALSAR-JAXA" \ | |
source2="ESSC, 2013" description="PALSAR, radar" title="${PREFIX2} HHdivHV" | |
r.timestamp map=${PREFIX2}_${EPOCH}_sl_HHoverHV date="${DATE}" | |
r.support map=${PREFIX2}_${EPOCH}_linci history="$METASTRING" source1="PALSAR-JAXA" \ | |
source2="ESSC, 2013" description="PALSAR, radar" title="${PREFIX2} Incidence Angle" | |
r.timestamp map=${PREFIX2}_${EPOCH}_linci date="${DATE}" | |
r.support map=${PREFIX2}_${EPOCH}_mask history="$METASTRING" source1="PALSAR-JAXA" \ | |
source2="ESSC, 2013" description="PALSAR, radar" title="${PREFIX2} Mask" | |
r.timestamp map=${PREFIX2}_${EPOCH}_mask date="${DATE}" | |
r.support map=${PREFIX2}_${EPOCH}_date history="$METASTRING" source1="PALSAR-JAXA" \ | |
source2="ESSC, 2013" description="PALSAR, radar" title="${PREFIX2} Acquisition Date" | |
r.timestamp map=${PREFIX2}_${EPOCH}_date date="${DATE}" | |
echo "Imported as ${PREFIX2}" | |
# Assign histogram-equalized grey scale color. | |
r.colors map=${PREFIX2}_${EPOCH}_sl_HH color=grey.eq | |
r.colors map=${PREFIX2}_${EPOCH}_sl_HV color=grey.eq | |
r.colors map=${PREFIX2}_${EPOCH}_sl_HHoverHV color=grey.eq | |
#Remove all temporary files | |
cd .. | |
rm -rf ${TEMPDIR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment