Skip to content

Instantly share code, notes, and snippets.

@cynici
Created December 6, 2012 13:09
Show Gist options
  • Save cynici/4224351 to your computer and use it in GitHub Desktop.
Save cynici/4224351 to your computer and use it in GitHub Desktop.
NPP: Run DRL software for NPP raw data to produce truecolor GeoTiff image
#! /bin/bash
#
# Use DRL software suite to process NPP data and produce
# geolocated truecolor GeoTiff image
#
if [ $# -lt 1 ] || [ ! -f "$1" ]; then
echo "usage: $0 NPP_DAT" >&2
exit 1
fi
DRLHOME=$HOME/drl
# e.g. NPP.20120827.114454.dat
DAT=$(basename "$1")
YYYYMMDD=$(echo $DAT | cut -d. -f2)
YYYY=${YYYYMMDD:0:4}
HHMMSS=$(echo $DAT | cut -d. -f3)
RDRDIR="/data/drl/work-${YYYYMMDD}.${HHMMSS}"
VIIRSDIR=$RDRDIR
TIFDIR="/data/drl/geotiff/$YYYY/${YYYYMMDD}.${HHMMSS}"
set -x
set -e
set -u
if [ $HHMMSS -lt "050000" ] || [ $HHMMSS -gt 200000 ]; then
echo "Skipped night time overpass: $1"
exit 0
fi
#
# TODO: single hardcoded /data directory prevents parallel backlog processing
#
cd $DRLHOME/rt-stps
if [ ! -f $RDRDIR/svm16.h5 ]; then
# Run only if there is no RT-STPS output produced previously
mkdir -p $RDRDIR
if [ -L $DRLHOME/data ]; then
rm $DRLHOME/data
fi
ln -s $RDRDIR $DRLHOME/data
bin/batch.sh config/npp.xml "$1"
rm $DRLHOME/data
fi
#
# Get fullpath to latest ancillary files
# Must be updated frequently from ftp://is.sci.gsfc.nasa.gov/ancillary/
#
# For VIIRS:
# The age of the TLE file must be within 30 days of the
# input RDR file. Use the TLE closest to, but prior,
# to the date of the input RDR file.
# For CrlS:
# The TLE file must be within 14 days of the input RDR file.
# Use the TLE closest to, but prior, to the date of the input RDR file.
leapsec_file=`$HOME/Apps/bin/list_prior_file.py -t leapsec $1`
# Use the VIIRS-SDR LUT collection set that is closest to,
# but prior, to the date of the input RDR file.
viirslut_file=`$HOME/Apps/bin/list_prior_file.py -t viirslut $1`
# For VIIRS TrueColorGen:
# Global Data Assimilation System (GDAS) grib1 files are
# produced every 6 hours at 00, 0600, 1200 and 1800 UTC daily.
# When choosing the GDAS ancillary file (grib1 format),
# choose one which is closer in time (±3 hours) rather than the date.
# For example if you have an SDR granule at 1700 UTC, the GDAS
# file for 1800 hours on the same day would be the best match.
# However, if that is not available, it would be preferable to
# use the GDAS file corresponding to 1800 UTC for the day before
# rather than the GDAS file at 1200 UTC for the same day. It is
# recommended to use a gdas file for ncep_met that is within ±7 days
# of the granule time.
gdas_file=$($HOME/Apps/bin/list_matching_gdas.py $1 | head -1)
if [ ! -d $VIIRSDIR ]; then
mkdir -p $VIIRSDIR
fi
$DRLHOME/SPA/VIIRS-SDR/wrapper/VIIRS-SDR/run \
viirs.rdr ${RDRDIR}/RNSCA-RVIRS_*.h5 \
tle $DRLHOME/ancillary/tle/drl.tle \
leapsec $leapsec_file \
sdr.lut $viirslut_file \
viirs.gitco ${VIIRSDIR}/gitco.h5 \
viirs.gmodo ${VIIRSDIR}/gmodo.h5 \
viirs.gdnbo ${VIIRSDIR}/gdnbo.h5 \
viirs.svdnb ${VIIRSDIR}/svdnb.h5 \
viirs.svi01 ${VIIRSDIR}/svi01.h5 \
viirs.svi02 ${VIIRSDIR}/svi02.h5 \
viirs.svi03 ${VIIRSDIR}/svi03.h5 \
viirs.svi04 ${VIIRSDIR}/svi04.h5 \
viirs.svi05 ${VIIRSDIR}/svi05.h5 \
viirs.svm01 ${VIIRSDIR}/svm01.h5 \
viirs.svm02 ${VIIRSDIR}/svm02.h5 \
viirs.svm03 ${VIIRSDIR}/svm03.h5 \
viirs.svm04 ${VIIRSDIR}/svm04.h5 \
viirs.svm05 ${VIIRSDIR}/svm05.h5 \
viirs.svm06 ${VIIRSDIR}/svm06.h5 \
viirs.svm07 ${VIIRSDIR}/svm07.h5 \
viirs.svm08 ${VIIRSDIR}/svm08.h5 \
viirs.svm09 ${VIIRSDIR}/svm09.h5 \
viirs.svm10 ${VIIRSDIR}/svm10.h5 \
viirs.svm11 ${VIIRSDIR}/svm11.h5 \
viirs.svm12 ${VIIRSDIR}/svm12.h5 \
viirs.svm13 ${VIIRSDIR}/svm13.h5 \
viirs.svm14 ${VIIRSDIR}/svm14.h5 \
viirs.svm15 ${VIIRSDIR}/svm15.h5 \
viirs.svm16 ${VIIRSDIR}/svm16.h5
mkdir -p $TIFDIR
$DRLHOME/SPA/TrueColorGen/wrapper/TrueColorGen/run \
viirs.svm01 $VIIRSDIR/svm01.h5 \
viirs.svm02 $VIIRSDIR/svm02.h5 \
viirs.svm03 $VIIRSDIR/svm03.h5 \
viirs.svm04 $VIIRSDIR/svm04.h5 \
viirs.svm05 $VIIRSDIR/svm05.h5 \
viirs.svm06 $VIIRSDIR/svm06.h5 \
viirs.svm07 $VIIRSDIR/svm07.h5 \
viirs.svm08 $VIIRSDIR/svm08.h5 \
viirs.svm09 $VIIRSDIR/svm09.h5 \
viirs.svm10 $VIIRSDIR/svm10.h5 \
viirs.svm11 $VIIRSDIR/svm11.h5 \
viirs.gmodo $VIIRSDIR/gmodo.h5 \
viirs.svi01 $VIIRSDIR/svi01.h5 \
viirs.svi02 $VIIRSDIR/svi02.h5 \
viirs.svi03 $VIIRSDIR/svi03.h5 \
viirs.gitco $VIIRSDIR/gitco.h5 \
ncep_met $gdas_file \
viirs.crefl $TIFDIR/IVICR_npp.h5
#MODISL1DB Geolocation Product
GMODO=$VIIRSDIR/gmodo.h5
IVICR=$TIFDIR/IVICR_npp.h5
$DRLHOME/SPA/h2g/wrapper/h2g/run \
config.type standard \
config.name vsreflh5d \
input.data $IVICR \
geo $GMODO \
h2gout $TIFDIR/IVICR_npp_TRUECOLOR-${YYYYMMDD}.${HHMMSS}.tif \
output.type geotiff.argb
rm -rf $IVICR $RDRDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment